Ejemplo n.º 1
0
def candidate_basis_vectors_fft1d(reciprocal_lattice_vectors, params,
                                  max_cell=None):

  # Spot_positions: Centroid positions for spotfinder spots, in pixels
  # Return value: Corrected for parallax, converted to mm

  # derive a max_cell from mm spots
  # derive a grid sampling from spots

  from rstbx.indexing_api.lattice import DPS_primitive_lattice
  # max_cell: max possible cell in Angstroms; set to None, determine from data
  # recommended_grid_sampling_rad: grid sampling in radians; guess for now

  DPS = DPS_primitive_lattice(max_cell=max_cell,
                              recommended_grid_sampling_rad = None,
                              horizon_phil = params)
  from scitbx import matrix
  #DPS.S0_vector = matrix.col(beam.get_s0())
  #DPS.inv_wave = 1./beam.get_wavelength()

  # transform input into what Nick needs
  # i.e., construct a flex.vec3 double consisting of mm spots, phi in degrees

  DPS.index(reciprocal_space_vectors=reciprocal_lattice_vectors)
  solutions = DPS.getSolutions()
  return [matrix.col(s.bvec()) for s in solutions],DPS.getXyzData()
Ejemplo n.º 2
0
    def find_basis_vectors(self, reciprocal_lattice_vectors):
        """Find a list of likely basis vectors.

        Args:
            reciprocal_lattice_vectors (scitbx.array_family.flex.vec3_double):
                The list of reciprocal lattice vectors to search for periodicity.

        Returns:
            A tuple containing the list of basis vectors and a flex.bool array
            identifying which reflections were used in indexing.

        """
        from rstbx.phil.phil_preferences import indexing_api_defs
        import iotbx.phil

        used_in_indexing = flex.bool(reciprocal_lattice_vectors.size(), True)

        hardcoded_phil = iotbx.phil.parse(
            input_string=indexing_api_defs).extract()

        # Spot_positions: Centroid positions for spotfinder spots, in pixels
        # Return value: Corrected for parallax, converted to mm

        # derive a max_cell from mm spots
        # derive a grid sampling from spots

        from rstbx.indexing_api.lattice import DPS_primitive_lattice

        # max_cell: max possible cell in Angstroms; set to None, determine from data
        # recommended_grid_sampling_rad: grid sampling in radians; guess for now

        DPS = DPS_primitive_lattice(
            max_cell=self._max_cell,
            recommended_grid_sampling_rad=self._params.characteristic_grid,
            horizon_phil=hardcoded_phil,
        )

        # transform input into what Nick needs
        # i.e., construct a flex.vec3 double consisting of mm spots, phi in degrees
        DPS.index(reciprocal_space_vectors=reciprocal_lattice_vectors)
        solutions = DPS.getSolutions()
        candidate_basis_vectors = [matrix.col(s.bvec()) for s in solutions]
        return candidate_basis_vectors, used_in_indexing
Ejemplo n.º 3
0
def candidate_basis_vectors_fft1d(reciprocal_lattice_vectors,
                                  params,
                                  max_cell=None):

    # Spot_positions: Centroid positions for spotfinder spots, in pixels
    # Return value: Corrected for parallax, converted to mm

    # derive a max_cell from mm spots
    # derive a grid sampling from spots

    from rstbx.indexing_api.lattice import DPS_primitive_lattice
    # max_cell: max possible cell in Angstroms; set to None, determine from data
    # recommended_grid_sampling_rad: grid sampling in radians; guess for now

    DPS = DPS_primitive_lattice(max_cell=max_cell,
                                recommended_grid_sampling_rad=None,
                                horizon_phil=params)
    from scitbx import matrix
    #DPS.S0_vector = matrix.col(beam.get_s0())
    #DPS.inv_wave = 1./beam.get_wavelength()

    # transform input into what Nick needs
    # i.e., construct a flex.vec3 double consisting of mm spots, phi in degrees

    DPS.index(reciprocal_space_vectors=reciprocal_lattice_vectors)
    solutions = DPS.getSolutions()
    return [matrix.col(s.bvec()) for s in solutions], DPS.getXyzData()
Ejemplo n.º 4
0
def run_dps(args):
    imageset, spots_mm, max_cell, params = args

    detector = imageset.get_detector()
    beam = imageset.get_beam()
    goniometer = imageset.get_goniometer()
    scan = imageset.get_scan()

    from rstbx.indexing_api.lattice import DPS_primitive_lattice
    # max_cell: max possible cell in Angstroms; set to None, determine from data
    # recommended_grid_sampling_rad: grid sampling in radians; guess for now

    DPS = DPS_primitive_lattice(max_cell=max_cell,
                                recommended_grid_sampling_rad=None,
                                horizon_phil=params)

    from scitbx import matrix
    DPS.S0_vector = matrix.col(beam.get_s0())
    DPS.inv_wave = 1. / beam.get_wavelength()
    if goniometer is None:
        DPS.axis = matrix.col((1, 0, 0))
    else:
        DPS.axis = matrix.col(goniometer.get_rotation_axis())
    DPS.set_detector(detector)

    # transform input into what Nick needs
    # i.e., construct a flex.vec3 double consisting of mm spots, phi in degrees

    data = flex.vec3_double()
    for spot in spots_mm:
        data.append((spot['xyzobs.mm.value'][0], spot['xyzobs.mm.value'][1],
                     spot['xyzobs.mm.value'][2] * 180. / math.pi))

    #from matplotlib import pyplot as plt
    #plt.plot([spot.centroid_position[0] for spot in spots_mm] , [spot.centroid_position[1] for spot in spots_mm], 'ro')
    #plt.show()

    logger.info("Running DPS using %i reflections" % len(data))

    DPS.index(raw_spot_input=data,
              panel_addresses=flex.int([s['panel'] for s in spots_mm]))
    solutions = DPS.getSolutions()
    from libtbx.utils import plural_s
    logger.info("Found %i solution%s with max unit cell %.2f Angstroms." %
                (len(solutions), plural_s(len(solutions))[1], DPS.amax))
    if len(solutions) < 3:
        from libtbx.utils import Sorry
        raise Sorry("Not enough solutions: found %i, need at least 3" %
                    (len(solutions)))
    return dict(solutions=flex.vec3_double([s.dvec for s in solutions]),
                amax=DPS.amax)
Ejemplo n.º 5
0
def run_dps(experiment, spots_mm, max_cell):
    # max_cell: max possible cell in Angstroms; set to None, determine from data
    # recommended_grid_sampling_rad: grid sampling in radians; guess for now

    horizon_phil = iotbx.phil.parse(input_string=indexing_api_defs).extract()
    DPS = DPS_primitive_lattice(max_cell=max_cell,
                                recommended_grid_sampling_rad=None,
                                horizon_phil=horizon_phil)

    DPS.S0_vector = matrix.col(experiment.beam.get_s0())
    DPS.inv_wave = 1.0 / experiment.beam.get_wavelength()
    if experiment.goniometer is None:
        DPS.axis = matrix.col((1, 0, 0))
    else:
        DPS.axis = matrix.col(experiment.goniometer.get_rotation_axis())
    DPS.set_detector(experiment.detector)

    # transform input into what DPS needs
    # i.e., construct a flex.vec3 double consisting of mm spots, phi in degrees
    data = flex.vec3_double()
    for spot in spots_mm.rows():
        data.append((
            spot["xyzobs.mm.value"][0],
            spot["xyzobs.mm.value"][1],
            spot["xyzobs.mm.value"][2] * 180.0 / math.pi,
        ))

    logger.info("Running DPS using %i reflections" % len(data))

    DPS.index(
        raw_spot_input=data,
        panel_addresses=flex.int(s["panel"] for s in spots_mm.rows()),
    )
    solutions = DPS.getSolutions()

    logger.info("Found %i solution%s with max unit cell %.2f Angstroms." %
                (len(solutions), plural_s(len(solutions))[1], DPS.amax))

    # There must be at least 3 solutions to make a set, otherwise return empty result
    if len(solutions) < 3:
        return {}
    return dict(solutions=flex.vec3_double(s.dvec for s in solutions),
                amax=DPS.amax)
Ejemplo n.º 6
0
def test_out(process_dictionary,data,phil_set):
    from rstbx.indexing_api.lattice import DPS_primitive_lattice
    from scitbx.matrix import col

    sample_to_beamspot = col((0.,0.,float(process_dictionary['distance'])))
    detector_d1 = col((1., 0., 0.))
    detector_d2 = col((0., 1., 0.))
    detector_origin = sample_to_beamspot - \
      detector_d1 * float(process_dictionary['xbeam']) - \
      detector_d2 * float(process_dictionary['ybeam'])
    assert detector_d1.length() == 1.0
    assert detector_d2.length() == 1.0
    assert detector_d1.dot(detector_d2) == 0.0

    beam_vector = sample_to_beamspot.normalize() * (
                  1./float(process_dictionary['wavelength']))
    rot_axis = col(process_dictionary["endstation"].rot_axi) - col((0.0,0.0,0.0)) # coerce to float type

    DPS = DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
          recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
          horizon_phil = phil_set)
    DPS.set_beam_vector(beam = -beam_vector)
    DPS.set_rotation_axis(axis = rot_axis)
    DPS.set_detector_position(origin = detector_origin, d1 = detector_d1, d2 = detector_d2)

    DPS.index(raw_spot_input = data)
    L = DPS.get_basis_general()


    new_detector = DPS.optimize_origin_offset_local_scope()

    DPS2= DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
        recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
        horizon_phil = phil_set)
    DPS2.set_beam_vector(beam = -beam_vector)
    DPS2.set_rotation_axis(axis = rot_axis)
    DPS2.set_detector(new_detector)
    DPS2.index(raw_spot_input = data)
    L = DPS2.get_basis_general()

    from rstbx.indexing_api.outlier_procedure import main_go
    main_go(index_engine=DPS2, phil_set=phil_set)

    print "Finishing"
    exit()
Ejemplo n.º 7
0
def test_dps_single_panel_labelit_input_optimal_origin(process_dictionary,data,phil_set):
    from rstbx.indexing_api.lattice import DPS_primitive_lattice
    from scitbx.matrix import col

    sample_to_beamspot = col((0.,0.,float(process_dictionary['distance'])))
    detector_d1 = col((1., 0., 0.))
    detector_d2 = col((0., 1., 0.))
    detector_origin = sample_to_beamspot - \
      detector_d1 * float(process_dictionary['xbeam']) - \
      detector_d2 * float(process_dictionary['ybeam'])
    assert detector_d1.length() == 1.0
    assert detector_d2.length() == 1.0
    assert detector_d1.dot(detector_d2) == 0.0

    from dxtbx.model.detector import detector_factory
    detector = detector_factory.make_detector(
      stype = "indexing",
      fast_axis = detector_d1,
      slow_axis = detector_d2,
      origin = detector_origin,
      pixel_size = (float(process_dictionary['pixel_size']),
                    float(process_dictionary['pixel_size'])),
      image_size = (int(process_dictionary['size1']),
                    int(process_dictionary['size2']))
      )

    beam_vector = sample_to_beamspot.normalize() * (
                  1./float(process_dictionary['wavelength']))
    rot_axis = col(process_dictionary["endstation"].rot_axi) - col((0.0,0.0,0.0)) # coerce to float type

    DPS = DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
          recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
          horizon_phil = phil_set)
    DPS.set_beam_vector(beam = -beam_vector)
    DPS.set_rotation_axis(axis = rot_axis)
    DPS.set_detector(detector)

    DPS.index(raw_spot_input = data)
    #L = DPS.get_basis_general() # can skip this first time around
    new_detector = DPS.optimize_origin_offset_local_scope()

    DPS2= DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
        recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
        horizon_phil = phil_set)
    DPS2.set_beam_vector(beam = -beam_vector)
    DPS2.set_rotation_axis(axis = rot_axis)
    DPS2.set_detector(new_detector)
    DPS2.index(raw_spot_input = data)
    L = DPS2.get_basis_general()
Ejemplo n.º 8
0
def test_out(process_dictionary,data,phil_set):
    from rstbx.indexing_api.lattice import DPS_primitive_lattice
    from scitbx.matrix import col

    sample_to_beamspot = col((0.,0.,float(process_dictionary['distance'])))
    detector_d1 = col((1., 0., 0.))
    detector_d2 = col((0., 1., 0.))
    detector_origin = sample_to_beamspot - \
      detector_d1 * float(process_dictionary['xbeam']) - \
      detector_d2 * float(process_dictionary['ybeam'])
    assert detector_d1.length() == 1.0
    assert detector_d2.length() == 1.0
    assert detector_d1.dot(detector_d2) == 0.0

    beam_vector = sample_to_beamspot.normalize() * (
                  1./float(process_dictionary['wavelength']))
    rot_axis = col(process_dictionary["endstation"].rot_axi) - col((0.0,0.0,0.0)) # coerce to float type

    DPS = DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
          recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
          horizon_phil = phil_set)
    DPS.set_beam_vector(beam = -beam_vector)
    DPS.set_rotation_axis(axis = rot_axis)
    DPS.set_detector_position(origin = detector_origin, d1 = detector_d1, d2 = detector_d2)

    DPS.index(raw_spot_input = data)
    L = DPS.get_basis_general()


    new_detector = DPS.optimize_origin_offset_local_scope()

    DPS2= DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
        recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
        horizon_phil = phil_set)
    DPS2.set_beam_vector(beam = -beam_vector)
    DPS2.set_rotation_axis(axis = rot_axis)
    DPS2.set_detector(new_detector)
    DPS2.index(raw_spot_input = data)
    L = DPS2.get_basis_general()

    from rstbx.indexing_api.outlier_procedure import main_go
    main_go(index_engine=DPS2, phil_set=phil_set)

    print "Finishing"
    exit()
Ejemplo n.º 9
0
def test_dps_single_panel_labelit_input_optimal_origin(process_dictionary,data,phil_set):
    from rstbx.indexing_api.lattice import DPS_primitive_lattice
    from scitbx.matrix import col

    sample_to_beamspot = col((0.,0.,float(process_dictionary['distance'])))
    detector_d1 = col((1., 0., 0.))
    detector_d2 = col((0., 1., 0.))
    detector_origin = sample_to_beamspot - \
      detector_d1 * float(process_dictionary['xbeam']) - \
      detector_d2 * float(process_dictionary['ybeam'])
    assert detector_d1.length() == 1.0
    assert detector_d2.length() == 1.0
    assert detector_d1.dot(detector_d2) == 0.0

    from dxtbx.model import DetectorFactory
    detector = DetectorFactory.make_detector(
      stype = "indexing",
      fast_axis = detector_d1,
      slow_axis = detector_d2,
      origin = detector_origin,
      pixel_size = (float(process_dictionary['pixel_size']),
                    float(process_dictionary['pixel_size'])),
      image_size = (int(process_dictionary['size1']),
                    int(process_dictionary['size2']))
      )

    beam_vector = sample_to_beamspot.normalize() * (
                  1./float(process_dictionary['wavelength']))
    rot_axis = col(process_dictionary["endstation"].rot_axi) - col((0.0,0.0,0.0)) # coerce to float type

    DPS = DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
          recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
          horizon_phil = phil_set)
    DPS.set_beam_vector(beam = -beam_vector)
    DPS.set_rotation_axis(axis = rot_axis)
    DPS.set_detector(detector)

    DPS.index(raw_spot_input = data)
    #L = DPS.get_basis_general() # can skip this first time around
    new_detector = DPS.optimize_origin_offset_local_scope()

    DPS2= DPS_primitive_lattice(max_cell = float(process_dictionary['ref_maxcel']),
        recommended_grid_sampling_rad = process_dictionary['recommended_grid_sampling'],
        horizon_phil = phil_set)
    DPS2.set_beam_vector(beam = -beam_vector)
    DPS2.set_rotation_axis(axis = rot_axis)
    DPS2.set_detector(new_detector)
    DPS2.index(raw_spot_input = data)
    L = DPS2.get_basis_general()
Ejemplo n.º 10
0
def run_dps(args):
    imageset, spots_mm, max_cell, params = args

    detector = imageset.get_detector()
    beam = imageset.get_beam()
    goniometer = imageset.get_goniometer()

    # max_cell: max possible cell in Angstroms; set to None, determine from data
    # recommended_grid_sampling_rad: grid sampling in radians; guess for now

    DPS = DPS_primitive_lattice(max_cell=max_cell,
                                recommended_grid_sampling_rad=None,
                                horizon_phil=params)

    DPS.S0_vector = matrix.col(beam.get_s0())
    DPS.inv_wave = 1.0 / beam.get_wavelength()
    if goniometer is None:
        DPS.axis = matrix.col((1, 0, 0))
    else:
        DPS.axis = matrix.col(goniometer.get_rotation_axis())
    DPS.set_detector(detector)

    # transform input into what Nick needs
    # i.e., construct a flex.vec3 double consisting of mm spots, phi in degrees

    data = flex.vec3_double()
    for spot in spots_mm.rows():
        data.append((
            spot["xyzobs.mm.value"][0],
            spot["xyzobs.mm.value"][1],
            spot["xyzobs.mm.value"][2] * 180.0 / math.pi,
        ))

    logger.info("Running DPS using %i reflections" % len(data))

    DPS.index(
        raw_spot_input=data,
        panel_addresses=flex.int(s["panel"] for s in spots_mm.rows()),
    )
    solutions = DPS.getSolutions()

    logger.info("Found %i solution%s with max unit cell %.2f Angstroms." %
                (len(solutions), plural_s(len(solutions))[1], DPS.amax))
    if len(solutions) < 3:

        raise Sorry("Not enough solutions: found %i, need at least 3" %
                    (len(solutions)))
    return dict(solutions=flex.vec3_double([s.dvec for s in solutions]),
                amax=DPS.amax)
def run_dps(args):
  imageset, spots_mm, max_cell, params = args

  detector = imageset.get_detector()
  beam = imageset.get_beam()
  goniometer = imageset.get_goniometer()
  scan = imageset.get_scan()

  from rstbx.indexing_api.lattice import DPS_primitive_lattice
  # max_cell: max possible cell in Angstroms; set to None, determine from data
  # recommended_grid_sampling_rad: grid sampling in radians; guess for now

  DPS = DPS_primitive_lattice(max_cell=max_cell,
                              recommended_grid_sampling_rad=None,
                              horizon_phil=params)

  from scitbx import matrix
  DPS.S0_vector = matrix.col(beam.get_s0())
  DPS.inv_wave = 1./beam.get_wavelength()
  if goniometer is None:
    DPS.axis = matrix.col((1,0,0))
  else:
    DPS.axis = matrix.col(goniometer.get_rotation_axis())
  DPS.set_detector(detector)

  # transform input into what Nick needs
  # i.e., construct a flex.vec3 double consisting of mm spots, phi in degrees

  data = flex.vec3_double()
  for spot in spots_mm:
    data.append((spot['xyzobs.mm.value'][0],
                 spot['xyzobs.mm.value'][1],
                 spot['xyzobs.mm.value'][2]*180./math.pi))

  #from matplotlib import pyplot as plt
  #plt.plot([spot.centroid_position[0] for spot in spots_mm] , [spot.centroid_position[1] for spot in spots_mm], 'ro')
  #plt.show()

  logger.info("Running DPS using %i reflections" %len(data))

  DPS.index(raw_spot_input=data,
            panel_addresses=flex.int([s['panel'] for s in spots_mm]))
  logger.info("Found %i solutions with max unit cell %.2f Angstroms." %(
    len(DPS.getSolutions()), DPS.amax))
  return dict(solutions=flex.vec3_double(
    [s.dvec for s in DPS.getSolutions()]), amax=DPS.amax)