def setUp(self): self.traj = pt.iterload(fn("tz2.nc"), fn("tz2.parm7")) cm_avg = ''' average avg.pdb run ''' pt.load_batch(self.traj, cm_avg).run()
def test_loading(self): for frame_slice in [(0, -1, 1), (0, 8, 2), (3, 9, 3)]: traj = pt.iterload('data/tz2.nc', './data/tz2.parm7', frame_slice=frame_slice) # load from text text = ''' rms @CA radgyr @CA nomax ''' s = load_batch(traj, text) s.run() rmsd0 = pt.rmsd(traj, '@CA', ref=0) r0 = pt.radgyr(traj, '@CA') s.data._pop(0) aa_eq(rmsd0, s.data[0]) aa_eq(r0, s.data[1]) assert len(s.data[0]) == traj.n_frames # load from list lines = ['rms @CA', ' radgyr @CA nomax'] s = load_batch(traj, lines) s.run() s.data._pop(0) rmsd0 = pt.rmsd(traj, '@CA', ref=0) r0 = pt.radgyr(traj, '@CA') aa_eq(rmsd0, s.data[0]) aa_eq(r0, s.data[1]) assert len(s.data[0]) == traj.n_frames
def test_loading(self): for frame_slice in [(0, -1, 1), (0, 8, 2), (3, 9, 3)]: traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'), frame_slice=frame_slice) # load from text text = ''' rms @CA radgyr @CA nomax ''' s = load_batch(traj, text) s.run() rmsd0 = pt.rmsd(traj, '@CA', ref=0) r0 = pt.radgyr(traj, '@CA') s.data._pop(0) aa_eq(rmsd0, s.data[0]) aa_eq(r0, s.data[1]) assert len(s.data[0]) == traj.n_frames # load from list lines = ['rms @CA', ' radgyr @CA nomax'] s = load_batch(traj, lines) s.run() s.data._pop(0) rmsd0 = pt.rmsd(traj, '@CA', ref=0) r0 = pt.radgyr(traj, '@CA') aa_eq(rmsd0, s.data[0]) aa_eq(r0, s.data[1]) assert len(s.data[0]) == traj.n_frames
def test_nomass(self): traj = self.traj # cpptraj output cm = ''' reference avg.pdb rms R0 reference @CA,C,N,O savematrices ''' state = pt.load_batch(traj, cm) state.run() saved_mat = state.data[-1].values # pytraj output avg = pt.mean_structure(traj) mat = pt.calc_rotation_matrix(traj, ref=avg, mask='@CA,C,N,O') assert mat.shape == (traj.n_frames, 3, 3), 'mat shape' aa_eq(mat.flatten(), saved_mat.flatten()) # not specify reference cm = ''' rms R0 @CA,C,N,O savematrices ''' state = pt.load_batch(traj, cm) state.run() saved_mat = state.data[-1].values mat = pt.calc_rotation_matrix(traj, mask='@CA,C,N,O') aa_eq(mat.flatten(), saved_mat.flatten())
def setUp(self): self.traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") cm_avg = ''' average avg.pdb run ''' pt.load_batch(self.traj, cm_avg).run()
def test_raise_if_not_trajiter(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) t0 = traj[:] text = ''' rms @CA radgyr @CA nomax ''' with pytest.raises(ValueError): load_batch(t0, text)
def test_frame_indices(self): traj = pt.iterload("data/tz2.truncoct.nc", "data/tz2.truncoct.parm7") traj2 = pt.iterload("data/tz2.truncoct.nc", "data/tz2.truncoct.parm7", frame_slice=(2, 8)) txt = ''' reference ./data/tz2.truncoct.nc 2 2 rmsd :2-11 refindex 0 perres perresout center.agr range 1 perrescenter ''' state = pt.load_batch(traj2, txt) state.run() frame_indices = range(2, 8) rmsd0 = pt.rmsd(traj, ref=1, mask=':2-11', frame_indices=frame_indices) rmsdperres = pt.rmsd_perres(traj, ref=1, mask=':2-11', perres_mask='*', resrange='1', perres_center=True, frame_indices=frame_indices) aa_eq(rmsd0, state.data[2]) aa_eq(rmsdperres[1], state.data[3].values)
def normal_(traj=traj): print('serial') state = pt.load_batch(traj, ''' matrix dist @P ''') state.run() return state.data[1:].values
def normal_(traj=traj): print('serial') state = pt.load_batch(traj, ''' rms !:WAT ''') state.run() return state.data[1:].values
def test_multivector(self): traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") state = pt.load_batch(traj, ''' multivector resrange 3-7 name1 C name2 N ''') state.run() cpp_data = state.data[1:].values aa_eq( pt.multivector(traj, resrange='3-7', names=('C', 'N'), dtype='ndarray'), cpp_data) aa_eq( pt.multivector(traj, resrange='3-7', names='C N', dtype='ndarray'), cpp_data) aa_eq( pt.multivector(traj, resrange='3-7', names='name1 C name2 N', dtype='ndarray'), cpp_data)
def test_diagmatrix(self): traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") state = pt.load_batch(traj, ''' #matrix covar @CA name mymat matrix dist @CA name mymat diagmatrix mymat vecs 6''') state.run() mat = state.data['mymat'] cpp_evals, cpp_evecs = state.data[-1].eigenvalues, state.data[ -1].eigenvectors # test triu_indices mat2 = mat.__class__() indices = np.triu_indices(mat.n_cols) mat2._set_data_half_matrix(mat._to_cpptraj_sparse_matrix(), mat.size, mat.n_cols) # OK data = matrix.diagonalize(mat.values, n_vecs=6, dtype='dataset')[-1] data2 = matrix.diagonalize(mat, n_vecs=6, dtype='dataset')[0] aa_eq(data.eigenvalues, cpp_evals, decimal=10) aa_eq(data2.eigenvalues, cpp_evals, decimal=10) # try numpy np_vals, np_vecs = np.linalg.eigh(mat2.values, UPLO='U') np_vals = np_vals[::-1][:6] np_vecs = np_vecs[:, ::-1].T[:6] # at least the absolute values are equal aa_eq(np.abs(data.eigenvectors), np.abs(cpp_evecs)) aa_eq(np.abs(np_vecs), np.abs(cpp_evecs)) # test raise if not having supported dtype self.assertRaises(ValueError, lambda: pt.matrix.diagonalize(mat, 3, dtype='ndarray')) # plot def plot_(): try: from pytraj.plot import plot_matrix from matplotlib import pyplot as plt fig, ax, bar = plot_matrix(np.abs(data.eigenvectors) - np.abs( cpp_evecs)) fig.colorbar(bar) plt.title('data vs cpp_evecs') fig, ax, bar = plot_matrix(np.abs(np_vecs) - np.abs(cpp_evecs)) fig.colorbar(bar) plt.title('np vs cpp_evecs') fig, ax, bar = plot_matrix(np.abs(np_vecs) - np.abs( data.eigenvectors)) fig.colorbar(bar) plt.title('np vs data') pt.show() except ImportError: pass
def test_mass(self): traj = self.traj # cpptraj output cm = ''' reference avg.pdb rms R0 reference @CA,C,N,O savematrices mass ''' state = pt.load_batch(traj, cm) state.run() saved_mat = state.data[-1].values # pytraj output avg = pt.mean_structure(traj) mat = pt.calc_rotation_matrix(traj, ref=avg, mask='@CA,C,N,O', mass=True) assert mat.shape == (traj.n_frames, 3, 3), 'mat shape' aa_eq(mat.flatten(), saved_mat.flatten()) # with rmsd avg = pt.mean_structure(traj) mat2, rmsd_ = pt.calc_rotation_matrix(traj, ref=avg, mask='@CA,C,N,O', mass=True, with_rmsd=True) aa_eq(mat2.flatten(), saved_mat.flatten()) assert pt.tools.rmsd(rmsd_, state.data['R0']) < 1E-3
def test_frame_indices(self): traj = pt.iterload(fn("tz2.truncoct.nc"), fn("tz2.truncoct.parm7")) traj2 = pt.iterload(fn("tz2.truncoct.nc"), fn("tz2.truncoct.parm7"), frame_slice=(2, 8)) txt = ''' reference {} 2 2 rmsd :2-11 refindex 0 perres perresout center.agr range 1 perrescenter '''.format(fn('tz2.truncoct.nc')) state = pt.load_batch(traj2, txt) with tempfolder(): state.run() frame_indices = range(2, 8) rmsd0 = pt.rmsd(traj, ref=1, mask=':2-11', frame_indices=frame_indices) rmsdperres = pt.rmsd_perres(traj, ref=1, mask=':2-11', perres_mask='*', resrange='1', perres_center=True, frame_indices=frame_indices) aa_eq(rmsd0, state.data[2]) aa_eq(rmsdperres[1], state.data[3].values)
def test_multivector(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch(traj, ''' multivector resrange 3-7 name1 C name2 N ''') state.run() cpp_data = state.data[1:].values aa_eq( pt.multivector(traj, resrange='3-7', names=('C', 'N'), dtype='ndarray'), cpp_data) aa_eq( pt.multivector(traj, resrange='3-7', names='C N', dtype='ndarray'), cpp_data) aa_eq( pt.multivector(traj, resrange='3-7', names='name1 C name2 N', dtype='ndarray'), cpp_data)
def test_atomiccorr(self): traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") state = pt.load_batch(traj, ''' atomiccorr out test.dat :1-13 byres ''') state.run() data = pt.atomiccorr(traj, ':1-13', byres=True) aa_eq(data, state.data[1].values)
def normal_(traj=traj): print('serial') state = pt.load_batch( traj, ''' distance :3 :2 molsurf !:WAT ''') state.run() return state.data[1:].values
def test_raise_if_not_trajiter(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) t0 = traj[:] text = ''' rms @CA radgyr @CA nomax ''' self.assertRaises(ValueError, lambda: load_batch(t0, text))
def test_atomiccorr(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch( traj, ''' atomiccorr out test.dat :1-13 byres ''') state.run() data = pt.atomiccorr(traj, ':1-13', byres=True) aa_eq(data, state.data[1].values)
def test_raise_if_not_trajiter(self): traj = pt.iterload('data/tz2.nc', './data/tz2.parm7') t0 = traj[:] text = ''' rms @CA radgyr @CA nomax ''' self.assertRaises(ValueError, lambda: load_batch(t0, text))
def test_RMSF_with_options(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch( traj, ''' atomicfluct @CA byres out fluct.agr''') state.run() data = pt.rmsf(traj, '@CA', options='byres') aa_eq(data, state.data[-1].values)
def test_cpptraj(traj=traj): state = pt.load_batch( traj, ''' autoimage distance :1 :3 distance :5 :18 molsurf @CA multidihedral ''') state.run() return state
def test_watershell(self): traj = pt.iterload("data/tz2.truncoct.nc", "data/tz2.truncoct.parm7") state = pt.load_batch(traj, ''' watershell :1-7 ''') d0 = pt.watershell(traj, solute_mask=':1-7') state.run() aa_eq(d0.values, state.data[[1, 2]].values) # need to provide solute_mask self.assertRaises(ValueError, lambda: pt.watershell(traj))
def test_watershell(self): traj = pt.iterload(fn('tz2.truncoct.nc'), fn('tz2.truncoct.parm7')) state = pt.load_batch(traj, ''' watershell :1-7 ''') d0 = pt.watershell(traj, solute_mask=':1-7') state.run() aa_eq(d0.values, state.data[[1, 2]].values) # need to provide solute_mask self.assertRaises(ValueError, lambda: pt.watershell(traj))
def test_autoimage_rms_strip(self): traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7") state = pt.load_batch(traj, ''' autoimage rms strip !@CA createcrd''') state.run() # get last datset (DatasetCoordsCRD) crd = state.data[-1] t0 = traj[:] new_traj = t0.autoimage().superpose()['@CA'] aa_eq(new_traj.xyz, crd.xyz)
def test_autoimage_rms_strip(self): traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7") state = pt.load_batch( traj, ''' autoimage rms strip !@CA createcrd''') state.run() # get last datset (DatasetCoordsCRD) crd = state.data[-1] t0 = traj[:] new_traj = t0.autoimage().superpose()['@CA'] aa_eq(new_traj.xyz, crd.xyz)
def test_RMSF(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch(traj, ''' rms first average crdset MyAvg run rms ref MyAvg atomicfluct out fluct.agr''') state.run() t0 = traj[:] pt.superpose(t0, ref=0) avg = pt.mean_structure(t0) pt.superpose(t0, ref=avg) data = pt.rmsf(t0) aa_eq(data, state.data[-1].values)
def test_RMSF(self): traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7") state = pt.load_batch(traj, ''' rms first average crdset MyAvg run rms ref MyAvg atomicfluct out fluct.agr''') state.run() t0 = traj[:] pt.superpose(t0, ref=0) avg = pt.mean_structure(t0) pt.superpose(t0, ref=avg) data = pt.rmsf(t0) aa_eq(data, state.data[-1].values)
def test_diagmatrix_mwcovar(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch(traj, ''' matrix mwcovar @CA name mymat diagmatrix mymat vecs 6 name mydiag''') state.run() mat = pt.matrix.mwcovar(traj, '@CA') ca_indices = traj.top.select('@CA') eigenvectors, eigenvalues = pt.matrix.diagonalize( mat, n_vecs=6, scalar_type='mwcovar', mass=traj.top.mass[ca_indices]) aa_eq(np.abs(state.data['mydiag'].eigenvalues), np.abs(eigenvalues)) aa_eq(np.abs(state.data['mydiag'].eigenvectors), np.abs(eigenvectors))
def test_matrix(self): import numpy as np from pytraj import ArgList from pytraj import matrix as ma from pytraj.externals.six import iteritems matrix_test_dir = cpptraj_test_dir + "/Test_Matrix/" top_file = matrix_test_dir + "/1rrb_vac.prmtop" crd_file = matrix_test_dir + "/1rrb_vac.mdcrd" traj = pt.iterload(crd_file, top_file) with tempfolder(): state = pt.load_cpptraj_state(all_commands, traj) state.run() state_byres = pt.load_batch(traj, byres_cm) state_byres.run() byres_matlist = [] # no byres keyword for idx, line in enumerate(command_list): arg = ArgList(line) # get function act_key = arg.get_string_key("matrix") slist = arg.get_string_key('out').split(".") mask = arg.get_next_mask() fname = ".".join((slist[0], slist[-1], slist[1])) # get correct name func = ma.__dict__[act_key] # get command command = line.split(act_key)[1] matout = func(traj, command, dtype='ndarray') # cpptraj output has only 3 digits after decimal if 'byres' not in command: aa_eq(matout.flatten(), state.data[idx + 1].values) else: # save data for asserting later byres_matlist.append(matout) byres_arr = np.array(byres_matlist, dtype='f8') # only take byres datasets saved_matbyres = state_byres.data[[1, 3]].values aa_eq(byres_arr, saved_matbyres)
def test_reference(self): traj = pt.iterload("./data/tz2.truncoct.nc", "data/tz2.truncoct.parm7") txt = ''' reference data/tz2.truncoct.nc 2 2 rmsd :2-11 refindex 0 perres perresout center.agr range 1 perrescenter ''' state = pt.load_batch(traj, txt).run() # state.data has 3 datasets: ref, rmsd, rmsd perres # cpptraj use 2nd reference rmsd0 = pt.rmsd(traj, ref=1, mask=':2-11') rmsdperres = pt.rmsd_perres(traj, ref=1, mask=':2-11', perres_mask='*', resrange='1', perres_center=True) aa_eq(rmsd0, state.data[2]) aa_eq(rmsdperres[1], state.data[3].values)
def test_distance_with_dry_traj_and_PBC_topology(self): '''Situation: there is dry traj (no box) but Topology has box info ''' traj = pt.iterload( fn('dry_traj_with_PBC_top/strip.nc'), fn('dry_traj_with_PBC_top/strip.prmtop')) assert traj.top.has_box(), 'Topology must have box for testing' correct_distance_with_image_True = pt.distance( traj, ':8@OP2 :5@N1', image=True) correct_distance_with_image_False = pt.distance( traj, ':8@OP2 :5@N1', image=False) state = pt.load_batch(traj, ''' distance :8@OP2 :5@N1 ''') state.run() expected_distance = [3.08030475, 2.68452183] aa_eq(correct_distance_with_image_False, expected_distance) aa_eq(correct_distance_with_image_True, [0., 0.])
def test_mpi_load_batch(): # create ``comm`` so you can have the info about n_cpus, cpu id comm = MPI.COMM_WORLD # you are free to update anything below here # _load_batch_pmap is temp method name, will be changed in future traj_name = fn("tz2.nc") parm_name = fn("tz2.parm7") # load to TrajectoryIterator traj = pt.iterload(traj_name, parm_name, frame_slice=(0, 4000)) # make a list of things you want to lines = ['autoimage', 'distance :3 :10', 'molsurf @CA'] # gather the data to 1st core (rank=0) # n_cores = comm.size data = _load_batch_pmap(n_cores, lines=lines, traj=traj, mode='mpi', dtype='dict') if comm.rank != 0: assert data is None if comm.rank == 0: # each core return a tuple (core_id, dict) # so you need to concat the dict # use `from pytraj.tools import concat_dict data_0 = concat_dict(x[0] for x in data) # assert to serial version (do not need to copy below to your script) state = pt.load_batch(traj, lines) state.run() data = state.data[1:].to_dict() for key_0, key in zip(sorted(data_0.keys()), sorted(data.keys())): aa_eq(data_0[key_0], data[key])
def test_reference(self): traj = pt.iterload(fn("tz2.truncoct.nc"), fn("tz2.truncoct.parm7")) txt = ''' reference {} 2 2 rmsd :2-11 refindex 0 perres perresout center.agr range 1 perrescenter '''.format(fn('tz2.truncoct.nc')) with tempfolder(): state = pt.load_batch(traj, txt).run() # state.data has 3 datasets: ref, rmsd, rmsd perres # cpptraj use 2nd reference rmsd0 = pt.rmsd(traj, ref=1, mask=':2-11') rmsdperres = pt.rmsd_perres(traj, ref=1, mask=':2-11', perres_mask='*', resrange='1', perres_center=True) aa_eq(rmsd0, state.data[2]) aa_eq(rmsdperres[1], state.data[3].values)
def test_diagmatrix(self): traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7')) state = pt.load_batch( traj, ''' #matrix covar @CA name mymat matrix dist @CA name mymat diagmatrix mymat vecs 6''') state.run() mat = state.data['mymat'] cpp_evals, cpp_evecs = state.data[-1].eigenvalues, state.data[ -1].eigenvectors # test triu_indices mat2 = mat.__class__() np.triu_indices(mat.n_cols) mat2._set_data_half_matrix(mat._to_cpptraj_sparse_matrix(), mat.size, mat.n_cols) # OK data = matrix.diagonalize(mat.values, n_vecs=6, dtype='dataset')[-1] data2 = matrix.diagonalize(mat, n_vecs=6, dtype='dataset')[0] aa_eq(data.eigenvalues, cpp_evals, decimal=10) aa_eq(data2.eigenvalues, cpp_evals, decimal=10) # try numpy np_vals, np_vecs = np.linalg.eigh(mat2.values, UPLO='U') np_vals = np_vals[::-1][:6] np_vecs = np_vecs[:, ::-1].T[:6] # at least the absolute values are equal aa_eq(np.abs(data.eigenvectors), np.abs(cpp_evecs)) aa_eq(np.abs(np_vecs), np.abs(cpp_evecs)) # test raise if not having supported dtype self.assertRaises( ValueError, lambda: pt.matrix.diagonalize(mat, 3, dtype='ndarray'))
def test_ired_vector(self): '''test mask as a list of strings or as a 2D array of integers ''' parm_dir = os.path.join(cpptraj_test_dir, 'Test_IRED', '1IEE_A_prot.prmtop') trajin_dir = os.path.join(cpptraj_test_dir, 'Test_IRED', '1IEE_A_test.mdcrd') traj = pt.iterload(trajin_dir, parm_dir) # get a list of mask from cpptraj input maskes = [] lines = None n_indices_cpp = [] with open('data/ired.in', 'r') as fh: lines = fh.readlines() for line in lines: if 'vector' in line and 'ired' in line: # example: vector v100 @1541 ired @1542 sline = line.split() mask = ' '.join((sline[2], sline[4])) n_indices_cpp.append(int(sline[2][1:]) - 1) maskes.append(mask) h_indices_cpp = [i + 1 for i in n_indices_cpp] # calcuate vector from a list of strings data_vec = va.vector_mask(traj, maskes) # calcuate vector from a 2d array of integers nh_indices = np.array(list(zip(n_indices_cpp, h_indices_cpp))) data_vec_2 = va.vector_mask(traj, nh_indices) # re-create cpptraj input to run cpptraj txt = ''.join(lines) # add parm and trajin lines txt = 'parm ' + parm_dir + '\n' + \ 'trajin ' + trajin_dir + '\n' + \ txt state = pt.datafiles.load_cpptraj_output(txt, dtype='state') state.run() cpp_data = state.datasetlist cpp_vectors = cpp_data.grep('vector', mode='dtype').values cpp_matired = cpp_data.grep('matrix', mode='dtype')['matired'] # assert between pytraj's data_vec and cpptraj's cpp_vectors aa_eq(data_vec, cpp_vectors) # from a 2D array of integers aa_eq(data_vec_2, cpp_vectors) # test ired vector with ired matrix # open file with open('data/ired_reduced.in', 'r') as fh: text = ''.join(fh.readlines()) state2 = pt.load_batch(traj, text) state2.run() data = pt.ired_vector_and_matrix(traj, nh_indices, order=2) data_vec_3 = data[0] assert len(data_vec_3) == 126, 'must have 126 vectors' matired = data[1] # TODO: know why?? matired /= matired[0, 0] aa_eq(data_vec_3, cpp_vectors) assert pt.tools.rmsd(matired.flatten(), cpp_matired.values) < 1E-6, 'matired'
#!/usr/bin/env python import pytraj as pt root_dir = "../../tests/data/" traj_name = root_dir + "tz2.nc" parm_name = root_dir + "tz2.parm7" # load to TrajectoryIterator traj = pt.iterload(traj_name, parm_name, frame_slice=(0, 4000)) state = pt.load_batch(traj, ''' autoimage distance :3 :10 molsurf @CA ''') state.run() print([d for d in state.data])
# make a list of things you want to lines = ['autoimage', 'distance :3 :10', 'molsurf @CA'] # gather the data to 1st core (rank=0) # n_cores = comm.size data = _load_batch_pmap(n_cores, lines=lines, traj=traj, mode='mpi', dtype='dict') if comm.rank != 0: assert data is None if comm.rank == 0: from pytraj.tools import concat_dict # each core return a tuple (core_id, dict) # so you need to concat the dict # use `from pytraj.tools import concat_dict data_0 = concat_dict(x[1] for x in data) # assert to serial version (do not need to copy below to your script) state = pt.load_batch(traj, lines) state.run() data = state.data[1:].to_dict() for key_0, key in zip(sorted(data_0.keys()), sorted(data.keys())): aa_eq(data_0[key_0], data[key])
traj_name = root_dir + "tz2.nc" parm_name = root_dir + "tz2.parm7" # load to TrajectoryIterator traj = pt.iterload(traj_name, parm_name, frame_slice=(0, 4000)) # make a list of things you want to lines = ['autoimage', 'distance :3 :10', 'molsurf @CA'] # gather the data to 1st core (rank=0) # n_cores = comm.size data = _load_batch_pmap(n_cores, lines=lines, traj=traj, mode='mpi', dtype='dict') if comm.rank != 0: assert data is None if comm.rank == 0: # each core return a tuple (core_id, dict) # so you need to concat the dict # use `from pytraj.tools import concat_dict data_0 = concat_dict(x[0] for x in data) # assert to serial version (do not need to copy below to your script) state = pt.load_batch(traj, lines) state.run() data = state.data[1:].to_dict() for key_0, key in zip(sorted(data_0.keys()), sorted(data.keys())): aa_eq(data_0[key_0], data[key])
def test_rdf(self): traj = pt.iterload("./data/tz2.truncoct.nc", "./data/tz2.truncoct.parm7", frame_slice=(0, 10)) command = ''' radial output/Radial.agr 0.5 10.0 :5@CD :WAT@O radial output/cRadial.agr 0.5 10.0 :5 :WAT@O center1 radial output/cRadial.agr 0.5 10.0 :5 :WAT@O center2 radial output/cRadial.agr 0.5 20.0 :3 :WAT@O radial output/cRadial.agr 0.5 20.0 :3 :WAT@O noimage radial output/radial.dat 0.5 10.0 :5@CD :WAT@O radial output/radial2.dat 0.25 10.0 :5@CD :WAT@O ''' # get data directly from cpptraj state = pt.load_batch(traj, command) state.run() # get data from pytraj data0 = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=10.0, solute_mask=':5@CD') data01 = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=10.0, solute_mask=':5@CD') data1 = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=10.0, center_solvent=True, solute_mask=':5') data2 = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=10.0, center_solute=True, solute_mask=':5') data3 = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=20.0, center_solute=False, solute_mask=':3') data4 = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.5, maximum=20.0, center_solute=False, image=False, solute_mask=':3') data5 = pt.rdf(traj, solvent_mask=':WAT@O', bin_spacing=0.25, maximum=10.0, solute_mask=':5@CD') # solvent_mask is array solvent_indices = pt.select(':WAT@O', traj.top) data6 = pt.rdf(traj, solvent_mask=solvent_indices, bin_spacing=0.25, maximum=10.0, solute_mask=':5@CD') # do assertion aa_eq(data0[1], state.data[1], decimal=7) aa_eq(data1[1], state.data[2], decimal=7) aa_eq(data2[1], state.data[3], decimal=7) aa_eq(data3[1], state.data[4], decimal=7) aa_eq(data4[1], state.data[5], decimal=7) # default solvent mask :WAT@O aa_eq(data01[1], state.data[1], decimal=7) steps = np.loadtxt('output/radial.dat').T[0] aa_eq(data0[0], steps) steps2 = np.loadtxt('output/radial2.dat').T[0] aa_eq(data5[0], steps2) aa_eq(data6[0], steps2)