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 10 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
37 changes: 25 additions & 12 deletions package/MDAnalysis/analysis/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
minimized RMSD between the reference and mobile structure.

>>> rmsd(mobile.select_atoms('name CA').positions, ref.select_atoms('name CA').positions,
>>> superposition=True)
... 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,17 +126,22 @@
>>> 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).

To **fit a whole trajectory** to a reference structure with the
:class:`AlignTraj` class::

>>> import doctest
>>> doctest.ELLIPSIS_MARKER = '-etc-'
MohitKumar020291 marked this conversation as resolved.
Show resolved Hide resolved
>>> ref = mda.Universe(PSF, PDB_small) # reference structure 1AKE
>>> trj = mda.Universe(PSF, DCD) # trajectory of change 1AKE->4AKE
>>> alignment = align.AlignTraj(trj, ref, filename='rmsfit.dcd')
>>> alignment.run()
>>> alignment.run() # doctest:+ELLIPSIS
-etc-
MohitKumar020291 marked this conversation as resolved.
Show resolved Hide resolved


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 +151,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 @@ -246,9 +254,14 @@ 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]
>>> from MDAnalysisTests.datafiles import TPR, TRR
>>> from MDAnalysis.analysis import align
>>> A = mda.Universe(TPR, TRR)
>>> B = A.copy()
>>> R = align.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 Down