Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #881 from marscher/fix_xtc_seeking
Browse files Browse the repository at this point in the history
[coordinates/FeatureReader|xtc] in case of a too large seek argument stop iteration
  • Loading branch information
marscher authored Jul 28, 2016
2 parents 49e4a3d + bba3a6a commit dccd871
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pyemma/coordinates/tests/test_featurereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setUpClass(cls):
cls.trajfile2, cls.xyz2, cls.n_frames2 = create_traj(cls.topfile, dir=cls.tmpdir)
traj = mdtraj.load(cls.trajfile, top=cls.topfile)
for fo in traj._savers():
if fo in ('.crd', '.mdcrd', '.h5', '.ncrst', '.lh5'):
if fo in ('.crd', '.mdcrd', '.h5', '.ncrst', '.lh5',):
continue
log.debug("creating traj for " + fo)
traj_file = create_traj(cls.topfile, format=fo, dir=cls.tmpdir)[0]
Expand Down Expand Up @@ -95,6 +95,14 @@ def testIteratorAccess(self):

self.assertTrue(np.allclose(data, self.xyz.reshape(-1, 9)))

def test_lagged_iterator_short_trajs(self):
trajs = [create_traj(self.topfile, '.xtc', dir=self.tmpdir, length=20)[0],
create_traj(self.topfile, '.xtc', dir=self.tmpdir, length=25)[0]
]
reader = api.source(trajs, top=self.topfile)
for itraj, X, Y in reader.iterator(lag=22):
raise RuntimeError("should never get here!!!")

def testIteratorAccess2(self):
reader = FeatureReader([self.trajfile, self.trajfile2], self.topfile)
reader.chunksize = 100
Expand Down
7 changes: 5 additions & 2 deletions pyemma/coordinates/util/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ def next(self):
# apply skip offset only once.
# (we want to do this here, since we want to be able to re-set self.skip)
if not self._seeked:
self._f.seek(self.skip)
self._seeked = True
try:
self._f.seek(self.skip)
self._seeked = True
except IndexError:
raise StopIteration("too short trajectory")

if not isinstance(self._stride, np.ndarray) and self._chunksize == 0:
# If chunk was 0 then we want to avoid filetype-specific code
Expand Down

0 comments on commit dccd871

Please sign in to comment.