File tree Expand file tree Collapse file tree
MDAnalysis/transformations
testsuite/MDAnalysisTests/transformations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ The rules for this file:
2020 * 2.11.0
2121
2222Fixes
23+ * NoJump shows a more informative message and fails when applied
24+ outside of the first frame (Issue #4915, PR #5199)
2325 * DSSP now explicitly checks for a minimum of 6 residues and raises a clear
2426 error message, unlike the previous behavior where it would fail with an
2527 incomprehensible broadcasting error at execution time (Issue #5046, PR #5163)
Original file line number Diff line number Diff line change @@ -118,6 +118,14 @@ def _transform(self, ts):
118118 except np .linalg .LinAlgError :
119119 msg = f"Periodic box dimensions are not invertible at step { ts .frame } "
120120 raise NoDataError (msg )
121+
122+ if self .prev is None and ts .frame != 0 :
123+ raise ValueError (
124+ "NoJump transformation must be applied starting from frame 0. "
125+ f"Currently at frame { ts .frame } . Please reset trajectory to frame 0 "
126+ "before adding this transformation."
127+ )
128+
121129 if ts .frame == 0 :
122130 # We don't need to apply the transformation here. However, we need to
123131 # ensure we have the 0th frame coordinates in reduced form. We also need to
Original file line number Diff line number Diff line change @@ -379,3 +379,32 @@ def test_notinvertible(nojump_universe):
379379 ]
380380 u .trajectory .add_transformations (* workflow )
381381 transformed_coordinates = u .trajectory .timeseries ()[0 ]
382+
383+
384+ def test_nojump_fails_when_not_at_frame_0 ():
385+ """
386+ Test that NoJump raises a clear error when applied to a trajectory
387+ that is not at frame 0.
388+ """
389+ u = mda .Universe (data .PSF_TRICLINIC , data .DCD_TRICLINIC )
390+ u .trajectory [- 1 ]
391+
392+ with pytest .raises (
393+ ValueError , match = "must be applied starting from frame 0"
394+ ):
395+ u .trajectory .add_transformations (NoJump ())
396+ _ = u .trajectory [0 ]
397+
398+
399+ def test_nojump_fails_midtrajectory ():
400+ """
401+ Test that NoJump raises a clear error when applied in the middle of a trajectory.
402+ """
403+ u = mda .Universe (data .PSF_TRICLINIC , data .DCD_TRICLINIC )
404+ u .trajectory [5 ]
405+
406+ with pytest .raises (
407+ ValueError , match = "must be applied starting from frame 0"
408+ ):
409+ u .trajectory .add_transformations (NoJump ())
410+ _ = u .trajectory .timeseries ()
You can’t perform that action at this time.
0 commit comments