-
Notifications
You must be signed in to change notification settings - Fork 832
Standardize atomicdistances to use results #5347
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
base: develop
Are you sure you want to change the base?
Changes from all commits
2cef10c
f858d04
b744dc1
965f590
db79395
0fb7c36
1970f59
139ef3a
2531f26
8a64521
d4f7cab
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 |
|---|---|---|
|
|
@@ -74,10 +74,10 @@ | |
| >>> ag2 = u.atoms[4000:4005] | ||
|
|
||
| We can run the calculations using any variable of choice such as | ||
| ``my_dists`` and access our results using ``my_dists.results``: :: | ||
| ``my_dists`` and access our results using ``my_dists.results.distances``: :: | ||
|
|
||
| >>> my_dists = ad.AtomicDistances(ag1, ag2).run() | ||
| >>> my_dists.results | ||
| >>> my_dists.results.distances | ||
| array([[37.80813681, 33.2594864 , 34.93676414, 34.51183299, 34.96340209], | ||
| [27.11746625, 31.19878079, 31.69439435, 32.63446126, 33.10451345], | ||
| [23.27210749, 30.38714688, 32.48269361, 31.91444505, 31.84583838], | ||
|
|
@@ -94,7 +94,7 @@ | |
| in this case: :: | ||
|
|
||
| >>> my_dists_nopbc = ad.AtomicDistances(ag1, ag2, pbc=False).run() | ||
| >>> my_dists_nopbc.results | ||
| >>> my_dists_nopbc.results.distances | ||
| array([[37.80813681, 33.2594864 , 34.93676414, 34.51183299, 34.96340209], | ||
| [27.11746625, 31.19878079, 31.69439435, 32.63446126, 33.10451345], | ||
| [23.27210749, 30.38714688, 32.482695 , 31.91444505, 31.84583838], | ||
|
|
@@ -108,9 +108,13 @@ | |
|
|
||
| """ | ||
|
|
||
|
|
||
| import numpy as np | ||
|
|
||
| from MDAnalysis.lib.distances import calc_bonds | ||
| from MDAnalysis.analysis.results import ( | ||
|
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. Could probably remove the comma and parenthesis to truncate into one line |
||
| Results, | ||
| ) | ||
|
|
||
| import logging | ||
| from .base import AnalysisBase | ||
|
|
@@ -134,7 +138,7 @@ class AtomicDistances(AnalysisBase): | |
|
|
||
| Attributes | ||
| ---------- | ||
| results : :class:`numpy.ndarray` | ||
| results.distances : :class:`numpy.ndarray` | ||
| The distances :math:`|ag1[i] - ag2[i]|` for all :math:`i` | ||
| from :math:`0` to `n_atoms` :math:`- 1` for each frame over | ||
| the trajectory. | ||
|
|
@@ -145,6 +149,14 @@ class AtomicDistances(AnalysisBase): | |
|
|
||
|
|
||
| .. versionadded:: 2.5.0 | ||
|
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. do not remove any of the versionchanged/versionadded; just add the new one below
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. and do not remove empty lines – they are necessary for the proper formatting |
||
| .. versionchanged:: 2.11.0 | ||
charity-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Distance data are now made available in :attr:`results.distances` instead | ||
| of :attr:`results` and :attr:`results` is now a | ||
| :class:`~MDAnalysis.analysis.results.Results` instance; this fixes an API issue | ||
| (see `Issue #4819`_) in a *backwards-incompatible* manner. | ||
|
|
||
| .. _Issue #4819`: https://github.com/MDAnalysis/mdanalysis/issues/4819 | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, ag1, ag2, pbc=True, **kwargs): | ||
|
|
@@ -167,11 +179,12 @@ def __init__(self, ag1, ag2, pbc=True, **kwargs): | |
|
|
||
| def _prepare(self): | ||
| # initialize NumPy array of frames x distances for results | ||
| self.results = np.zeros((self.n_frames, self._ag1.atoms.n_atoms)) | ||
| distances = np.zeros((self.n_frames, self._ag1.atoms.n_atoms)) | ||
| self.results = Results(distances=distances) | ||
|
|
||
| def _single_frame(self): | ||
| # if PBCs considered, get box size | ||
| box = self._ag1.dimensions if self._pbc else None | ||
| self.results[self._frame_index] = calc_bonds( | ||
|
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. https://github.com/MDAnalysis/mdanalysis/actions/runs/23987727902/job/69962349164?pr=5347#step:8:518 Tests show that an all zeros array is passed back in both tests, suggesting the actual numbers/results are not saved properly into the |
||
| self._ag1.positions, self._ag2.positions, box | ||
| ) | ||
| ) | ||
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.
Not sure why this is changed.