Example #1
0
    def __init__(self, det, beam, particles):
        self.det = det
        self.beam = beam
        self.particles = particles
        self.n_particle_kinds = len(particles)

        # Create mesh, reinitializing detector with highest k-beam spike
        highest_k_beam = self.beam.get_highest_wavenumber_beam()
        self.det.initialize_pixels_with_beam(beam=highest_k_beam)
        mesh, self.voxel_length = det.get_reciprocal_mesh(
            voxel_number_1d=self.mesh_size)

        # Create volumes
        import skopi.gpu as pg
        self.volumes = []
        for particle in particles:
            if particle is None:
                self.volumes.append(np.zeros(mesh.shape[:-1], np.complex128))
                continue
            self.volumes.append(
                pg.calculate_diffraction_pattern_gpu(
                    mesh, particle, return_type='complex_field'))

        # set up lists to track diplacements from beam center and variations in fluence
        self.beam_displacements = list()
        self.fluences = list()
Example #2
0
    def test_volume_calculation(self):
        """
        Validation for calculate_diffraction_pattern_gpu using a reference calculation.
        """

        fi_indices_list = [np.zeros(5).astype(int), np.array([0, 0, 0, 1, 1])]
        atoms_list = [['C', 'C', 'C', 'C', 'C'], ['C', 'C', 'C', 'S', 'S']]

        for fi_indices, atoms in zip(fi_indices_list, atoms_list):

            # generate a simple 5-atom particle
            particle, xyz = self.generate_pentagon(atoms)

            # compute atomic form factors
            fi = sk.diffraction.calculate_atomic_factor(
                particle, self.stol, self.stol.shape[0])

            # compute reference volume
            I_ref = reference_diffraction_calculation(self.qgrid, xyz, fi,
                                                      fi_indices)

            # compute skopi volume, which expects s-vectors (q=2*pi*s) in m-1
            reciprocal_space = self.qgrid / (2 * np.pi) * 1e10
            I_skopi = pg.calculate_diffraction_pattern_gpu(
                reciprocal_space, particle, return_type='intensity')

            assert np.allclose(I_ref, I_skopi)

        return
Example #3
0
    def setup_class(cls):
        ex_dir_ = os.path.dirname(__file__) + '/../../../examples'

        # Load beam
        beam = sk.Beam(ex_dir_+'/input/beam/amo86615.beam')

        # Load and initialize the detector
        np.random.seed(0)
        det = sk.Epix10kDetector(
            geom=ex_dir_+'/input/lcls/xcsx35617/'
                 'Epix10ka2M::CalibV1/XcsEndstation.0:Epix10ka2M.0/geometry/0-end.data',
            run_num=0,
            beam=beam,
            cameraConfig='fixedMedium')
        cls.det = det
            
        cls.pos_recip = det.pixel_position_reciprocal

        # Ref Particle
        cls.particle_0 = sk.Particle()
        cls.particle_0.create_from_atoms([  # Angstrom
            ("O", cst.vecx),
            ("O", 2*cst.vecy),
            ("O", 3*cst.vecz),
        ])
        cls.pattern_0 = sg.calculate_diffraction_pattern_gpu(
            cls.pos_recip, cls.particle_0, return_type="complex_field")

        # Second Particle
        cls.part_coord_1 = np.array((0.5, 0.2, 0.1))  # Angstrom
        cls.particle_1 = sk.Particle()
        cls.particle_1.create_from_atoms([  # Angstrom
            ("O", cst.vecx + cls.part_coord_1),
            ("O", 2*cst.vecy + cls.part_coord_1),
            ("O", 3*cst.vecz + cls.part_coord_1),
        ])
        cls.part_coord_1 *= 1e-10  # Angstrom -> meter
        cls.pattern_1 = sg.calculate_diffraction_pattern_gpu(
            cls.pos_recip, cls.particle_1, return_type="complex_field")

        # Flat Field
        cls.flatField = np.ones((cls.det.panel_num, cls.det.panel_pixel_num_x[0], cls.det.panel_pixel_num_y[0]))*1.0
        cls.I0width = 0.03
        cls.I0min = 0
        cls.I0max = 150000
        cls.bauf = BuildAutoRangeFrames(cls.det, cls.I0width, cls.I0min, cls.I0max, cls.flatField)
        cls.bauf.makeFrame()    
Example #4
0
    def setup_class(cls):
        ex_dir_ = os.path.dirname(__file__) + '/../../examples'

        # Load beam
        beam = sk.Beam(ex_dir_ + '/input/beam/amo86615.beam')

        # Load and initialize the detector
        det = sk.PnccdDetector(
            geom=ex_dir_ + '/input/lcls/amo86615/'
            'PNCCD::CalibV1/Camp.0:pnCCD.1/geometry/0-end.data',
            beam=beam)

        cls.mesh_length = 15
        cls.mesh, voxel_length = det.get_reciprocal_mesh(
            voxel_number_1d=cls.mesh_length)

        # 1 Atom
        cls.particle_1 = sk.Particle()
        cls.particle_1.create_from_atoms([("O", np.array([0., 0., 0.]))])
        cls.volume_1 = pg.calculate_diffraction_pattern_gpu(
            cls.mesh, cls.particle_1)

        # 2 Atoms x
        cls.particle_2x = sk.Particle()
        cls.particle_2x.create_from_atoms([("O", cst.vecx), ("O", -cst.vecx)])
        cls.volume_2x = pg.calculate_diffraction_pattern_gpu(
            cls.mesh, cls.particle_2x)

        # 2 Atoms y
        cls.particle_2y = sk.Particle()
        cls.particle_2y.create_from_atoms([("O", cst.vecy), ("O", -cst.vecy)])
        cls.volume_2y = pg.calculate_diffraction_pattern_gpu(
            cls.mesh, cls.particle_2y)

        # 2 Atoms z
        cls.particle_2z = sk.Particle()
        cls.particle_2z.create_from_atoms([("O", cst.vecz), ("O", -cst.vecz)])
        cls.volume_2z = pg.calculate_diffraction_pattern_gpu(
            cls.mesh, cls.particle_2z)
Example #5
0
    def setup_class(cls):
        ex_dir_ = os.path.dirname(__file__) + '/../../../examples'

        # Load beam
        beam = sk.Beam(ex_dir_ + '/input/beam/amo86615.beam')

        # Load and initialize the detector
        det = sk.PnccdDetector(
            geom=ex_dir_ + '/input/lcls/amo86615/'
            'PNCCD::CalibV1/Camp.0:pnCCD.1/geometry/0-end.data',
            beam=beam)
        cls.det = det

        cls.pos_recip = det.pixel_position_reciprocal

        # Ref Particle
        cls.particle_0 = sk.Particle()
        cls.particle_0.create_from_atoms([  # Angstrom
            ("O", cst.vecx),
            ("O", 2 * cst.vecy),
            ("O", 3 * cst.vecz),
        ])
        cls.pattern_0 = sg.calculate_diffraction_pattern_gpu(
            cls.pos_recip, cls.particle_0, return_type="complex_field")

        # Second Particle
        cls.part_coord_1 = np.array((0.5, 0.2, 0.1))  # Angstrom
        cls.particle_1 = sk.Particle()
        cls.particle_1.create_from_atoms([  # Angstrom
            ("O", cst.vecx + cls.part_coord_1),
            ("O", 2 * cst.vecy + cls.part_coord_1),
            ("O", 3 * cst.vecz + cls.part_coord_1),
        ])
        cls.part_coord_1 *= 1e-10  # Angstrom -> meter
        cls.pattern_1 = sg.calculate_diffraction_pattern_gpu(
            cls.pos_recip, cls.particle_1, return_type="complex_field")
Example #6
0
 def compute(self):
     import skopi.gpu as gpu
     stack = gpu.calculate_diffraction_pattern_gpu(self.hkl,
                                                   self.particle,
                                                   return_type="intensity")
     dist = xp.linalg.norm(self.hkl, axis=-1)
     bins = xp.rint(dist / 1e7).astype(xp.int)
     saxs_weights = xp.bincount(bins)
     saxs_acc = xp.bincount(bins, weights=stack)
     saxs = saxs_acc / saxs_weights
     qaccs = xp.bincount(bins, weights=dist)
     qs = qaccs / saxs_weights
     if xp is np:
         return qs, saxs
     else:
         return qs.get(), saxs.get()
Example #7
0
    def __init__(self, pdb_file, colors=False, debug=False):
        super(ApplicationWindow, self).__init__()
        self.debug = debug

        # Create a particle object
        self.particle = sk.Particle()
        self.particle.read_pdb(pdb_file, ff='WK')

        # Load beam
        beam = sk.Beam('../input/beam/amo86615.beam')

        # Load and initialize the detector
        self.det = sk.PnccdDetector(
            geom='../input/lcls/amo86615/PNCCD::CalibV1/'
            'Camp.0:pnCCD.1/geometry/0-end.data',
            beam=beam)

        mesh_length = 151 if not debug else 31
        mesh, self.voxel_length = self.det.get_reciprocal_mesh(
            voxel_number_1d=mesh_length)

        self.volume = sg.calculate_diffraction_pattern_gpu(
            mesh, self.particle, return_type='intensity')

        self.pixel_momentum = self.det.pixel_position_reciprocal

        if colors:
            color_map = collections.defaultdict(lambda: "#000000", {
                "C": "#ff0000",
                "N": "#00ff00",
                "O": "#0000ff",
            })
            colors = [color_map[s] for s in self.particle.atomic_symbol]
        else:
            colors = None

        self._azim = None
        self._elev = None
        self._time = 0.
        self._uptodate = False

        self._main = QtWidgets.QWidget()
        self.setCentralWidget(self._main)
        layout = QtWidgets.QHBoxLayout(self._main)

        real3d_canvas = FigureCanvas(Figure(figsize=(4, 4)))
        layout.addWidget(real3d_canvas)
        self.addToolBar(NavigationToolbar(real3d_canvas, self))

        self._real3d_ax = real3d_canvas.figure.subplots(
            subplot_kw={"projection": '3d'})
        self._real3d_ax.scatter(
            -self.particle.atom_pos[:, 2],
            self.particle.atom_pos[:, 1],
            self.particle.atom_pos[:, 0],
            s=1,
            c=colors,
        )
        self._real3d_ax.set_title("3D Protein")
        self._real3d_ax.set_xlabel('-Z')
        self._real3d_ax.set_ylabel('Y')
        self._real3d_ax.set_zlabel('X')

        if self.debug:
            real2d_canvas = FigureCanvas(Figure(figsize=(4, 4)))
            layout.addWidget(real2d_canvas)
            self.addToolBar(NavigationToolbar(real2d_canvas, self))

            self._real2d_ax = real2d_canvas.figure.subplots()

        recip_canvas = FigureCanvas(Figure(figsize=(4, 4)))
        layout.addWidget(recip_canvas)
        self.addToolBar(NavigationToolbar(recip_canvas, self))

        self._recip_ax = recip_canvas.figure.subplots()

        self._timer = recip_canvas.new_timer(100,
                                             [(self._update_canvas, (), {})])
        self._timer.start()