Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS: Align.py changes made #4182

Merged
merged 20 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Chronological list of authors
- Egor Marin
- Shaivi Malik
- Daniel J. Evans
- Mohit Kumar

External code
-------------
Expand Down
2 changes: 1 addition & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/?? IAlibay, jaclark5
??/??/?? IAlibay, jaclark5, MohitKumar020291
MohitKumar020291 marked this conversation as resolved.
Show resolved Hide resolved

* 2.6.0

Expand Down
55 changes: 33 additions & 22 deletions package/MDAnalysis/analysis/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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())
<AtomGroup with 3341 atoms>
>>> mobile.atoms.rotate(R)
<AtomGroup with 3341 atoms>
>>> mobile.atoms.translate(ref.select_atoms('name CA').center_of_mass())
<AtomGroup with 3341 atoms>
>>> mobile.atoms.write("mobile_on_ref.pdb")


Expand All @@ -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).
Expand All @@ -134,6 +138,7 @@
>>> trj = mda.Universe(PSF, DCD) # trajectory of change 1AKE->4AKE
>>> alignment = align.AlignTraj(trj, ref, filename='rmsfit.dcd')
>>> alignment.run()
<MDAnalysis.analysis.align.AlignTraj object at ...>

It is also possible to align two arbitrary structures by providing a
mapping between atoms based on a sequence alignment. This allows
Expand All @@ -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.)

Expand Down Expand Up @@ -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
-------
Expand All @@ -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)
<AtomGroup with 47681 atoms>
>>> A.atoms.write("rotated.pdb")

Notes
-----
Expand All @@ -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)

Expand Down