def test_trajs_larger_than_frame_index(self): """ file list is larger than largest traj file """ from pyemma.coordinates.tests.util import create_traj, get_top files = [create_traj(length=10)[0] for _ in range(20)] inds = np.vstack((np.arange(20), np.arange(20))).T with self.assertRaises(ValueError) as cm: _frames_from_file(files, top=get_top(), frames=inds) import re matches = re.match(".*10\).*is larger than trajectory length.*\= 10", cm.exception.args[0]) assert matches
def test_gets_the_right_frames_with_stride_with_copy(self): for stride in [2, 3, 5, 6, 10, 15]: # Make sure we don't overshoot the number of available frames (100) frames = randint(0, high=floor(100 / stride), size=self.n_frames) traj_test = _frames_from_file(self.trajfiles, self.pdbfile, frames, chunksize=self.chunksize, stride=stride, verbose=False, copy_not_join=True) traj_ref = md.load(self.trajfiles, top=self.pdbfile, stride=stride)[frames] (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_test, traj_ref, atom=0, mess=False) self.assertFalse(found_diff, errmsg) assert allclose(traj_test.time, traj_ref.time) assert allclose(traj_test.unitcell_lengths, traj_ref.unitcell_lengths) assert allclose(traj_test.unitcell_angles, traj_ref.unitcell_angles)
def test_pass_reader(self): from pyemma.coordinates import source reader = source(self.trajfiles, top=self.pdbfile) reader.in_memory = True inds = np.vstack((np.random.randint(0, 1), np.random.randint(0, 100))).T traj_test = _frames_from_file(reader.filenames, self.pdbfile, inds, reader=reader)
def test_gets_the_right_frames_no_stride_with_chunk(self): traj_test = _frames_from_file(self.trajfiles, self.pdbfile, self.frames, chunksize=self.chunksize, verbose=False) traj_ref = md.load(self.trajfiles, top=self.pdbfile)[self.frames] (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_test, traj_ref, atom=0, mess=False) self.assertFalse(found_diff, errmsg)
def test_gets_the_right_frames_no_stride_no_chunk(self): # I am calling this "no_chunk" because chunksize = int(1e3) will force frames_from_file to load one single chunk traj_test = _frames_from_file(self.trajfiles, self.pdbfile, self.frames, chunksize=int(1e3), verbose=False) traj_ref = md.load(self.trajfiles, top=self.pdbfile)[self.frames] (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_test, traj_ref, atom=0, mess=False) self.assertFalse(found_diff, errmsg)
def test_gets_the_right_frames_with_stride_no_chunk(self): # I am calling this "no_chunk" because chunksize = int(1e3) will force frames_from_file to load one single chunk for stride in [2, 5, 10]: # Make sure we don't overshoot the number of available frames (100) frames = randint(0, high=floor(100 / stride), size=self.n_frames) traj_test = _frames_from_file(self.trajfiles, self.pdbfile, frames, stride=stride, verbose=False) traj_ref = md.load(self.trajfiles, top=self.pdbfile, stride=stride)[frames] (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_test, traj_ref, atom=0, mess=False) self.assertFalse(found_diff, errmsg)
def test_gets_the_right_frames_with_stride_with_chunk_mdTopology_input( self): for stride in [2, 3, 5, 6, 10, 15]: # Make sure we don't overshoot the number of available frames (100) frames = randint(0, high=floor(100 / stride), size=self.n_frames) traj_test = _frames_from_file(self.trajfiles, self.mdTrajectory.top, frames, chunksize=self.chunksize, stride=stride, verbose=False) traj_ref = md.load(self.trajfiles, top=self.pdbfile, stride=stride)[frames] (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_test, traj_ref, atom=0, mess=False) self.assertFalse(found_diff, errmsg)
def test_returns_trajectory(self): assert isinstance( _frames_from_file(self.trajfiles, self.pdbfile, self.frames), md.Trajectory)