def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") mdio.write_traj("test_1.pdb", traj[0], top=traj.top, overwrite=True) mdio.write_traj("test_1.dcd", traj[0], top=traj.top, overwrite=True) with TrajectoryWriter("./output/test_1", overwrite=True) as trajout: trajout.write(traj[0])
def save(self, filename='', overwrite=False, options='', *args, **kwd): '''save to different file format. Notes ----- FrameIterator will be exhausted since this is an iterator. Examples -------- >>> import pytraj as pt >>> traj = pt.load_sample_data('tz2') >>> fi = traj(2, 8, 2, mask='@CA') >>> fi.save('output/test.nc', overwrite=True) >>> # short version >>> traj(2, 8, 2, mask='@CA').save('output/test.nc', overwrite=True) ''' from pytraj.io import write_traj write_traj(filename=filename, traj=self, top=self.top, frame_indices=None, overwrite=overwrite, options=options, *args, **kwd)
def test_load_and_save_0(self): traj = mdio.iterload(filename="./data/Tc5b.x", top="./data/Tc5b.top")[:10] indices = list(range(2, 3, 5)) + [3, 8, 9, 8] mdio.write_traj(filename="./output/test_io_saved_.x", traj=traj, top="./data/Tc5b.top", frame_indices=indices, overwrite=True) # check frames traj2 = mdio.iterload(filename="./output/test_io_saved_.x", top="./data/Tc5b.top") assert traj2.n_frames == len(indices)
def test_0(self): trajlist = [] N = 4 for i in range(N): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") trajlist.append(traj) traj0 = trajlist[0] mdio.write_traj("./output/test_savedtrajlist.x", traj=trajlist, top=traj.top, overwrite=True) # test loading traj2 = mdio.iterload("./output/test_savedtrajlist.x", traj.top) Nsize = int(traj2.n_frames / 4) traj0_new = traj2[:Nsize] for frame0, frame0_new in zip(traj0, traj0_new): assert (frame0.rmsd(frame0_new) < 1E-3)
def test_trajlist(self): trajlist = [] N = 4 for i in range(N): traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top')) trajlist.append(traj) traj0 = trajlist[0] with tempfolder(): pt.write_traj("test_savedtrajlist.x", traj=trajlist, top=traj.top, overwrite=True) # test loading traj2 = pt.iterload("test_savedtrajlist.x", traj.top) Nsize = int(traj2.n_frames / 4) traj0_new = traj2[:Nsize] for frame0, frame0_new in zip(traj0, traj0_new): assert (frame0.rmsd(frame0_new) < 1E-3)
def test_1(self): # TODO: get absolute path so we can use `tempfolder` # if not: wrong dir if using TrajectoryIterator traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top")[:] trajout = TrajectoryWriter() # multiple pdb in multiple files, using `save` method in traj with tempfolder(): basename = "test_pdb_files.pdb" traj.save(basename, overwrite=True, options="multi") for i in range(10): fname = basename + "." + str(i + 1) # cpptraj use `1` frame = mdio.iterload(fname, traj.top)[0] aa_eq(frame.xyz, traj[i].xyz) # multiple pdb in multiple files, using `mdio.write_traj` with tempfolder(): basename = "test_pdb_files_mdio_write_traj.pdb" mdio.write_traj(basename, traj, overwrite=True, options="multi") for i in range(10): fname = basename + "." + str(i + 1) # cpptraj use `1` frame = pt.iterload(fname, traj.top)[0] aa_eq(frame.xyz, traj[i].xyz) # multiple pdb in SINGLE file with tempfolder(): basename = "test_pdb_files.pdb" traj.save(basename, overwrite=True) traj2 = mdio.load(basename, traj.top) aa_eq(traj.xyz, traj2.xyz) # multiple pdb in SINGLE file with `model` keyword # write to output so we can manually check basename = "./output/test_pdb_files_model.pdb" traj.save(basename, overwrite=True, options='model') traj3 = mdio.load(basename, traj.top) aa_eq(traj.xyz, traj3.xyz)
def test_1(self): # TODO: get absolute path so we can use `tempfolder` # if not: wrong dir if using TrajectoryIterator traj = mdio.iterload("../tests/data/Tc5b.x", "../tests/data/Tc5b.top")[:] trajout = TrajectoryWriter() # multiple pdb in multiple files, using `save` method in traj with tempfolder(): basename = "test_pdb_files.pdb" traj.save(basename, overwrite=True, options="multi") for i in range(10): fname = basename + "." + str(i + 1) # cpptraj use `1` frame = mdio.iterload(fname, traj.top)[0] aa_eq(frame.xyz, traj[i].xyz) # multiple pdb in multiple files, using `mdio.write_traj` with tempfolder(): basename = "test_pdb_files_mdio_write_traj.pdb" mdio.write_traj(basename, traj, overwrite=True, options="multi") for i in range(10): fname = basename + "." + str(i + 1) # cpptraj use `1` frame = mdio.iterload(fname, traj.top)[0] aa_eq(frame.xyz, traj[i].xyz) # multiple pdb in SINGLE file with tempfolder(): basename = "test_pdb_files.pdb" traj.save(basename, overwrite=True) traj2 = mdio.load(basename, traj.top) aa_eq(traj.xyz, traj2.xyz) # multiple pdb in SINGLE file with `optionsl` keyword # write to output so we can manually check basename = "./output/test_pdb_files_model.pdb" traj.save(basename, overwrite=True, options='model') traj3 = mdio.load(basename, traj.top) aa_eq(traj.xyz, traj3.xyz)