def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") itertraj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") for idx, (f0, f1) in enumerate(izip(traj, itertraj)): assert_almost_equal(f0.xyz, f1.xyz) assert idx == traj.n_frames - 1
def test_1(self): traj = mdio.iterload("./data/ala3.dcd", "./data/ala3.psf") traj.save("./output/_save_charmm_to_amber.x", overwrite=True) # test loading trajamber = mdio.iterload("./output/_save_charmm_to_amber.x", "./data/ala3.psf") for i in range(traj.n_frames): aa_eq(trajamber[i].xyz, traj[i].xyz, decimal=3)
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): # create TrajectoryIter (readonly) traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") # convert to Trajectory fa = traj[:] # frame view f0 = fa[0] aa_eq(f0.xyz, fa[0].xyz) # assign new values f0[0, 0] = 1000. assert f0[0, 0] == 1000. aa_eq(f0.xyz, fa[0].xyz) # sub-Trajectory view fa1 = fa[2:8:2] aa_eq(fa1.xyz, fa[2:8:2].xyz) fa1[0, 0] = 200. assert fa1[0, 0, 0] == 200. assert fa[2, 0, 0] == 200. aa_eq(fa1.xyz, fa[2:8:2].xyz) # make sure we can make a copy facp = fa.copy() facp.xyz[0, 0, 0] = 501. assert facp.xyz[0, 0, 0] == 501. assert fa.xyz[0, 0, 0] != 501.
def main(): # require 'sanderapi' and 'parmed' packages in AmberTools15 # http://ambermd.org/#AmberTools # more info about `sanderapi` in Amber15 manual # http://ambermd.org/doc12/Amber15.pdf (page 341) traj = io.iterload("../tests/data/Tc5b.x", "../tests/data/Tc5b.top") print(traj) edict0 = pyca.energy_decomposition(parm="../tests/data/Tc5b.top", traj=traj, igb=8, input_options=None) print(edict0) # edict1: use default igb=8 edict1 = pyca.energy_decomposition(traj=traj) print(edict1) aa_eq(edict0['tot'], edict1['tot']) # update `input` and get minimal output import sander inp = sander.gas_input(6) edict2 = pyca.energy_decomposition(traj, input_options=inp, mode='minimal') print(edict2)
def test_0(self): import numpy as np traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") fa = traj[:] for i in range(3): fa.append_xyz(fa.xyz) xyz = fa.xyz / 10. fa.xyz = xyz aa_eq(xyz, fa.xyz) # try to build Trajectory from scratch fa2 = Trajectory() fa2.top = fa.top fa2._allocate(fa.n_frames, fa.n_atoms) fa2.xyz = fa.xyz[:] aa_eq(fa2.xyz, fa.xyz) # try to build Trajectory from scratch fa2 = Trajectory(xyz=fa.xyz, top=fa.top) aa_eq(fa2.xyz, fa.xyz) # timing xyz0 = np.empty((fa.n_frames, fa.n_atoms, 3))
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 test_0(self): traj = mdio.iterload("data/Tc5b.x", "data/Tc5b.top") farray = traj[:] traj0_CA = traj[:] traj0_CA.strip("!@CA") # test TrajectoryIterator for idx, f0 in enumerate(traj(mask='@CA')): f1 = traj0_CA[idx] assert_almost_equal(f0.xyz, f1.xyz) # test TrajectoryIterator with indices as mask indices = traj.top("@CA").indices for idx, f0 in enumerate(traj(mask=indices)): f1 = traj0_CA[idx] assert_almost_equal(f0.xyz, f1.xyz) # test Trajectory for idx, f0 in enumerate(farray(mask='@CA')): f1 = traj0_CA[idx] assert_almost_equal(f0.xyz, f1.xyz) # test Trajectory with indices for idx, f0 in enumerate(farray(mask=indices)): f1 = traj0_CA[idx] assert_almost_equal(f0.xyz, f1.xyz) assert idx + 1 == traj0_CA.n_frames
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") frame0 = traj[0] assert frame0._buffer2d[0, 0] == frame0[0, 0] assert frame0._buffer2d[0, 1] == frame0[0, 1] assert frame0._buffer2d[0, 2] == frame0[0, 2] assert frame0._buffer2d[1, 0] == frame0[1, 0] assert frame0._buffer2d[19, 0] == frame0[19, 0] frame0._buffer2d[19, 0] = 1000. # make sure changing _buffer2d will update frame0.xyz too assert frame0._buffer2d[19, 0] == frame0[19, 0] arr0 = np.asarray(frame0._buffer2d) arr0[19] = [200, 300, 400.] assert frame0._buffer2d[19, 0] == frame0[19, 0] == arr0[19, 0] frame1 = frame0.copy() frame1.strip(traj.top("!@CA")) _f = pt.Frame(frame0, traj.top("@CA")) CA_2 = _f[2, :] aa_eq(CA_2, frame1[2, :]) assert frame0._buffer1d.shape == (912, ) assert frame0._buffer2d.shape == (304, 3) assert frame0._buffer1d.is_c_contig() == True frame0._buffer2d[1:3, 0] = array('d', [1., 2.]) aa_eq(frame0[1:3, 0], array('d', frame0._buffer2d[1:3, 0])) aa_eq(frame0._buffer2d[1:3, 0], array('d', frame0._buffer2d[1:3, 0]))
def test_0(self): import numpy as np traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") fa = traj[:] mask = ':1@CA :14@CB :15CA' d0 = pt.calc_angle(traj, mask, dtype='dataset').to_ndarray() d1 = pt.angle(traj, mask) d2 = pt.angle(fa, mask) aa_eq(d0, d1) aa_eq(d0, d2) Nsize = 10 arr = np.random.randint(0, 300, size=Nsize * 3).reshape(Nsize, 3) d3 = pt.angle(fa, arr) d4 = pt.angle(traj, arr) d5 = pt.calc_angle(traj, arr) d6 = pt.calc_angle(fa, arr) d7 = pt.calc_angle([fa, traj], arr, n_frames=2 * fa.n_frames) aa_eq(d3, d4) aa_eq(d3, d5) aa_eq(d3, d6) aa_eq(d3.T, d7.T[:fa.n_frames]) aa_eq(d3.T, d7.T[fa.n_frames:]) d8 = pt.angle(traj, mask, dtype='dataset') d9 = pt.tools.dict_to_ndarray(pt.angle(traj, mask, dtype='dict')) aa_eq(d0, d8.values) aa_eq(d0, d9)
def test_1(self): traj = mdio.iterload(fn('Tc5b.x'), fn('Tc5b.top')) i = 0 for farray in traj.iterchunk(chunksize=4, stop=8): i += 1 assert i == 2 i = 0 for farray in traj.iterchunk(chunksize=4): i += 1 assert i == 3 i = 0 for farray in traj.iterchunk(chunksize=2): i += 1 assert i == 5 i = 0 for farray in traj.iterchunk(start=3, chunksize=4, stop=8): i += 1 assert i == 2 # action on chunk_iter pt.calc_distance( [traj.iterchunk(), traj.iterchunk(), traj[0]], '@CA @CB', top=traj.top) rmsd0 = pt.rmsd(traj.iterchunk(3), ref=traj[-1], top=traj.top) rmsd1 = pt.rmsd(traj, ref=-1) assert_almost_equal(rmsd0, rmsd1)
def test_0(self): traj = mdio.iterload(fn('Tc5b.x'), fn('Tc5b.top')) frame0 = traj[0] assert frame0._buffer2d[0, 0] == frame0[0, 0] assert frame0._buffer2d[0, 1] == frame0[0, 1] assert frame0._buffer2d[0, 2] == frame0[0, 2] assert frame0._buffer2d[1, 0] == frame0[1, 0] assert frame0._buffer2d[19, 0] == frame0[19, 0] frame0._buffer2d[19, 0] = 1000. # make sure changing _buffer2d will update frame0.xyz too assert frame0._buffer2d[19, 0] == frame0[19, 0] arr0 = np.asarray(frame0._buffer2d) arr0[19] = [200, 300, 400.] assert frame0._buffer2d[19, 0] == frame0[19, 0] == arr0[19, 0] frame1 = frame0.copy() frame1.strip(traj.top("!@CA")) _f = pt.Frame(frame0, traj.top("@CA")) CA_2 = _f[2, :] aa_eq(CA_2, frame1[2, :]) assert frame0._buffer1d.shape == (912, ) assert frame0._buffer2d.shape == (304, 3) assert frame0._buffer1d.is_c_contig() == True frame0._buffer2d[1:3, 0] = array('d', [1., 2.]) aa_eq(frame0[1:3, 0], array('d', frame0._buffer2d[1:3, 0])) aa_eq(frame0._buffer2d[1:3, 0], array('d', frame0._buffer2d[1:3, 0]))
def test_1(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") i = 0 for farray in traj.iterchunk(chunksize=4, stop=8): i += 1 assert i == 2 i = 0 for farray in traj.iterchunk(chunksize=4): i += 1 assert i == 3 i = 0 for farray in traj.iterchunk(chunksize=2): i += 1 assert i == 5 i = 0 for farray in traj.iterchunk(start=3, chunksize=4, stop=8): i += 1 assert i == 2 # action on chunk_iter pt.calc_distance( [traj.iterchunk(), traj.iterchunk(), traj[0]], '@CA @CB', top=traj.top) rmsd0 = pt.rmsd(traj.iterchunk(3), ref=traj[-1], top=traj.top) rmsd1 = pt.rmsd(traj, ref=-1) assert_almost_equal(rmsd0, rmsd1)
def test_0(self): import numpy as np traj = mdio.iterload(fn('Tc5b.x'), fn('Tc5b.top')) fa = traj[:] mask = ':1@CA :14@CB :15CA' d0 = pt.calc_angle(traj, mask, dtype='dataset').to_ndarray() d1 = pt.angle(traj, mask) d2 = pt.angle(fa, mask) aa_eq(d0, d1) aa_eq(d0, d2) Nsize = 10 arr = np.random.randint(0, 300, size=Nsize * 3).reshape(Nsize, 3) d3 = pt.angle(fa, arr) d4 = pt.angle(traj, arr) d5 = pt.calc_angle(traj, arr) d6 = pt.calc_angle(fa, arr) d7 = pt.calc_angle([fa, traj], arr, n_frames=2 * fa.n_frames) aa_eq(d3, d4) aa_eq(d3, d5) aa_eq(d3, d6) aa_eq(d3.T, d7.T[:fa.n_frames]) aa_eq(d3.T, d7.T[fa.n_frames:]) d8 = pt.angle(traj, mask, dtype='dataset') d9 = pt.tools.dict_to_ndarray(pt.angle(traj, mask, dtype='dict')) aa_eq(d0, d8.values) aa_eq([d0], d9)
def test_IterWithMask(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") farray = traj[:] for frame in farray(mask='@CA'): pass f0 = traj[-1] f0.strip(traj.top('!@CA')) assert_almost_equal(f0.xyz, frame.xyz)
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") indices = traj.top("@CA").indices for frame in traj(mask=indices): pass for frame in traj(mask=[1, 5, 8, 10]): pass
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") f0 = traj[0] # creat new frame based on f0 and atommask f1 = Frame(f0, traj.top('@CA')) atm = AtomMask("") traj.top.set_integer_mask(atm)
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") # += f0 = traj[0].copy() xyz = f0.xyz.copy() f0 += 1. aa_eq(f0.xyz, xyz + 1.) # -= f0 = traj[0].copy() xyz = f0.xyz.copy() f0 -= 1. aa_eq(f0.xyz, xyz - 1.) # *= f0 = traj[0].copy() xyz = f0.xyz.copy() f0 *= 2. aa_eq(f0.xyz, xyz * 2) # /= single value f0 = traj[0].copy() xyz = f0.xyz.copy() f0 /= 2. aa_eq(f0.xyz, xyz / 2) # /= other Frame f0 = traj[0].copy() xyz = f0.xyz.copy() f1 = traj[1].copy() xyz1 = f1.xyz.copy() f0 /= f1 aa_eq(f0.xyz, xyz / xyz1) # + f0 = traj[0].copy() xyz = f0.xyz.copy() f1 = f0 + 1. aa_eq(f1.xyz, xyz + 1.) # - f0 = traj[0].copy() xyz = f0.xyz.copy() f1 = f0 - 1. aa_eq(f1.xyz, xyz - 1.) # * f0 = traj[0].copy() xyz = f0.xyz.copy() f1 = f0 * 10. aa_eq(f1.xyz, xyz * 10.) # / f0 = traj[0].copy() xyz = f0.xyz.copy() f1 = f0 / 10. aa_eq(f1.xyz, xyz / 10.)
def test_0(self): import numpy as np traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") f0 = traj[0] arr0 = np.asarray(f0._buffer2d) arr1 = np.asarray(f0) aa_eq(arr0.flatten(), arr1.flatten()) arr0[0, 0] = 100. aa_eq(arr0.flatten(), arr1.flatten()) aa_eq(arr0.flatten(), f0.xyz.flatten())
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") top = traj.top mlist = [] for atom in top: mlist.append(atom.mass) mlist = array('d', mlist) assert_almost_equal(top.mass, mlist)
def test_1(self): # why Trajectory is here? because I am lazy to move mask = "@CA" # creat Trajectory ( [:] ) traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top")[:] top = traj.top atm = traj.top(mask) newtraj = traj[atm] newtraj2 = traj[mask + ' :frame'] assert_almost_equal(newtraj2.xyz.flatten(), newtraj.xyz.flatten()) assert_almost_equal(newtraj2.xyz.flatten(), newtraj.xyz.flatten())
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") frame0 = traj[0] assert frame0.has_box() == False box = frame0.box assert frame0.box.type == 'nobox' bview = frame0._boxview bview[3:] = np.asarray([109.471220634, 109.471220634, 109.471220634]) bview[:3] = np.array([100, 100, 100], dtype='f8') assert frame0.box.type == 'truncoct'
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_2(self): from pytraj import iterframe_master as frame_iter traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") farray = traj[:] count = 0 for frame in frame_iter(traj): count += 1 assert_almost_equal(frame.xyz, traj[-1].xyz) count = 0 for frame in frame_iter(farray): count += 1 assert_almost_equal(frame.xyz, traj[-1].xyz)
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_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") if has_("numpy"): import numpy as np from numpy.testing import assert_almost_equal arr0 = traj.xyz aa_eq(arr0, traj[:, :, :].xyz) # create Trajectory farray = traj[:] aa_eq(arr0, farray[:, :, :].xyz) else: pass
def test_4(self): """test write Trajectory""" farray = pt.load("data/Tc5b.x", "./data/Tc5b.top", frame_indices=list(range(10))) pt.write_traj("./output/test_write_output.x", farray, top=farray.top, overwrite=True) pt.write_traj("./output/test_pdb_1.dummyext", farray[0], top=farray.top, overwrite=True) # test 'save' farray.save("./output/test_write_output_save_method.x", overwrite=True) # reproduce result? f0 = mdio.iterload("./output/test_write_output.x", "./data/Tc5b.top") f1 = mdio.iterload("./output/test_write_output_save_method.x", "./data/Tc5b.top") aa_eq(f0[:, :, :].xyz, f1[:, :, :].xyz)
def test_0(self): import numpy as np traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") # 3 atoms x 2 arr = np.array([[12, 13, 15], [16, 17, 18]]) f0saved = traj[0].copy() f0 = traj[0].copy() f0.swap_atoms(arr) aa_eq(f0saved[12], f0[16]) aa_eq(f0saved[13], f0[17]) aa_eq(f0saved[15], f0[18])
def test_0(self): traj = mdio.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7") fa1 = traj[:] # do inplace-autoimage for Trajectory fa1.autoimage() # fa2 will store frame when iterating `traj` (TrajectoryIterator) fa2 = Trajectory() fa2.top = traj.top.copy() # frame_iter for frame in traj(autoimage=True): fa2.append(frame) aa_eq(fa1.xyz, fa2.xyz) # frame_iter with mask and autoimage fa3 = fa2.copy() # fa3 is a copy of autoimaged fa2. then we strip all but CA atoms # just want to make sure we can use `mask` fa3.strip("!@CA") fa4 = Trajectory() fa4.top = fa3.top.copy() for frame in traj(mask='@CA', autoimage=True): fa4.append(frame) aa_eq(fa3.xyz, fa4.xyz) # frame_iter with mask and autoimage, and rmsfit # fa3 is a copy of autoimaged fa2. then we strip all but CA atoms # just want to make sure we can use `mask` fa3 = traj[:] fa3.autoimage() fa3.rmsfit(ref=5, mask='@CB') fa3.strip("!@CA") fa4 = Trajectory() fa4.top = fa3.top.copy() ref1 = traj[5].copy() for frame in traj(mask='@CA', autoimage=True, rmsfit=(ref1, '@CB')): fa4.append(frame) aa_eq(fa3.xyz, fa4.xyz) for f0, f1 in zip(fa3, fa4): assert f0.rmsd_nofit(f1) < 1E-7
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)
def test_0(self): from pytraj import DatasetList traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") from pytraj.all_actions import calc_multidihedral command = "resrange 2-19 phi psi" d0 = calc_multidihedral(traj, command) d1 = calc_multidihedral(traj, command) assert isinstance(d0, DatasetList) == True assert (len(d0.keys()) == len(d1.keys())) d3 = calc_multidihedral(traj) import numpy as np d0np = calc_multidihedral(traj, command, dtype='ndarray') self.assertIsInstance(d0np, np.ndarray)
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") start, stop, stride = 0, 8, 2 indices = list(range(start, stop, stride)) flist = [] count = 0 for i, frame in enumerate(traj[:stop + 1]): count += 1 if i in indices: flist.append(frame) if i > stop: traj.end_traj()
def test_0(self): flist = glob("./data/Test_RemdTraj/rem.nc.*") trajlist = [] for fh in flist: topfile = "./data/Test_RemdTraj/ala2.99sb.mbondi2.parm7" trajlist.append(mdio.iterload(fh, topfile)) Tset = set([]) f4922 = Trajectory() f4922._allocate(trajlist[0].n_frames, trajlist[0].n_atoms) f4922.top = trajlist[0].top.copy() for traj in trajlist: for idx, frame in enumerate(traj): if frame.temperature == 492.2: f4922[idx] = frame # make sure we reproduce cpptraj output cpptraj = mdio.iterload("./data/Test_RemdTraj/temp0.crd.492.20", topfile) for idx, framepy in enumerate(f4922): assert_almost_equal(framepy.xyz, cpptraj[idx].xyz, decimal=3)
def test_0(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") farray = traj[:] xyz_save = farray[0].xyz.copy() farray[9].xyz[:] = farray[0].xyz assert_almost_equal(farray[9].xyz, farray[0].xyz) assert_almost_equal(farray[9].xyz, xyz_save.flatten()) f0 = Frame(traj.n_atoms) f0.xyz[:] = farray[0].xyz f1 = Frame() f1.append_xyz(farray[0].xyz) assert_almost_equal(f1.xyz, farray[0].xyz)
def test_1(self): traj = mdio.iterload("./data/Tc5b.x", "./data/Tc5b.top") act = adict['distance'] dslist = DatasetList() act.read_input(":2@CA :10@CA", traj.top, dslist=dslist) act.check_topology(traj.top) for frame in traj.iterframe(stop=5): act.compute(frame) dslist = DatasetList() act2 = adict['distance'] act2.read_input(":2@CA :10@CA", traj.top, dslist=dslist) act2.check_topology(traj.top) act2.compute(traj.iterframe(stop=5)) assert act2.n_frames == 5
def test_0(self): dslist = CpptrajDatasetList() traj = mdio.iterload(fn('Tc5b.x'), fn('Tc5b.top')) calc_distance = adict['distance'] act = calc_distance act.read_input(":2@CA :10@CA", traj.top, dslist=dslist) act.setup(traj.top) act.compute((traj.iterchunk(2), )) assert dslist.size == 1 assert dslist[0].size == traj.n_frames cppout = np.loadtxt( fn('CAres2_CAres10.Tc5b.dat'), skiprows=1).transpose()[1] assert_almost_equal(dslist[0][:], cppout) act.compute((traj.iterchunk(chunksize=4, stop=8), ))