Ejemplo n.º 1
0
def do_index(reciprocal_space_vectors, verbose=True):
  D = dps_core()
  D.setMaxcell(algorithm_parameters.max_cell_edge_for_dps_fft)
  D.setXyzData(reciprocal_space_vectors)
  hemisphere_shortcut(ai = D,
    characteristic_sampling = algorithm_parameters.directional_sampling_granularity,
    max_cell = algorithm_parameters.max_cell_edge_basis_choice)
  M = SelectBasisMetaprocedure(D)

  from rstbx.dps_core.lepage import iotbx_converter
  L = iotbx_converter(D.getOrientation().unit_cell().minimum_cell(),5.0)
  supergroup = L[0]

  triclinic = D.getOrientation().unit_cell()

  cb_op = supergroup['cb_op_inp_best'].c().as_double_array()[0:9]
  orient = D.getOrientation()
  orient_best = orient.change_basis(matrix.sqr(cb_op).transpose())
  constrain_orient = orient_best.constrain(supergroup['system'])
  D.setOrientation(constrain_orient)

  if verbose:
    for subgroup in L:
      print subgroup.short_digest()
    print "\ntriclinic cell=%s volume(A^3)=%.3f"%(triclinic,triclinic.volume())
    print "\nafter symmetrizing to %s:"%supergroup.reference_lookup_symbol()
    M.show_rms()
  return D,L
Ejemplo n.º 2
0
def do_index(reciprocal_space_vectors, verbose=True):
    D = dps_core()
    D.setMaxcell(algorithm_parameters.max_cell_edge_for_dps_fft)
    D.setXyzData(reciprocal_space_vectors)
    hemisphere_shortcut(
        ai=D,
        characteristic_sampling=algorithm_parameters.
        directional_sampling_granularity,
        max_cell=algorithm_parameters.max_cell_edge_basis_choice)
    M = SelectBasisMetaprocedure(D)

    from rstbx.dps_core.lepage import iotbx_converter
    L = iotbx_converter(D.getOrientation().unit_cell().minimum_cell(), 5.0)
    supergroup = L[0]

    triclinic = D.getOrientation().unit_cell()

    cb_op = supergroup['cb_op_inp_best'].c().as_double_array()[0:9]
    orient = D.getOrientation()
    orient_best = orient.change_basis(matrix.sqr(cb_op).transpose())
    constrain_orient = orient_best.constrain(supergroup['system'])
    D.setOrientation(constrain_orient)

    if verbose:
        for subgroup in L:
            print subgroup.short_digest()
        print "\ntriclinic cell=%s volume(A^3)=%.3f" % (triclinic,
                                                        triclinic.volume())
        print "\nafter symmetrizing to %s:" % supergroup.reference_lookup_symbol(
        )
        M.show_rms()
    return D, L
Ejemplo n.º 3
0
  def get_input_symmetry_subgroups(self):
    cb_op_input_to_primitive = self.symmetry.change_of_basis_op_to_primitive_setting()
    primitive_symmetry = self.symmetry.primitive_setting()
    cb_op_input_to_minimum = primitive_symmetry.change_of_basis_op_to_minimum_cell() * cb_op_input_to_primitive

    subgroup_list = iotbx_converter(
      self.symmetry.change_basis(cb_op_input_to_minimum).unit_cell(),max_delta=3.0,
      bravais_types_only=False,
      space_group_symbol= str(self.symmetry.change_basis(cb_op_input_to_minimum).space_group_info()),
      force_minimum=False,interest_focus="input_symmetry")

    return subgroup_list
Ejemplo n.º 4
0
  def get_input_symmetry_subgroups(self):
    cb_op_input_to_primitive = self.symmetry.change_of_basis_op_to_primitive_setting()
    primitive_symmetry = self.symmetry.primitive_setting()
    cb_op_input_to_minimum = primitive_symmetry.change_of_basis_op_to_minimum_cell() * cb_op_input_to_primitive

    subgroup_list = iotbx_converter(
      self.symmetry.change_basis(cb_op_input_to_minimum).unit_cell(),max_delta=3.0,
      bravais_types_only=False,
      space_group_symbol= str(self.symmetry.change_basis(cb_op_input_to_minimum).space_group_info()),
      force_minimum=False,interest_focus="input_symmetry")

    return subgroup_list
Ejemplo n.º 5
0
    def apply_symmetry(self, crystal_model):
        if not (self.target_symmetry_primitive
                and self.target_symmetry_primitive.space_group()):
            return crystal, sgtbx.change_of_basis_op()

        target_space_group = self.target_symmetry_primitive.space_group()

        A = crystal_model.get_A()

        max_delta = self._max_delta
        items = iotbx_converter(crystal_model.get_unit_cell(),
                                max_delta=max_delta)
        target_sg_ref = target_space_group.info().reference_setting().group()
        best_angular_difference = 1e8
        best_subgroup = None
        for item in items:
            if bravais_lattice(group=target_sg_ref) != bravais_lattice(
                    group=item["ref_subsym"].space_group()):
                continue
            if item["max_angular_difference"] < best_angular_difference:
                best_angular_difference = item["max_angular_difference"]
                best_subgroup = item

        if best_subgroup is None:
            return None, None

        cb_op_inp_best = best_subgroup["cb_op_inp_best"]
        orient = crystal_orientation(A, True)
        orient_best = orient.change_basis(
            scitbx.matrix.sqr(
                cb_op_inp_best.c().as_double_array()[0:9]).transpose())
        constrain_orient = orient_best.constrain(best_subgroup["system"])

        best_subsym = best_subgroup["best_subsym"]
        cb_op_best_ref = best_subsym.change_of_basis_op_to_reference_setting()
        target_sg_best = target_sg_ref.change_basis(cb_op_best_ref.inverse())
        ref_subsym = best_subsym.change_basis(cb_op_best_ref)
        cb_op_ref_primitive = ref_subsym.change_of_basis_op_to_primitive_setting(
        )
        cb_op_best_primitive = cb_op_ref_primitive * cb_op_best_ref
        cb_op_inp_primitive = cb_op_ref_primitive * cb_op_best_ref * cb_op_inp_best

        direct_matrix = constrain_orient.direct_matrix()

        a = scitbx.matrix.col(direct_matrix[:3])
        b = scitbx.matrix.col(direct_matrix[3:6])
        c = scitbx.matrix.col(direct_matrix[6:9])
        model = Crystal(a, b, c, space_group=target_sg_best)
        assert target_sg_best.is_compatible_unit_cell(model.get_unit_cell())

        model = model.change_basis(cb_op_best_primitive)
        return model, cb_op_inp_primitive
Ejemplo n.º 6
0
    def get_basis_general(self):
        """
    In this function, self requires the following abstract interface:
       n_candidates() = number of candidate basis solutions presented
       __getitem__(i) = return the ith candidate basis vector of type rstbx_ext.Direction
       setOrientation(orientation) where orientation is a cctbx.crystal_orientation object.
          must represent the primitive setting.
       getOrientation()
       niggli() adjusts the stored orientation to the niggli setting
       getMosaicity() = mosaicity in degrees, from labelit, will be removed from interface
       hklobserved()
       combos()
       rmsdev()
       model_likelihood()

    """
        """side-effect: sets orientation matrix"""
        from rstbx.indexing_api.basis_choice import SelectBasisMetaprocedure as SBM
        pd = {}
        M = SBM(input_index_engine=self,
                input_dictionary=pd,
                horizon_phil=self.horizon_phil)  # extended API

        print("Finished SELECT BASIS with solution M", M)

        from rstbx.dps_core.lepage import iotbx_converter
        L = iotbx_converter(self.getOrientation().unit_cell().minimum_cell(),
                            5.0)  # extended API
        supergroup = L[0]

        triclinic = self.getOrientation().unit_cell()  # extended API

        cb_op = supergroup['cb_op_inp_best'].c().as_double_array()[0:9]
        orient = self.getOrientation()  # extended API
        orient_best = orient.change_basis(matrix.sqr(cb_op).transpose())
        constrain_orient = orient_best.constrain(supergroup['system'])
        self.setOrientation(constrain_orient)  # extended API
        L[-1]["orient"] = orient

        if True:
            for subgroup in L:
                print(subgroup.short_digest())
            print("\ntriclinic cell=%s volume(A^3)=%.3f" %
                  (triclinic, triclinic.volume()))
            print("\nafter symmetrizing to %s:" %
                  supergroup.reference_lookup_symbol())
            #M.show_rms()
        return L
Ejemplo n.º 7
0
  def get_basis_general(self):
    """
    In this function, self requires the following abstract interface:
       n_candidates() = number of candidate basis solutions presented
       __getitem__(i) = return the ith candidate basis vector of type rstbx_ext.Direction
       setOrientation(orientation) where orientation is a cctbx.crystal_orientation object.
          must represent the primitive setting.
       getOrientation()
       niggli() adjusts the stored orientation to the niggli setting
       getMosaicity() = mosaicity in degrees, from labelit, will be removed from interface
       hklobserved()
       combos()
       rmsdev()
       model_likelihood()

    """

    """side-effect: sets orientation matrix"""
    from rstbx.indexing_api.basis_choice import SelectBasisMetaprocedure as SBM
    pd = {}
    M = SBM(input_index_engine = self,input_dictionary = pd, horizon_phil = self.horizon_phil) # extended API

    print "Finished SELECT BASIS with solution M",M

    from rstbx.dps_core.lepage import iotbx_converter
    L = iotbx_converter(self.getOrientation().unit_cell().minimum_cell(),5.0) # extended API
    supergroup = L[0]

    triclinic = self.getOrientation().unit_cell() # extended API

    cb_op = supergroup['cb_op_inp_best'].c().as_double_array()[0:9]
    orient = self.getOrientation() # extended API
    orient_best = orient.change_basis(matrix.sqr(cb_op).transpose())
    constrain_orient = orient_best.constrain(supergroup['system'])
    self.setOrientation(constrain_orient) # extended API
    L[-1]["orient"] = orient

    if True:
      for subgroup in L:
        print subgroup.short_digest()
      print "\ntriclinic cell=%s volume(A^3)=%.3f"%(triclinic,triclinic.volume())
      print "\nafter symmetrizing to %s:"%supergroup.reference_lookup_symbol()
      #M.show_rms()
    return L
Ejemplo n.º 8
0
def refined_settings_factory_from_refined_triclinic(params,
                                                    experiments,
                                                    reflections,
                                                    i_setting=None,
                                                    lepage_max_delta=5.0,
                                                    nproc=1,
                                                    refiner_verbosity=0):

    assert len(experiments.crystals()) == 1
    crystal = experiments.crystals()[0]

    used_reflections = copy.deepcopy(reflections)
    UC = crystal.get_unit_cell()

    from rstbx.dps_core.lepage import iotbx_converter

    Lfat = refined_settings_list()
    for item in iotbx_converter(UC, lepage_max_delta):
        Lfat.append(bravais_setting(item))

    supergroup = Lfat.supergroup()
    triclinic = Lfat.triclinic()
    triclinic_miller = used_reflections['miller_index']

    # assert no transformation between indexing and bravais list
    assert str(triclinic['cb_op_inp_best']) == "a,b,c"

    Nset = len(Lfat)
    for j in xrange(Nset):
        Lfat[j].setting_number = Nset - j

    from cctbx.crystal_orientation import crystal_orientation
    from cctbx import sgtbx
    from scitbx import matrix
    for j in xrange(Nset):
        cb_op = Lfat[j]['cb_op_inp_best'].c().as_double_array()[0:9]
        orient = crystal_orientation(crystal.get_A(), True)
        orient_best = orient.change_basis(matrix.sqr(cb_op).transpose())
        constrain_orient = orient_best.constrain(Lfat[j]['system'])
        bravais = Lfat[j]["bravais"]
        cb_op_best_ref = Lfat[j][
            'best_subsym'].change_of_basis_op_to_reference_setting()
        space_group = sgtbx.space_group_info(
            number=bravais_lattice_to_lowest_symmetry_spacegroup_number[
                bravais]).group()
        space_group = space_group.change_basis(cb_op_best_ref.inverse())
        bravais = str(bravais_types.bravais_lattice(group=space_group))
        Lfat[j]["bravais"] = bravais
        Lfat[j].unrefined_crystal = dials_crystal_from_orientation(
            constrain_orient, space_group)

    args = []
    for subgroup in Lfat:
        args.append((params, subgroup, used_reflections, experiments,
                     refiner_verbosity))

    results = easy_mp.parallel_map(func=refine_subgroup,
                                   iterable=args,
                                   processes=nproc,
                                   method="multiprocessing",
                                   preserve_order=True,
                                   asynchronous=True,
                                   preserve_exception_message=True)

    for i, result in enumerate(results):
        Lfat[i] = result
    identify_likely_solutions(Lfat)
    return Lfat
Ejemplo n.º 9
0
    def apply_symmetry(self, crystal_model):
        """Apply symmetry constraints to a crystal model.

        Returns the crystal model (with symmetry constraints applied) in the same
        setting as provided as input. The cb_op returned by the method is
        that necessary to transform that model to the user-provided
        target symmetry.

        Args:
            crystal_model (dxtbx.model.Crystal): The input crystal model to which to
              apply symmetry constraints.

        Returns: (dxtbx.model.Crystal, cctbx.sgtbx.change_of_basis_op):
        The crystal model with symmetry constraints applied, and the change_of_basis_op
        that transforms the returned model to the user-specified target symmetry.
        """
        if not (
            self.target_symmetry_primitive
            and self.target_symmetry_primitive.space_group()
        ):
            return crystal, sgtbx.change_of_basis_op()

        target_space_group = self.target_symmetry_primitive.space_group()

        A = crystal_model.get_A()

        max_delta = self._max_delta
        items = iotbx_converter(crystal_model.get_unit_cell(), max_delta=max_delta)
        target_sg_ref = target_space_group.info().reference_setting().group()
        best_angular_difference = 1e8

        best_subgroup = None
        for item in items:
            if bravais_lattice(group=target_sg_ref) != item["bravais"]:
                continue
            if item["max_angular_difference"] < best_angular_difference:
                best_angular_difference = item["max_angular_difference"]
                best_subgroup = item

        if best_subgroup is None:
            return None, None

        cb_op_inp_best = best_subgroup["cb_op_inp_best"]
        best_subsym = best_subgroup["best_subsym"]
        ref_subsym = best_subgroup["ref_subsym"]
        cb_op_ref_best = ref_subsym.change_of_basis_op_to_best_cell()
        cb_op_best_ref = cb_op_ref_best.inverse()
        cb_op_inp_ref = cb_op_best_ref * cb_op_inp_best
        cb_op_ref_inp = cb_op_inp_ref.inverse()

        orient = crystal_orientation(A, True)
        orient_ref = orient.change_basis(
            scitbx.matrix.sqr((cb_op_inp_ref).c().as_double_array()[0:9]).transpose()
        )
        constrain_orient = orient_ref.constrain(best_subgroup["system"])
        direct_matrix = constrain_orient.direct_matrix()

        a = scitbx.matrix.col(direct_matrix[:3])
        b = scitbx.matrix.col(direct_matrix[3:6])
        c = scitbx.matrix.col(direct_matrix[6:9])
        model = Crystal(a, b, c, space_group=target_sg_ref)
        assert target_sg_ref.is_compatible_unit_cell(model.get_unit_cell())

        model = model.change_basis(cb_op_ref_inp)

        if self.cb_op_inp_best is not None:
            # Then the unit cell has been provided: this is the cb_op to map to the
            # user-provided input unit cell
            return model, self.cb_op_inp_best.inverse() * cb_op_inp_best
        if not self.cb_op_ref_inp.is_identity_op():
            if self.target_symmetry_inp.space_group() == best_subsym.space_group():
                # Handle where e.g. the user has requested I2 instead of the reference C2
                return model, cb_op_inp_best
            # The user has specified a setting that is not the reference setting
            return model, self.cb_op_ref_inp * cb_op_inp_ref
        # Default to reference setting
        # This change of basis op will ensure that we get the best beta angle without
        # changing the centring (e.g. from C2 to I2)
        cb_op_ref_best = ref_subsym.change_of_basis_op_to_best_cell(
            best_monoclinic_beta=False
        )
        return model, cb_op_ref_best * cb_op_inp_ref
Ejemplo n.º 10
0
def refined_settings_from_refined_triclinic(experiments, reflections, params):
    """Generate a RefinedSettingsList from a triclinic model.

    Args:
        experiments: The experiments refined with a triclinic model
        reflections: A reflection table containing observed centroids
        params: The working PHIL parameters.

    Returns:
        RefinedSettingsList: A list of the refined settings. The highest symmetry
        setting will be first item in the list, and the triclinic setting will be last.
    """

    if params.nproc is libtbx.Auto:
        params.nproc = number_of_processors()

    if params.refinement.reflections.outlier.algorithm in ("auto",
                                                           libtbx.Auto):
        if experiments[0].goniometer is None:
            params.refinement.reflections.outlier.algorithm = "sauter_poon"
        else:
            # different default to dials.refine
            # tukey is faster and more appropriate at the indexing step
            params.refinement.reflections.outlier.algorithm = "tukey"

    assert len(experiments.crystals()) == 1
    crystal = experiments.crystals()[0]

    used_reflections = copy.deepcopy(reflections)
    UC = crystal.get_unit_cell()

    refined_settings = RefinedSettingsList()
    for item in iotbx_converter(
            UC,
            params.lepage_max_delta,
            best_monoclinic_beta=params.best_monoclinic_beta):
        refined_settings.append(BravaisSetting(item))

    triclinic = refined_settings.triclinic()

    # assert no transformation between indexing and bravais list
    assert str(triclinic["cb_op_inp_best"]) == "a,b,c"

    Nset = len(refined_settings)
    for j in range(Nset):
        refined_settings[j].setting_number = Nset - j

    for subgroup in refined_settings:
        bravais_lattice = str(
            bravais_types.bravais_lattice(
                group=subgroup["best_subsym"].space_group()))
        space_group = lowest_symmetry_space_group_for_bravais_lattice(
            bravais_lattice)
        orient = crystal_orientation(crystal.get_A(), True).change_basis(
            scitbx.matrix.sqr(subgroup["cb_op_inp_best"].c().as_double_array()
                              [0:9]).transpose())
        constrain_orient = orient.constrain(subgroup["system"])
        subgroup["bravais"] = bravais_lattice
        subgroup.unrefined_crystal = dxtbx_crystal_from_orientation(
            constrain_orient, space_group)

    with concurrent.futures.ProcessPoolExecutor(
            max_workers=params.nproc) as pool:
        for i, result in enumerate(
                pool.map(
                    refine_subgroup,
                    ((params, subgroup, used_reflections, experiments)
                     for subgroup in refined_settings),
                )):
            refined_settings[i] = result

    identify_likely_solutions(refined_settings)
    return refined_settings
Ejemplo n.º 11
0
def refined_settings_factory_from_refined_triclinic(
  params, experiments, reflections, i_setting=None,
  lepage_max_delta=5.0, nproc=1, refiner_verbosity=0):

  assert len(experiments.crystals()) == 1
  crystal = experiments.crystals()[0]

  used_reflections = copy.deepcopy(reflections)
  UC = crystal.get_unit_cell()

  from rstbx.dps_core.lepage import iotbx_converter

  Lfat = refined_settings_list()
  for item in iotbx_converter(UC, lepage_max_delta):
    Lfat.append(bravais_setting(item))

  supergroup = Lfat.supergroup()
  triclinic = Lfat.triclinic()
  triclinic_miller = used_reflections['miller_index']

  # assert no transformation between indexing and bravais list
  assert str(triclinic['cb_op_inp_best'])=="a,b,c"

  Nset = len(Lfat)
  for j in xrange(Nset):  Lfat[j].setting_number = Nset-j

  from cctbx.crystal_orientation import crystal_orientation
  from cctbx import sgtbx
  from scitbx import matrix
  for j in xrange(Nset):
    cb_op = Lfat[j]['cb_op_inp_best'].c().as_double_array()[0:9]
    orient = crystal_orientation(crystal.get_A(),True)
    orient_best = orient.change_basis(matrix.sqr(cb_op).transpose())
    constrain_orient = orient_best.constrain(Lfat[j]['system'])
    bravais = Lfat[j]["bravais"]
    cb_op_best_ref = Lfat[j]['best_subsym'].change_of_basis_op_to_reference_setting()
    space_group = sgtbx.space_group_info(
      number=bravais_lattice_to_lowest_symmetry_spacegroup_number[bravais]).group()
    space_group = space_group.change_basis(cb_op_best_ref.inverse())
    bravais = str(bravais_types.bravais_lattice(group=space_group))
    Lfat[j]["bravais"] = bravais
    Lfat[j].unrefined_crystal = dials_crystal_from_orientation(
      constrain_orient, space_group)

  args = []
  for subgroup in Lfat:
    args.append((
      params, subgroup, used_reflections, experiments, refiner_verbosity))

  results = easy_mp.parallel_map(
    func=refine_subgroup,
    iterable=args,
    processes=nproc,
    method="multiprocessing",
    preserve_order=True,
    asynchronous=True,
    preserve_exception_message=True)

  for i, result in enumerate(results):
    Lfat[i] = result
  return Lfat