Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 @@ -277,6 +277,7 @@ Chronological list of authors
- Ayush Agarwal
- Parth Uppal
- Olivier Languin--Cattoën
- Charity Grey

External code
-------------
Expand Down
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Enhancements
Changes
* The msd.py inside analysis is changed, and ProgressBar is implemented inside
_conclude_simple and _conclude_fft functions instead of tqdm (Issue #5144, PR #5153)
* `MDAnalysis.analysis.atomicdistances.AtomicDistances` results are now consistent with expected`analysis` documentation data type = Results (Issue #4819)
Comment thread
charity-g marked this conversation as resolved.
Outdated

Deprecations

Expand Down
22 changes: 14 additions & 8 deletions package/MDAnalysis/analysis/atomicdistances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -108,6 +108,10 @@

"""

from mdanalysis.package.MDAnalysis.analysis.results import (
Comment thread
charity-g marked this conversation as resolved.
Outdated
Results,
ResultsGroup,
)
import numpy as np

from MDAnalysis.lib.distances import calc_bonds
Expand All @@ -134,17 +138,15 @@ 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.
n_frames : int
Number of frames included in the analysis.
n_atoms : int
Number of atoms in each atom group.


.. versionadded:: 2.5.0
Comment thread
charity-g marked this conversation as resolved.
.. versionchanged:: 2.11.0
Comment thread
charity-g marked this conversation as resolved.
"""

def __init__(self, ag1, ag2, pbc=True, **kwargs):
Expand All @@ -167,11 +169,15 @@ 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(
Comment thread
charity-g marked this conversation as resolved.
Outdated
self._ag1.positions, self._ag2.positions, box
)

def _get_aggregator(self):
return ResultsGroup(lookup={"distances": ResultsGroup.ndarray_vstack})
Comment thread
charity-g marked this conversation as resolved.
Outdated
11 changes: 8 additions & 3 deletions testsuite/MDAnalysisTests/analysis/test_atomicdistances.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
from mdanalysis.package.MDAnalysis.analysis.results import Results
Comment thread
charity-g marked this conversation as resolved.
Outdated
import pytest

import MDAnalysis as mda
Expand Down Expand Up @@ -121,15 +122,19 @@ def test_ad_pairwise_dist(self, ad_ag1, ad_ag2, expected_dist):
correctly calculated without PBCs."""
pairwise_no_pbc = ad.AtomicDistances(ad_ag1, ad_ag2, pbc=False).run()
actual = pairwise_no_pbc.results

assert isinstance(actual, Results)

distances = actual.distances
# compare with expected values from dist()
assert_allclose(actual, expected_dist)
assert_allclose(distances, expected_dist)

def test_ad_pairwise_dist_pbc(self, ad_ag1, ad_ag2, expected_pbc_dist):
"""Ensure that pairwise distances between atoms are
correctly calculated with PBCs."""
pairwise_pbc = ad.AtomicDistances(ad_ag1, ad_ag2).run()
actual = pairwise_pbc.results
assert isinstance(actual, Results)

distances = actual.distances
# compare with expected values from dist()
assert_allclose(actual, expected_pbc_dist)
assert_allclose(distances, expected_pbc_dist)
Loading