Aligning a trajectory to itself¶
We use align.AlignTraj
to align a trajectory to a reference frame and write it to a file.
Last updated: June 26, 2020 with MDAnalysis 1.0.0
Minimum version of MDAnalysis: 1.0.0
Packages required:
See also
Note
MDAnalysis implements RMSD calculation using the fast QCP algorithm ([The05]) and a rotation matrix R that minimises the RMSD ([LAT09]). Please cite ([The05]) and ([LAT09]) when using the MDAnalysis.analysis.align
module in published work.
[1]:
import MDAnalysis as mda
from MDAnalysis.analysis import align, rms
from MDAnalysis.tests.datafiles import PSF, DCD
Loading files¶
The test files we will be working with here feature adenylate kinase (AdK), a phosophotransferase enzyme. ([BDPW09]) The trajectory samples a transition from a closed to an open conformation.
[2]:
mobile = mda.Universe(PSF, DCD)
ref = mda.Universe(PSF, DCD)
Aligning a trajectory to the first frame¶
While align.alignto aligns structures, or a frame of a trajectory, align.AlignTraj
(API docs) efficiently aligns an entire trajectory to a reference.
We first check the root mean square deviation (RMSD) values of our unaligned trajectory, so we can compare results (please see the linked notebook for an explanation of RMSD). The code below sets the mobile
trajectory to the last frame by indexing the last timestep, ref
to the first frame by indexing the first timestep, and computes the root mean squared deviation between the alpha-carbon positions.
[3]:
mobile.trajectory[-1] # set mobile trajectory to last frame
ref.trajectory[0] # set reference trajectory to first frame
mobile_ca = mobile.select_atoms('name CA')
ref_ca = ref.select_atoms('name CA')
rms.rmsd(mobile_ca.positions, ref_ca.positions, superposition=False)
[3]:
6.842901296805416
Now we can align the trajectory. We have already set ref
to the first frame. In the cell below, we load the positions of the trajectory into memory so we can modify the trajectory in Python.
[4]:
aligner = align.AlignTraj(mobile, ref, select='name CA', in_memory=True).run()
If you don’t have enough memory to do that, write the trajectory out to a file and reload it into MDAnalysis (uncomment the cell below). Otherwise, you don’t have to run it.
[5]:
# aligner = align.AlignTraj(mobile, ref, select='backbone',
# filename='aligned_to_first_frame.dcd').run()
# mobile = mda.Universe(PSF, 'aligned_to_first_frame.dcd')
Now we can see that the RMSD has reduced (minorly).
[6]:
mobile.trajectory[-1] # set mobile trajectory to last frame
ref.trajectory[0] # set reference trajectory to first frame
mobile_ca = mobile.select_atoms('name CA')
ref_ca = ref.select_atoms('name CA')
rms.rmsd(mobile_ca.positions, ref_ca.positions, superposition=False)
[6]:
6.8144278141354455
Aligning a trajectory to the third frame¶
We can align the trajectory to any frame: for example, the third one. The procedure is much the same, except that we must set ref
to the third frame by indexing the third timestep.
[7]:
mobile.trajectory[-1] # set mobile trajectory to last frame
ref.trajectory[2] # set reference trajectory to third frame
rms.rmsd(mobile.atoms.positions, ref.atoms.positions, superposition=False)
[7]:
6.7298538548006395
[8]:
aligner = align.AlignTraj(mobile, ref, select='all', in_memory=True).run()
[9]:
mobile.trajectory[-1] # set mobile trajectory to last frame
ref.trajectory[2] # set reference trajectory to third frame
rms.rmsd(mobile.atoms.positions, ref.atoms.positions, superposition=False)
[9]:
6.724950470583631
References¶
[1] Oliver Beckstein, Elizabeth J. Denning, Juan R. Perilla, and Thomas B. Woolf. Zipping and Unzipping of Adenylate Kinase: Atomistic Insights into the Ensemble of Open↔Closed Transitions. Journal of Molecular Biology, 394(1):160–176, November 2009. 00107. URL: https://linkinghub.elsevier.com/retrieve/pii/S0022283609011164, doi:10.1016/j.jmb.2009.09.009.
[2] Richard J. Gowers, Max Linke, Jonathan Barnoud, Tyler J. E. Reddy, Manuel N. Melo, Sean L. Seyler, Jan Domański, David L. Dotson, Sébastien Buchoux, Ian M. Kenney, and Oliver Beckstein. MDAnalysis: A Python Package for the Rapid Analysis of Molecular Dynamics Simulations. Proceedings of the 15th Python in Science Conference, pages 98–105, 2016. 00152. URL: https://conference.scipy.org/proceedings/scipy2016/oliver_beckstein.html, doi:10.25080/Majora-629e541a-00e.
[3] Pu Liu, Dimitris K. Agrafiotis, and Douglas L. Theobald. Fast determination of the optimal rotational matrix for macromolecular superpositions. Journal of Computational Chemistry, pages n/a–n/a, 2009. URL: http://doi.wiley.com/10.1002/jcc.21439, doi:10.1002/jcc.21439.
[4] Naveen Michaud-Agrawal, Elizabeth J. Denning, Thomas B. Woolf, and Oliver Beckstein. MDAnalysis: A toolkit for the analysis of molecular dynamics simulations. Journal of Computational Chemistry, 32(10):2319–2327, July 2011. 00778. URL: http://doi.wiley.com/10.1002/jcc.21787, doi:10.1002/jcc.21787.
[5] Douglas L. Theobald. Rapid calculation of RMSDs using a quaternion-based characteristic polynomial. Acta Crystallographica Section A Foundations of Crystallography, 61(4):478–480, July 2005. 00127. URL: http://scripts.iucr.org/cgi-bin/paper?S0108767305015266, doi:10.1107/S0108767305015266.