def create_crystal_symmetry(sg, cell): space_group = None if sg is None else sgtbx.space_group_info(sg).group() unit_cell = uctbx.infer_unit_cell_from_symmetry(cell, space_group) xs = crystal.symmetry(unit_cell, space_group=space_group) return xs
"Unit cell parameters not found in the cif file") unit_cell = None elif (ic == 0): try: vals = [float_from_string(s) for s in items] except ValueError: raise CifBuilderError("Invalid unit cell parameters are given") try: unit_cell = uctbx.unit_cell(vals) except RuntimeError, e: if "cctbx Error: Unit cell" in str(e): raise CifBuilderError(e) else: raise elif (space_group is not None): unit_cell = uctbx.infer_unit_cell_from_symmetry( [float_from_string(s) for s in items if s is not None], space_group) else: raise CifBuilderError( "Not all unit cell parameters are given in the cif file") if unit_cell is not None and space_group is not None: if not space_group.is_compatible_unit_cell(unit_cell): # try primitive setting space_group_input = space_group space_group = space_group.info().primitive_setting().group() if not space_group.is_compatible_unit_cell(unit_cell): raise CifBuilderError( "Space group is incompatible with unit cell parameters:\n" + \ " Space group: %s\n" %space_group_input.info() + \ " Unit cell: %s" %unit_cell) self.crystal_symmetry = crystal.symmetry(unit_cell=unit_cell, space_group=space_group)
unit_cell = None elif (ic == 0): try: vals = [float_from_string(s) for s in items] except ValueError: raise CifBuilderError("Invalid unit cell parameters are given") try: unit_cell = uctbx.unit_cell(vals) except RuntimeError, e: if "cctbx Error: Unit cell" in str(e): raise CifBuilderError(e) else: raise elif (space_group is not None): unit_cell = uctbx.infer_unit_cell_from_symmetry( [float_from_string(s) for s in items if s is not None], space_group) else: raise CifBuilderError( "Not all unit cell parameters are given in the cif file") if (unit_cell is not None and space_group is not None and not space_group.is_compatible_unit_cell(unit_cell)): raise CifBuilderError( "Space group is incompatible with unit cell parameters") self.crystal_symmetry = crystal.symmetry(unit_cell=unit_cell, space_group=space_group) class crystal_structure_builder(crystal_symmetry_builder): def __init__(self, cif_block): # XXX To do: interpret _atom_site_refinement_flags
def __init__(self, cif_block, strict=False): # The order of priority for determining space group is: # sym_ops, hall symbol, H-M symbol, space group number self.cif_block = cif_block sym_ops = self.get_cif_item('_space_group_symop_operation_xyz') sym_op_ids = self.get_cif_item('_space_group_symop_id') space_group = None if sym_ops is not None: if isinstance(sym_ops, string_types): sym_ops = flex.std_string([sym_ops]) if sym_op_ids is not None: if isinstance(sym_op_ids, string_types): sym_op_ids = flex.std_string([sym_op_ids]) assert len(sym_op_ids) == len(sym_ops) self.sym_ops = {} space_group = sgtbx.space_group() if isinstance(sym_ops, string_types): sym_ops = [sym_ops] for i, op in enumerate(sym_ops): try: s = sgtbx.rt_mx(op) except RuntimeError as e: str_e = str(e) if "Parse error: " in str_e: raise CifBuilderError( "Error interpreting symmetry operator: %s" % (str_e.split("Parse error: ")[-1])) else: raise if sym_op_ids is None: sym_op_id = i + 1 else: try: sym_op_id = int(sym_op_ids[i]) except ValueError as e: raise CifBuilderError( "Error interpreting symmetry operator id: %s" % (str(e))) self.sym_ops[sym_op_id] = s space_group.expand_smx(s) else: hall_symbol = self.get_cif_item('_space_group_name_Hall') hm_symbol = self.get_cif_item('_space_group_name_H-M_alt') sg_number = self.get_cif_item('_space_group_IT_number') if space_group is None and hall_symbol not in (None, '?'): try: space_group = sgtbx.space_group(hall_symbol) except Exception: pass if space_group is None and hm_symbol not in (None, '?'): try: space_group = sgtbx.space_group_info( symbol=hm_symbol).group() except Exception: pass if space_group is not None and sg_number not in (None, '?'): try: space_group = sgtbx.space_group_info( number=sg_number).group() except Exception: pass if (space_group is None and strict): raise CifBuilderError( "No symmetry instructions could be extracted from the cif block" ) items = [self.get_cif_item("_cell_length_" + s) for s in "abc"] for i, item in enumerate(items): if isinstance(item, flex.std_string): raise CifBuilderError( "Data item _cell_length_%s cannot be declared in a looped list" % ("abc"[i])) for s in ["alpha", "beta", "gamma"]: item = self.get_cif_item("_cell_angle_" + s) if isinstance(item, flex.std_string): raise CifBuilderError( "Data item _cell_angle_%s cannot be declared in a looped list" % s) if (item == "?"): item = "90" # enumeration default for angles is 90 degrees items.append(item) ic = items.count(None) if (ic == 6): if (strict): raise CifBuilderError( "Unit cell parameters not found in the cif file") unit_cell = None elif (ic == 0): try: vals = [float_from_string(s) for s in items] except ValueError: raise CifBuilderError("Invalid unit cell parameters are given") try: unit_cell = uctbx.unit_cell(vals) except RuntimeError as e: if "cctbx Error: Unit cell" in str(e): raise CifBuilderError(e) else: raise elif (space_group is not None): unit_cell = uctbx.infer_unit_cell_from_symmetry( [float_from_string(s) for s in items if s is not None], space_group) else: raise CifBuilderError( "Not all unit cell parameters are given in the cif file") if unit_cell is not None and space_group is not None: if not space_group.is_compatible_unit_cell(unit_cell): # try primitive setting space_group_input = space_group space_group = space_group.info().primitive_setting().group() if not space_group.is_compatible_unit_cell(unit_cell): raise CifBuilderError( "Space group is incompatible with unit cell parameters:\n" + \ " Space group: %s\n" %space_group_input.info() + \ " Unit cell: %s" %unit_cell) self.crystal_symmetry = crystal.symmetry(unit_cell=unit_cell, space_group=space_group)
def unit_cell(self): self._unit_cell = uctbx.infer_unit_cell_from_symmetry( self.unit_cell_parameters, self.space_group()) if (self._unit_cell is None): raise RuntimeError, "Cannot interpret unit cell parameters." return self._unit_cell