Unverified Commit 116aed39 authored by Raul's avatar Raul Committed by GitHub
Browse files

Fix "off by one" error in xtc time reporting. (#4168)

parent d8c67699
......@@ -141,7 +141,7 @@ class XTCFile(object):
)
else:
boxVectors = np.zeros((3, 3)).astype(np.float32)
step = self._modelCount * self._interval + self._firstStep
step = (self._modelCount - 1) * self._interval + self._firstStep
time = step * self._dt
xtc_write_frame(
self._filename.encode("utf-8"),
......
......@@ -49,9 +49,9 @@ class TestXtcFile(unittest.TestCase):
box = np.array(box).transpose(1, 2, 0)
self.assertTrue(np.allclose(box_read, box, atol=1e-3))
self.assertTrue(
np.allclose(time, np.arange(1, nframes + 1) * 0.001, atol=1e-5)
np.allclose(time, np.arange(0, nframes) * 0.001, atol=1e-5)
)
self.assertTrue(np.allclose(step, np.arange(1, nframes + 1), atol=1e-5))
self.assertTrue(np.allclose(step, np.arange(0, nframes), atol=1e-5))
def test_xtc_cubic(self):
"""Test the XTC file by writing a trajectory and reading it back. Using a cubic box"""
......@@ -87,9 +87,9 @@ class TestXtcFile(unittest.TestCase):
box = np.array(box).transpose(1, 2, 0)
self.assertTrue(np.allclose(box_read, box, atol=1e-3))
self.assertTrue(
np.allclose(time, np.arange(1, nframes + 1) * 0.001, atol=1e-5)
np.allclose(time, np.arange(0, nframes) * 0.001, atol=1e-5)
)
self.assertTrue(np.allclose(step, np.arange(1, nframes + 1), atol=1e-5))
self.assertTrue(np.allclose(step, np.arange(0, nframes), atol=1e-5))
def test_xtc_box_from_topology(self):
"""Test the XTC file by writing a trajectory and reading it back. Letting the box be set from the topology"""
......@@ -131,9 +131,9 @@ class TestXtcFile(unittest.TestCase):
box = np.array(np.tile(boxVectors, (nframes, 1, 1))).transpose(1, 2, 0)
self.assertTrue(np.allclose(box_read, box, atol=1e-3))
self.assertTrue(
np.allclose(time, np.arange(1, nframes + 1) * 0.001, atol=1e-5)
np.allclose(time, np.arange(0, nframes) * 0.001, atol=1e-5)
)
self.assertTrue(np.allclose(step, np.arange(1, nframes + 1), atol=1e-5))
self.assertTrue(np.allclose(step, np.arange(0, nframes), atol=1e-5))
def testLongTrajectory(self):
"""Test writing a trajectory that has more than 2^31 steps."""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment