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.

While align.alignto aligns structures, or a frame of a trajectory, align.AlignTraj efficiently aligns an entire trajectory to a reference.

We first check the RMSD of our unaligned trajectory, we can compare results. 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 frameref.trajectory[0]# set reference trajectory to first framemobile_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.

mobile.trajectory[-1]# set mobile trajectory to last frameref.trajectory[0]# set reference trajectory to first framemobile_ca=mobile.select_atoms('name CA')ref_ca=ref.select_atoms('name CA')rms.rmsd(mobile_ca.positions,ref_ca.positions,superposition=False)