-
Notifications
You must be signed in to change notification settings - Fork 826
Accept AtomGroup alongwith Universe in the DistanceMatrix #3541
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
Changes from all commits
d373177
ae9e9df
64fe2fe
3cb2544
747e486
571cfa5
477400f
910f48a
5bbeb81
04b0a55
4335817
2a50647
9251e50
af23f05
86136ba
09588f6
2799ad9
e6f0fe1
adda3f6
28cf0bd
f4a457c
f1b63be
17415d5
f79e9c5
2afccf7
765f942
f366946
2670166
b1dd5f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,6 +156,7 @@ | |
| import numpy as np | ||
|
|
||
| from MDAnalysis.core.universe import Universe | ||
| from MDAnalysis.core.groups import AtomGroup, UpdatingAtomGroup | ||
| from .rms import rmsd | ||
| from .base import AnalysisBase | ||
|
|
||
|
|
@@ -171,7 +172,7 @@ class DistanceMatrix(AnalysisBase): | |
|
|
||
| Parameters | ||
| ---------- | ||
| universe : `~MDAnalysis.core.universe.Universe` | ||
| universe : `~MDAnalysis.core.universe.Universe` or `~MDAnalysis.core.groups.AtomGroup` | ||
| The MD Trajectory for dimension reduction, remember that | ||
| computational cost of eigenvalue decomposition | ||
| scales at O(N^3) where N is the number of frames. | ||
|
|
@@ -243,12 +244,20 @@ class DistanceMatrix(AnalysisBase): | |
| .. versionchanged:: 2.0.0 | ||
| :attr:`dist_matrix` is now stored in a | ||
| :class:`MDAnalysis.analysis.base.Results` instance. | ||
|
|
||
| .. versionchanged:: 2.2.0 | ||
| :class:`DistanceMatrix` now also accepts `AtomGroup`. | ||
| """ | ||
| def __init__(self, universe, select='all', metric=rmsd, cutoff=1E0-5, | ||
| weights=None, **kwargs): | ||
| # remember that this must be called before referencing self.n_frames | ||
| super(DistanceMatrix, self).__init__(universe.trajectory, **kwargs) | ||
| super(DistanceMatrix, self).__init__(universe.universe.trajectory, | ||
IAlibay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| **kwargs) | ||
|
|
||
| if isinstance(universe, UpdatingAtomGroup): | ||
| wmsg = ("U must be a static AtomGroup. Parsing an updating AtomGroup " | ||
| "will result in a static AtomGroup with the current frame " | ||
| "atom selection.") | ||
| warnings.warn(wmsg) | ||
|
|
||
| self.atoms = universe.select_atoms(select) | ||
| self._metric = metric | ||
|
|
@@ -309,14 +318,18 @@ class DiffusionMap(object): | |
| transform(n_eigenvectors, time) | ||
| Perform an embedding of a frame into the eigenvectors representing | ||
| the collective coordinates. | ||
|
|
||
|
|
||
| .. versionchanged:: 2.2.0 | ||
| :class:`DiffusionMap` now also accepts `AtomGroup`. | ||
| """ | ||
|
|
||
| def __init__(self, u, epsilon=1, **kwargs): | ||
| """ | ||
| Parameters | ||
| ------------- | ||
| u : MDAnalysis Universe or DistanceMatrix object | ||
| Can be a Universe, in which case one must supply kwargs for the | ||
| u : MDAnalysis Universe or AtomGroup or DistanceMatrix object. | ||
| Can be a Universe or AtomGroup, in which case one must supply kwargs for the | ||
| initialization of a DistanceMatrix. Otherwise, this can be a | ||
| DistanceMatrix already initialized. Either way, this will be made | ||
| into a diffusion kernel. | ||
|
|
@@ -328,12 +341,12 @@ def __init__(self, u, epsilon=1, **kwargs): | |
| Parameters to be passed for the initialization of a | ||
| :class:`DistanceMatrix`. | ||
| """ | ||
| if isinstance(u, Universe): | ||
| if isinstance(u, AtomGroup) or isinstance(u, Universe): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change does not appear in the docstring just above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies! I have updated the docstrings.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick question here - what happens if you pass an UpdatingAtomGroup, does the code still work?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it works fine. PFA example code snippet I tried on.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add in a test that uses an UpdatingAtomGroup?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, will add a separate test for updating atomgroups.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, I'm not very sure about what kind of test do we want here. Do I make a test out of the example.zip that I attached before and compare the DistMatrix constructed by updating atom group with just universe and selection string of the atom group?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IAlibay I did the above for updating AG checks. Please let me know if it is fine. |
||
| self._dist_matrix = DistanceMatrix(u, **kwargs) | ||
| elif isinstance(u, DistanceMatrix): | ||
| self._dist_matrix = u | ||
| else: | ||
| raise ValueError("U is not a Universe or DistanceMatrix and" | ||
| raise ValueError("U is not a Universe or AtomGroup or DistanceMatrix and" | ||
| " so the DiffusionMap has no data to work with.") | ||
| self._epsilon = epsilon | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.