def test_0(): t1 = load(get_fn('native2.xml'), top=get_fn('native2.pdb')) t2 = load(get_fn('native2.pdb')) t1.center_coordinates() t2.center_coordinates() yield lambda: eq(t1.xyz, t2.xyz) yield lambda: eq(t1.unitcell_vectors, t2.unitcell_vectors)
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.createEArray(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.traj = trajectory.load(ref_file('ala2.pdb')) self.num_shots = 2 self.rings = xray.Rings.simulate(self.traj, 1, self.q_values, self.num_phi, self.num_shots) # 1 molec
def test_rm_com(): t = trajectory.load( ref_file('ala2.pdb') ) r = structure.remove_COM(t) masses = [ a.element.mass for a in t.topology.atoms() ] for i in range(t.n_frames): assert_array_almost_equal(np.zeros(3), np.average(t.xyz[i,:,:], weights=masses, axis=0))
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.i = np.abs(np.random.randn(self.d.num_pixels)) self.t = trajectory.load(ref_file('ala2.pdb')) self.shot = xray.Shotset(self.i, self.d)
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.i = np.abs( np.random.randn(self.d.num_pixels) ) self.t = trajectory.load(ref_file('ala2.pdb')) self.shot = xray.Shotset(self.i, self.d)
def test_python_call(self): print "testing python wrapper fxn..." traj = trajectory.load(ref_file('ala2.pdb')) num_molecules = 512 detector = Detector.generic() py_I = xray.simulate_shot(traj, num_molecules, detector, verbose=True)
def test_replicate(): if TRAVIS: raise SkipTest cmd = 'replicate -i %s -n 10 -d 0.1 > /dev/null 2>&1' % ref_file('goldBenchMark.coor') subprocess.check_call(cmd, shell=True) if not os.path.exists('replicated.pdb'): raise RuntimeError('no output produced') else: o = trajectory.load('replicated.pdb') os.remove('replicated.pdb')
def test_solvate(): if not OPENMM: raise SkipTest if TRAVIS: raise SkipTest cmd = 'solvate -i %s > /dev/null 2>&1' % ref_file('ala2.pdb') subprocess.check_call(cmd, shell=True) if not os.path.exists('solvated.pdb'): raise RuntimeError('no output produced') else: o = trajectory.load('solvated.pdb') os.remove('solvated.pdb')
def setup(self): self.t = trajectory.load(ref_file('ala2.pdb')) # make a fake restraint array self.restraint_array = np.zeros((2, 4)) self.restraint_array[0, :] = np.array([0, 5, 1.0, 1]) self.restraint_array[1, :] = np.array([4, 10, 10.0, 0]) self.dr = exptdata.DistanceRestraint(self.restraint_array)
def setup(self): self.t = trajectory.load( ref_file('ala2.pdb') ) # make a fake restraint array self.restraint_array = np.zeros((2,4)) self.restraint_array[0,:] = np.array([0, 5, 1.0, 1]) self.restraint_array[1,:] = np.array([4, 10, 10.0, 0]) self.dr = exptdata.DistanceRestraint(self.restraint_array)
def test_load_coor(): s = structure.load_coor( ref_file('goldBenchMark.coor') ) s.save('s.pdb') t = trajectory.load('s.pdb') assert_array_almost_equal(s.xyz, t.xyz, decimal=3) for a in t.topology.atoms(): assert a.element.symbol == 'Au' if os.path.exists('s.pdb'): os.remove('s.pdb')
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 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 setup(self): self.d = xray.Detector.generic(spacing=0.3) self.t = trajectory.load(ref_file('ala2.pdb'))
def test_m_confs(): # smoke test t = trajectory.load( ref_file('ala2.pdb') ) m = structure.multiply_conformations(t, 10, 1.0)
#!/usr/bin/env python import numpy as np from odin import xray from odin import _cpuscatter from mdtraj import trajectory import matplotlib.pyplot as plt q_values = [1.4] traj = trajectory.load('3LYZ.pdb') xyzlist = traj.xyz[0] atomic_numbers = np.array([ a.element.atomic_number for a in traj.topology.atoms() ]) b = xray.Beam(None, energy=10.) # same as was used to make reference.dtc pol_q_grid = xray._q_grid_as_xyz(q_values, 360, b.k) dtc = xray.load('reference.dtc') dtc_q_grid = dtc.reciprocal num_molecules = 1 rfloats = np.random.rand(num_molecules, 3) pol_i = _cpuscatter.simulate(num_molecules, pol_q_grid, xyzlist, atomic_numbers, rfloats=rfloats) dtc_i = _cpuscatter.simulate(num_molecules, dtc_q_grid, xyzlist, atomic_numbers, rfloats=rfloats)
def convert_dcd_xtc(pdb_name, dcd_name, xtc_name): t = trajectory.load(dcd_name, top=pdb_name) t.save(xtc_name)
import numpy as np from odin import xray from mdtraj import trajectory import matplotlib.pyplot as plt t = trajectory.load('reference/ala2.pdb') dp = xray.Detector.generic_polar(q_lim=0.6) xp = xray.Shot.simulate(t, 10, dp) dc = xray.Detector.generic(spacing=0.6) xc = xray.Shot.simulate(t, 10, dc) # make sure it matches up decently with non-polar ref = xc.I_ring(0.4) pol = xp.I_ring(0.4) ref = ref * (pol[0]/ref[0]) # scale them to be the same-ish print np.abs(ref - pol) / ref plt.figure() plt.plot(ref, lw=2) plt.plot(pol, lw=2) plt.show()