def exercise_sdb(verbose=0): structure = random_structure.xray_structure( space_group_info=sgtbx.space_group_info("P 31"), elements=["N", "C", "C", "O"] * 2, volume_per_atom=500, min_distance=2., general_positions_only=False, random_u_iso=True) f_abs = abs( structure.structure_factors(anomalous_flag=False, d_min=2, algorithm="direct").f_calc()) sdb_out = structure.as_cns_sdb_file(file="foo.sdb", description="random_structure", comment=["any", "thing"], group="best") if (0 or verbose): sys.stdout.write(sdb_out) sdb_files = sdb_reader.multi_sdb_parser(StringIO(sdb_out)) assert len(sdb_files) == 1 structure_read = sdb_files[0].as_xray_structure( crystal_symmetry=crystal.symmetry(unit_cell=structure.unit_cell(), space_group_info=None)) f_read = abs( f_abs.structure_factors_from_scatterers(xray_structure=structure_read, algorithm="direct").f_calc()) regression = flex.linear_regression(f_abs.data(), f_read.data()) assert regression.is_well_defined() if (0 or verbose): regression.show_summary() assert abs(regression.slope() - 1) < 1.e-4 assert abs(regression.y_intercept()) < 1.e-3
def exercise_sdb(verbose=0): structure = random_structure.xray_structure( space_group_info=sgtbx.space_group_info("P 31"), elements=["N","C","C","O"]*2, volume_per_atom=500, min_distance=2., general_positions_only=False, random_u_iso=True) f_abs = abs(structure.structure_factors( anomalous_flag=False, d_min=2, algorithm="direct").f_calc()) sdb_out = structure.as_cns_sdb_file( file="foo.sdb", description="random_structure", comment=["any", "thing"], group="best") if (0 or verbose): sys.stdout.write(sdb_out) sdb_files = sdb_reader.multi_sdb_parser(StringIO(sdb_out)) assert len(sdb_files) == 1 structure_read = sdb_files[0].as_xray_structure( crystal_symmetry=crystal.symmetry( unit_cell=structure.unit_cell(), space_group_info=None)) f_read = abs(f_abs.structure_factors_from_scatterers( xray_structure=structure_read, algorithm="direct").f_calc()) regression = flex.linear_regression(f_abs.data(), f_read.data()) assert regression.is_well_defined() if (0 or verbose): regression.show_summary() assert abs(regression.slope()-1) < 1.e-4 assert abs(regression.y_intercept()) < 1.e-3
def sdb_files_as_xray_structures(lines, unit_cell, space_group_info, min_distance_sym_equiv): sdb_files = sdb_reader.multi_sdb_parser(lines) xray_structures = [] for sdb in sdb_files: if (unit_cell is not None): sdb.unit_cell = unit_cell if (space_group_info is not None): sdb.space_group_info = space_group_info xray_structure = sdb.as_xray_structure(min_distance_sym_equiv=min_distance_sym_equiv) xray_structures.append(xray_structure) return xray_structures
def extract_from(file_name=None, file=None): assert [file_name, file].count(None) == 1 if (file is None): file = open(file_name) sdb_files = sdb_reader.multi_sdb_parser(file) assert len(sdb_files) > 0 crystal_symmetry = sdb_files[0].crystal_symmetry() assert [crystal_symmetry.unit_cell(), crystal_symmetry.space_group_info()].count(None) < 2 return crystal_symmetry
def sdb_files_as_xray_structures(lines, unit_cell, space_group_info, min_distance_sym_equiv): sdb_files = sdb_reader.multi_sdb_parser(lines) xray_structures = [] for sdb in sdb_files: if (unit_cell is not None): sdb.unit_cell = unit_cell if (space_group_info is not None): sdb.space_group_info = space_group_info xray_structure = sdb.as_xray_structure( min_distance_sym_equiv=min_distance_sym_equiv) xray_structures.append(xray_structure) return xray_structures
def __init__(self, ucparams, sgsymbol, convention, format, coor_type, skip_columns, coordinates, other_symmetry=None): self.ucparams = ucparams self.sgsymbol = sgsymbol self.convention = convention self.other_symmetry = other_symmetry self.coordinate_format = None if (format == "generic"): skip_columns = io_utils.interpret_skip_columns(skip_columns) self.positions = [] for line in coordinates: label, site = interpret_generic_coordinate_line( line, skip_columns) if (label == ""): label = "Site" + str(len(self.positions) + 1) if (coor_type != "Fractional"): site = self.get_unit_cell().fractionalize(site) self.positions.append(emma.position(label, site)) self.coordinate_format = "generic" else: if (self.coordinate_format is None): try: import iotbx.pdb pdb_inp = iotbx.pdb.input(source_info=None, lines=coordinates) except KeyboardInterrupt: raise except Exception: pass else: self.pdb_model = pdb_file_to_emma_model( self.crystal_symmetry(), pdb_inp, other_symmetry) if (len(self.pdb_model.positions()) > 0): self.coordinate_format = "pdb" if (self.coordinate_format is None): try: from iotbx.cns import sdb_reader self.sdb_files = sdb_reader.multi_sdb_parser(coordinates) except KeyboardInterrupt: raise except Exception: pass else: self.coordinate_format = "sdb" if (self.coordinate_format is None): raise RuntimeError("Coordinate format unknown.") self.i_next_model = 0
def __init__(self, ucparams, sgsymbol, convention, format, coor_type, skip_columns, coordinates, other_symmetry=None): self.ucparams = ucparams self.sgsymbol = sgsymbol self.convention = convention self.other_symmetry = other_symmetry self.coordinate_format = None if (format == "generic"): skip_columns = io_utils.interpret_skip_columns(skip_columns) self.positions = [] for line in coordinates: label, site = interpret_generic_coordinate_line(line, skip_columns) if (label == ""): label = "Site" + str(len(self.positions)+1) if (coor_type != "Fractional"): site = self.get_unit_cell().fractionalize(site) self.positions.append(emma.position(label, site)) self.coordinate_format = "generic" else: if (self.coordinate_format is None): try: import iotbx.pdb pdb_inp = iotbx.pdb.input(source_info=None, lines=coordinates) except KeyboardInterrupt: raise except Exception: pass else: self.pdb_model = pdb_file_to_emma_model( self.crystal_symmetry(), pdb_inp, other_symmetry) if (len(self.pdb_model.positions()) > 0): self.coordinate_format = "pdb" if (self.coordinate_format is None): try: from iotbx.cns import sdb_reader self.sdb_files = sdb_reader.multi_sdb_parser(coordinates) except KeyboardInterrupt: raise except Exception: pass else: self.coordinate_format = "sdb" if (self.coordinate_format is None): raise RuntimeError("Coordinate format unknown.") self.i_next_model = 0
def get_emma_model_from_sdb(file_name, crystal_symmetry): sdb_files = sdb_reader.multi_sdb_parser(open(file_name)) if (len(sdb_files) > 1): raise MultipleEntriesError( "SDB file %s may contain only one structure." % file_name) assert len(sdb_files) == 1 sdb_file = sdb_files[0] crystal_symmetry = crystal_symmetry.join_symmetry( other_symmetry=sdb_file.crystal_symmetry(), force=True) positions = [] for i,site in enumerate(sdb_file.sites): if (crystal_symmetry.unit_cell() is None): raise RuntimeError("Unit cell parameters unknown.") positions.append(emma.position( ":".join((str(i+1), site.segid, site.type)), crystal_symmetry.unit_cell().fractionalize((site.x, site.y, site.z)))) assert len(positions) > 0 result = emma.model( crystal_symmetry.special_position_settings(), positions) result.label = sdb_file.file_name return result
def get_emma_model_from_sdb(file_name, crystal_symmetry): sdb_files = sdb_reader.multi_sdb_parser(open(file_name)) if (len(sdb_files) > 1): raise MultipleEntriesError( "SDB file %s may contain only one structure." % file_name) assert len(sdb_files) == 1 sdb_file = sdb_files[0] crystal_symmetry = crystal_symmetry.join_symmetry( other_symmetry=sdb_file.crystal_symmetry(), force=True) positions = [] for i, site in enumerate(sdb_file.sites): if (crystal_symmetry.unit_cell() is None): raise RuntimeError("Unit cell parameters unknown.") positions.append( emma.position( ":".join((str(i + 1), site.segid, site.type)), crystal_symmetry.unit_cell().fractionalize( (site.x, site.y, site.z)))) assert len(positions) > 0 result = emma.model(crystal_symmetry.special_position_settings(), positions) result.label = sdb_file.file_name return result