def setup(self): self.q_values = np.array([1.0, 2.0]) self.num_phi = 360 self.traj = Trajectory.load(ref_file('ala2.pdb')) self.num_shots = 4 self.rings = xray.Rings.simulate(self.traj, 1, self.q_values, self.num_phi, self.num_shots) # 1 molec
def setup(self): self.q_values = np.array([1.0, 2.0]) self.num_phi = 360 self.traj = Trajectory.load(ref_file('ala2.pdb')) self.num_shots = 2 # generate the tables file on disk, then re-open it intensities = np.abs( np.random.randn(self.num_shots, len(self.q_values), self.num_phi) / 100.0 + \ np.cos( np.linspace(0.0, 4.0*np.pi, self.num_phi) ) ) if os.path.exists('tmp_tables.h5'): os.remove('tmp_tables.h5') hdf = tables.File('tmp_tables.h5', 'w') a = tables.Atom.from_dtype(np.dtype(np.float64)) node = hdf.create_earray(where='/', name='data', shape=(0, len(self.q_values), self.num_phi), atom=a, filters=io.COMPRESSION) node.append(intensities) hdf.close() self.tables_file = tables.File('tmp_tables.h5', 'r+') pi = self.tables_file.root.data pm = np.random.binomial(1, 0.9, size=(len(self.q_values), self.num_phi)) k = 1.0 self.rings = xray.Rings(self.q_values, pi, k, pm) return
def setup(self): self.q_values = np.array([1.0, 2.0]) self.num_phi = 360 self.l = 50.0 self.d = xray.Detector.generic(spacing=0.4, l=self.l) self.num_shots = 2 self.i = np.abs( np.random.randn(self.num_shots, self.d.num_pixels) ) self.t = Trajectory.load(ref_file('ala2.pdb')) self.shot = xray.Shotset(self.i, self.d)
def test_sph_harm(): # ----------------------- traj = Trajectory.load(ref_file('pentagon.pdb')) q_magnitudes = [1.6] num_coefficients = 44 num_molecules = 1 num_shots = 20000 num_phi = 2048 # ----------------------- q = q_magnitudes[0] # compute the Kam-theoretic values of the Legendre coefficients C_ell, which # we will call "coeffsh" coeffsh_even = scatter.sph_harm_coefficients(traj, q_magnitudes, num_coefficients=num_coefficients/2) coeffsh_even = np.nan_to_num(coeffsh_even) coeffsh_even /= coeffsh_even[1] coeffsh = np.zeros(num_coefficients) coeffsh[0::2] = coeffsh_even.flatten() # next, preform a simulation of the scattering and empirically compute the # correlation function rings = xray.Rings.simulate(traj, num_molecules, q_magnitudes, num_phi, num_shots) c = rings.correlate_intra(q, q, mean_only=True) # it seems best to compare the solutions in the expanded basis c_sh = np.polynomial.legendre.legval(rings.cospsi(q, q), coeffsh.flatten()) c = c - c.mean() c_sh = c_sh - c_sh.mean() # plt.figure() # plt.plot(c_sh / c_sh[0]) # plt.plot(c / c[0]) # plt.show() # if these are more than 10% different, fail the test error = (np.sum(np.abs( (c_sh / c_sh[0]) - (c / c[0]) )) / float(num_phi)) assert error < 0.1, 'simulation and analytical computation >10%% different (%f %%)' % error return
def test_py_cpu_smoke(self): traj = Trajectory.load(ref_file('ala2.pdb')) num_molecules = 1 detector = xray.Detector.generic() detector.beam.photons_scattered_per_shot = 1e3 I = scatter.simulate_shot(traj, num_molecules, detector, finite_photon=True) # simple statistical sanity check assert np.abs(I.sum() - detector.beam.photons_scattered_per_shot) < \ np.sqrt(detector.beam.photons_scattered_per_shot)*6.0
def test_python_call(self): """ Test the GPU scattering simulation interface (scatter.simulate) """ if not GPU: raise SkipTest print "testing python wrapper fxn..." traj = Trajectory.load(ref_file('ala2.pdb')) num_molecules = 512 detector = xray.Detector.generic() py_I = scatter.simulate_shot(traj, num_molecules, detector) assert not np.all( py_I == 0.0 ) assert not np.isnan(np.sum( py_I ))
def setup(self): self.q_values = np.array([1.0, 2.0]) self.num_phi = 360 self.l = 50.0 self.d = xray.Detector.generic(spacing=0.4, l=self.l) self.t = Trajectory.load(ref_file('ala2.pdb')) self.num_shots = 2 intensities = np.abs(np.random.randn(self.num_shots, self.d.num_pixels)) io.saveh('tmp_tables.h5', data=intensities) self.tables_file = tables.File('tmp_tables.h5') self.i = self.tables_file.root.data self.shot = xray.Shotset(self.i, self.d) return
def test_no_hydrogens(): traj = Trajectory.load(ref_file('ala2.pdb')) num_molecules = 1 detector = xray.Detector.generic() detector.beam.photons_scattered_per_shot = 1e3 I_noH = scatter.simulate_shot(traj, num_molecules, detector, ignore_hydrogens=True, dont_rotate=True) I_wH = scatter.simulate_shot(traj, num_molecules, detector, ignore_hydrogens=False, dont_rotate=True) assert not np.all(I_noH == I_wH) # compute the differece -- we're not setting random numbers here so just # looking at radially averaged stuff... diff = np.sum(np.abs(I_noH - I_wH) / I_wH) / float(len(I_wH)) print diff assert diff < 1.0, 'ignoring hydrogens makes too big of a difference...'
#!/usr/bin/env python import mdtraj from mdtraj import Trajectory as t import os # combine trajectories trjs = [f for f in os.listdir('.') if 'trj' in f] ts = {} tn = [] for i in trjs: num = i.split('.')[0].split('j')[-1] tn.append(num) ts[i] = t.load('./trj%i.h5' % int(num)) tn.sort() z = ts['trj0.h5'] for i in tn: z = z.join(ts['trj%s.h5' % i]) # trim data to have a frame every 1 ns frames = [] for i in range(len(z)): if i % 10 == 0: frames.append(i) zp = z.slice(frames) # save combined data zp.save_pdb('ns.pdb')
parser.add_argument('--pro', action='store_true', help='write trj of protein only', default=False) parser.add_argument('--sr', type=str, help='script root', default='/home/kmckiern/scripts/') args = parser.parse_args() sr = args.sr sys.path.insert(0, sr + 'py_general/') from toolz import natural_sort ext_i = '.' + args.trj_ext td = args.trj_dir # combine trajectories trjs = [f for f in os.listdir(td) if ext_i in f] trjs = natural_sort(trjs) ts = t.load(trjs[0], top=args.top, stride=args.stride1) if args.vs: # i'm going to pad these residues by 8 arg = ts.top.select('resid 23 to 39') lysglu = ts.top.select('resid 118 to 135') lys = ts.top.select('resid 308 to 324') vs = np.concatenate([arg, lysglu, lys]) ts = ts.atom_slice(vs) try: ts[0].save_pdb('/home/kmckiern/clc/analysis/vs_dihed/pro/vs_ref.pdb') except: print 'usual protonation error, probably' nt = len(trjs) for ndx, i in enumerate(trjs[1:]): # for newest trj, cut end just in case write is incomplete if ndx + 1 == nt: