Plotting a Ramachandran map with matplotlib

In [1]:
%matplotlib inline
from __future__ import print_function
import mdtraj as md

Lets load up the trajectory that we simulated in a previous example

In [2]:
traj = md.load('ala2.h5')
atoms, bonds = traj.topology.to_dataframe()
atoms
##############################################################################

The code at topology.py:397 requires the "pandas" package, which is
an open source, BSD-licensed library providing high-performance, easy-to-use
data structures and data analysis tools for the Python programming language.

pandas can be downloaded from https://pypi.python.org/pypi/pandas or installed
with the python "easy_install" or "pip" package managers using:

# easy_install pandas
or
# pip install pandas

##############################################################################
---------------------------------------------------------------------------
DelayImportError                          Traceback (most recent call last)
<ipython-input-2-4306c8b27ed5> in <module>()
      1 traj = md.load('ala2.h5')
----> 2 atoms, bonds = traj.topology.to_dataframe()
      3 atoms

/home/travis/miniconda3/envs/py27/lib/python2.7/site-packages/mdtraj/core/topology.pyc in to_dataframe(self)
    395             of the indices of the atoms involved in each bond.
    396         """
--> 397         pd = import_('pandas')
    398         data = [(atom.serial, atom.name, atom.element.symbol,
    399                  atom.residue.resSeq, atom.residue.name,

/home/travis/miniconda3/envs/py27/lib/python2.7/site-packages/mdtraj/utils/delay_import.pyc in import_(module)
    196         print(m, file=sys.stderr)
    197         print(bar, file=sys.stderr)
--> 198         raise DelayImportError(m)

DelayImportError: 
The code at topology.py:397 requires the "pandas" package, which is
an open source, BSD-licensed library providing high-performance, easy-to-use
data structures and data analysis tools for the Python programming language.

pandas can be downloaded from https://pypi.python.org/pypi/pandas or installed
with the python "easy_install" or "pip" package managers using:

# easy_install pandas
or
# pip install pandas

Because alanine dipeptide is a little nonstandard in the sense that it's basically dominated by the ACE and NME capping residues, we need to find the indicies of the atoms involved in the phi and psi angles somewhat manually. For standard cases, see compute_phi() and compute_psi() for easier solutions that don't require you to manually find the indices of each dihedral angle.

In this case, we're just specifying the four atoms that together parameterize the phi and psi dihedral angles.

In [3]:
psi_indices, phi_indices = [6, 8, 14, 16], [4, 6, 8, 14]
angles = md.compute_dihedrals(traj, [phi_indices, psi_indices])

Lets plot our dihedral angles in a scatter plot using matplotlib. What conformational states of Alanine dipeptide did we sample?

In [4]:
from pylab import *
from math import pi

figure()
title('Dihedral Map: Alanine dipeptide')
scatter(angles[:, 0], angles[:, 1], marker='x', c=traj.time)
cbar = colorbar()
cbar.set_label('Time [ps]')
xlabel(r'$\Phi$ Angle [radians]')
xlim(-pi, pi)
ylabel(r'$\Psi$ Angle [radians]')
ylim(-pi, pi)
Out[4]:
(-3.141592653589793, 3.141592653589793)
In [5]:
 

(ramachandran-plot.ipynb; ramachandran-plot_evaluated.ipynb; ramachandran-plot.py)

Versions