MDAnalysis | Resources | Beckstein Lab

. . . . .
MDAnalysis

MDAnalysis

MDAnalysis is an open source, versatile, object-oriented Python library for analyzing molecular dynamics trajectories. It makes it easy to develop new tools that go beyond what is typically found in established packages. It can deal with a number of file formats, including Gromacs, CHARMM, LAMMPS, Amber, NAMD trajectories and coordinates, and PDB and PQR files.

Our papers on MDAnalysis1,2 explain the philosophy and general layout of the toolkit together with a number of examples (but see below for Paper Errata for Reference1).

MDAnalysis is an open source project, developed by an active user community with a friendly mailing list. The project welcomes all user contributions and typically quickly integrates working and tested code. It is developed according to “best software engineering practices”3 including a publicly visible git-managed source code repository, bug tracking, and a large and growing suite of unit tests.

Availability

MDAnalysis is available at www.mdanalysis.org including the Online Documentation, a source code repository and the MDAnalysis Issue Tracker . MDAnalysis is also listed on PyPi so that one can simply install it with pip install MDAnalysis.

First steps

Simple Example

MDAnalysis 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:

# frame-based analysis
import MDAnalysis
from MDAnalysis.tests.datafiles import PSF,DCD   # test trajectory
import numpy.linalg
u = MDAnalysis.Universe(PSF,DCD)                 # always start with a Universe
nterm = u.s4AKE.N[0]   # 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)

Video: Introduction to MDAnalysis

Oliver’s talk at SciPy 2016 gives an overview over the capabilities and philosophy of the most recent version of MDAnalysis:

Paper Errata

Note that the Python code in the online html version of the paper is useless because the crucial indentation of Python was not preserved in the conversion process. The PDF version is mostly correct although the final formatted version ended up with a few line breaks that are illegal in the Python syntax. The free PubmedCentral version (PMC3144279), however, contains perfectly formatted Python code.

Corrected code is listed here (and on the MDAnalysis Paper Errata page) and can also be found in the examples that are part of the MDAnalysis package. If you find further problems then please let us know by filing an issue in the MDAnalysis Issue Tracker or emailing me.

page 4: Writing the coordinates of a selection
universe.selectAtoms("byres (resname SOL and around 3.5 protein)").write("solvation-shell.pdb")
page 5: Block average example
def blocked(universe, nblocks, analyze): 
    size = universe.trajectory.numframes/nblocks
    blocks = [] 
    for block in xrange(nblocks): 
        a = [] 
        for ts in u.trajectory[block*size:(block+1)*size]: 
            a.append(analyze(universe)) 
        blocks.append(numpy.average(a)) 
    blockaverage = numpy.average(blocks) 
    blockstd = numpy.std(blocks) 
    return nblocks, size, blockaverage, blockstd
Radius of gyration analysis function
def rgyr(universe): 
    return universe.selectAtoms("protein").radiusOfGyration()
Time series analysis
MDAnalysis.collection.addTimeseries(\ 
    Timeseries.Dihedral(atomselection)) 
data = universe.trajectory.correl(\
    MDAnalysis.collection, skip=10)
page 6: radial distribution function
The normaliation is not correct in the simplified example in the paper; use radial_distribution_function.py from the distribution.
Table 1
CHARMM has a way to calculate 3D densities using the COORdinates ANALysis … IHIS facility. The table states incorrectly that CHARMM can not presently carry out this kind of calculations.

References

1 N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, O. Beckstein. MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. J. Comp. Chem. 32 (2011), 2319–2327. doi: 10.1002/jcc.21787, PubMedCentral: PMC3144279

2 R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. MDAnalysis: A Python package for the rapid analysis of molecular dynamics simulations. In S. Benthall and S. Rostrup, editors, Proceedings of the 15th Python in Science Conference, pages 102 – 109, Austin, TX, 2016. SciPy.

3 G. Wilson. Software Carpentry: Getting Scientists to Write Better Code by Making Them More Productive. Computing in Science and Engineering. 8 (2006), 66—69. doi: 10.1109/MCSE.2006.122. See also Software Carpentry