diff --git a/package/AUTHORS b/package/AUTHORS index 0279ba7dde5..ba4164e49bc 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -217,6 +217,7 @@ Chronological list of authors - Egor Marin - Shaivi Malik - Daniel J. Evans + - Mohit Kumar External code ------------- diff --git a/package/CHANGELOG b/package/CHANGELOG index 7b655028939..9fe5ab5228b 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -13,7 +13,7 @@ The rules for this file: * release numbers follow "Semantic Versioning" http://semver.org ------------------------------------------------------------------------------ -??/??/?? IAlibay, jaclark5 +??/??/?? IAlibay, jaclark5, MohitKumar020291 * 2.6.0 diff --git a/package/MDAnalysis/analysis/align.py b/package/MDAnalysis/analysis/align.py index 9bb9f4798e2..acb3943c576 100644 --- a/package/MDAnalysis/analysis/align.py +++ b/package/MDAnalysis/analysis/align.py @@ -74,7 +74,7 @@ two structures, using :func:`rmsd`:: >>> ref = mda.Universe(PDB_small) - >>> mobile = mda.Universe(PSF,DCD) + >>> mobile = mda.Universe(PSF, DCD) >>> rmsd(mobile.select_atoms('name CA').positions, ref.select_atoms('name CA').positions) 28.20178579474479 @@ -89,8 +89,8 @@ rotational superposition use the superposition keyword. This will calculate a minimized RMSD between the reference and mobile structure. - >>> rmsd(mobile.select_atoms('name CA').positions, ref.select_atoms('name CA').positions, - >>> superposition=True) + >>> rmsd(mobile.select_atoms('name CA').positions, ref.select_atoms('name CA').positions, + ... superposition=True) 6.809396586471815 The rotation matrix that superimposes *mobile* on *ref* while @@ -100,18 +100,21 @@ >>> mobile0 = mobile.select_atoms('name CA').positions - mobile.select_atoms('name CA').center_of_mass() >>> ref0 = ref.select_atoms('name CA').positions - ref.select_atoms('name CA').center_of_mass() >>> R, rmsd = align.rotation_matrix(mobile0, ref0) - >>> print rmsd + >>> rmsd 6.809396586471805 - >>> print R - [[ 0.14514539 -0.27259113 0.95111876] - [ 0.88652593 0.46267112 -0.00268642] - [-0.43932289 0.84358136 0.30881368]] + >>> R + array([[ 0.14514539, -0.27259113, 0.95111876], + ... [ 0.88652593, 0.46267112, -0.00268642], + ... [-0.43932289, 0.84358136, 0.30881368]]) Putting all this together one can superimpose all of *mobile* onto *ref*:: >>> mobile.atoms.translate(-mobile.select_atoms('name CA').center_of_mass()) + >>> mobile.atoms.rotate(R) + >>> mobile.atoms.translate(ref.select_atoms('name CA').center_of_mass()) + >>> mobile.atoms.write("mobile_on_ref.pdb") @@ -123,6 +126,7 @@ >>> ref = mda.Universe(PSF, PDB_small) >>> mobile = mda.Universe(PSF, DCD) # we use the first frame >>> align.alignto(mobile, ref, select="protein and name CA", weights="mass") + (21.892591663632704, 6.809396586471809) This will change *all* coordinates in *mobile* so that the protein C-alpha atoms are optimally superimposed (translation and rotation). @@ -134,6 +138,7 @@ >>> trj = mda.Universe(PSF, DCD) # trajectory of change 1AKE->4AKE >>> alignment = align.AlignTraj(trj, ref, filename='rmsfit.dcd') >>> alignment.run() + It is also possible to align two arbitrary structures by providing a mapping between atoms based on a sequence alignment. This allows @@ -143,9 +148,9 @@ the appropriate MDAnalysis selections with the :func:`fasta2select` function and then feed the resulting dictionary to :class:`AlignTraj`:: - >>> seldict = align.fasta2select('sequences.aln') - >>> alignment = align.AlignTraj(trj, ref, filename='rmsfit.dcd', select=seldict) - >>> alignment.run() + >>> seldict = align.fasta2select('sequences.aln') # doctest: +SKIP + >>> alignment = align.AlignTraj(trj, ref, filename='rmsfit.dcd', select=seldict) # doctest: +SKIP + >>> alignment.run() # doctest: +SKIP (See the documentation of the functions for this advanced usage.) @@ -222,15 +227,15 @@ def rotation_matrix(a, b, weights=None): Parameters ---------- a : array_like - coordinates that are to be rotated ("mobile set"); array of N atoms - of shape N*3 as generated by, e.g., - :attr:`MDAnalysis.core.groups.AtomGroup.positions`. + coordinates that are to be rotated ("mobile set"); array of N atoms + of shape N*3 as generated by, e.g., + :attr:`MDAnalysis.core.groups.AtomGroup.positions`. b : array_like - reference coordinates; array of N atoms of shape N*3 as generated by, - e.g., :attr:`MDAnalysis.core.groups.AtomGroup.positions`. + reference coordinates; array of N atoms of shape N*3 as generated by, + e.g., :attr:`MDAnalysis.core.groups.AtomGroup.positions`. weights : array_like (optional) - array of floats of size N for doing weighted RMSD fitting (e.g. the - masses of the atoms) + array of floats of size N for doing weighted RMSD fitting (e.g. the + masses of the atoms) Returns ------- @@ -246,10 +251,15 @@ def rotation_matrix(a, b, weights=None): :meth:`MDAnalysis.core.groups.AtomGroup.rotate` to generate a rotated selection, e.g. :: - >>> R = rotation_matrix(A.select_atoms('backbone').positions, - >>> B.select_atoms('backbone').positions)[0] - >>> A.atoms.rotate(R) - >>> A.atoms.write("rotated.pdb") + >>> from MDAnalysisTests.datafiles import TPR, TRR + >>> from MDAnalysis.analysis import align + >>> A = mda.Universe(TPR,TRR) + >>> B = A.copy() + >>> R = rotation_matrix(A.select_atoms('backbone').positions, + ... B.select_atoms('backbone').positions)[0] + >>> A.atoms.rotate(R) + + >>> A.atoms.write("rotated.pdb") Notes ----- @@ -263,6 +273,7 @@ def rotation_matrix(a, b, weights=None): AlignTraj: Fit a whole trajectory. """ + a = np.asarray(a, dtype=np.float64) b = np.asarray(b, dtype=np.float64)