Example #1
0
        def get_values(invert_y):

            from dxtbx.model.beam import beam_factory
            beam = beam_factory.simple(wavelength=1)

            if invert_y:
                y_direction = "-y"
            else:
                y_direction = "+y"

            from dxtbx.model.detector import detector_factory
            detector = detector_factory.simple(
                sensor=detector_factory.sensor("PAD"),
                distance=100,
                beam_centre=[50, 50],
                fast_direction="+x",
                slow_direction=y_direction,
                pixel_size=[0.1, 0.1],
                image_size=[1000, 1000])

            from dxtbx.model import ParallaxCorrectedPxMmStrategy
            from cctbx.eltbx import attenuation_coefficient
            wavelength = beam.get_wavelength()
            thickness = 0.5
            table = attenuation_coefficient.get_table("Si")
            mu = table.mu_at_angstrom(wavelength) / 10.0
            t0 = thickness

            for panel in detector:
                panel.set_px_mm_strategy(ParallaxCorrectedPxMmStrategy(mu, t0))
            v1 = detector[0].pixel_to_millimeter((0, 0))
            v2 = detector[0].pixel_to_millimeter((1000, 1000))

            return v1, v2
  def __init__(self,params):
    import cPickle as pickle
    from dxtbx.model.beam import beam_factory
    from dxtbx.model.detector import detector_factory
    from dxtbx.model.crystal import crystal_model
    from cctbx.crystal_orientation import crystal_orientation,basis_type
    from dxtbx.model.experiment.experiment_list import Experiment, ExperimentList
    from scitbx import matrix
    self.experiments = ExperimentList()
    self.unique_file_names = []

    self.params = params
    data = pickle.load(open(self.params.output.prefix+"_frame.pickle","rb"))
    frames_text = data.split("\n")

    for item in frames_text:
      tokens = item.split(' ')
      wavelength = float(tokens[order_dict["wavelength"]])

      beam = beam_factory.simple(wavelength = wavelength)

      detector = detector_factory.simple(
        sensor = detector_factory.sensor("PAD"), # XXX shouldn't hard code for XFEL
        distance = float(tokens[order_dict["distance"]]),
        beam_centre = [float(tokens[order_dict["beam_x"]]), float(tokens[order_dict["beam_y"]])],
        fast_direction = "+x",
        slow_direction = "+y",
        pixel_size = [self.params.pixel_size,self.params.pixel_size],
        image_size = [1795,1795],  # XXX obviously need to figure this out
        )

      reciprocal_matrix = matrix.sqr([float(tokens[order_dict[k]]) for k in [
'res_ori_1','res_ori_2','res_ori_3','res_ori_4','res_ori_5','res_ori_6','res_ori_7','res_ori_8','res_ori_9']])
      ORI = crystal_orientation(reciprocal_matrix, basis_type.reciprocal)
      direct = matrix.sqr(ORI.direct_matrix())
      crystal = crystal_model(
        real_space_a = matrix.row(direct[0:3]),
        real_space_b = matrix.row(direct[3:6]),
        real_space_c = matrix.row(direct[6:9]),
        space_group_symbol = "P63",  # XXX obviously another gap in the database paradigm
        mosaicity = float(tokens[order_dict["half_mosaicity_deg"]]),
      )
      crystal.domain_size = float(tokens[order_dict["domain_size_ang"]])
      #if isoform is not None:
      #  newB = matrix.sqr(isoform.fractionalization_matrix()).transpose()
      #  crystal.set_B(newB)

      self.experiments.append(Experiment(beam=beam,
                                  detector=None, #dummy for now
                                  crystal=crystal))
      self.unique_file_names.append(tokens[order_dict["unique_file_name"]])

    self.show_summary()
Example #3
0
    def __init__(self, filename, experiment, HKL, i_sigi, measurements,
                 params):
        from libtbx import adopt_init_args
        adopt_init_args(self, locals())
        self.stash_type = None
        self.stash_res_filter = None

        from dxtbx.model.detector import detector_factory
        self.dummy_detector = detector_factory.simple(
            sensor=detector_factory.sensor("PAD"),
            distance=100,
            beam_centre=[1000, 1000],
            fast_direction="+x",
            slow_direction="+y",
            pixel_size=[0.2, 0.2],
            image_size=[2000, 2000],
        )
Example #4
0
def test_detector():
    """A test class for the detector class."""

    d = detector_factory.simple("CCD", 100.0, (45.0, 52.0), "+x", "-y", (0.172, 0.172), (516, 590), (0, 1024), [])
    t = detector_factory.two_theta(
        "CCD", 60.0, (35.0, 34.0), "+x", "+y", "+x", 30, (0.07, 0.07), (1042, 1042), (0, 1024), []
    )

    import libtbx.load_env
    import os

    dxtbx_dir = libtbx.env.dist_path("dxtbx")

    image = os.path.join(dxtbx_dir, "tests", "phi_scan_001.cbf")
    xparm = os.path.join(dxtbx_dir, "tests", "example-xparm.xds")

    c = detector_factory.imgCIF(image, "CCD")
    # x = detector_factory.XDS(xparm)

    print "OK"
Example #5
0
def test_detector():
    '''A test class for the detector class.'''

    d = detector_factory.simple('CCD', 100.0, (45.0, 52.0), '+x', '-y',
                                (0.172, 0.172), (516, 590), (0, 1024), [])
    t = detector_factory.two_theta('CCD', 60.0, (35.0, 34.0), '+x', '+y', '+x',
                                   30, (0.07, 0.07), (1042, 1042), (0, 1024),
                                   [])

    import libtbx.load_env
    import os

    dxtbx_dir = libtbx.env.dist_path('dxtbx')

    image = os.path.join(dxtbx_dir, 'tests', 'phi_scan_001.cbf')
    xparm = os.path.join(dxtbx_dir, 'tests', 'example-xparm.xds')

    c = detector_factory.imgCIF(image, 'CCD')
    #x = detector_factory.XDS(xparm)

    print 'OK'
  def prepare_dxtbx_models(self,setting_specific_ai,sg,isoform=None):

    from dxtbx.model.beam import beam_factory
    beam = beam_factory.simple(wavelength = self.inputai.wavelength)

    from dxtbx.model.detector import detector_factory
    detector = detector_factory.simple(
      sensor = detector_factory.sensor("PAD"),
      distance = setting_specific_ai.distance(),
      beam_centre = [setting_specific_ai.xbeam(), setting_specific_ai.ybeam()],
      fast_direction = "+x",
      slow_direction = "+y",
      pixel_size = [self.pixel_size,self.pixel_size],
      image_size = [self.inputpd['size1'],self.inputpd['size1']],
      )

    direct = matrix.sqr(setting_specific_ai.getOrientation().direct_matrix())
    from dxtbx.model.crystal import crystal_model
    crystal = crystal_model(
      real_space_a = matrix.row(direct[0:3]),
      real_space_b = matrix.row(direct[3:6]),
      real_space_c = matrix.row(direct[6:9]),
      space_group_symbol = sg,
      mosaicity = setting_specific_ai.getMosaicity()
    )
    if isoform is not None:
      newB = matrix.sqr(isoform.fractionalization_matrix()).transpose()
      crystal.set_B(newB)

    from dxtbx.model.experiment.experiment_list import Experiment, ExperimentList
    experiments = ExperimentList()
    experiments.append(Experiment(beam=beam,
                                  detector=detector,
                                  crystal=crystal))

    print beam
    print detector
    print crystal
    return experiments
Example #7
0
img_root = libtbx.env.find_in_repositories("dials_regression")
if img_root is not None:
    img_path = os.path.join(img_root, "spotfinding_test_data/idx-s00-20131106040304531.cbf")
else:
    img_path = None

if img_path is not None and os.path.exists(img_path):
    img = dxtbx.load(img_path)
    detector = img.get_detector()
    # Manually push the detector in to 100 mm
    h = detector.hierarchy()
    h.set_local_frame(h.get_fast_axis(), h.get_slow_axis(), (0, 0, -100))
else:
    # If dials_regression not present, use a simple detector with a single panel, similar to a CSPAD
    detector = detector_factory.simple("SENSOR_UNKNOWN", 100, (97.075, 97.075), "+x", "-y", (0.11, 0.11), (1765, 1765))

# Here's the MarCCD at XPP if desired.
# detector=detector_factory.simple('SENSOR_UNKNOWN',150,(162.5,162.5),'+x','-y',(0.079346,0.079346),(4096,4096))


# Beam model
wavelength = 1.32  # from Boutet 2012
beam = beam_factory.simple_directional((0, 0, 1), wavelength)

# Unit cell and space group for lysozyme from Boutet 2012
known_symmetry = crystal.symmetry("79,79,38,90,90,90", "P43212")
# known_symmetry=crystal.symmetry("79,79,38,90,90,90","P1")
uc = known_symmetry.unit_cell()
spgrp = known_symmetry.space_group()
    def __init__(self, params):
        import cPickle as pickle
        from dxtbx.model.beam import beam_factory
        from dxtbx.model.detector import detector_factory
        from dxtbx.model.crystal import crystal_model
        from cctbx.crystal_orientation import crystal_orientation, basis_type
        from dxtbx.model.experiment.experiment_list import Experiment, ExperimentList
        from scitbx import matrix
        self.experiments = ExperimentList()
        self.unique_file_names = []

        self.params = params
        data = pickle.load(
            open(self.params.output.prefix + "_frame.pickle", "rb"))
        frames_text = data.split("\n")

        for item in frames_text:
            tokens = item.split(' ')
            wavelength = float(tokens[order_dict["wavelength"]])

            beam = beam_factory.simple(wavelength=wavelength)

            detector = detector_factory.simple(
                sensor=detector_factory.sensor(
                    "PAD"),  # XXX shouldn't hard code for XFEL
                distance=float(tokens[order_dict["distance"]]),
                beam_centre=[
                    float(tokens[order_dict["beam_x"]]),
                    float(tokens[order_dict["beam_y"]])
                ],
                fast_direction="+x",
                slow_direction="+y",
                pixel_size=[self.params.pixel_size, self.params.pixel_size],
                image_size=[1795,
                            1795],  # XXX obviously need to figure this out
            )

            reciprocal_matrix = matrix.sqr([
                float(tokens[order_dict[k]]) for k in [
                    'res_ori_1', 'res_ori_2', 'res_ori_3', 'res_ori_4',
                    'res_ori_5', 'res_ori_6', 'res_ori_7', 'res_ori_8',
                    'res_ori_9'
                ]
            ])
            ORI = crystal_orientation(reciprocal_matrix, basis_type.reciprocal)
            direct = matrix.sqr(ORI.direct_matrix())
            crystal = crystal_model(
                real_space_a=matrix.row(direct[0:3]),
                real_space_b=matrix.row(direct[3:6]),
                real_space_c=matrix.row(direct[6:9]),
                space_group_symbol=self.params.target_space_group.type().
                lookup_symbol(),
                mosaicity=float(tokens[order_dict["half_mosaicity_deg"]]),
            )
            crystal.domain_size = float(tokens[order_dict["domain_size_ang"]])
            #if isoform is not None:
            #  newB = matrix.sqr(isoform.fractionalization_matrix()).transpose()
            #  crystal.set_B(newB)

            self.experiments.append(
                Experiment(
                    beam=beam,
                    detector=None,  #dummy for now
                    crystal=crystal))
            self.unique_file_names.append(
                tokens[order_dict["unique_file_name"]])

        self.show_summary()
def run(args):

    distance = 125
    centre = (97.075, 97.075)
    pix_size = (0.11, 0.11)
    image_size = (1765, 1765)
    wavelength = args.w or 1.0
    # 1. Make a dummy detector
    detector = detector_factory.simple(
        'SENSOR_UNKNOWN',  # Sensor
        distance,
        centre,
        '+x',
        '-y',  # fast/slow direction
        pix_size,
        image_size)

    # 2. Get the miller array!
    mill_array = process_mtz(args.mtzfile[0]).as_intensity_array()
    ortho = sqr(mill_array.crystal_symmetry().unit_cell().reciprocal() \
              .orthogonalization_matrix())

    # 3.Create some image_pickle dictionairies that contain 'full' intensities,
    # but are otherwise complete.
    im = 0
    while im < args.n:
        im += 1
        A = sqr(flex.random_double_r3_rotation_matrix()) * ortho
        orientation = crystal_orientation(A, basis_type.reciprocal)
        pix_coords, miller_set = get_pix_coords(wavelength, A, mill_array,
                                                detector)
        if len(miller_set) > 10:  # at least 10 reflections
            miller_set = cctbx.miller.set(mill_array.crystal_symmetry(),
                                          miller_set,
                                          anomalous_flag=False)
            obs = mill_array.common_set(miller_set)
            temp_dict = {
                'observations': [obs],
                'mapped_predictions': [pix_coords],
                'pointgroup': None,
                'current_orientation': [orientation],
                'xbeam': centre[0],
                'ybeam': centre[1],
                'wavelength': wavelength
            }
            old_node = ImageNode(dicti=temp_dict, scale=False)
            # Remove all reflection that are not at least p partial
            partial_sel = (old_node.partialities > p_threshold)

            temp_dict['full_observations'] = [obs.select(partial_sel)]
            temp_dict['observations'] = [
                obs.select(partial_sel) *
                old_node.partialities.select(partial_sel)
            ]
            temp_dict['mapped_predictions'] = \
                        [temp_dict['mapped_predictions'][0].select(partial_sel)]

            if logging.Logger.root.level <= logging.DEBUG:  # debug!
                before = temp_dict['full_observations'][0]
                after = temp_dict['observations'][0] / old_node.partialities
                assert sum(abs(before.data() - after.data())) < eps

            if args.r:
                partials = list(temp_dict['observations'][0].data())
                jiggled_partials = flex.double(
                    [random.gauss(obs, args.r * obs) for obs in partials])
                temp_dict['observations'][0] = temp_dict['observations'][0] \
                                            .customized_copy(data=jiggled_partials)

            pkl_name = "simulated_data_{0:04d}.pickle".format(im)
            with (open(pkl_name, 'wb')) as pkl:
                cPickle.dump(temp_dict, pkl)
            ''' Only works with no noise:
def run(args):

  distance = 125
  centre = (97.075, 97.075)
  pix_size = (0.11, 0.11)
  image_size = (1765, 1765)
  wavelength = args.w or 1.0
  # 1. Make a dummy detector
  detector = detector_factory.simple('SENSOR_UNKNOWN', # Sensor
                                          distance,
                                          centre,
                                          '+x','-y', # fast/slow direction
                                          pix_size,
                                          image_size)

  # 2. Get the miller array!
  mill_array = process_mtz(args.mtzfile[0]).as_intensity_array()
  ortho = sqr(mill_array.crystal_symmetry().unit_cell().reciprocal() \
            .orthogonalization_matrix())

  # 3.Create some image_pickle dictionairies that contain 'full' intensities,
  # but are otherwise complete.
  im = 0
  while im < args.n:
    im += 1
    A = sqr(flex.random_double_r3_rotation_matrix()) * ortho
    orientation = crystal_orientation(A, basis_type.reciprocal)
    pix_coords, miller_set = get_pix_coords(wavelength, A, mill_array, detector)
    if len(miller_set) > 10:  # at least 10 reflections
        miller_set = cctbx.miller.set(mill_array.crystal_symmetry(), miller_set,
                anomalous_flag=False)
        obs = mill_array.common_set(miller_set)
        temp_dict = {'observations': [obs],
                     'mapped_predictions': [pix_coords],
                     'pointgroup': None,
                     'current_orientation': [orientation],
                     'xbeam': centre[0],
                     'ybeam': centre[1],
                     'wavelength': wavelength}
        old_node = ImageNode(dicti=temp_dict, scale=False)
        # Remove all reflection that are not at least p partial
        partial_sel = (old_node.partialities > p_threshold)

        temp_dict['full_observations'] = [obs.select(partial_sel)]
        temp_dict['observations'] = [obs.select(partial_sel)
                            * old_node.partialities.select(partial_sel)]
        temp_dict['mapped_predictions'] = \
                    [temp_dict['mapped_predictions'][0].select(partial_sel)]

        if logging.Logger.root.level <= logging.DEBUG:  # debug!
          before = temp_dict['full_observations'][0]
          after = temp_dict['observations'][0] / old_node.partialities
          assert sum(abs(before.data() - after.data())) < eps

        if args.r:
          partials = list(temp_dict['observations'][0].data())
          jiggled_partials = flex.double([random.gauss(obs, args.r * obs)
                                          for obs in partials])
          temp_dict['observations'][0] = temp_dict['observations'][0] \
                                      .customized_copy(data=jiggled_partials)

        pkl_name = "simulated_data_{0:04d}.pickle".format(im)
        with(open(pkl_name, 'wb')) as pkl:
          cPickle.dump(temp_dict, pkl)

        ''' Only works with no noise:
Example #11
0
img_root = libtbx.env.find_in_repositories("dials_regression")
if img_root is not None:
    img_path = os.path.join(
        img_root, "spotfinding_test_data/idx-s00-20131106040304531.cbf")
else:
    img_path = None

if img_path is not None and os.path.exists(img_path):
    img = dxtbx.load(img_path)
    detector = img.get_detector()
    # Manually push the detector in to 100 mm
    h = detector.hierarchy()
    h.set_local_frame(h.get_fast_axis(), h.get_slow_axis(), (0, 0, -100))
else:
    # If dials_regression not present, use a simple detector with a single panel, similar to a CSPAD
    detector = detector_factory.simple("SENSOR_UNKNOWN", 100, (97.075, 97.075),
                                       "+x", "-y", (0.11, 0.11), (1765, 1765))

# Here's the MarCCD at XPP if desired.
# detector=detector_factory.simple('SENSOR_UNKNOWN',150,(162.5,162.5),'+x','-y',(0.079346,0.079346),(4096,4096))

# Beam model
wavelength = 1.32  # from Boutet 2012
beam = beam_factory.simple_directional((0, 0, 1), wavelength)

# Unit cell and space group for lysozyme from Boutet 2012
known_symmetry = crystal.symmetry("79,79,38,90,90,90", "P43212")
# known_symmetry=crystal.symmetry("79,79,38,90,90,90","P1")
uc = known_symmetry.unit_cell()
spgrp = known_symmetry.space_group()