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.unitcell_lengths, traj_ref.unitcell_lengths) assert allclose(traj_test.unitcell_angles, traj_ref.unitcell_angles)
def test_save_SaveTrajs_multipass_with_stride(self): # With the inmemory option = True for stride in self.strides[:]: # Since none of the trajfiles have more than 30 frames, the frames have to be re-drawn for every stride sets = np.copy(self.sets) sets[0][:, 1] = np.random.randint(0, high=30 / stride, size=np.shape(sets[0])[0]) sets[1][:, 1] = np.random.randint(0, high=30 / stride, size=np.shape(sets[1])[0]) __ = save_trajs(self.reader, sets, outfiles=self.one_pass_files, inmemory=False, stride=stride) traj_1_pass = single_traj_from_n_files(self.one_pass_files, top=self.pdbfile) # Also the reference has to be re-drawn using the stride. For this, we use the re-scale the strided # frame-indexes to the unstrided value sets[0][:, 1] *= stride sets[1][:, 1] *= stride traj_ref = save_traj_w_md_load_frame(self.reader, sets) # Check for diffs (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_1_pass, traj_ref, atom=0) self.assertFalse(found_diff, errmsg)
def test_reader_input_save_correct_frames_with_stride_in_memory(self): # With the inmemory option = True for stride in self.strides[:]: # Since none of the trajfiles have more than 30 frames, the frames have to be re-drawn for every stride sets = np.copy(self.sets) sets[0][:, 1] = np.random.randint(0, high=30 / stride, size=np.shape(sets[0])[0]) sets[1][:, 1] = np.random.randint(0, high=30 / stride, size=np.shape(sets[1])[0]) traj = save_traj(self.reader, sets, None, stride=stride, verbose=False) # Also the reference has to be re-drawn using the stride. For this, we use the re-scale the strided # frame-indexes to the unstrided value sets[0][:, 1] *= stride sets[1][:, 1] *= stride traj_ref = save_traj_w_md_load_frame(self.reader, sets) # Check for diffs (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj, traj_ref, atom=0) self.assertFalse(found_diff, errmsg)
def test_list_input_save_correct_frames_mem(self): # Keep object in memory traj = save_traj(self.trajfiles, self.sets, None, top=self.pdbfile) # Check for diffs (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj, self.traj_ref, atom=0) self.assertFalse(found_diff, errmsg)
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_list_input_save_correct_frames_disk(self): save_traj(self.trajfiles, self.sets, self.outfile, top=self.pdbfile) # Reload the object to memory traj = md.load(self.outfile, top=self.pdbfile) # Check for diffs (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj, self.traj_ref, atom=0) 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_with_fragmented_reader_chunksize_0(self): # intentionally group bpti dataset to a fake fragmented traj frag_traj = [[self.trajfiles[0], self.trajfiles[1]], self.trajfiles[2], self.trajfiles[2]] reader = coor.source(frag_traj, top=self.pdbfile, chunksize=0) assert reader.chunksize == 0 traj = save_traj(reader, self.sets, None) traj_ref = save_traj_w_md_load_frame(self.reader, self.sets) # Check for diffs (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj, traj_ref, atom=0) np.testing.assert_equal(traj.xyz, traj_ref.xyz) self.assertFalse(found_diff, errmsg)
def test_save_SaveTrajs_multipass(self): # Without the "inmemory" option, i.e. multipass __ = save_trajs(self.reader, self.sets, outfiles=self.n_pass_files) # Reload the object to memory traj_n_pass = single_traj_from_n_files(self.n_pass_files, top=self.pdbfile) # Check for diffs (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_n_pass, self.traj_ref, atom=0) self.assertFalse(found_diff, errmsg)
def test_save_SaveTrajs_onepass(self): # With the inmemory option = True __ = save_trajs(self.reader, self.sets, outfiles=self.one_pass_files, inmemory=True) traj_1_pass = single_traj_from_n_files(self.one_pass_files, top=self.pdbfile) # Check for diffs (found_diff, errmsg) = compare_coords_md_trajectory_objects(traj_1_pass, self.traj_ref, atom=0) 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)