Skip to content

Commit

Permalink
Remove reset_timestep option and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCentauri committed Mar 23, 2023
1 parent a1b6cdf commit 3ba9d23
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Fixes
(Issue #3336)

Enhancements
* Add an `AnalayisCollection` class to perform multiple analysis on the same
* Add an `AnalaysisCollection` class to perform multiple analysis on the same
trajectory (#3569, PR #4017).
* Added AtomGroup TopologyAttr to calculate gyration moments (Issue #3904,
PR #3905)
Expand Down
29 changes: 8 additions & 21 deletions package/MDAnalysis/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def __setstate__(self, state):
self.data = state


class AnalysisCollection(object):
class AnalysisCollection:
"""
Class for running a collection of analysis classes on a single trajectory.
Expand All @@ -238,11 +238,7 @@ class AnalysisCollection(object):
By default, it is ensured that all analysis instances use the
*same original* timestep and not an altered one from a previous analysis
object. This behavior can be changed with the `reset_timestep` parameter
of the :meth:`MDAnalysis.analysis.base.AnalysisCollection.run` method.
Changing the default behaviour of `reset_timestep` might be useful to
avoid that subsequent analysis instances have to perform the same
transformation on the timestep.
object.
Parameters
----------
Expand Down Expand Up @@ -313,7 +309,6 @@ def run(
step=None,
frames=None,
verbose=None,
reset_timestep=True,
):
"""Perform the calculation
Expand All @@ -332,11 +327,6 @@ def run(
non-default value will raise a :exc:`ValueError`.
verbose : bool, optional
Turn on verbosity
reset_timestep : bool, optional
Reset the timestep object after for each ``analysis_object``.
Setting this to ``False`` can be useful if an ``analysis_object``
is performing a trajectory manipulation which is also useful for the
subsequent ``analysis_instances`` e.g. unwrapping of molecules.
"""

# Ensure compatibility with API of version 0.15.0
Expand Down Expand Up @@ -367,8 +357,7 @@ def run(
for i, ts in enumerate(
ProgressBar(self._analysis_instances[0]._sliced_trajectory, verbose=verbose)
):
if reset_timestep:
ts_original = ts.copy()
ts_original = ts.copy()

for analysis_object in self._analysis_instances:
# Set attributes before calling `_single_frame()`. Setting
Expand All @@ -382,8 +371,7 @@ def run(
# Call the actual analysis of each instance.
analysis_object._single_frame()

if reset_timestep:
ts = ts_original
ts = ts_original

logger.info("Finishing up")

Expand Down Expand Up @@ -489,7 +477,7 @@ def __init__(self, trajectory, verbose=False, **kwargs):
self._trajectory = trajectory
self._verbose = verbose
self.results = Results()
super(AnalysisBase, self).__init__(self)
super().__init__(self)

def _setup_frames(self, trajectory, start=None, stop=None, step=None,
frames=None):
Expand Down Expand Up @@ -594,7 +582,7 @@ def run(self, start=None, stop=None, step=None, frames=None,
frame indices in the `frames` keyword argument.
"""
return super(AnalysisBase, self).run(
return super().run(
start=start, stop=stop, step=step, frames=frames, verbose=verbose
)

Expand Down Expand Up @@ -671,7 +659,7 @@ def __init__(self, function, trajectory=None, *args, **kwargs):

self.kwargs = kwargs

super(AnalysisFromFunction, self).__init__(trajectory)
super().__init__(trajectory)

def _prepare(self):
self.results.timeseries = []
Expand Down Expand Up @@ -739,8 +727,7 @@ def RotationMatrix(mobile, ref):

class WrapperClass(AnalysisFromFunction):
def __init__(self, trajectory=None, *args, **kwargs):
super(WrapperClass, self).__init__(function, trajectory,
*args, **kwargs)
super().__init__(function, trajectory, *args, **kwargs)

return WrapperClass

Expand Down
12 changes: 4 additions & 8 deletions testsuite/MDAnalysisTests/analysis/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def test_run(self, universe):
assert rdf_OO.results is not None
assert rdf_OH.results is not None

@pytest.mark.parametrize("reset_timestep", [True, False])
def test_trajectory_manipulation(self, universe, reset_timestep):
def test_trajectory_manipulation(self, universe):
"""Test that the timestep is the same for each analysis class."""
class CustomAnalysis(base.AnalysisBase):
"""Custom class that is shifting positions in every step by 10."""

Expand All @@ -185,13 +185,9 @@ def _single_frame(self):
ana_2 = CustomAnalysis(universe.trajectory)

collection = base.AnalysisCollection(ana_1, ana_2)
collection.run(frames=[0])

collection.run(frames=[0], reset_timestep=reset_timestep)

if reset_timestep:
assert ana_2.ref_pos == ana_1.ref_pos
else:
assert_allclose(ana_2.ref_pos, ana_1.ref_pos + 10)
assert ana_2.ref_pos == ana_1.ref_pos

def test_inconsistent_trajectory(self, universe):
v = mda.Universe(TPR, XTC)
Expand Down

0 comments on commit 3ba9d23

Please sign in to comment.