def test_trajiter_with_actionlist(self): traj = pt.iterload(fn('tz2.ortho.nc'), fn('tz2.ortho.parm7')) traj.autoimage().center('origin').superpose('@CA') pk_fn = 'test.pk' pt.to_pickle(traj, pk_fn) traj2 = pt.read_pickle(pk_fn) print(traj2._transform_commands) aa_eq(traj.xyz, traj2.xyz)
def test_pickle_frame(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) f0 = traj[0] print(f0.mass) fn = 'f.pk' pt.to_pickle(f0, fn) f1 = pt.read_pickle(fn) print(f1.mass)
def test_pickle_frame(self): traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") f0 = traj[0] print(f0.mass) fn = 'output/f.pk' pt.to_pickle(f0, fn) f1 = pt.read_pickle(fn) print(f1.mass)
def test_nupars(self): pdb_fn = fn('Test_NAstruct/adh026.3.pdb') traj = pt.iterload(pdb_fn, pdb_fn) data = pt.nastruct(traj) # default text = ''' parm {} trajin {} nastruct groovecalc 3dna '''.format(fn('Test_NAstruct/adh026.3.pdb'), fn('Test_NAstruct/adh026.3.pdb')) state = pt.load_cpptraj_state(text) state.run() for key in ['major', 'minor', 'twist']: cpp_data = np.array( [x.values for x in state.data if x.aspect == key]) # need to transpose to get shape=(n_frames, n_pairs) cpp_data = cpp_data.T aa_eq(data[key][1], cpp_data) # TODO: assert data._summary(np.mean, indices=None) data._summary(np.mean, indices=[ 1, ]) data._summary(np.mean, keys=['major', 'twist'], indices=[ 1, ]) data._summary(np.mean, keys='major', indices=[ 1, ]) data._summary(np.std, indices=[ 1, ]) data._summary([np.std, np.mean], indices=[ 1, ]) data._explain() dir(data) # pickle pt.to_pickle(data, 'na.pk') na2 = pt.read_pickle('na.pk') for key in data.keys(): aa_eq(data[key][1], na2[key][1]) # raise self.assertRaises(ValueError, lambda: pt.nastruct(traj, dtype='ndarray'))
def test_pickle_progress_bar(): traj = pt.datafiles.load_tz2() with tempfolder(): t2 = ProgressBarTrajectory(traj) pt.to_pickle(t2, 'test.pk') t3 = pt.read_pickle('test.pk') data0 = pt.rmsd(traj) data1 = pt.rmsd(t2) data2 = pt.rmsd(t3) aa_eq(data0, data1) aa_eq(data0, data2)
def test_frame(self): traj = pt.iterload("data/Tc5b.x", "data/Tc5b.top") frame = traj[0] pt.to_pickle(frame, 'output/frame.pk') frame0 = pt.read_pickle('output/frame.pk') aa_eq(frame0.xyz, frame.xyz) # test list of frames fname = 'output/flist.pk' pt.to_pickle([traj[0], traj[1]], fname) f01 = pt.read_pickle(fname) aa_eq(np.array([f.xyz for f in f01]), traj[[0, 1]].xyz)
def test_frame(self): traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top')) frame = traj[0] pt.to_pickle(frame, 'frame.pk') frame0 = pt.read_pickle('frame.pk') aa_eq(frame0.xyz, frame.xyz) # test list of frames fname = 'flist.pk' pt.to_pickle([traj[0], traj[1]], fname) f01 = pt.read_pickle(fname) aa_eq(np.array([f.xyz for f in f01]), traj[[0, 1]].xyz)
def test_nupars(self): fn = "./data/Test_NAstruct/adh026.3.pdb" traj = pt.iterload(fn, fn) data = pt.nastruct(traj) # default text = ''' parm "./data/Test_NAstruct/adh026.3.pdb" trajin "./data/Test_NAstruct/adh026.3.pdb" nastruct groovecalc 3dna ''' state = pt.load_cpptraj_state(text) state.run() for key in ['major', 'minor', 'twist']: cpp_data = np.array([x.values for x in state.data if x.aspect == key]) # need to transpose to get shape=(n_frames, n_pairs) cpp_data = cpp_data.T aa_eq(data[key][1], cpp_data) # TODO: assert data._summary(np.mean, indices=None) data._summary(np.mean, indices=[1, ]) data._summary(np.mean, keys=['major', 'twist'], indices=[1, ]) data._summary(np.mean, keys='major', indices=[1, ]) data._summary(np.std, indices=[1, ]) data._summary([np.std, np.mean], indices=[1, ]) data._explain() dir(data) # pickle pt.to_pickle(data, 'data/na.pk') na2 = pt.read_pickle('data/na.pk') for key in data.keys(): aa_eq(data[key][1], na2[key][1]) # raise self.assertRaises(ValueError, lambda: pt.nastruct(traj, dtype='ndarray'))
# load pytraj and mpi4py import pytraj as pt from mpi4py import MPI # create mpi handler to get cpu rank comm = MPI.COMM_WORLD # load trajectory # create filenames (could be a single filename or a list of filenames that cpptraj supported) # (restart file, pdb, netcdf, mdcrd, dcd, ...) # check more: http://amber-md.github.io/pytraj/latest/trajectory_exercise.html filenames = ['fn1.pdb', 'fn2.pdb',] topology_name = 'fn1.parm7' traj = pt.iterload(filenames, top=topology_name) # perform parallel calculation data = pt.pmap_mpi(pt.energy_decomposition, traj, igb=8) # data is a Python dict, it's up to you to save the data # you can use pt.to_pickle to save the dict to disk and then use pt.read_pickle to reload the dict # use rank == 0 since pytraj sends output to first cpu. if comm.rank == 0: #print(data) pt.to_pickle(data, 'my_data.pk') # reload for another analysis # data = pt.read_pickle('my_data.pk')
def test_pickle_datasetlist(self): traj = pt.iterload("data/Tc5b.x", "data/Tc5b.top") dslist = pt.multidihedral(traj) pt.to_pickle(dslist, 'output/ds.pk') dslist2 = pt.read_pickle('output/ds.pk') aa_eq(dslist.values, dslist2.values)
else: pdb_dirs[index] = pdb # get min filenames _min_files = [ pdb_dir + '/no_restraint/' + 'min_NoH_' + x for pdb_dir, x in zip(pdb_dirs, df[2]) ] end = '_0001' min_files = [] for mf in _min_files: if '0001_0001' in mf: min_files.append(mf.replace('0001_0001', '0001') + '.rst7') elif '0002_0001' in mf: min_files.append(mf.replace('0002_0001', '0002') + '.rst7') else: min_files.append(mf) epots = [] for pdb_dir, mf in zip(pdb_dirs, min_files): if os.path.exists(mf): parmfile = glob(pdb_dir + '/*.parm7')[0] traj = pt.iterload(mf, parmfile) epots.append(pt.energy_decomposition(traj, igb=8)['tot'][0]) else: epots.append(None) pt.to_pickle(epots, 'epots.pk')
def test_picle(self): '''test_picle ''' pt.to_pickle(self.traj.top, 'output/new_top.pk') new_top = pt.read_pickle('output/new_top.pk') assert_equal_topology(self.traj.top, new_top, self.traj)
def pick_topology_(top): pt.to_pickle(top, 'test.pk')
def test_pickle_datasetlist(self): traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top')) dslist = pt.multidihedral(traj) pt.to_pickle(dslist, 'ds.pk') dslist2 = pt.read_pickle('ds.pk') aa_eq(dslist.values, dslist2.values)
def test_picle(self): '''test_picle ''' pt.to_pickle(self.traj.top, 'new_top.pk') new_top = pt.read_pickle('new_top.pk') assert_equal_topology(self.traj.top, new_top, self.traj)
def main(): from MMPBSA_mods import API as MMPBSA_API data = MMPBSA_API.load_mmpbsa_info('_MMPBSA_info') decomp_data = data['decomp']['gb']['complex']['TDC'] pt.to_pickle(decomp_data, 'energy_per_residue_per_structure.pk')
elif 'decoys.set2' in pdb: pdb_dirs[index] = pdb.replace('decoys.set2', 'decoys.set2.init') else: pdb_dirs[index] = pdb # get min filenames _min_files = [pdb_dir + '/no_restraint/' + 'min_NoH_' + x for pdb_dir, x in zip(pdb_dirs, df[2])] end = '_0001' min_files = [] for mf in _min_files: if '0001_0001' in mf: min_files.append(mf.replace('0001_0001', '0001') + '.rst7') elif '0002_0001' in mf: min_files.append(mf.replace('0002_0001', '0002') + '.rst7') else: min_files.append(mf) epots = [] for pdb_dir, mf in zip(pdb_dirs, min_files): if os.path.exists(mf): parmfile = glob(pdb_dir + '/*.parm7')[0] traj = pt.iterload(mf, parmfile) epots.append(pt.energy_decomposition(traj, igb=8)['tot'][0]) else: epots.append(None) pt.to_pickle(epots, 'epots.pk')