Skip to content
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

Ensure Timestep in ChainReader is updated for multiple trajectory files #3834

Closed
wants to merge 13 commits into from
Closed
3 changes: 2 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/?? IAlibay, Luthaf, hmacdope, rafaelpap, jbarnoud
??/??/?? IAlibay, Luthaf, hmacdope, rafaelpap, jbarnoud, jaclark5

* 2.4.0

Fixes
* Fixes distances.between not always returning AtomGroup (Issue #3794)
* Upgrade to chemfiles 0.10.3 (Issue #3798)
* Ensure Timestep passed to transform is the same as AtomGroup Trajectory Timestep (Issue #3657)

Enhancements
* Added benchmarks for bonds topology attribute (Issue #3785, PR #3806)
Expand Down
2 changes: 2 additions & 0 deletions package/MDAnalysis/transformations/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def __init__(self, ag, compound='atoms',
self.compound = compound

def _transform(self, ts):
if id(ts) != id(self.ag.universe.trajectory.ts):
self.ag.universe.trajectory.ts = ts
self.ag.wrap(compound=self.compound)
return ts

Expand Down
15 changes: 14 additions & 1 deletion testsuite/MDAnalysisTests/transformations/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from numpy.testing import assert_array_almost_equal

import MDAnalysis as mda
from MDAnalysis.transformations import translate, center_in_box
from MDAnalysis.transformations import translate, center_in_box, wrap
from MDAnalysisTests import make_Universe


Expand All @@ -49,6 +49,19 @@ def test_translate_coords(translate_universes):
trans = translate(vector)(trans_u.trajectory.ts)
assert_array_almost_equal(trans.positions, ref.positions, decimal=6)

def test_wrap_id(translate_universes):
# If the translation is given a different timestep from what is has, the timestep will
jaclark5 marked this conversation as resolved.
Show resolved Hide resolved
# be updated to the new one given. This should only matter in a ChainReader
ref_u, trans_u = translate_universes
trans_u.dimensions = [363., 364., 365., 90., 90., 90.]
ref_u.dimensions = [363., 364., 365., 90., 90., 90.]

ag = trans_u.residues[24].atoms
trans = wrap(ag)
id_trans = id(trans_u.trajectory.ts)
trans = trans._transform(ref_u.trajectory.ts)
assert id_trans != id(trans_u.trajectory.ts) and id(trans_u.trajectory.ts) == id(ref_u.trajectory.ts)
jaclark5 marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize('vector', (
[0, 1],
Expand Down