示例#1
0
文件: test_xray.py 项目: tjlane/thor
    def test_q_values(self):

        q_values = np.array([1.0, 2.0, 3.0])
        num_phi = 360
        k = 2.0 * np.pi / 1.4

        qxyz = xray._q_grid_as_xyz(q_values, num_phi, k)

        # assert that the above vectors are the correct length
        assert np.all( np.abs( np.sqrt( np.sum( np.power(qxyz,2), axis=1 ) ) - \
                               np.repeat(q_values, num_phi)) < 1e-6 )
示例#2
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-300) ) > 1e-3)
        print np.sum(diff)
        assert np.sum(diff) < 300