def test_multi_panel_interp(self): # regression test ensuring detectors w/multiple basisgrid panels # are handled correctly t = structure.load_coor(ref_file('gold1k.coor')) q_values = np.array([2.66]) multi_d = xray.Detector.load(ref_file('lcls_test.dtc')) num_phi = 1080 num_molecules = 1 xyzlist = t.xyz[0, :, :] * 10.0 # convert nm -> ang. / first snapshot atomic_numbers = np.array( [a.element.atomic_number for a in t.topology.atoms()]) # generate a set of random numbers that we can use to make sure the # two simulations have the same molecular orientation (and therefore) # output rfloats = np.random.rand(num_molecules, 3) # --- first, scatter onto a perfect ring q_grid = xray._q_grid_as_xyz(q_values, num_phi, multi_d.k) ring_i = cpuscatter.simulate(num_molecules, q_grid, xyzlist, atomic_numbers, rfloats=rfloats) perf = xray.Rings(q_values, ring_i[None, None, :], multi_d.k) # --- next, to the full detector q_grid2 = multi_d.reciprocal real_i = cpuscatter.simulate(num_molecules, q_grid2, xyzlist, atomic_numbers, rfloats=rfloats) # interpolate ss = xray.Shotset(real_i, multi_d) real = ss.to_rings(q_values, num_phi) # count the number of points that differ significantly between the two diff = ( np.abs((perf.polar_intensities[0,0,:] - real.polar_intensities[0,0,:]) \ / real.polar_intensities[0,0,:]) > 1e-3) print np.sum(diff) assert np.sum(diff) < 300
def test_gpu(self): # just makes sure that CPU and GPU match if not GPU: raise SkipTest gpu_I = gpuscatter.simulate(self.num_molecules, self.q_grid, self.xyzlist, self.atomic_numbers, rfloats=self.rfloats, poisson_parameter=1.0) cpu_I = cpuscatter.simulate(self.num_molecules, self.q_grid, self.xyzlist, self.atomic_numbers, rfloats=self.rfloats, poisson_parameter=1.0)
def test_multi_panel_interp(self): # regression test ensuring detectors w/multiple basisgrid panels # are handled correctly t = structure.load_coor(ref_file('gold1k.coor')) q_values = np.array([2.66]) multi_d = xray.Detector.load(ref_file('lcls_test.dtc')) num_phi = 1080 num_molecules = 1 xyzlist = t.xyz[0,:,:] * 10.0 # convert nm -> ang. / first snapshot atomic_numbers = np.array([ a.element.atomic_number for a in t.topology.atoms() ]) # generate a set of random numbers that we can use to make sure the # two simulations have the same molecular orientation (and therefore) # output rfloats = np.random.rand(num_molecules, 3) # --- first, scatter onto a perfect ring q_grid = xray._q_grid_as_xyz(q_values, num_phi, multi_d.k) ring_i = cpuscatter.simulate(num_molecules, q_grid, xyzlist, atomic_numbers, rfloats=rfloats) perf = xray.Rings(q_values, ring_i[None,None,:], multi_d.k) # --- next, to the full detector q_grid2 = multi_d.reciprocal real_i = cpuscatter.simulate(num_molecules, q_grid2, xyzlist, atomic_numbers, rfloats=rfloats) # interpolate ss = xray.Shotset(real_i, multi_d) real = ss.to_rings(q_values, num_phi) # count the number of points that differ significantly between the two diff = ( np.abs((perf.polar_intensities[0,0,:] - real.polar_intensities[0,0,:]) \ / real.polar_intensities[0,0,:]) > 1e-3) print np.sum(diff) assert np.sum(diff) < 300
def test_cpu_scatter(self): print "testing c cpu code..." cpu_I = cpuscatter.simulate(self.num_molecules, self.q_grid, self.xyzlist, self.atomic_numbers, rfloats=self.rfloats) print "CPU", cpu_I print "REF", self.ref_I assert_allclose(cpu_I, self.ref_I, rtol=1e-03, err_msg='scatter: c-cpu/cpu reference mismatch') assert not np.all( cpu_I == 0.0 ) assert not np.sum( cpu_I == np.nan )
def test_cpu(self): cpu_I = cpuscatter.simulate(self.num_molecules, self.q_grid, self.xyzlist, self.atomic_numbers, rfloats=self.rfloats, poisson_parameter=1.0)