def possible_twin_laws(self):
     cosets = sgtbx.cosets.left_decomposition_point_groups_only(
         g=self.lattice_group,
         h=self.intensity_symmetry.space_group(
         ).build_derived_acentric_group().make_tidy())
     return cosets.best_partition_representatives(
         cb_op=self.change_of_basis_op_to_minimum_cell.inverse(),
         omit_first_partition=True,
         omit_negative_determinants=True)
 def possible_twin_laws(self):
     cosets = sgtbx.cosets.left_decomposition_point_groups_only(
         g=self.lattice_group, h=self.intensity_symmetry.space_group().build_derived_acentric_group().make_tidy()
     )
     return cosets.best_partition_representatives(
         cb_op=self.change_of_basis_op_to_minimum_cell.inverse(),
         omit_first_partition=True,
         omit_negative_determinants=True,
     )
Exemplo n.º 3
0
 def __init__(O, lattice_group, intensity_group, miller_indices):
   O.lattice_group = lattice_group
   O.intensity_group = intensity_group
   O.miller_indices = miller_indices
   import cctbx.miller
   import cctbx.sgtbx.cosets
   cosets = cctbx.sgtbx.cosets.left_decomposition_point_groups_only(
     g=lattice_group,
     h=intensity_group)
   reps = cosets.best_partition_representatives(omit_first_partition=False)
   O.cb_ops = []
   O.perms = []
   O.inv_perms = []
   for rep in reps:
     assert rep.t().is_zero()
     cb_op = cctbx.sgtbx.change_of_basis_op(rep)
     O.cb_ops.append(cb_op)
     mi_cb = cb_op.apply(miller_indices)
     matches = cctbx.miller.match_indices(mi_cb, miller_indices)
     assert not matches.have_singles()
     perm = matches.permutation()
     O.perms.append(perm)
     O.inv_perms.append(perm.inverse_permutation())
   lookup_dict = {}
   for i_part,part in enumerate(cosets.partitions):
     for s in part:
       assert s.t().is_zero()
       key = str(s.r().as_hkl())
       lookup_dict[key] = i_part
   def multiplication_table(reps_i, reps_j):
     result = []
     for rep_i in reps_i:
       row = []
       for rep_j in reps_j:
         s = rep_i.multiply(rep_j)
         assert s.t().is_zero()
         key = str(s.r().as_hkl())
         row.append(lookup_dict[key])
       result.append(row)
     return result
   reps_inv = [_.inverse() for _ in reps]
   O.i_j_multiplication_table = multiplication_table(reps, reps)
   O.i_inv_j_multiplication_table = multiplication_table(reps_inv, reps)
   O.i_j_inv_multiplication_table = multiplication_table(reps, reps_inv)
Exemplo n.º 4
0
 def __init__(O, lattice_group, intensity_group, miller_indices):
   O.lattice_group = lattice_group
   O.intensity_group = intensity_group
   O.miller_indices = miller_indices
   import cctbx.miller
   import cctbx.sgtbx.cosets
   cosets = cctbx.sgtbx.cosets.left_decomposition_point_groups_only(
     g=lattice_group,
     h=intensity_group)
   reps = cosets.best_partition_representatives(omit_first_partition=False)
   O.cb_ops = []
   O.perms = []
   O.inv_perms = []
   for rep in reps:
     assert rep.t().is_zero()
     cb_op = cctbx.sgtbx.change_of_basis_op(rep)
     O.cb_ops.append(cb_op)
     mi_cb = cb_op.apply(miller_indices)
     matches = cctbx.miller.match_indices(mi_cb, miller_indices)
     assert not matches.have_singles()
     perm = matches.permutation()
     O.perms.append(perm)
     O.inv_perms.append(perm.inverse_permutation())
   lookup_dict = {}
   for i_part,part in enumerate(cosets.partitions):
     for s in part:
       assert s.t().is_zero()
       key = str(s.r().as_hkl())
       lookup_dict[key] = i_part
   def multiplication_table(reps_i, reps_j):
     result = []
     for rep_i in reps_i:
       row = []
       for rep_j in reps_j:
         s = rep_i.multiply(rep_j)
         assert s.t().is_zero()
         key = str(s.r().as_hkl())
         row.append(lookup_dict[key])
       result.append(row)
     return result
   reps_inv = [_.inverse() for _ in reps]
   O.i_j_multiplication_table = multiplication_table(reps, reps)
   O.i_inv_j_multiplication_table = multiplication_table(reps_inv, reps)
   O.i_j_inv_multiplication_table = multiplication_table(reps, reps_inv)
Exemplo n.º 5
0
def exercise_unmerged(space_group_info):
    import random
    from cctbx import sgtbx
    # shuffle the
    space_group = sgtbx.space_group('P 1', no_expand=True)
    perm = list(range(len(space_group_info.group())))
    random.shuffle(perm)
    for i in perm:
        space_group.expand_smx(space_group_info.group()[i])
    unit_cell = space_group_info.any_compatible_unit_cell(volume=1000)
    for cb_op in (None,
                  space_group.info().change_of_basis_op_to_primitive_setting(),
                  unit_cell.change_of_basis_op_to_niggli_cell()):
        miller_set = crystal.symmetry(
            unit_cell=unit_cell,
            space_group=space_group).build_miller_set(d_min=1,
                                                      anomalous_flag=True)
        miller_set = miller_set.expand_to_p1().customized_copy(
            space_group_info=miller_set.space_group_info())
        if cb_op is not None:
            miller_set = miller_set.change_basis(cb_op)

        m = mtz.object()
        m.set_title('This is a title')
        m.set_space_group_info(miller_set.space_group_info())
        x = m.add_crystal('XTAL', 'CCTBX', miller_set.unit_cell().parameters())
        d = x.add_dataset('TEST', 1)

        indices = miller_set.indices()
        original_indices = indices.deep_copy()

        # map the miller indices to one hemisphere (i.e. just I+)
        miller.map_to_asu(m.space_group().type(), False, indices)

        h, k, l = [i.iround() for i in indices.as_vec3_double().parts()]
        m.adjust_column_array_sizes(len(h))
        m.set_n_reflections(len(h))

        # assign H, K, L
        d.add_column('H', 'H').set_values(h.as_double().as_float())
        d.add_column('K', 'H').set_values(k.as_double().as_float())
        d.add_column('L', 'H').set_values(l.as_double().as_float())

        d.add_column('M_ISYM', 'Y').set_values(flex.float(len(indices)))

        m.replace_original_index_miller_indices(original_indices)

        assert (m.extract_original_index_miller_indices() == original_indices
                ).count(False) == 0
        # check the indices in the mtz file are actually in the asu
        extracted_indices = m.extract_miller_indices()
        miller.map_to_asu(m.space_group().type(), False, extracted_indices)
        assert (
            extracted_indices == m.extract_miller_indices()).count(False) == 0

        # test change_basis_in_place if appropriate for current space group
        import cctbx.sgtbx.cosets

        cb_op_to_niggli_cell \
          = miller_set.change_of_basis_op_to_niggli_cell()

        minimum_cell_symmetry = crystal.symmetry.change_basis(
            miller_set.crystal_symmetry(), cb_op=cb_op_to_niggli_cell)

        lattice_group = sgtbx.lattice_symmetry.group(
            minimum_cell_symmetry.unit_cell(), max_delta=3.0)
        lattice_group.expand_inv(sgtbx.tr_vec((0, 0, 0)))
        lattice_group.make_tidy()

        cosets = sgtbx.cosets.left_decomposition_point_groups_only(
            g=lattice_group,
            h=minimum_cell_symmetry.reflection_intensity_symmetry(
                anomalous_flag=True).space_group(
                ).build_derived_acentric_group().make_tidy())

        possible_twin_laws = cosets.best_partition_representatives(
            cb_op=cb_op_to_niggli_cell.inverse(),
            omit_first_partition=True,
            omit_negative_determinants=True)

        for twin_law in possible_twin_laws:
            cb_op = sgtbx.change_of_basis_op(twin_law.as_xyz())
            #print cb_op.as_hkl()
            # forward direction
            m.change_basis_in_place(cb_op)
            assert (m.extract_original_index_miller_indices() == cb_op.apply(
                original_indices)).count(False) == 0
            ## check the indices in the mtz file are actually in the asu
            #extracted_indices = m.extract_miller_indices()
            #miller.map_to_asu(m.space_group().type(), False, extracted_indices)
            #assert (extracted_indices == m.extract_miller_indices()).count(False) == 0
            # and back again
            m.change_basis_in_place(cb_op.inverse())
            assert (m.extract_original_index_miller_indices() ==
                    original_indices).count(False) == 0
Exemplo n.º 6
0
def exercise_unmerged(space_group_info):
    import random
    from cctbx import sgtbx

    # shuffle the
    space_group = sgtbx.space_group("P 1", no_expand=True)
    perm = list(range(len(space_group_info.group())))
    random.shuffle(perm)
    for i in perm:
        space_group.expand_smx(space_group_info.group()[i])
    unit_cell = space_group_info.any_compatible_unit_cell(volume=1000)
    for cb_op in (
        None,
        space_group.info().change_of_basis_op_to_primitive_setting(),
        unit_cell.change_of_basis_op_to_niggli_cell(),
    ):
        miller_set = crystal.symmetry(unit_cell=unit_cell, space_group=space_group).build_miller_set(
            d_min=1, anomalous_flag=True
        )
        miller_set = miller_set.expand_to_p1().customized_copy(space_group_info=miller_set.space_group_info())
        if cb_op is not None:
            miller_set = miller_set.change_basis(cb_op)

        m = mtz.object()
        m.set_title("This is a title")
        m.set_space_group_info(miller_set.space_group_info())
        x = m.add_crystal("XTAL", "CCTBX", miller_set.unit_cell().parameters())
        d = x.add_dataset("TEST", 1)

        indices = miller_set.indices()
        original_indices = indices.deep_copy()

        # map the miller indices to one hemisphere (i.e. just I+)
        miller.map_to_asu(m.space_group().type(), False, indices)

        h, k, l = [i.iround() for i in indices.as_vec3_double().parts()]
        m.adjust_column_array_sizes(len(h))
        m.set_n_reflections(len(h))

        # assign H, K, L
        d.add_column("H", "H").set_values(h.as_double().as_float())
        d.add_column("K", "H").set_values(k.as_double().as_float())
        d.add_column("L", "H").set_values(l.as_double().as_float())

        d.add_column("M_ISYM", "Y").set_values(flex.float(len(indices)))

        m.replace_original_index_miller_indices(original_indices)

        assert (m.extract_original_index_miller_indices() == original_indices).count(False) == 0
        # check the indices in the mtz file are actually in the asu
        extracted_indices = m.extract_miller_indices()
        miller.map_to_asu(m.space_group().type(), False, extracted_indices)
        assert (extracted_indices == m.extract_miller_indices()).count(False) == 0

        # test change_basis_in_place if appropriate for current space group
        import cctbx.sgtbx.cosets

        cb_op_to_niggli_cell = miller_set.change_of_basis_op_to_niggli_cell()

        minimum_cell_symmetry = crystal.symmetry.change_basis(miller_set.crystal_symmetry(), cb_op=cb_op_to_niggli_cell)

        lattice_group = sgtbx.lattice_symmetry.group(minimum_cell_symmetry.unit_cell(), max_delta=3.0)
        lattice_group.expand_inv(sgtbx.tr_vec((0, 0, 0)))
        lattice_group.make_tidy()

        cosets = sgtbx.cosets.left_decomposition_point_groups_only(
            g=lattice_group,
            h=minimum_cell_symmetry.reflection_intensity_symmetry(anomalous_flag=True)
            .space_group()
            .build_derived_acentric_group()
            .make_tidy(),
        )

        possible_twin_laws = cosets.best_partition_representatives(
            cb_op=cb_op_to_niggli_cell.inverse(), omit_first_partition=True, omit_negative_determinants=True
        )

        for twin_law in possible_twin_laws:
            cb_op = sgtbx.change_of_basis_op(twin_law.as_xyz())
            # print cb_op.as_hkl()
            # forward direction
            m.change_basis_in_place(cb_op)
            assert (m.extract_original_index_miller_indices() == cb_op.apply(original_indices)).count(False) == 0
            ## check the indices in the mtz file are actually in the asu
            # extracted_indices = m.extract_miller_indices()
            # miller.map_to_asu(m.space_group().type(), False, extracted_indices)
            # assert (extracted_indices == m.extract_miller_indices()).count(False) == 0
            # and back again
            m.change_basis_in_place(cb_op.inverse())
            assert (m.extract_original_index_miller_indices() == original_indices).count(False) == 0