This notebook contains material from PyRosetta; content is available on Github.

Getting spatial features from a Pose

Keywords: conformation(), bond_length(), AtomID, atom_index()

In [ ]:
# Notebook setup
import sys
if 'google.colab' in sys.modules:
    !pip install pyrosettacolabsetup
    import pyrosettacolabsetup
    print ("Notebook is set for PyRosetta use in Colab.  Have fun!")
In [ ]:
from pyrosetta import *

From previous section: Make sure you are in the directory with the pdb files:

cd google_drive/My\ Drive/student-notebooks/

In [ ]:
pose = pose_from_pdb("inputs/5tj3.pdb")
In [1]:
from IPython.display import Image

Pose objects make it easy to access angles, distances, and torsions for analysis. Lets take a look at how to get backbone torsions first.

In [1]:
#resid = "get the pose residue number for chain A:res 28 using the pdb2pose function"
resid = pose.pdb_info().pdb2pose('A', 28)
In [21]:
print("phi:", pose.phi(resid))
print("psi:", pose.psi(resid))
print("chi1:", pose.chi(1, resid))
phi: -149.17513487055064
psi: 151.30037995499168
chi1: -82.850785668982

Say we want to find the length of the $N$-$C_\alpha$ and $C_\alpha$-$C$ bonds for residue A:28 from the PDB file. We can use a couple approaches. The first involves using the bond length in the Conformation class, which stores some info on protein geometry. Take a look at some of the methods in the Conformation class using tab completion.

In [22]:
conformation = pose.conformation()
# do some tab completion here to explore the Conformation class methods

Look at the documentation for the method conformation.bond_length below. Remember using the ?

In [1]:
# ?conformation.bond_length
Object `conformation.bond_length` not found.

To use the bond_length method in the Conformation class, it looks like we'll need to make AtomID objects. We can do this using an atom index and residue ID as follows:

In [23]:
# Double Check: does resid contain the Pose numbering or PDB numbering?
res_28 = pose.residue(resid)
N28 = AtomID(res_28.atom_index("N"), resid)
CA28 = AtomID(res_28.atom_index("CA"), resid)
C28 = AtomID(res_28.atom_index("C"), resid)

# try printing out an AtomID object!
In [24]:
 atomno= 1 rsd= 5 

As usual, if you did not know how to construct an AtomID, you could check the documentation using ?AtomID.

Now we can compute the bond lengths:

In [25]:
print(pose.conformation().bond_length(N28, CA28))
print(pose.conformation().bond_length(CA28, C28))

Alternatively, we can compute bond lengths ourselves starting from the xyz coordinates of the atoms.

The method xyz of Residue returns a Vector class. The Vector class has various useful builtin methods including computing dot products, cross products, and norms. Through operator overloading in the Vector class, you can just subtract and add vector objects and they will manipulate the corresponding vectors appropriately.

In [26]:
N_xyz ="N")
CA_xyz ="CA")
C_xyz ="C")
N_CA_vector = CA_xyz - N_xyz
CA_C_vector = CA_xyz - C_xyz

Thankfully, the two approaches for computing distances check out!

Note: Not all bond lengths, angles, and torsions will be accessible using the Conformation object. That is because the Conformation object stores only the subset it needs to generate xyz locations for the atoms in the pose. The most stable way to get this information is to compute it using the xyz Cartesian coordinate vectors as a starting point.

In [ ]:


This notebook includes some concepts and exercises from:

"Workshop #2: PyRosetta" in the PyRosetta workbook:

"Workshop #4.1: PyMOL_Mover" in the PyRosetta workbook:

In [ ]: