-
Notifications
You must be signed in to change notification settings - Fork 824
Add unwrap keyword to radius of gyration #2294
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
Closed
Closed
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
2052a80
Merge pull request #2 from MDAnalysis/develop
NinadBhat 0c5ebc3
Merge pull request #3 from MDAnalysis/develop
NinadBhat 4ac9ab0
Merge pull request #4 from MDAnalysis/develop
NinadBhat 4819464
Adds unwrap to center
NinadBhat 300c955
Adds tests
NinadBhat 6f21b31
Review changes
NinadBhat 55d0a84
add unwrap to 'cog'
NinadBhat 76876d4
Merge develop
NinadBhat 6ae780b
check for pbc and unwrap
NinadBhat 6d33fe9
Removes unnecessary lines
NinadBhat 71f5dc9
:Merge remote-tracking branch 'upstream/develop' into develop
NinadBhat cc6dae2
Merge remote-tracking branch 'upstream/develop' into develop
NinadBhat 38478f8
Merge upstream-develop
NinadBhat 33e609c
Merge upstream/develop
NinadBhat 1783fa0
Add unwrap to group.radius_of_gyration
NinadBhat 09c8aae
added transformations based on alignto ; added translations fitting t…
davidercruz ce3ac2b
added rotation+translation fitting with plane support
davidercruz 5a702d3
updated __init__
davidercruz a0390ac
corrected some errors in fit_rot_trans ; added more tests
davidercruz 9f7791e
corrected plane rot+trans fitting; removed alignto
davidercruz 408243a
added plane tests
davidercruz e5fef8e
improved docs
davidercruz cdc1205
MAINT: reviewer adjusts PR 1991
tylerjereddy df3684c
MAINT: final reviewer adjustments in PR 1991
tylerjereddy 46483eb
Merge remote-tracking branch 'upstream/develop' into develop
NinadBhat 7eaf796
Add unwrap to group.radius_of_gyration
NinadBhat 94cac24
Adds docstring
NinadBhat f72ca18
Adds CHANGELOG
NinadBhat 55a6157
Resolving conflicts
NinadBhat b1c68e4
Merge pull request #1991 from davidercruz/fitting-transforms
tylerjereddy 9fe2c6b
Adds decorator
NinadBhat 6a791d4
Adds unwrap to center
NinadBhat 9c18ce4
Adds tests
NinadBhat 93d5ce8
Review changes
NinadBhat 918d5a0
add unwrap to 'cog'
NinadBhat 3ebbe23
Removes unnecessary lines
NinadBhat e844781
Add unwrap to group.radius_of_gyration
NinadBhat c37d2ac
Adds docstring
NinadBhat c5ca308
Adds CHANGELOG
NinadBhat 2e17578
Adds decorator
NinadBhat cc81cba
Rebase
NinadBhat d66ab5f
Adds unwrap to center
NinadBhat 95a7c0f
Adds tests
NinadBhat ca5268f
Review changes
NinadBhat d2948bb
add unwrap to 'cog'
NinadBhat f789e34
Removes unnecessary lines
NinadBhat 3afb0a5
Add unwrap to group.radius_of_gyration
NinadBhat 9d8e618
Add unwrap to group.radius_of_gyration
NinadBhat 0d14950
Adds docstring
NinadBhat bab1bf7
Adds CHANGELOG
NinadBhat a287e5d
Adds decorator
NinadBhat 9f51e9a
Adds unwrap to center
NinadBhat 7c96ded
Adds tests
NinadBhat 2fd92d8
Review changes
NinadBhat 8145606
add unwrap to 'cog'
NinadBhat 6200e32
Removes unnecessary lines
NinadBhat 0edc9a7
Add unwrap to group.radius_of_gyration
NinadBhat 68e5329
Adds docstring
NinadBhat f381d3d
Merge branch 'rog_unwrap' of https://github.com/NinadBhat/mdanalysis …
NinadBhat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| # -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- | ||
| # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
| # | ||
| # MDAnalysis --- https://www.mdanalysis.org | ||
| # Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors | ||
| # (see the file AUTHORS for the full list of names) | ||
| # | ||
| # Released under the GNU Public Licence, v2 or any higher version | ||
| # | ||
| # Please cite your use of MDAnalysis in published work: | ||
| # | ||
| # R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, | ||
| # D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. | ||
| # MDAnalysis: A Python package for the rapid analysis of molecular dynamics | ||
| # simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th | ||
| # Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy. | ||
| # | ||
| # N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. | ||
| # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. | ||
| # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 | ||
| # | ||
|
|
||
| """\ | ||
| Fitting transformations --- :mod:`MDAnalysis.transformations.fit` | ||
| ================================================================= | ||
|
|
||
| Translate and/or rotates the coordinates of a given trajectory to align | ||
| a given AtomGroup to a reference structure. | ||
|
|
||
| .. autofunction:: fit_translation | ||
|
|
||
| .. autofunction:: fit_rot_trans | ||
|
|
||
| """ | ||
| from __future__ import absolute_import | ||
|
|
||
| import numpy as np | ||
| from functools import partial | ||
|
|
||
| from ..analysis import align | ||
| from ..lib.util import get_weights | ||
| from ..lib.transformations import euler_from_matrix, euler_matrix | ||
|
|
||
|
|
||
| def fit_translation(ag, reference, plane=None, weights=None): | ||
|
|
||
| """Translates a given AtomGroup so that its center of geometry/mass matches | ||
| the respective center of the given reference. A plane can be given by the | ||
| user using the option `plane`, and will result in the removal of | ||
| the translation motions of the AtomGroup over that particular plane. | ||
|
|
||
| Example | ||
| ------- | ||
| Removing the translations of a given AtomGroup `ag` on the XY plane by fitting | ||
| its center of mass to the center of mass of a reference `ref`: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| ag = u.select_atoms("protein") | ||
| ref = mda.Universe("reference.pdb") | ||
| transform = mda.transformations.fit_translation(ag, ref, plane="xy", | ||
| weights="mass") | ||
| u.trajectory.add_transformations(transform) | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ag : Universe or AtomGroup | ||
| structure to translate, a | ||
| :class:`~MDAnalysis.core.groups.AtomGroup` or a whole | ||
| :class:`~MDAnalysis.core.universe.Universe` | ||
| reference : Universe or AtomGroup | ||
| reference structure, a :class:`~MDAnalysis.core.groups.AtomGroup` or a whole | ||
| :class:`~MDAnalysis.core.universe.Universe` | ||
| plane: str, optional | ||
| used to define the plane on which the translations will be removed. Defined as a | ||
| string of the plane. Suported planes are yz, xz and xy planes. | ||
| weights : {"mass", ``None``} or array_like, optional | ||
| choose weights. With ``"mass"`` uses masses as weights; with ``None`` | ||
| weigh each atom equally. If a float array of the same length as | ||
| `ag` is provided, use each element of the `array_like` as a | ||
| weight for the corresponding atom in `ag`. | ||
|
|
||
| Returns | ||
| ------- | ||
| MDAnalysis.coordinates.base.Timestep | ||
| """ | ||
|
|
||
| if plane is not None: | ||
| axes = {'yz' : 0, 'xz' : 1, 'xy' : 2} | ||
| try: | ||
| plane = axes[plane] | ||
| except (TypeError, KeyError): | ||
| raise ValueError('{} is not a valid plane'.format(plane)) | ||
| try: | ||
| if ag.atoms.n_residues != reference.atoms.n_residues: | ||
| raise ValueError("{} and {} have mismatched number of residues".format(ag,reference)) | ||
| except AttributeError: | ||
| raise AttributeError("{} or {} is not valid Universe/AtomGroup".format(ag,reference)) | ||
| ref, mobile = align.get_matching_atoms(reference.atoms, ag.atoms) | ||
| try: | ||
| weights = align.get_weights(ref.atoms, weights=weights) | ||
| except (ValueError, TypeError): | ||
| raise ValueError("weights must be {'mass', None} or an iterable of the " | ||
| "same size as the atomgroup.") | ||
|
|
||
| ref_com = np.asarray(ref.center(weights), np.float32) | ||
|
|
||
| def wrapped(ts): | ||
| mobile_com = np.asarray(mobile.atoms.center(weights), np.float32) | ||
| vector = ref_com - mobile_com | ||
| if plane is not None: | ||
| vector[plane] = 0 | ||
| ts.positions += vector | ||
|
|
||
| return ts | ||
|
|
||
| return wrapped | ||
|
|
||
|
|
||
| def fit_rot_trans(ag, reference, plane=None, weights=None): | ||
| """Perform a spatial superposition by minimizing the RMSD. | ||
|
|
||
| Spatially align the group of atoms `ag` to `reference` by doing a RMSD | ||
| fit. | ||
|
|
||
| This fit works as a way to remove translations and rotations of a given | ||
| AtomGroup in a trajectory. A plane can be given using the flag `plane` | ||
| so that only translations and rotations in that particular plane are | ||
| removed. This is useful for protein-membrane systems to where the membrane | ||
| must remain in the same orientation. | ||
|
|
||
| Example | ||
| ------- | ||
| Removing the translations and rotations of a given AtomGroup `ag` on the XY plane | ||
| by fitting it to a reference `ref`, using the masses as weights for the RMSD fit: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| ag = u.select_atoms("protein") | ||
| ref = mda.Universe("reference.pdb") | ||
| transform = mda.transformations.fit_rot_trans(ag, ref, plane="xy", | ||
| weights="mass") | ||
| u.trajectory.add_transformations(transform) | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ag : Universe or AtomGroup | ||
| structure to translate and rotate, a | ||
| :class:`~MDAnalysis.core.groups.AtomGroup` or a whole | ||
| :class:`~MDAnalysis.core.universe.Universe` | ||
| reference : Universe or AtomGroup | ||
| reference structure, a :class:`~MDAnalysis.core.groups.AtomGroup` or a whole | ||
| :class:`~MDAnalysis.core.universe.Universe` | ||
| plane: str, optional | ||
| used to define the plane on which the rotations and translations will be removed. | ||
| Defined as a string of the plane. Supported planes are "yz", "xz" and "xy" planes. | ||
| weights : {"mass", ``None``} or array_like, optional | ||
| choose weights. With ``"mass"`` uses masses as weights; with ``None`` | ||
| weigh each atom equally. If a float array of the same length as | ||
| `ag` is provided, use each element of the `array_like` as a | ||
| weight for the corresponding atom in `ag`. | ||
|
|
||
| Returns | ||
| ------- | ||
| MDAnalysis.coordinates.base.Timestep | ||
| """ | ||
| if plane is not None: | ||
| axes = {'yz' : 0, 'xz' : 1, 'xy' : 2} | ||
| try: | ||
| plane = axes[plane] | ||
| except (TypeError, KeyError): | ||
| raise ValueError('{} is not a valid plane'.format(plane)) | ||
| try: | ||
| if ag.atoms.n_residues != reference.atoms.n_residues: | ||
| raise ValueError("{} and {} have mismatched number of residues".format(ag,reference)) | ||
| except AttributeError: | ||
| raise AttributeError("{} or {} is not valid Universe/AtomGroup".format(ag,reference)) | ||
| ref, mobile = align.get_matching_atoms(reference.atoms, ag.atoms) | ||
| try: | ||
| weights = align.get_weights(ref.atoms, weights=weights) | ||
| except (ValueError, TypeError): | ||
| raise ValueError("weights must be {'mass', None} or an iterable of the " | ||
| "same size as the atomgroup.") | ||
| ref_com = ref.center(weights) | ||
| ref_coordinates = ref.atoms.positions - ref_com | ||
|
|
||
| def wrapped(ts): | ||
| mobile_com = mobile.atoms.center(weights) | ||
| mobile_coordinates = mobile.atoms.positions - mobile_com | ||
| rotation, dump = align.rotation_matrix(mobile_coordinates, ref_coordinates, weights=weights) | ||
| vector = ref_com | ||
| if plane is not None: | ||
| matrix = np.r_[rotation, np.zeros(3).reshape(1,3)] | ||
| matrix = np.c_[matrix, np.zeros(4)] | ||
| euler_angs = np.asarray(euler_from_matrix(matrix, axes='sxyz'), np.float32) | ||
| for i in range(0, euler_angs.size): | ||
| euler_angs[i] = ( euler_angs[plane] if i == plane else 0) | ||
| rotation = euler_matrix(euler_angs[0], euler_angs[1], euler_angs[2], axes='sxyz')[:3, :3] | ||
| vector[plane] = mobile_com[plane] | ||
| ts.positions = ts.positions - mobile_com | ||
| ts.positions = np.dot(ts.positions, rotation.T) | ||
| ts.positions = ts.positions + vector | ||
|
|
||
| return ts | ||
|
|
||
| return wrapped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
package/doc/sphinx/source/documentation_pages/transformations/fit.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .. automodule:: MDAnalysis.transformations.fit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to update the docstring to include all keywords