def space_group_symbol(space_group): symbol = ccp4_symbol(space_group.info(), lib_name="syminfo.lib", require_at_least_one_lib=False) if symbol != "P 1": symbol = symbol.replace(" 1", "") symbol = symbol.replace(" ", "") return symbol
def space_group_symbol(space_group): symbol = ccp4_symbol(space_group.info(), lib_name='syminfo.lib', require_at_least_one_lib=False) if symbol != 'P 1': symbol = symbol.replace(' 1', '') symbol = symbol.replace(' ', '') return symbol
def exercise_230(): for space_group_number in range(1, 231): space_group_info = sgtbx.space_group_info(number=space_group_number, table_id="A1983") symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="symop.lib") if (symbol[0] == "H"): symbol = "R" + symbol[1:] + ":H" assert sgtbx.space_group_info( symbol=symbol, table_id="A1983").group() == space_group_info.group() # symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="syminfo.lib") if (symbol[0] == "H"): symbol = "R" + symbol[1:] + ":H" assert sgtbx.space_group_info( symbol=symbol, table_id="A1983").group() == space_group_info.group()
def build_ccp4_symmetry_table(): symbol_to_number = {} ccp4_to_number = {} # Open file file_iter = open(op.join( extract_from_symmetry_lib.ccp4io_lib_data, "symop.lib")) ccp4_id_counts = libtbx.dict_with_default_0() ccp4_symbol_counts = libtbx.dict_with_default_0() # Run through the file for line in file_iter: # print "\n", line.rstrip() flds = line.split(None, 4) ccp4_id = flds[0] ccp4_id_counts[ccp4_id] += 1 space_group_number = int(ccp4_id[-3:]) order_z = int(flds[1]) given_ccp4_symbol = flds[3] symbol_to_number[given_ccp4_symbol] = space_group_number ccp4_symbol_counts[given_ccp4_symbol] += 1 group = extract_from_symmetry_lib.collect_symops( file_iter=file_iter, order_z=order_z) assert group.order_z() == order_z space_group_info = sgtbx.space_group_info(group=group) retrieved_ccp4_symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="symop.lib") # print "retrieved_ccp4_symbol", retrieved_ccp4_symbol assert retrieved_ccp4_symbol == given_ccp4_symbol assert space_group_info.type().number() == space_group_number if (1): from iotbx.pdb import format_cryst1_sgroup sgroup = format_cryst1_sgroup(space_group_info=space_group_info) # if (len(sgroup) > 11): # print "ccp4 symop.lib setting leads to pdb CRYST1 overflow:",\ # ccp4_id, given_ccp4_symbol, sgroup # print "sgroup", sgroup ccp4_to_number[sgroup] = space_group_number # for ccp4_id,count in ccp4_id_counts.items(): # if (count != 1): # raise RuntimeError( # 'ccp4 id "%s" appears %d times (should be unique).' # % (ccp4_id, count)) # ccp4_symbol_counts = libtbx.dict_with_default_0() # for ccp4_symbol,count in ccp4_symbol_counts.items(): # if (count != 1): # raise RuntimeError( # 'ccp4 symbol "%s" appears %d times (should be unique).' # % (ccp4_symbol, count)) return (symbol_to_number, ccp4_to_number)
def build_ccp4_symmetry_table(): symbol_to_number = {} ccp4_to_number = {} # Open file file_iter = open( op.join(extract_from_symmetry_lib.ccp4io_lib_data, "symop.lib")) ccp4_id_counts = libtbx.dict_with_default_0() ccp4_symbol_counts = libtbx.dict_with_default_0() # Run through the file for line in file_iter: # print "\n", line.rstrip() flds = line.split(None, 4) ccp4_id = flds[0] ccp4_id_counts[ccp4_id] += 1 space_group_number = int(ccp4_id[-3:]) order_z = int(flds[1]) given_ccp4_symbol = flds[3] symbol_to_number[given_ccp4_symbol] = space_group_number ccp4_symbol_counts[given_ccp4_symbol] += 1 group = extract_from_symmetry_lib.collect_symops(file_iter=file_iter, order_z=order_z) assert group.order_z() == order_z space_group_info = sgtbx.space_group_info(group=group) retrieved_ccp4_symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="symop.lib") # print "retrieved_ccp4_symbol", retrieved_ccp4_symbol assert retrieved_ccp4_symbol == given_ccp4_symbol assert space_group_info.type().number() == space_group_number if (1): from iotbx.pdb import format_cryst1_sgroup sgroup = format_cryst1_sgroup(space_group_info=space_group_info) # if (len(sgroup) > 11): # print "ccp4 symop.lib setting leads to pdb CRYST1 overflow:",\ # ccp4_id, given_ccp4_symbol, sgroup # print "sgroup", sgroup ccp4_to_number[sgroup] = space_group_number # for ccp4_id,count in ccp4_id_counts.items(): # if (count != 1): # raise RuntimeError( # 'ccp4 id "%s" appears %d times (should be unique).' # % (ccp4_id, count)) # ccp4_symbol_counts = libtbx.dict_with_default_0() # for ccp4_symbol,count in ccp4_symbol_counts.items(): # if (count != 1): # raise RuntimeError( # 'ccp4 symbol "%s" appears %d times (should be unique).' # % (ccp4_symbol, count)) return (symbol_to_number, ccp4_to_number)
def exercise_230(): for space_group_number in xrange(1,231): space_group_info = sgtbx.space_group_info( number=space_group_number, table_id="A1983") symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="symop.lib") if (symbol[0] == "H"): symbol = "R" + symbol[1:] + ":H" assert sgtbx.space_group_info( symbol=symbol, table_id="A1983").group() == space_group_info.group() # symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="syminfo.lib") if (symbol[0] == "H"): symbol = "R" + symbol[1:] + ":H" assert sgtbx.space_group_info( symbol=symbol, table_id="A1983").group() == space_group_info.group()
def set_space_group_info(self, space_group_info, symbol=None): if (symbol is None): symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="symop.lib") if (symbol is None): symbol = "No.%d" % space_group_info.type().number() group = space_group_info.group() self.set_space_group_name(name=symbol) self.set_space_group_number(number=space_group_info.type().number()) self.set_point_group_name(name=group.point_group_type()) self.set_lattice_centring_type( symbol=group.conventional_centring_type_symbol()) if (self.lattice_centring_type() == "\0"): self.set_lattice_centring_type(symbol="?") self.set_space_group(space_group=space_group_info.group()) return self
def exercise_symop_lib_recycling(): file_iter = open( op.join(extract_from_symmetry_lib.ccp4io_lib_data, "symop.lib")) ccp4_id_counts = libtbx.dict_with_default_0() ccp4_symbol_counts = libtbx.dict_with_default_0() for line in file_iter: flds = line.split(None, 4) ccp4_id = flds[0] ccp4_id_counts[ccp4_id] += 1 space_group_number = int(ccp4_id[-3:]) order_z = int(flds[1]) given_ccp4_symbol = flds[3] ccp4_symbol_counts[given_ccp4_symbol] += 1 group = extract_from_symmetry_lib.collect_symops(file_iter=file_iter, order_z=order_z) assert group.order_z() == order_z space_group_info = sgtbx.space_group_info(group=group) retrieved_ccp4_symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="symop.lib") assert retrieved_ccp4_symbol == given_ccp4_symbol assert space_group_info.type().number() == space_group_number if (1): from iotbx.pdb import format_cryst1_sgroup sgroup = format_cryst1_sgroup(space_group_info=space_group_info) if (len(sgroup) > 11): print("ccp4 symop.lib setting leads to pdb CRYST1 overflow:",\ ccp4_id, given_ccp4_symbol, sgroup) file_iter.close() for ccp4_id, count in ccp4_id_counts.items(): if (count != 1): raise RuntimeError( 'ccp4 id "%s" appears %d times (should be unique).' % (ccp4_id, count)) ccp4_symbol_counts = libtbx.dict_with_default_0() for ccp4_symbol, count in ccp4_symbol_counts.items(): if (count != 1): raise RuntimeError( 'ccp4 symbol "%s" appears %d times (should be unique).' % (ccp4_symbol, count))
def exercise_syminfo_lib_pdb_cryst1_recycling(): # this call is to build _syminfo_lib_cache assert extract_from_symmetry_lib.ccp4_symbol( space_group_info=sgtbx.space_group_info("P 1"), lib_name="syminfo.lib") == "P 1" # import iotbx.pdb.cryst1_interpretation n_need_more_special = 0 for number in range(1, 230 + 1): for hall,ccp4_symbol in \ extract_from_symmetry_lib._syminfo_lib_cache[number]: sgi_hall = sgtbx.space_group_info(symbol="Hall: " + hall) if (sgi_hall.group().is_centric()): continue sgroup = iotbx.pdb.format_cryst1_sgroup(space_group_info=sgi_hall) if (len(sgroup) > 11): print("ccp4 syminfo.lib setting leads to pdb CRYST1 overflow:",\ ccp4_symbol, sgroup) cs = sgi_hall.any_compatible_crystal_symmetry(volume=1000) pdb_str = iotbx.pdb.format_cryst1_record(crystal_symmetry=cs) cs2 = iotbx.pdb.cryst1_interpretation.crystal_symmetry( cryst1_record=pdb_str) if (cs2.space_group_info() is None): if (n_need_more_special == 0): print() print('"%s": "Hall: %s",' % (ccp4_symbol.replace(" ", "").upper(), hall)) n_need_more_special += 1 else: assert cs2.is_similar_symmetry(other=cs) if (ccp4io_adaptbx is not None): exercise_mmdb_cryst1_interpretation(sgi_hall=sgi_hall, pdb_str=pdb_str) if (n_need_more_special != 0): print() from libtbx.utils import plural_s raise RuntimeError("""\ Please edit iotbx/pdb/cryst1_interpretation.py: Add the %d line%s above with "Hall:" to the "special" dictionary. """ % plural_s(n_need_more_special))
def exercise_symop_lib_recycling(): file_iter = open(op.join( extract_from_symmetry_lib.ccp4io_lib_data, "symop.lib")) ccp4_id_counts = libtbx.dict_with_default_0() ccp4_symbol_counts = libtbx.dict_with_default_0() for line in file_iter: flds = line.split(None, 4) ccp4_id = flds[0] ccp4_id_counts[ccp4_id] += 1 space_group_number = int(ccp4_id[-3:]) order_z = int(flds[1]) given_ccp4_symbol = flds[3] ccp4_symbol_counts[given_ccp4_symbol] += 1 group = extract_from_symmetry_lib.collect_symops( file_iter=file_iter, order_z=order_z) assert group.order_z() == order_z space_group_info = sgtbx.space_group_info(group=group) retrieved_ccp4_symbol = extract_from_symmetry_lib.ccp4_symbol( space_group_info=space_group_info, lib_name="symop.lib") assert retrieved_ccp4_symbol == given_ccp4_symbol assert space_group_info.type().number() == space_group_number if (1): from iotbx.pdb import format_cryst1_sgroup sgroup = format_cryst1_sgroup(space_group_info=space_group_info) if (len(sgroup) > 11): print "ccp4 symop.lib setting leads to pdb CRYST1 overflow:",\ ccp4_id, given_ccp4_symbol, sgroup for ccp4_id,count in ccp4_id_counts.items(): if (count != 1): raise RuntimeError( 'ccp4 id "%s" appears %d times (should be unique).' % (ccp4_id, count)) ccp4_symbol_counts = libtbx.dict_with_default_0() for ccp4_symbol,count in ccp4_symbol_counts.items(): if (count != 1): raise RuntimeError( 'ccp4 symbol "%s" appears %d times (should be unique).' % (ccp4_symbol, count))
def exercise_syminfo_lib_pdb_cryst1_recycling(): # this call is to build _syminfo_lib_cache assert extract_from_symmetry_lib.ccp4_symbol( space_group_info=sgtbx.space_group_info("P 1"), lib_name="syminfo.lib") == "P 1" # import iotbx.pdb.cryst1_interpretation n_need_more_special = 0 for number in xrange(1,230+1): for hall,ccp4_symbol in \ extract_from_symmetry_lib._syminfo_lib_cache[number]: sgi_hall = sgtbx.space_group_info(symbol="Hall: "+hall) if (sgi_hall.group().is_centric()): continue sgroup = iotbx.pdb.format_cryst1_sgroup(space_group_info=sgi_hall) if (len(sgroup) > 11): print "ccp4 syminfo.lib setting leads to pdb CRYST1 overflow:",\ ccp4_symbol, sgroup cs = sgi_hall.any_compatible_crystal_symmetry(volume=1000) pdb_str = iotbx.pdb.format_cryst1_record(crystal_symmetry=cs) cs2 = iotbx.pdb.cryst1_interpretation.crystal_symmetry( cryst1_record=pdb_str) if (cs2.space_group_info() is None): if (n_need_more_special == 0): print print '"%s": "Hall: %s",' % ( ccp4_symbol.replace(" ", "").upper(), hall) n_need_more_special += 1 else: assert cs2.is_similar_symmetry(other=cs) if (ccp4io_adaptbx is not None): exercise_mmdb_cryst1_interpretation( sgi_hall=sgi_hall, pdb_str=pdb_str) if (n_need_more_special != 0): print from libtbx.utils import plural_s raise RuntimeError("""\ Please edit iotbx/pdb/cryst1_interpretation.py: Add the %d line%s above with "Hall:" to the "special" dictionary. """ % plural_s(n_need_more_special))
def write_par_file(file_name, experiment): from scitbx import matrix from dxtbx.model.crystal import crystal_model from rstbx.cftbx.coordinate_frame_helpers import align_reference_frame from iotbx.mtz.extract_from_symmetry_lib import ccp4_symbol imageset = experiment.imageset detector = imageset.get_detector() goniometer = imageset.get_goniometer() beam = imageset.get_beam() scan = imageset.get_scan() R_to_mosflm = align_reference_frame( beam.get_s0(), (1.0, 0.0, 0.0), goniometer.get_rotation_axis(), (0.0, 0.0, 1.0)) cryst = experiment.crystal cryst = cryst.change_basis( cryst.get_space_group().info()\ .change_of_basis_op_to_reference_setting()) A = cryst.get_A() A_inv = A.inverse() real_space_a = R_to_mosflm * A_inv.elems[:3] real_space_b = R_to_mosflm * A_inv.elems[3:6] real_space_c = R_to_mosflm * A_inv.elems[6:9] cryst_mosflm = crystal_model( real_space_a, real_space_b, real_space_c, space_group=cryst.get_space_group(), mosaicity=cryst.get_mosaicity()) A_mosflm = cryst_mosflm.get_A() U_mosflm = cryst_mosflm.get_U() B_mosflm = cryst_mosflm.get_B() UB_mosflm = U_mosflm * B_mosflm uc_params = cryst_mosflm.get_unit_cell().parameters() assert U_mosflm.is_r3_rotation_matrix(), U_mosflm symmetry = cryst_mosflm.get_space_group().type().number() beam_centre = tuple(reversed(detector[0].get_beam_centre(beam.get_s0()))) distance = detector[0].get_directed_distance() polarization = R_to_mosflm * matrix.col(beam.get_polarization_normal()) rotation = matrix.col(goniometer.get_rotation_axis()) if (rotation.angle(matrix.col(detector[0].get_fast_axis())) < rotation.angle(matrix.col(detector[0].get_slow_axis()))): direction = 'FAST' else: direction = 'SLOW' rotation = R_to_mosflm * rotation with open(file_name, 'wb') as f:# print >> f, '# parameter file for BEST' print >> f, 'TITLE From DIALS' print >> f, 'DETECTOR PILA' print >> f, 'SITE Not set' print >> f, 'DIAMETER %6.2f' %(max(detector[0].get_image_size()) * detector[0].get_pixel_size()[0]) print >> f, 'PIXEL %s' %detector[0].get_pixel_size()[0] print >> f, 'ROTAXIS %4.2f %4.2f %4.2f' %rotation.elems, direction print >> f, 'POLAXIS %4.2f %4.2f %4.2f' %polarization.elems print >> f, 'GAIN 1.00' # correct for Pilatus images print >> f, 'CMOSAIC %.2f' %experiment.profile.sigma_m() print >> f, 'PHISTART %.2f' %scan.get_oscillation_range()[0] print >> f, 'PHIWIDTH %.2f' %scan.get_oscillation()[1] print >> f, 'DISTANCE %7.2f' %distance print >> f, 'WAVELENGTH %.5f' %beam.get_wavelength() print >> f, 'POLARISATION %7.5f' %beam.get_polarization_fraction() print >> f, 'SYMMETRY %s' %ccp4_symbol( cryst.get_space_group().info(), lib_name='syminfo.lib', require_at_least_one_lib=False).replace(' ', '') print >> f, 'UB %9.6f %9.6f %9.6f' %UB_mosflm[:3] print >> f, ' %9.6f %9.6f %9.6f' %UB_mosflm[3:6] print >> f, ' %9.6f %9.6f %9.6f' %UB_mosflm[6:] print >> f, 'CELL %8.2f %8.2f %8.2f %6.2f %6.2f %6.2f' %uc_params print >> f, 'RASTER 13 13 7 3 4' print >> f, 'SEPARATION 2.960 2.960' print >> f, 'BEAM %8.3f %8.3f' %beam_centre print >> f, '# end of parameter file for BEST'