def test_run_0(self): # load traj farray = pt.load(filename="./data/tz2.truncoct.nc", top="./data/tz2.truncoct.parm7")[:2] fold = farray.copy() act = allactions.Action_Image() ptrajin = """ center :2-11 image center familiar com :6 """ # create 'strip' action stripact = allactions.Action_Strip() # creat datasetlist to hold distance data dsetlist = CpptrajDatasetList() dflist = DataFileList() # creat ActionList to hold actions alist = ActionList() top = farray.top # add two actions: Action_Strip and Action_Distance alist.add(allactions.Action_Center(), ArgList(":2-11"), top=top) alist.add(allactions.Action_Image(), ArgList("center familiar com :6"), top=top) # do checking alist.check_topology(top) farray2 = Trajectory() frame0 = Frame() # testing how fast to do the actions # loop all frames # use iterator to make faster loop # don't use "for i in range(farray.n_frames)" for frame in farray: # perform actions for each frame # we make a copy since we want to keep orginal Frame frame0 = frame.copy() alist.compute(frame0) # we need to keep the modified frame in farray2 farray2.append(frame0) # make sure that Action_Strip does its job in stripping assert farray2.n_frames == farray.n_frames fsaved = pt.iterload(cpptraj_test_dir + "/Test_Image/image4.crd.save", "data/tz2.truncoct.parm7") assert fsaved.n_frames == 2
def test_run_0(self): # load traj farray = pt.load(filename="./data/tz2.truncoct.nc", top="./data/tz2.truncoct.parm7")[:2] fold = farray.copy() act = allactions.Action_Image() ptrajin = """ center :2-11 image center familiar com :6 """ # create 'strip' action stripact = allactions.Action_Strip() # creat datasetlist to hold distance data dsetlist = CpptrajDatasetList() dflist = DataFileList() # creat ActionList to hold actions alist = ActionList() top = farray.top # add two actions: Action_Strip and Action_Distance alist.add(allactions.Action_Center(), ArgList(":2-11"), top=top) alist.add(allactions.Action_Image(), ArgList("center familiar com :6"), top=top) # do checking alist.check_topology(top) farray2 = Trajectory() frame0 = Frame() # testing how fast to do the actions # loop all frames # use iterator to make faster loop # don't use "for i in range(farray.n_frames)" for frame in farray: # perform actions for each frame # we make a copy since we want to keep orginal Frame frame0 = frame.copy() alist.compute(frame0) # we need to keep the modified frame in farray2 farray2.append(frame0) # make sure that Action_Strip does its job in stripping assert farray2.n_frames == farray.n_frames fsaved = pt.iterload(cpptraj_test_dir + "/Test_Image/image4.crd.save", "data/tz2.truncoct.parm7") assert fsaved.n_frames == 2
def load_MDAnalysis(universe, top=None): """load MDAnalysis' Universe object to pytra's traj object Notes ----- All coords will be loaded See Also -------- load_MDAnalysisIterator """ from MDAnalysis import Universe from pytraj.Trajectory import Trajectory from ..Frame import Frame # don't import here since we import load_pseudo_parm in # TrajectoryMDAnalysisIterator # MDAnalysis needs numpy. So we always have numpy when using this if not isinstance(universe, Universe): raise ValueError("must be a Universe") # creat pseudotop if top is None: raise ValueError("need a Topology or pdb/mol2/...") else: pseudotop = top # creat atom group ag = universe.atoms farray = Trajectory() farray.top = pseudotop for _ in universe.trajectory: frame = Frame(farray.top.n_atoms) # set box for each Frame frame.boxview[:] = farray.top.box[:] # load xyz coords, let numpy do automatically casting frame.xyz[:] = ag.positions # we don't need to make copy=True since we already created # frame and `farray` can 'keep' it farray.append(frame, copy=False) return farray
def load_MDAnalysis(its_obj, top=None): """load MDAnalysis' Universe object to pytra's traj object Notes ----- All coords will be loaded See Also -------- load_MDAnalysisIterator """ from MDAnalysis import Universe from pytraj.Trajectory import Trajectory from ..Frame import Frame # don't import here since we import load_pseudo_parm in # TrajectoryMDAnalysisIterator # MDAnalysis needs numpy. So we always have numpy when using this if not isinstance(its_obj, Universe): raise ValueError("must be a Universe") # creat pseudotop if top is None: raise ValueError("need a Topology or pdb/mol2/...") else: pseudotop = top # creat atom group ag = its_obj.atoms farray = Trajectory() farray.top = pseudotop for _ in its_obj.trajectory: frame = Frame(farray.top.n_atoms) # set box for each Frame frame.boxview[:] = farray.top.box[:] # load xyz coords, let numpy do automatically casting frame.xyz[:] = ag.positions # we don't need to make copy=True since we already created # frame and `farray` can 'keep' it farray.append(frame, copy=False) return farray