def test_iterframe(self): '''test iterframe for both Trajectory and TrajectoryIterator ''' orig_traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) # iterframe (already in doctest), just throwing raise to increase coverage score for traj in [orig_traj, orig_traj[:]]: with pytest.raises(ValueError): traj.iterframe(rmsfit='crazy') # rmsfit is an int t0 = orig_traj[:].rmsfit(ref=3) aa_eq(pt.rmsd_nofit(traj(rmsfit=3), ref=orig_traj[-1]), pt.rmsd_nofit(t0, ref=orig_traj[-1])) # test TypeError if not has n_frames info t0 = orig_traj[:] def int_gen(k): for i in range(k): yield i fi = pt.iterframe(t0, frame_indices=int_gen(3)) aa_eq(pt.radgyr(fi, top=traj.top), pt.radgyr(orig_traj[:3]))
def test_iterframe(self): '''test iterframe for both Trajectory and TrajectoryIterator ''' orig_traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") # iterframe (already in doctest), just throwing raise to increase coverage score for traj in [orig_traj, orig_traj[:]]: self.assertRaises(ValueError, lambda: traj.iterframe(rmsfit='crazy')) # rmsfit is an int t0 = orig_traj[:].rmsfit(ref=3) aa_eq( pt.rmsd_nofit( traj(rmsfit=3), ref=orig_traj[-1]), pt.rmsd_nofit(t0, ref=orig_traj[-1])) # test TypeError if not has n_frames info t0 = orig_traj[:] def int_gen(k): for i in range(k): yield i fi = pt.iterframe(t0, frame_indices=int_gen(3)) aa_eq(pt.radgyr(fi, top=traj.top), pt.radgyr(orig_traj[:3]))
def test_combine_cpptraj_iterating_with_pytraj(self): traj = pt.iterload(fn("tz2.ortho.nc"), fn("tz2.ortho.parm7")) commands = [ 'autoimage', 'rms', ] dslist = CpptrajDatasetList() actlist = ActionList(commands, top=traj.top, dslist=dslist) def get_fi(actlist, traj): '''create a frame iterator with pre-processed by cpptraj ''' for frame in traj: actlist.compute(frame) yield frame ref = traj[3] pt.autoimage(ref, top=traj.top) fi = get_fi(actlist, traj) rmsd_nofit_after_fitting = pt.rmsd_nofit(fi, ref=ref, top=traj.top) t0 = traj[:].autoimage().superpose() saved_rmsd_ = pt.rmsd_nofit(t0, ref=ref) aa_eq(rmsd_nofit_after_fitting, saved_rmsd_)
def test_fit_and_then_nofit(self): traj = pt.iterload(tc5b_trajin, tc5b_top) t0 = traj[:] pt.superpose(t0, ref=traj[3], mask='@CA') rmsd_0 = pt.rmsd_nofit(traj, ref=traj[3], mask='@CB') rmsd_1 = pt.rmsd(traj, ref=traj[3], mask='@CB', nofit=True) aa_eq(rmsd_1, rmsd_0)
def calc_node_rmsd(self) -> float: logger.info(f"calculating rmsd for node {self.node_id}") crd_file = self.get_relative_file(SETTINGS["md"]["rst_file"]) top_file = self.get_relative_file(SETTINGS["md"]["top_file"]) ref_file = self.get_relative_file(SETTINGS["md"]["ref_file"]) if not all( os.path.exists(file) for file in [crd_file, top_file, ref_file]): logger.warning( f"Unable to calculate rmsd for node {self.node_id}. Some files are missing" ) load_mask = SETTINGS["system"]["load_mask"] traj = pytraj.load(crd_file, top=top_file, mask=load_mask) # this one is causing some trouble in CI. need to inspect why, though. # traj = pytraj.autoimage(traj) ref_top_file = self.get_relative_file( os.path.join(os.path.pardir, SETTINGS["data_files"]["ref_top_file"])) ref = pytraj.load(ref_file, top=ref_top_file, mask=load_mask) align_mask = SETTINGS["system"]["protein_mask"] pytraj.rmsd(traj, mask=align_mask, ref=ref) ligand_mask = SETTINGS["system"]["ligand_mask"] rmsd = pytraj.rmsd_nofit(traj, mask=ligand_mask, ref=ref) self.rmsd = float(rmsd[0]) self.nrmsd = self.rmsd / traj[ligand_mask].top.n_atoms self.write_node_info() return self.rmsd
def test_fit_and_then_nofit(self): traj = pt.iterload("data/Tc5b.x", "data/Tc5b.top") t0 = traj[:] pt.superpose(t0, ref=traj[3], mask='@CA') rmsd_0 = pt.rmsd_nofit(traj, ref=traj[3], mask='@CB') rmsd_1 = pt.rmsd(traj, ref=traj[3], mask='@CB', nofit=True) aa_eq(rmsd_1, rmsd_0)
def test_trajectoryiterator_with_transformation(self): traj_on_disk = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) traj_on_mem = pt.load(fn('tz2.nc'), fn('tz2.parm7')) traj_on_disk.superpose(mask='@CA', ref=3) traj_on_mem.superpose(mask='@CA', ref=3) rmsd0_dict = pt.pmap( pt.rmsd_nofit, traj_on_disk, mask='@CB', n_cores=2, ref=0) rmsd1 = pt.rmsd_nofit(traj_on_mem, mask='@CB', ref=0) aa_eq(pt.tools.dict_to_ndarray(rmsd0_dict), [rmsd1])
def test_combine_cpptraj_iterating_with_pytraj(self): traj = pt.iterload("data/tz2.ortho.nc", "data/tz2.ortho.parm7") commands = ['autoimage', 'rms', ] dslist = CpptrajDatasetList() actlist = ActionList(commands, top=traj.top, dslist=dslist) def get_fi(actlist, traj): '''create a frame iterator with pre-processed by cpptraj ''' for frame in traj: actlist.compute(frame) yield frame ref = traj[3] pt.autoimage(ref, top=traj.top) fi = get_fi(actlist, traj) rmsd_nofit_after_fitting = pt.rmsd_nofit(fi, ref=ref, top=traj.top) t0 = traj[:].autoimage().superpose() saved_rmsd_ = pt.rmsd_nofit(t0, ref=ref) aa_eq(rmsd_nofit_after_fitting, saved_rmsd_)