diff --git a/pyemma/coordinates/tests/test_featurereader.py b/pyemma/coordinates/tests/test_featurereader.py index 251a742a3..3b3626f20 100644 --- a/pyemma/coordinates/tests/test_featurereader.py +++ b/pyemma/coordinates/tests/test_featurereader.py @@ -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] @@ -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 diff --git a/pyemma/coordinates/util/patches.py b/pyemma/coordinates/util/patches.py index b2d7c1a74..33e3c7bb5 100644 --- a/pyemma/coordinates/util/patches.py +++ b/pyemma/coordinates/util/patches.py @@ -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