MDAnalysis is an object-oriented Python toolkit to analyze molecular dynamics trajectories generated by CHARMM, Gromacs, LAMMPS, NAMD or Amber.
It allows one to read molecular dynamics trajectories and access the atomic coordinates through numpy arrays. This provides a flexible and relatively fast framework for complex analysis tasks. In addition, CHARMM-style atom selection commands are implemented. Trajectories can also be manipulated (for instance, fit to a reference structure) and written out.
A typical usage pattern is to iterate through a trajectory and analyze coordinates for every frame. In the following example the end-to-end distance of a protein and the radius of gyration of the backbone atoms are calculated:
from MDAnalysis.tests.datafiles import PSF,DCD # test trajectory
u = MDAnalysis.Universe(PSF,DCD) # always start with a Universe
nterm = u.s4AKE.N # can access structure via segid (s4AKE) and atom name
cterm = u.s4AKE.C[-1] # ... takes the last atom named 'C'
bb = u.selectAtoms('protein and backbone') # a selection (a AtomGroup)
for ts in u.trajectory: # iterate through all frames
r = cterm.pos - nterm.pos # end-to-end vector from atom positions
d = numpy.linalg.norm(r) # end-to-end distance
rgyr = bb.radiusOfGyration() # method of a AtomGroup; updates with each frame
print "frame = %d: d = %f Angstroem, Rgyr = %f Angstroem" % (ts.frame, d, rgyr)