def test_center(self): traj = pt.iterload(fn('tz2.ortho.nc'), fn('tz2.ortho.parm7')) pt.load(fn("tz2.center_mass.nc"), traj.top) fa = traj[:] fa2 = traj[:].copy() pt.center(fa, mask=':1', mass=True) aa_eq(fa.xyz, fa.xyz, decimal=5) # raise if center not in 'origin', 'box' with pytest.raises(ValueError): pt.center(fa, center='oh') # center to point pt.center(fa, ':1', center=[0, 1, 2], mass=True) aa_eq(pt.center_of_mass(fa, ':1')[0], [0, 1, 2]) pt.center(fa, ':1', center=[0, 1, 2], mass=False) aa_eq(pt.center_of_geometry(fa, ':1')[0], [0, 1, 2]) fa2.center(':1', center=[0, 1, 2], mass=False) aa_eq(pt.center_of_geometry(fa2, ':1')[0], [0, 1, 2]) # on_disk traj_on_disk = pt.iterload(fn('tz2.ortho.nc'), fn('tz2.ortho.parm7')) pt.center(traj_on_disk, ':1', center=[0, 1, 2], mass=True) aa_eq(pt.center_of_mass(traj_on_disk, ':1')[0], [0, 1, 2])
def prepare(self): '''Load trajectory, print information and perform initial alignment and fit.''' self.load_traj() self.atoms = self.traj.n_atoms self.frames = self.traj.n_frames print('\nPROTEIN INFORMATION') print('PDB code: {}'.format(self.PDB)) print('residues: {}'.format(self.atoms)) print('frames: {}'.format(self.frames)) print('temperature: {}'.format(self.temperature)) # Align molecule to principal axes pt.principal_axes(self.traj, dorotation=True) # Center molecule at the origin pt.center(self.traj, center='origin') # First rmsd fit pt.rmsd(self.traj) # Calculate average structure self.avg = pt.mean_structure(self.traj) # Perform rms fit to average structure pt.rmsd(self.traj, ref=self.avg) # Initialize arrays self.initialize_arrays()
def test_density(self): rst7 = fn('DOPC.rst7') tn = fn('DOPC.parm7') traj = pt.load(fn('DOPC.rst7'), fn('DOPC.parm7')) delta = '0.25' masks = [":PC@P31", ":PC@N31", ":PC@C2", ":PC | :OL | :OL2"] keys_no_space = [''.join(m.split()) for m in masks] mask_str = ' '.join(['"' + m + '"' for m in masks]) density_types = ['number', 'mass', 'charge', 'electron'] state_data_dict = dict() for density_type in density_types: command = """ parm {parm} trajin {trajin} center ":PC | :OL | :OL2" origin density {density_type} delta {delta} {mask} """.format( parm=tn, trajin=rst7, delta=delta, mask=mask_str, density_type=density_type) state = pt.load_cpptraj_state(command) state.run() state_data_dict[density_type] = state.data[1:].to_dict() pt.center(traj, '":PC | :OL | :OL2" origin') density_dict = {} for density_type in density_types: density_data = pt.density( traj, mask=masks, delta=delta, density_type=density_type) density_dict[density_type] = density_data # compate to cpptraj for density_type in density_types: for key in keys_no_space: aa_eq(state_data_dict[density_type][key], density_dict[density_type][key]) # assert raise: wrong density_type def func(): pt.density(traj, mask=':WAT', density_type='hello') with pytest.raises(AssertionError): func() # test 'z' value saved_z_values = np.linspace(-24.1250, 23.8750, 193) aa_eq(density_data['z'], saved_z_values)
def test_center_autoimagesuperpose(self): traj = pt.iterload(fn('tz2.ortho.nc'), fn('tz2.ortho.parm7')) t0 = traj[:] t1 = traj[:] pt.center(t0) pt.autoimage(t0) pt.superpose(t0) aa_eq(pt.center(t1).autoimage().superpose().xyz, t0.xyz)
def test_center(self): traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7") saved_traj = pt.load("./data/tz2.center_mass.nc", traj.top) fa = traj[:] pt.center(fa, mask=':1', mass=True) aa_eq(fa.xyz, fa.xyz, decimal=5) # raise if center not in 'origin', 'box' self.assertRaises(ValueError, lambda: pt.center(fa, center='oh'))
def test_center_autoimagesuperpose(self): traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7") t0 = traj[:] t1 = traj[:] pt.center(t0) pt.autoimage(t0) pt.superpose(t0) aa_eq(pt.center(t1).autoimage().superpose().xyz, t0.xyz)
def test_center_autoimagesuperpose(self): traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7") t0 = traj[:] t1 = traj[:] pt.center(t0) pt.autoimage(t0) pt.superpose(t0) aa_eq(pt.center(t1).autoimage().superpose().xyz, t0.xyz)
def test_center(self): traj = pt.iterload("./data/tz2.ortho.nc", "./data/tz2.ortho.parm7") saved_traj = pt.load("./data/tz2.center_mass.nc", traj.top) fa = traj[:] pt.center(fa, mask=':1', mass=True) aa_eq(fa.xyz, fa.xyz, decimal=5) # raise if center not in 'origin', 'box' self.assertRaises(ValueError, lambda: pt.center(fa, center='oh'))
def clean_traj(self): # Align molecule to principal axes pt.principal_axes(self.traj, dorotation=True) # Center molecule at the origin pt.center(self.traj, center='origin') # First rmsd fit pt.rmsd(self.traj) # Calculate average structure self.avg = pt.mean_structure(self.traj) # Perform rms fit to average structure pt.rmsd(self.traj, ref=self.avg)
def test_mpi_cpptraj_style(): comm = MPI.COMM_WORLD # end. you are free to update anything below here # split remd.x.000 to N cores and do calc_surf in parallel root_dir = "data/" traj_name = root_dir + "tz2.ortho.nc" parm_name = root_dir + "tz2.ortho.parm7" # load to TrajectoryIterator traj = pt.iterload(traj_name, parm_name) # save `total_arr` to rank=0 # others: total_arr = None total_arr = pt.pmap_mpi( ['autoimage', 'center :2', 'distance :3 :7', 'angle :3 :7 :8'], traj) if comm.rank != 0: assert total_arr is None if comm.rank == 0: # assert to serial from pytraj.utils.tools import dict_to_ndarray arr = dict_to_ndarray(total_arr) t0 = pt.center(traj[:].autoimage(), ':2') aa_eq(pt.distance(t0, ':3 :7'), arr[0]) aa_eq(pt.angle(t0, ':3 :7 :8'), arr[1])
def test_center(): # OK for f in traj: pt.center(f, top=traj.top)
def test_center(): # OK for f in traj: pt.center(f, top=traj.top)
import pytraj as pt from pytraj.testing import aa_eq comm = MPI.COMM_WORLD # end. you are free to update anything below here # split remd.x.000 to N cores and do calc_surf in parallel root_dir = "data/" traj_name = root_dir + "tz2.ortho.nc" parm_name = root_dir + "tz2.ortho.parm7" # load to TrajectoryIterator traj = pt.iterload(traj_name, parm_name) # save `total_arr` to rank=0 # others: total_arr = None total_arr = pt.pmap_mpi( ['autoimage', 'center :2', 'distance :3 :7', 'angle :3 :7 :8'], traj) if comm.rank != 0: assert total_arr is None if comm.rank == 0: # assert to serial from pytraj.tools import dict_to_ndarray arr = dict_to_ndarray(total_arr) t0 = pt.center(traj[:].autoimage(), ':2') aa_eq(pt.distance(t0, ':3 :7'), arr[0]) aa_eq(pt.angle(t0, ':3 :7 :8'), arr[1])