Ejemplo n.º 1
0
 def space_group(self,space_group=None,format='symbol'):
     # format can be 'number', 'symbol' (Hermann-Mauguin)
     # As a setter method, no need to specify the format; always converts to symbol to store in self._space_group
     # and presumes standard setting if number is given
     # As a getter method, 'symbol' is the default
     if space_group is not None:
             sgs = space_group_symbols(space_group)
             self._space_group = sgs.universal_hermann_mauguin()
             # self._space_group = sgs.universal_hall() needs reading with sgs = space_group_symbols(self._space_group,table_id = "Hall")
     else:
         sgs = space_group_symbols(self._space_group)
         if format=='number':
             return sgs.number()
         elif format=='symbol':
             return sgs.universal_hermann_mauguin()
Ejemplo n.º 2
0
def map_sites_to_asu(spacegroup, pdb_in, pdb_out, invert=False):
    '''Map sites to asu of input spacegroup (as sites from shelxd claim
    P1 in CRYST1 record) inverting if necessary. N.B. if inverting sites
    also need to invert spacegroup.'''

    from cctbx.crystal import symmetry, direct_space_asu
    from iotbx.pdb import hierarchy
    from scitbx.array_family import flex

    sg = space_group(space_group_symbols(spacegroup).hall())
    coords = hierarchy.input(file_name=pdb_in)
    cs = coords.input.crystal_symmetry()
    uc = cs.unit_cell()
    cs2 = symmetry(unit_cell=uc, space_group=sg)
    xs = coords.xray_structure_simple().customized_copy(crystal_symmetry=cs2)

    if invert:
        xs = xs.change_hand()

    am = xs.crystal_symmetry().asu_mappings(0.0)
    xyz = xs.sites_cart()
    am.process_sites_cart(xyz)
    xyz = flex.vec3_double()
    for m in am.mappings():
        xyz.append(m[0].mapped_site())
    xs.set_sites_cart(xyz)

    open(pdb_out, 'w').write(xs.as_pdb_file())

    return
def generate_enantiomorph_unique_spacegroups(pointgroup):
    '''Generate an enantiomorph unique list of chiral spacegroups which
    share a pointgroup with this pointgroup.'''

    sg = space_group(space_group_symbols(pointgroup).hall())
    pg = sg.build_derived_patterson_group()

    eu_list = []

    for j in space_group_symbol_iterator():
        sg_test = space_group(j)

        if not sg_test.is_chiral():
            continue

        pg_test = sg_test.build_derived_patterson_group()
        if pg_test == pg:
            enantiomorph = sg_test.change_basis(
                sg_test.type().change_of_hand_op())
            if not sg_test in eu_list and not \
               enantiomorph in eu_list:
                eu_list.append(sg_test)

    return [
        sg_test.type().lookup_symbol().replace(' ', '') \
        for sg_test in eu_list]
Ejemplo n.º 4
0
def ref_gen_static(experiments):
  """Generate some reflections using the static predictor"""

  beam = experiments[0].beam
  crystal = experiments[0].crystal
  goniometer = experiments[0].goniometer
  detector = experiments[0].detector
  scan = experiments[0].scan

  # All indices to the detector max resolution
  dmin = detector.get_max_resolution(beam.get_s0())
  index_generator = IndexGenerator(crystal.get_unit_cell(),
                  space_group(space_group_symbols(1).hall()).type(), dmin)
  indices = index_generator.to_array()

  # Predict rays within the sweep range
  sweep_range = scan.get_oscillation_range(deg=False)
  ray_predictor = ScansRayPredictor(experiments, sweep_range)
  refs = ray_predictor(indices)

  # Take only those rays that intersect the detector
  intersects = ray_intersection(detector, refs)
  refs = refs.select(intersects)

  # Make a reflection predictor and re-predict for these reflections. The
  # result is the same, but we gain also the flags and xyzcal.px columns
  ref_predictor = ExperimentsPredictor(experiments)
  refs['id'] = flex.int(len(refs), 0)
  refs = ref_predictor(refs)

  return refs
Ejemplo n.º 5
0
 def __init__(self, sg_nr):
     """Initialize with SG number"""
     self._nr = sg_nr
     self._sg_hall = sgtbx.space_group_symbols(sg_nr).hall()
     super(SpaceGroup, self).__init__(self._sg_hall)
     self._order = self.order_z()
     self._symops = []
Ejemplo n.º 6
0
def modify_ins_text(_ins_text, _spacegroup, _nsites, _rlimit):
    '''Update the text in a SHELXD .ins file to handle the correct number
    of sites and spacegroup symmetry operations.'''

    new_text = []

    symm = [
        op.as_xyz().upper()
        for op in space_group(space_group_symbols(_spacegroup).hall()).smx()
    ]

    for record in _ins_text:
        if 'SYMM' in record:
            if not symm:
                continue
            for op in symm:
                if op == 'X,Y,Z':
                    continue
                new_text.append(('SYMM %s' % op))
            symm = None
        elif 'FIND' in record:
            new_text.append(('FIND %d' % _nsites))
        elif 'SHEL' in record:
            new_text.append(('SHEL 999 %.1f' % _rlimit))
        else:
            new_text.append(record.strip())

    return new_text
Ejemplo n.º 7
0
def to_crystal(filename):
  ''' Get the crystal model from the xparm file

  Params:
      filename The xparm/or integrate filename

  Return:
      The crystal model

  '''
  from rstbx.cftbx.coordinate_frame_converter import \
      coordinate_frame_converter
  from dxtbx.model.crystal import crystal_model
  from cctbx.sgtbx import space_group, space_group_symbols

  # Get the real space coordinate frame
  cfc = coordinate_frame_converter(filename)
  real_space_a = cfc.get('real_space_a')
  real_space_b = cfc.get('real_space_b')
  real_space_c = cfc.get('real_space_c')
  sg = cfc.get('space_group_number')
  space_group = space_group(space_group_symbols(sg).hall())
  mosaicity = cfc.get('mosaicity')

  # Return the crystal model
  return crystal_model(
      real_space_a=real_space_a,
      real_space_b=real_space_b,
      real_space_c=real_space_c,
      space_group=space_group,
      mosaicity=mosaicity)
Ejemplo n.º 8
0
def to_crystal(filename):
    ''' Get the crystal model from the xparm file

  Params:
      filename The xparm/or integrate filename

  Return:
      The crystal model

  '''
    from rstbx.cftbx.coordinate_frame_converter import \
        coordinate_frame_converter
    from dxtbx.model.crystal import crystal_model
    from cctbx.sgtbx import space_group, space_group_symbols

    # Get the real space coordinate frame
    cfc = coordinate_frame_converter(filename)
    real_space_a = cfc.get('real_space_a')
    real_space_b = cfc.get('real_space_b')
    real_space_c = cfc.get('real_space_c')
    sg = cfc.get('space_group_number')
    space_group = space_group(space_group_symbols(sg).hall())
    mosaicity = cfc.get('mosaicity')

    # Return the crystal model
    return crystal_model(real_space_a=real_space_a,
                         real_space_b=real_space_b,
                         real_space_c=real_space_c,
                         space_group=space_group,
                         mosaicity=mosaicity)
Ejemplo n.º 9
0
def run(server_info, inp, status):
    print "<pre>"

    symbols_inp = None
    lookup_symbol = inp.sgsymbol
    if (lookup_symbol == ""): lookup_symbol = "P 1"
    if (inp.convention == "Hall"):
        hall_symbol = lookup_symbol
    else:
        symbols_inp = sgtbx.space_group_symbols(lookup_symbol, inp.convention)
        hall_symbol = symbols_inp.hall()
        if (symbols_inp.number() == 0):
            symbols_inp = None
            inp.convention = "Hall"
        else:
            print "Result of symbol lookup:"
            show_symbols(symbols_inp)
            print

    try:
        ps = sgtbx.parse_string(hall_symbol)
        sg = sgtbx.space_group(ps)
    except RuntimeError, e:
        print "--&gt;" + ps.string() + "&lt;--"
        print("-" * (ps.where() + 3)) + "^"
        raise
Ejemplo n.º 10
0
    def generate_reflections(self):
        # Build a mock scan for a 3 degree sweep
        from dxtbx.model import ScanFactory
        sf = ScanFactory()
        self.scan = sf.make_scan(image_range=(1, 1),
                                 exposure_times=0.1,
                                 oscillation=(0, 3.0),
                                 epochs=range(1),
                                 deg=True)
        sweep_range = self.scan.get_oscillation_range(deg=False)

        # Create a scans ExperimentList, only for generating reflections
        experiments = ExperimentList()
        experiments.append(
            Experiment(beam=self.beam,
                       detector=self.detector,
                       goniometer=self.gonio,
                       scan=self.scan,
                       crystal=self.crystal,
                       imageset=None))

        # Create a ScansRayPredictor
        ray_predictor = ScansRayPredictor(experiments, sweep_range)

        # Generate rays - only to work out which hkls are predicted
        resolution = 2.0
        index_generator = IndexGenerator(
            self.crystal.get_unit_cell(),
            space_group(space_group_symbols(1).hall()).type(), resolution)
        indices = index_generator.to_array()
        rays = ray_predictor(indices)

        # Make a standard reflection_table and copy in the ray data
        self.reflections = flex.reflection_table.empty_standard(len(rays))
        self.reflections.update(rays)
  def generate_reflections(self):

    # Build a mock scan for a 3 degree sweep
    from dxtbx.model.scan import scan_factory
    sf = scan_factory()
    self.scan = sf.make_scan(image_range = (1,1),
                          exposure_times = 0.1,
                          oscillation = (0, 3.0),
                          epochs = range(1),
                          deg = True)
    sweep_range = self.scan.get_oscillation_range(deg=False)

    # Create a scans ExperimentList, only for generating reflections
    experiments = ExperimentList()
    experiments.append(Experiment(
          beam=self.beam, detector=self.detector, goniometer=self.gonio, scan=self.scan,
          crystal=self.crystal, imageset=None))

    # Create a ScansRayPredictor
    ray_predictor = ScansRayPredictor(experiments, sweep_range)

    # Generate rays - only to work out which hkls are predicted
    resolution = 2.0
    index_generator = IndexGenerator(self.crystal.get_unit_cell(),
                          space_group(space_group_symbols(1).hall()).type(),
                          resolution)
    indices = index_generator.to_array()
    rays = ray_predictor.predict(indices)

    # Make a standard reflection_table and copy in the ray data
    self.reflections = flex.reflection_table.empty_standard(len(rays))
    self.reflections.update(rays)

    return
def get_and_check_file():
  if ( not os.path.isfile(html_file)
       or open(html_file).read().lower().find("not found") >= 0):
    print "Skipping exercise(): input file not available"
    return
  table_lines = open(html_file).read().splitlines()[11:-4]
  assert len(table_lines) == 530, "%d != 530" % len(table_lines)
  space_group_symbol_iterator = sgtbx.space_group_symbol_iterator()
  for line in table_lines:
    flds = line.split()
    assert len(flds) == 3
    nc, hm, hall = flds
    assert hall.lower() == hall
    symbols = sgtbx.space_group_symbols(symbol=hm)
    hm_sgtbx = symbols.universal_hermann_mauguin().replace(" ", "_") \
      .replace("_:",":") \
      .replace(":H",":h") \
      .replace(":R",":r")
    hall_sgtbx = symbols.hall().lower().replace(" ", "_")
    if (hall_sgtbx[0] == "_"): hall_sgtbx = hall_sgtbx[1:]
    assert hm_sgtbx == hm
    assert hall_sgtbx == hall
    symbols_i = space_group_symbol_iterator.next()
    assert symbols_i.universal_hermann_mauguin() \
        == symbols.universal_hermann_mauguin()
Ejemplo n.º 13
0
def run(server_info, inp, status):
  print "<pre>"

  symbols_inp = None
  lookup_symbol = inp.sgsymbol
  if (lookup_symbol == ""): lookup_symbol = "P 1"
  if (inp.convention == "Hall"):
    hall_symbol = lookup_symbol
  else:
    symbols_inp = sgtbx.space_group_symbols(lookup_symbol, inp.convention)
    hall_symbol = symbols_inp.hall()
    if (symbols_inp.number() == 0):
      symbols_inp = None
      inp.convention = "Hall"
    else:
      print "Result of symbol lookup:"
      show_symbols(symbols_inp)
      print

  try:
    ps = sgtbx.parse_string(hall_symbol)
    sg = sgtbx.space_group(ps)
  except RuntimeError, e:
    print "--&gt;" + ps.string() + "&lt;--"
    print ("-" * (ps.where() + 3)) + "^"
    raise
Ejemplo n.º 14
0
    def reindex_old(self):
      self.set_executable(os.path.join(os.environ.get('CBIN', ''),
                                       'reindex'))
      self.check_hklin()
      self.check_hklout()

      if not self._spacegroup and not self._operator:
        raise RuntimeError, 'reindex requires spacegroup or operator'

      self.start()

      # look up the space group number to cope with complex symbols
      # that old fashioned CCP4 reindex does not understand...
      from cctbx.sgtbx import space_group, space_group_symbols
      sg_t = space_group(space_group_symbols(str(self._spacegroup))).type()

      if self._operator:
        self.input('reindex %s' % str(self._operator))
      if self._spacegroup:
        self.input('symmetry %d' % sg_t.number())
      self.close_wait()

      # check for errors

      try:
        self.check_for_errors()

      except RuntimeError, e:
        try:
          os.remove(self.get_hklout())
        except:
          pass

        raise e
Ejemplo n.º 15
0
def get_test_space_group_symbols(flag_AllSpaceGroups,
                                 flag_ChiralSpaceGroups,
                                 flag_AllSettings,
                                 flag_UnusualSettings):
  if (flag_UnusualSettings):
    namespace = {}
    execfile(os.path.join(
      libtbx.env.find_in_repositories(
        "phenix_regression"), "settings.py"), namespace)
    return namespace["settings"]
  if (flag_AllSettings):
    return [symbols.universal_hermann_mauguin()
            for symbols in sgtbx.space_group_symbol_iterator()]
  if (flag_AllSpaceGroups):
    sg_numbers = xrange(1, 231)
  elif (flag_ChiralSpaceGroups):
    sg_numbers = (1, 3, 4, 5, 16, 17, 18, 19, 20, 21, 22, 23, 24, 75,
                  76, 77, 78, 79, 80, 89, 90, 91, 92, 93, 94, 95, 96,
                  97, 98, 143, 144, 145, 146, 149, 150, 151, 152, 153,
                  154, 155, 168, 169, 170, 171, 172, 173, 177, 178,
                  179, 180, 181, 182, 195, 196, 197, 198, 199, 207,
                  208, 209, 210, 211, 212, 213, 214)
  else:
    sg_numbers = (1,2,3,15,16,74,75,76,142,143,144,157,167,168,194,195,230)
  return [sgtbx.space_group_symbols(n).universal_hermann_mauguin()
          for n in sg_numbers] + ["Hall: -F 4 21 (1,5,3)"]
Ejemplo n.º 16
0
def generate_primitive_cell(unit_cell_constants, space_group_name):
    '''For a given set of unit cell constants and space group, determine the
    corresponding primitive unit cell...'''

    uc = unit_cell(unit_cell_constants)
    sg = space_group(space_group_symbols(space_group_name).hall())
    cs = symmetry(unit_cell=uc, space_group=sg)
    csp = cs.change_basis(cs.change_of_basis_op_to_primitive_setting())

    return csp.unit_cell()
Ejemplo n.º 17
0
def is_centred(space_group_number):
  '''Test if space group # corresponds to a centred space group.'''

  sg_hall = sgtbx.space_group_symbols(space_group_number).hall()
  sg = sgtbx.space_group(sg_hall)

  if (sg.n_ltr() - 1):
    return True

  return False
Ejemplo n.º 18
0
def test_ersatz_pointgroup(acentric_space_groups):
    for sg in acentric_space_groups:
        symbol = sg.type().lookup_symbol()
        symbol = symbol.split(":")[0]
        if symbol.count(" 1") == 2:
            symbol = symbol.replace(" 1", "")
        symbol = symbol.replace(" ", "")
        assert (cell_spacegroup.ersatz_pointgroup(symbol) ==
                sgtbx.space_group_symbols(
                    ersatz_pointgroup_old(symbol)).hermann_mauguin())
Ejemplo n.º 19
0
def number_residues_estimate(cell, pointgroup):
    '''Guess the number of residues in the ASU, assuming 50% solvent etc.'''

    sg = space_group(space_group_symbols(pointgroup).hall())
    uc = unit_cell(cell)

    n_ops = len(sg.all_ops())

    v_asu = uc.volume() / n_ops

    return int(round(v_asu / (2.7 * 128)))
Ejemplo n.º 20
0
def remove_sys_absences(reflection_list, space_group_name):

    sg = space_group(space_group_symbols(space_group_name).hall())

    present_reflections = []

    for hkl in reflection_list:
        if not sg.is_sys_absent(hkl):
            present_reflections.append(hkl)

    return present_reflections
Ejemplo n.º 21
0
def regression_test():
    """Perform a regression test by comparing to indices generating
  by the brute force method used in the Use Case."""

    from rstbx.diffraction import rotation_angles
    from rstbx.diffraction import full_sphere_indices
    from cctbx.sgtbx import space_group, space_group_symbols
    from cctbx.uctbx import unit_cell

    # cubic, 50A cell, 1A radiation, 1 deg osciillation, everything ideal

    a = 50.0

    ub_beg = matrix.sqr(
        (1.0 / a, 0.0, 0.0, 0.0, 1.0 / a, 0.0, 0.0, 0.0, 1.0 / a))

    axis = matrix.col((0, 1, 0))

    r_osc = matrix.sqr(
        scitbx.math.r3_rotation_axis_and_angle_as_matrix(axis=axis,
                                                         angle=1.0,
                                                         deg=True))

    ub_end = r_osc * ub_beg

    uc = unit_cell((a, a, a, 90, 90, 90))
    sg = space_group(space_group_symbols('P23').hall())

    s0 = matrix.col((0, 0, 1))

    wavelength = 1.0
    dmin = 1.5

    indices = full_sphere_indices(unit_cell=uc,
                                  resolution_limit=dmin,
                                  space_group=sg)

    ra = rotation_angles(dmin, ub_beg, wavelength, axis)

    obs_indices, obs_angles = ra.observed_indices_and_angles_from_angle_range(
        phi_start_rad=0.0 * pi / 180.0,
        phi_end_rad=1.0 * pi / 180.0,
        indices=indices)

    r = reeke_model(ub_beg, ub_end, axis, s0, dmin, 1.0)
    reeke_indices = r.generate_indices()
    #r.visualize_with_rgl()

    for oi in obs_indices:
        assert (tuple(map(int, oi)) in reeke_indices)

    #TODO Tests for an oblique cell

    print "OK"
Ejemplo n.º 22
0
def symopSymList(sgNr):
    """For a S.G. Returns list of symmetry operations in symbolic form"""
    sg_hall = sgtbx.space_group_symbols(sgNr).hall()
    sg = sgtbx.space_group(sg_hall)
    print "\nGENERATING LIST OF SYMMETRY OPERATIONS FOR S.G. %d..." % (sgNr)
    symop_list = []
    sg_order = sg.order_z()
    for i in range(0, sg_order):
        symop_list.append(sg(i).as_xyz())
    print "A LIST OF %d SYMMETRY OPERATIONS WAS CREATED!\n" % (sg_order)
    return symop_list
Ejemplo n.º 23
0
def exercise_monoclinic_cell_choices_core(space_group_number, verbose):
  # transformation matrices for cell choices
  # columns are basis vectors "new in terms of old"
  # see Int. Tab. Vol. A, p. 22, Fig. 2.2.6.4.
  b1 = (1, 0, 0,
        0, 1, 0,
        0, 0, 1)
  b2 = (-1, 0, 1,
         0, 1, 0,
        -1, 0, 0)
  b3 = (0, 0, -1,
        0, 1,  0,
        1, 0, -1)
  flip = (0,  0, 1,
          0, -1, 0,
          1,  0, 0)
  p3s = sgtbx.space_group("P 3*")
  done = {}
  ref = sgtbx.space_group_info(number=space_group_number)
  ref_uhm = ref.type().universal_hermann_mauguin_symbol()
  for i_fl,fl in enumerate([b1, flip]):
    rfl = sgtbx.rot_mx(fl)
    cfl = sgtbx.change_of_basis_op(sgtbx.rt_mx(rfl))
    for i_rt,rt in enumerate(p3s):
      rp3 = rt.r()
      cp3 = sgtbx.change_of_basis_op(sgtbx.rt_mx(rp3))
      for i_cs,cs in enumerate([b1,b2,b3]):
        rcs = sgtbx.rot_mx(cs).inverse()
        ccs = sgtbx.change_of_basis_op(sgtbx.rt_mx(rcs))
        cb_all = cp3 * cfl * ccs
        refcb = ref.change_basis(cb_all)
        refcb2 = sgtbx.space_group_info(symbol=ref_uhm+"("+str(cb_all.c())+")")
        assert refcb2.group() == refcb.group()
        s = sgtbx.space_group_symbols(str(refcb))
        q = s.qualifier()
        hm = str(refcb)
        if (0 or verbose): print hm, q, cb_all.c()
        if (i_fl == 0):
          assert q[0] == "bca"[i_rt]
          if (len(q) == 2): assert q[1] == "123"[i_cs]
        elif (q[0] == "-"):
          assert q[1] == "bca"[i_rt]
          if (len(q) == 3): assert q[2] == "123"[i_cs]
        else:
          assert q[0] == "bca"[i_rt]
          if (len(q) == 2 and q[1] != "123"[i_cs]):
            assert done[hm] == 1
        done.setdefault(hm, 0)
        done[hm] += 1
  assert len(done) in [3, 9, 18]
  assert done.values() == [18/len(done)]*len(done)
  if (0 or verbose): print
  return done
Ejemplo n.º 24
0
    def generate_reflections(self):
        from cctbx.sgtbx import space_group, space_group_symbols

        from dials.algorithms.spot_prediction import IndexGenerator, ray_intersection

        sequence_range = self.scan.get_oscillation_range(deg=False)
        resolution = 2.0
        index_generator = IndexGenerator(
            self.crystal.get_unit_cell(),
            space_group(space_group_symbols(1).hall()).type(),
            resolution,
        )
        indices = index_generator.to_array()

        # Predict rays within the sequence range
        ray_predictor = ScansRayPredictor(self.experiments, sequence_range)
        obs_refs = ray_predictor(indices)

        # Take only those rays that intersect the detector
        intersects = ray_intersection(self.detector, obs_refs)
        obs_refs = obs_refs.select(intersects)

        # Re-predict using the Experiments predictor for all these reflections. The
        # result is the same, but we gain also the flags and xyzcal.px columns
        obs_refs["id"] = flex.int(len(obs_refs), 0)
        obs_refs = self.ref_predictor(obs_refs)

        # Set 'observed' centroids from the predicted ones
        obs_refs["xyzobs.mm.value"] = obs_refs["xyzcal.mm"]

        # Invent some variances for the centroid positions of the simulated data
        im_width = 0.1 * pi / 180.0
        px_size = self.detector[0].get_pixel_size()
        var_x = flex.double(len(obs_refs), (px_size[0] / 2.0)**2)
        var_y = flex.double(len(obs_refs), (px_size[1] / 2.0)**2)
        var_phi = flex.double(len(obs_refs), (im_width / 2.0)**2)
        obs_refs["xyzobs.mm.variance"] = flex.vec3_double(
            var_x, var_y, var_phi)

        # set the flex random seed to an 'uninteresting' number
        flex.set_random_seed(12407)

        # take 10 random reflections for speed
        reflections = obs_refs.select(flex.random_selection(len(obs_refs), 10))

        # use a BlockCalculator to calculate the blocks per image
        from dials.algorithms.refinement.reflection_manager import BlockCalculator

        block_calculator = BlockCalculator(self.experiments, reflections)
        reflections = block_calculator.per_image()

        return reflections
Ejemplo n.º 25
0
def number_sites_estimate(cell, pointgroup):
    '''Guess # heavy atoms likely to be in here (as a floating point number)
    based on Matthews coefficient, average proportion of methionine in
    protein sequences and typical mass of an amino acid.'''

    sg = space_group(space_group_symbols(pointgroup).hall())
    uc = unit_cell(cell)

    n_ops = len(sg.all_ops())

    v_asu = uc.volume() / n_ops

    return 0.023 * v_asu / (2.7 * 128)
Ejemplo n.º 26
0
def get_space_group_type_from_xparm(handle):
  """Get the space group tyoe object from an xparm file handle

  Params:
      handle The file handle

  Returns:
      The space group type object

  """
  from cctbx import sgtbx
  return sgtbx.space_group_type(sgtbx.space_group(
      sgtbx.space_group_symbols(handle.space_group).hall()))
Ejemplo n.º 27
0
def get_space_group_type_from_xparm(handle):
  """Get the space group tyoe object from an xparm file handle

  Params:
      handle The file handle

  Returns:
      The space group type object

  """
  from cctbx import sgtbx
  return sgtbx.space_group_type(sgtbx.space_group(
      sgtbx.space_group_symbols(handle.space_group).hall()))
Ejemplo n.º 28
0
def Py_remove_absent_indices(indices, space_group_number):
    '''From the given list of indices, remove those reflections which should
    be systematic absences according to the given space group.'''

    sg = space_group(space_group_symbols(space_group_number).hall())

    present = []

    for hkl in indices:
        if not sg.is_sys_absent(hkl):
            present.append(hkl)

    return present
Ejemplo n.º 29
0
 def assign_wyckoff(self, abc, tol=0.1):
     #FIXME This needs improvement and to be tested
     cctbx_name = self.space_group.cctbx_name
     sg_symbol = sgtbx.space_group_symbols(cctbx_name)
     sg = sgtbx.space_group(sg_symbol)
     unit_cell = uctbx.unit_cell(str(self.get_lattice()))
     symmetry = crystal.symmetry(unit_cell=unit_cell, space_group=sg)
     special_position_settings = crystal.special_position_settings(symmetry,min_distance_sym_equiv=0.5)
     site_symmetry = special_position_settings.site_symmetry(abc)
     wyckoff_table = special_position_settings.space_group_info().wyckoff_table()
     wyckoff_mapping = wyckoff_table.mapping(site_symmetry)
     letter = wyckoff_mapping.position().letter()
     return letter
def generate_all_spacegroups(pointgroup):
    '''Generate an enantiomorph unique list of chiral spacegroups which
    share a pointgroup with this pointgroup.'''

    sg = space_group(space_group_symbols(pointgroup).hall())
    pg = sg.build_derived_patterson_group()

    eu_list = []

    for j in range(1, 231):
        sg_test = space_group(space_group_symbols(j).hall())

        if not sg_test.is_chiral():
            continue

        pg_test = sg_test.build_derived_patterson_group()
        if pg_test == pg:
            if not sg_test in eu_list:
                eu_list.append(sg_test)

    return [
        sg_test.type().universal_hermann_mauguin_symbol().replace(' ', '') \
        for sg_test in eu_list]
Ejemplo n.º 31
0
def reduce_reflections_to_asu(space_group_number, indices):
    """Reduce reflection indices to asymmetric unit."""

    from cctbx.sgtbx import space_group, space_group_symbols
    from cctbx.array_family import flex
    from cctbx.miller import map_to_asu

    sg = space_group(space_group_symbols(space_group_number).hall())

    miller = flex.miller_index(indices)

    map_to_asu(sg.type(), False, miller)

    return [hkl for hkl in miller]
Ejemplo n.º 32
0
def reduce_reflections_to_asu(space_group_number, indices):
  '''Reduce reflection indices to asymmetric unit.'''

  from cctbx.sgtbx import space_group, space_group_symbols
  from cctbx.array_family import flex
  from cctbx.miller import map_to_asu

  sg = space_group(space_group_symbols(space_group_number).hall())

  miller = flex.miller_index(indices)

  map_to_asu(sg.type(), False, miller)

  return [hkl for hkl in miller]
    def __init__(
        self,
        real_space_a,
        real_space_b,
        real_space_c,
        space_group_symbol=None,
        space_group=None,
        mosaicity=None,
        deg=True,
    ):

        # Set the space group
        assert [space_group_symbol, space_group].count(None) == 1
        if space_group_symbol:
            self._sg = SG(space_group_symbols(space_group_symbol))
        else:
            self._sg = space_group

        # Set the mosaicity
        if mosaicity is not None:
            self.set_mosaicity(mosaicity, deg=deg)
        else:
            self._mosaicity = 0.0

        # setting matrix at initialisation
        real_space_a = matrix.col(real_space_a)
        real_space_b = matrix.col(real_space_b)
        real_space_c = matrix.col(real_space_c)
        A = matrix.sqr(real_space_a.elems + real_space_b.elems +
                       real_space_c.elems).inverse()

        # unit cell
        self.set_unit_cell(real_space_a, real_space_b, real_space_c)

        # reciprocal space orthogonalisation matrix (is the transpose of the
        # real space fractionalisation matrix, see http://goo.gl/H3p1s)
        self._update_B()

        # initial orientation matrix
        self._U = A * self._B.inverse()

        # set up attributes for scan-varying model
        self.reset_scan_points()

        # set up attributes for unit cell errors
        self.reset_unit_cell_errors()

        return
Ejemplo n.º 34
0
def regression_test():
    """Perform a regression test by comparing to indices generating
  by the brute force method used in the Use Case."""

    from rstbx.diffraction import rotation_angles
    from rstbx.diffraction import full_sphere_indices
    from cctbx.sgtbx import space_group, space_group_symbols
    from cctbx.uctbx import unit_cell

    # cubic, 50A cell, 1A radiation, 1 deg osciillation, everything ideal

    a = 50.0

    ub_beg = matrix.sqr((1.0 / a, 0.0, 0.0, 0.0, 1.0 / a, 0.0, 0.0, 0.0, 1.0 / a))

    axis = matrix.col((0, 1, 0))

    r_osc = matrix.sqr(scitbx.math.r3_rotation_axis_and_angle_as_matrix(axis=axis, angle=1.0, deg=True))

    ub_end = r_osc * ub_beg

    uc = unit_cell((a, a, a, 90, 90, 90))
    sg = space_group(space_group_symbols("P23").hall())

    s0 = matrix.col((0, 0, 1))

    wavelength = 1.0
    dmin = 1.5

    indices = full_sphere_indices(unit_cell=uc, resolution_limit=dmin, space_group=sg)

    ra = rotation_angles(dmin, ub_beg, wavelength, axis)

    obs_indices, obs_angles = ra.observed_indices_and_angles_from_angle_range(
        phi_start_rad=0.0 * pi / 180.0, phi_end_rad=1.0 * pi / 180.0, indices=indices
    )

    r = reeke_model(ub_beg, ub_end, axis, s0, dmin, 1.0)
    reeke_indices = r.generate_indices()
    # r.visualize_with_rgl()

    for oi in obs_indices:
        assert tuple(map(int, oi)) in reeke_indices

    # TODO Tests for an oblique cell

    print "OK"
Ejemplo n.º 35
0
    def __init__(self, real_space_a, real_space_b, real_space_c, sg=1):

        self._sg = space_group(space_group_symbols(sg).hall())

        # setting matrix at initialisation
        A = matrix.sqr(real_space_a.elems + real_space_b.elems +
                       real_space_c.elems).inverse()

        # unit cell
        self.set_unit_cell(real_space_a, real_space_b, real_space_c)

        # reciprocal space orthogonalisation matrix (is the transpose of the
        # real space fractionalisation matrix, see http://goo.gl/H3p1s)
        self._update_B()

        # initial orientation matrix
        self._U = A * self._B.inverse()
def test_versus_brute_force():
    """Perform a regression test by comparing to indices generated by the brute
    force method"""

    # cubic, 50A cell, 1A radiation, 1 deg osciillation, everything ideal
    a = 50.0
    ub_beg = matrix.sqr(
        (1.0 / a, 0.0, 0.0, 0.0, 1.0 / a, 0.0, 0.0, 0.0, 1.0 / a))
    axis = matrix.col((0, 1, 0))
    r_osc = matrix.sqr(
        r3_rotation_axis_and_angle_as_matrix(axis=axis, angle=1.0, deg=True))
    ub_end = r_osc * ub_beg
    uc = unit_cell((a, a, a, 90, 90, 90))
    sg = space_group(space_group_symbols("P23").hall())
    s0 = matrix.col((0, 0, 1))
    wavelength = 1.0
    dmin = 1.5

    # get the full set of indices
    indices = full_sphere_indices(unit_cell=uc,
                                  resolution_limit=dmin,
                                  space_group=sg)

    # find the observed indices
    ra = rotation_angles(dmin, ub_beg, wavelength, axis)
    obs_indices, obs_angles = ra.observed_indices_and_angles_from_angle_range(
        phi_start_rad=0.0 * math.pi / 180.0,
        phi_end_rad=1.0 * math.pi / 180.0,
        indices=indices,
    )

    # r = reeke_model(ub_beg, ub_end, axis, s0, dmin, 1.0)
    # reeke_indices = r.generate_indices()

    # now try the Reeke method to generate indices
    r = ReekeIndexGenerator(ub_beg,
                            ub_end,
                            sg.type(),
                            axis,
                            s0,
                            dmin,
                            margin=1)
    reeke_indices = r.to_array()

    for oi in obs_indices:
        assert tuple(map(int, oi)) in reeke_indices
Ejemplo n.º 37
0
def exercise_monoclinic_cell_choices_core(space_group_number, verbose):
    # transformation matrices for cell choices
    # columns are basis vectors "new in terms of old"
    # see Int. Tab. Vol. A, p. 22, Fig. 2.2.6.4.
    b1 = (1, 0, 0, 0, 1, 0, 0, 0, 1)
    b2 = (-1, 0, 1, 0, 1, 0, -1, 0, 0)
    b3 = (0, 0, -1, 0, 1, 0, 1, 0, -1)
    flip = (0, 0, 1, 0, -1, 0, 1, 0, 0)
    p3s = sgtbx.space_group("P 3*")
    done = {}
    ref = sgtbx.space_group_info(number=space_group_number)
    ref_uhm = ref.type().universal_hermann_mauguin_symbol()
    for i_fl, fl in enumerate([b1, flip]):
        rfl = sgtbx.rot_mx(fl)
        cfl = sgtbx.change_of_basis_op(sgtbx.rt_mx(rfl))
        for i_rt, rt in enumerate(p3s):
            rp3 = rt.r()
            cp3 = sgtbx.change_of_basis_op(sgtbx.rt_mx(rp3))
            for i_cs, cs in enumerate([b1, b2, b3]):
                rcs = sgtbx.rot_mx(cs).inverse()
                ccs = sgtbx.change_of_basis_op(sgtbx.rt_mx(rcs))
                cb_all = cp3 * cfl * ccs
                refcb = ref.change_basis(cb_all)
                refcb2 = sgtbx.space_group_info(symbol=ref_uhm + "(" +
                                                str(cb_all.c()) + ")")
                assert refcb2.group() == refcb.group()
                s = sgtbx.space_group_symbols(str(refcb))
                q = s.qualifier()
                hm = str(refcb)
                if (0 or verbose): print(hm, q, cb_all.c())
                if (i_fl == 0):
                    assert q[0] == "bca"[i_rt]
                    if (len(q) == 2): assert q[1] == "123"[i_cs]
                elif (q[0] == "-"):
                    assert q[1] == "bca"[i_rt]
                    if (len(q) == 3): assert q[2] == "123"[i_cs]
                else:
                    assert q[0] == "bca"[i_rt]
                    if (len(q) == 2 and q[1] != "123"[i_cs]):
                        assert done[hm] == 1
                done.setdefault(hm, 0)
                done[hm] += 1
    assert len(done) in [3, 9, 18]
    assert list(done.values()) == [18 / len(done)] * len(done)
    if (0 or verbose): print()
    return done
Ejemplo n.º 38
0
  def __init__(self, real_space_a, real_space_b, real_space_c, sg = 1):

    self._sg = space_group(space_group_symbols(sg).hall())

    # setting matrix at initialisation
    A = matrix.sqr(real_space_a.elems +  real_space_b.elems + \
                   real_space_c.elems).inverse()

    # unit cell
    self.set_unit_cell(real_space_a, real_space_b, real_space_c)

    # reciprocal space orthogonalisation matrix (is the transpose of the
    # real space fractionalisation matrix, see http://goo.gl/H3p1s)
    self._update_B()

    # initial orientation matrix
    self._U = A * self._B.inverse()
Ejemplo n.º 39
0
def generate_reflections(experiments):

  from dials.algorithms.spot_prediction import IndexGenerator
  from dials.algorithms.refinement.prediction import \
    ScansRayPredictor, ExperimentsPredictor
  from dials.algorithms.spot_prediction import ray_intersection
  from cctbx.sgtbx import space_group, space_group_symbols
  from scitbx.array_family import flex

  detector = experiments[0].detector
  crystal = experiments[0].crystal

  # All indices in a 2.0 Angstrom sphere
  resolution = 2.0
  index_generator = IndexGenerator(crystal.get_unit_cell(),
                  space_group(space_group_symbols(1).hall()).type(), resolution)
  indices = index_generator.to_array()

  # Predict rays within the sweep range
  scan = experiments[0].scan
  sweep_range = scan.get_oscillation_range(deg=False)
  ray_predictor = ScansRayPredictor(experiments, sweep_range)
  obs_refs = ray_predictor(indices)

  # Take only those rays that intersect the detector
  intersects = ray_intersection(detector, obs_refs)
  obs_refs = obs_refs.select(intersects)

  # Make a reflection predictor and re-predict for all these reflections. The
  # result is the same, but we gain also the flags and xyzcal.px columns
  ref_predictor = ExperimentsPredictor(experiments)
  obs_refs['id'] = flex.int(len(obs_refs), 0)
  obs_refs = ref_predictor(obs_refs)

  # Set 'observed' centroids from the predicted ones
  obs_refs['xyzobs.mm.value'] = obs_refs['xyzcal.mm']

  # Invent some variances for the centroid positions of the simulated data
  im_width = 0.1 * pi / 180.
  px_size = detector[0].get_pixel_size()
  var_x = flex.double(len(obs_refs), (px_size[0] / 2.)**2)
  var_y = flex.double(len(obs_refs), (px_size[1] / 2.)**2)
  var_phi = flex.double(len(obs_refs), (im_width / 2.)**2)
  obs_refs['xyzobs.mm.variance'] = flex.vec3_double(var_x, var_y, var_phi)

  return obs_refs, ref_predictor
Ejemplo n.º 40
0
def doohicky(integrate_hkl, space_group_name, symop):

    present = []
    absent = []

    sg = space_group(space_group_symbols(space_group_name).hall())

    r = change_of_basis_op(symop)

    for hkl, isig in read_integrate_hkl(integrate_hkl):
        rhkl = tuple(map(int, r.c() * hkl))
        if sg.is_sys_absent(rhkl):
            absent.append(isig[0])
        else:
            present.append(isig[0])

    print "Present: %.2e %.2e %.2e" % mean_variance(present), "%.2e %.2e %.2e" % quartiles(present)
    print "Absent:  %.2e %.2e %.2e" % mean_variance(absent), "%.2e %.2e %.2e" % quartiles(absent)
  def generate_reflections(self):
    sweep_range = self.scan.get_oscillation_range(deg=False)
    resolution = 2.0
    index_generator = IndexGenerator(self.crystal.get_unit_cell(),
                          space_group(space_group_symbols(1).hall()).type(),
                          resolution)
    indices = index_generator.to_array()

    # Predict rays within the sweep range
    ray_predictor = ScansRayPredictor(self.experiments, sweep_range)
    obs_refs = ray_predictor(indices)

    # Take only those rays that intersect the detector
    intersects = ray_intersection(self.detector, obs_refs)
    obs_refs = obs_refs.select(intersects)

    # Re-predict using the Experiments predictor for all these reflections. The
    # result is the same, but we gain also the flags and xyzcal.px columns
    obs_refs['id'] = flex.int(len(obs_refs), 0)
    obs_refs = self.ref_predictor(obs_refs)

    # Set 'observed' centroids from the predicted ones
    obs_refs['xyzobs.mm.value'] = obs_refs['xyzcal.mm']

    # Invent some variances for the centroid positions of the simulated data
    im_width = 0.1 * pi / 180.
    px_size = self.detector[0].get_pixel_size()
    var_x = flex.double(len(obs_refs), (px_size[0] / 2.)**2)
    var_y = flex.double(len(obs_refs), (px_size[1] / 2.)**2)
    var_phi = flex.double(len(obs_refs), (im_width / 2.)**2)
    obs_refs['xyzobs.mm.variance'] = flex.vec3_double(var_x, var_y, var_phi)

    # set the flex random seed to an 'uninteresting' number
    flex.set_random_seed(12407)

    # take 5 random reflections for speed
    reflections = obs_refs.select(flex.random_selection(len(obs_refs), 5))

    # use a BlockCalculator to calculate the blocks per image
    from dials.algorithms.refinement.reflection_manager import BlockCalculator
    block_calculator = BlockCalculator(self.experiments, reflections)
    reflections = block_calculator.per_image()

    return reflections
Ejemplo n.º 42
0
def read_xds_integrate(xds_integrate_file):

    # N.B. in here need to reduce indices to asymmetric unit

    sg_num = 0
    r = 0.0

    for record in open(xds_integrate_file):
        if not '!' in record[:1]:
            break
        if 'SPACE_GROUP_NUMBER' in record:
            sg_num = int(record.split()[-1])
        if 'OSCILLATION_RANGE' in record:
            r = float(record.split()[-1])

    if not sg_num:
        raise RuntimeError, 'spacegroup missing'

    if not r:
        raise RuntimeError, 'rotation missing'

    sg = space_group(space_group_symbols(sg_num).hall())

    observations = []

    hkls = flex.miller_index()
    xyzs = []
    isigmas = []

    for record in open(xds_integrate_file):
        if '!' in record[:1]:
            continue
        values = record.split()
        hkls.append(map(int, values[:3]))
        xyzs.append((float(values[5]), float(values[6]), float(values[7])))
        isigmas.append(map(float, values[3:5]))

    map_to_asu(sg.type(), False, hkls)

    for hkl, xyz, isigma in zip(hkls, xyzs, isigmas):
        observations.append((hkl, xyz, isigma))

    return observations
Ejemplo n.º 43
0
def exercise_orthorhombic_hm_qualifier_as_cb_symbol():
  cb_symbols = {
    "cab": ["c,a,b", "z,x,y"],
    "a-cb": ["a,-c,b", "x,-z,y"],
    "-cba": ["-c,b,a", "-z,y,x"],
    "bca": ["b,c,a", "y,z,x"],
    "ba-c": ["b,a,-c", "y,x,-z"]}
  for sgsyms1 in sgtbx.space_group_symbol_iterator():
    n = sgsyms1.number()
    if (n < 16 or n > 74): continue
    q = sgsyms1.qualifier()
    if (len(q) == 0): continue
    e = sgsyms1.extension()
    if (e == "\0"): e = ""
    ehm = sgtbx.space_group_symbols(
      space_group_number=n, extension=e).universal_hermann_mauguin()
    cabc, cxyz = cb_symbols[q]
    assert sgtbx.change_of_basis_op(cxyz).as_abc() == cabc
    assert sgtbx.change_of_basis_op(cabc).as_xyz() == cxyz
    uhm_xyz = ehm + " ("+cxyz+")"
    sgsyms2 = sgtbx.space_group_symbols(symbol=uhm_xyz)
    assert sgsyms2.change_of_basis_symbol() == cxyz
    assert sgsyms2.extension() == sgsyms1.extension()
    assert sgsyms2.universal_hermann_mauguin() == uhm_xyz
    g1 = sgtbx.space_group(space_group_symbols=sgsyms1)
    g2 = sgtbx.space_group(space_group_symbols=sgsyms2)
    assert g2 == g1
    g2 = sgtbx.space_group(
      sgtbx.space_group_symbols(symbol=ehm)).change_basis(
        sgtbx.change_of_basis_op(sgtbx.rt_mx(cxyz)))
    assert g2 == g1
    for c in [cxyz, cabc]:
      g2 = sgtbx.space_group_info(
        group=sgtbx.space_group(
          sgtbx.space_group_symbols(symbol=ehm))).change_basis(c).group()
      assert g2 == g1
    cit = sgtbx.rt_mx(cxyz).r().inverse().transpose()
    cit_xyz = cit.as_xyz()
    g2 = sgtbx.space_group_info(
      group=sgtbx.space_group(
        sgtbx.space_group_symbols(symbol=ehm))).change_basis(cit_xyz).group()
    assert g2 == g1
    assert cit.as_xyz(False, "abc") == cabc
    uhm_abc = ehm + " ("+cabc+")"
    sgsyms2 = sgtbx.space_group_symbols(symbol=uhm_abc)
    assert sgsyms2.change_of_basis_symbol() == cxyz
    assert sgsyms2.extension() == sgsyms1.extension()
    assert sgsyms2.universal_hermann_mauguin() == uhm_xyz
    g2 = sgtbx.space_group(space_group_symbols=sgsyms2)
    assert g2 == g1
Ejemplo n.º 44
0
def get_sgtype_cb_ops(argv):
    sgtype = None
    cb_ops = []

    for arg in argv:
        if not sgtype:
            try:
                from cctbx.sgtbx import space_group, space_group_symbols
                sgtype = space_group(space_group_symbols(arg)).type()
                continue
            except RuntimeError, e:
                pass
            
        try:
            from cctbx import sgtbx
            cb_op = sgtbx.change_of_basis_op(arg)
            cb_ops.append(cb_op)
            continue
        except ValueError, e:
            pass
Ejemplo n.º 45
0
def measure(hklin, spacegroup):
  '''Look at HKLIN, see how strong the absences (according to the given
  spacegroup) are... looking for IPR / SIGIPR.'''

  mtz_obj = mtz.object(hklin)

  sg = sgtbx.space_group(sgtbx.space_group_symbols(spacegroup).hall())
  mi = mtz_obj.extract_miller_indices()
  sg_m = mtz_obj.space_group()

  ipr_column = None
  sigipr_column = None

  for crystal in mtz_obj.crystals():
    for dataset in crystal.datasets():
      for column in dataset.columns():

        if column.label() == 'IPR':
          ipr_column = column
        elif column.label() == 'SIGIPR':
          sigipr_column = column

  assert(ipr_column != None)
  assert(sigipr_column != None)

  ipr_values = ipr_column.extract_values(not_a_number_substitute = 0.0)
  sigipr_values = sigipr_column.extract_values(not_a_number_substitute = 0.0)

  present = []
  absent = []

  for j in range(mi.size()):
    hkl = mi[j]

    if sg.is_sys_absent(hkl):
      absent.append(ipr_values[j] / sigipr_values[j])
    else:
      present.append(ipr_values[j] / sigipr_values[j])

  print 'A: %f' % (sum(absent) / len(absent))
  print 'P: %f' % (sum(present) / len(present))
Ejemplo n.º 46
0
  def __init__(self, real_space_a, real_space_b, real_space_c,
               space_group_symbol=None, space_group=None,
               mosaicity=None, deg=True):

    # Set the space group
    assert [space_group_symbol, space_group].count(None) == 1
    if space_group_symbol:
      self._sg = SG(space_group_symbols(space_group_symbol))
    else: self._sg = space_group

    # Set the mosaicity
    if mosaicity is not None:
      self.set_mosaicity(mosaicity, deg=deg)
    else:
      self._mosaicity = 0.0

    # setting matrix at initialisation
    real_space_a = matrix.col(real_space_a)
    real_space_b = matrix.col(real_space_b)
    real_space_c = matrix.col(real_space_c)
    A = matrix.sqr(real_space_a.elems +  real_space_b.elems + \
                   real_space_c.elems).inverse()

    # unit cell
    self.set_unit_cell(real_space_a, real_space_b, real_space_c)

    # reciprocal space orthogonalisation matrix (is the transpose of the
    # real space fractionalisation matrix, see http://goo.gl/H3p1s)
    self._update_B()

    # initial orientation matrix
    self._U = A * self._B.inverse()

    # set up attributes for scan-varying model
    self.reset_scan_points()

    # set up attributes for unit cell errors
    self.reset_unit_cell_errors()

    return
Ejemplo n.º 47
0
def exercise_change_of_basis_between_arbitrary_space_groups():
  from random import randint
  from scitbx import matrix as mat

  g = sgtbx.space_group_info('hall: P 2')
  h = sgtbx.space_group_info('hall: P 2c')
  assert g.change_of_basis_op_to(h) is None

  g = sgtbx.space_group_info('hall: C 2c 2 (x+y,x-y,z)')
  h = g.change_basis(sgtbx.change_of_basis_op(sgtbx.rt_mx('-y,x,z')))
  cb_op = g.change_of_basis_op_to(h)
  assert cb_op.as_xyz() == 'x,y,z+1/4'
  assert g.change_basis(cb_op).group() == h.group()

  g = sgtbx.space_group_info('hall: I 4 2 3')
  z2p_op = g.change_of_basis_op_to_primitive_setting()
  h = g.change_basis(z2p_op)
  cb_op = g.change_of_basis_op_to(h)
  assert cb_op.c() == z2p_op.c(), (cb_op.as_xyz(), z2p_op.as_xyz())

  for i in xrange(1, 231):
    s = sgtbx.space_group_symbols(space_group_number=i)
    g = sgtbx.space_group_info(group=sgtbx.space_group(s, t_den=24))

    o = tuple([ randint(0, 23) for j in xrange(3) ])
    cb_op = sgtbx.change_of_basis_op(sgtbx.rt_mx(sgtbx.tr_vec(o, 24)))
    h = g.change_basis(cb_op)
    cb_op_1 = g.change_of_basis_op_to(h)
    assert cb_op_1.c().r().is_unit_mx()
    delta = (mat.col(cb_op_1.c().t().as_double())
             - mat.col(cb_op.c().t().as_double()))
    assert h.is_allowed_origin_shift(delta, tolerance=1e-12)

    z2p_op = g.change_of_basis_op_to_primitive_setting()
    h = g.change_basis(z2p_op)
    cb_op = g.change_of_basis_op_to(h)
    h1 = g.change_basis(cb_op)
    assert (h.as_reference_setting().group()
            == h1.as_reference_setting().group())
Ejemplo n.º 48
0
def mmSpaceGroupFromSymbol(symbol):
    """Construct SpaceGroup instance from a string symbol using sgtbx data.
    """
    sginfo = sgtbx.space_group_info(symbol)
    symop_list = []
    unique_rotations = set()
    symop_list = getSymOpList(sginfo.group())
    sgtype = sginfo.type()
    uhm = sgtype.lookup_symbol()
    sgsmbls = sgtbx.space_group_symbols(uhm)
    kw = {}
    kw['number'] = sgtype.number()
    kw['num_sym_equiv'] = len(symop_list)
    kw['num_primitive_sym_equiv'] = countUniqueRotations(symop_list)
    kw['short_name'] = sgsmbls.hermann_mauguin().replace(' ', '')
    pgt = sgsmbls.point_group_type()
    pgn = "PG" + re.sub('-(\d)', '\\1bar', pgt)
    kw['point_group_name'] = pgn
    kw['crystal_system'] = sgsmbls.crystal_system().upper()
    kw['pdb_name'] = sgsmbls.hermann_mauguin()
    kw['symop_list'] = symop_list
    mmsg = SpaceGroup(**kw)
    return mmsg
Ejemplo n.º 49
0
def tst_map_to_asu_isym(anomalous_flag):
  from cctbx import sgtbx
  from cctbx.miller import map_to_asu_isym
  from cctbx.array_family import flex

  mi = flex.miller_index()
  i = flex.int()

  import random

  nhkl = 1000

  for j in range(nhkl):
    hkl = [random.randint(-10, 10) for j in range(3)]
    mi.append(hkl)
    i.append(0)

  spacegroup = sgtbx.space_group_symbols(195).hall()
  sg = sgtbx.space_group(spacegroup)
  mi_, isym_ = reference_map(sg, mi)
  map_to_asu_isym(sg.type(), anomalous_flag, mi, i)

  for j in range(nhkl):
    assert(i[j] == isym_[j])