def run(): settings = [0] for i in range(1, 231): settings.append({}) list_cb_op = [] for xyz in ("x,y,z", "z,x,y", "y,z,x"): list_cb_op.append(sgtbx.change_of_basis_op(sgtbx.rt_mx(xyz))) n_built = 0 for i in sgtbx.space_group_symbol_iterator(): hall_symbol = i.hall() for z in "PABCIRHF": hall_z = hall_symbol[0] + z + hall_symbol[2:] for cb_op in list_cb_op: group = sgtbx.space_group(hall_z).change_basis(cb_op) sg_type = group.type() settings[sg_type.number()][sg_type.lookup_symbol()] = 0 n_built += 1 print("# n_built =", n_built) n_non_redundant = 0 print("settings = (") for i in range(1, 231): print("#", i) symbols = list(settings[i].keys()) symbols.sort() for s in symbols: print("'" + s + "',") n_non_redundant += 1 print(")") print("# n_non_redundant =", n_non_redundant)
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()
def exercise_space_group_contains(): g = sgtbx.space_group("P 2") for s in ["x,y,z", "-x,-y,z", "-x+1,-y-2,z+3"]: assert g.contains(sgtbx.rt_mx(s)) for s in ["x,y,-z", "x+1/2,y,z"]: assert not g.contains(sgtbx.rt_mx(s)) for symbols in sgtbx.space_group_symbol_iterator(): g = sgtbx.space_group(symbols.hall()) for s in g: assert g.contains(s) rnd = flex.mersenne_twister(seed=0) n_c = 0 n_nc = 0 for symbol in sgtbx.bravais_types.centric: g = sgtbx.space_group_info(symbol=symbol, space_group_t_den=144).group() for s in g.change_basis( sgtbx.change_of_basis_op("x+1/12,y-1/12,z+1/12")): if (rnd.random_double() < 0.9): continue # avoid long runtime gc = sgtbx.space_group(g) gc.expand_smx(s) if (gc.order_z() == g.order_z()): assert g.contains(s) n_c += 1 else: assert not g.contains(s) n_nc += 1 assert n_c == 11, n_c assert n_nc == 53, n_nc
def run(): settings = [0] for i in xrange(1, 231): settings.append({}) list_cb_op = [] for xyz in ("x,y,z", "z,x,y", "y,z,x"): list_cb_op.append(sgtbx.change_of_basis_op(sgtbx.rt_mx(xyz))) n_built = 0 for i in sgtbx.space_group_symbol_iterator(): hall_symbol = i.hall() for z in "PABCIRHF": hall_z = hall_symbol[0] + z + hall_symbol[2:] for cb_op in list_cb_op: group = sgtbx.space_group(hall_z).change_basis(cb_op) sg_type = group.type() settings[sg_type.number()][sg_type.lookup_symbol()] = 0 n_built += 1 print "# n_built =", n_built n_non_redundant = 0 print "settings = (" for i in xrange(1, 231): print "#", i symbols = settings[i].keys() symbols.sort() for s in symbols: print "'" + s + "'," n_non_redundant += 1 print ")" print "# n_non_redundant =", n_non_redundant
def test_table(self): for sg in gemmi.spacegroup_table(): if sg.ccp4 != 0: self.assertEqual(sg.ccp4 % 1000, sg.number) if sg.operations().is_centric(): self.assertEqual(sg.laue_str(), sg.point_group_hm()) else: self.assertNotEqual(sg.laue_str(), sg.point_group_hm()) if sgtbx: hall = sg.hall.encode() cctbx_sg = sgtbx.space_group(hall) cctbx_info = sgtbx.space_group_info(group=cctbx_sg) self.assertEqual(sg.is_reference_setting(), cctbx_info.is_reference_setting()) #to_ref = cctbx_info.change_of_basis_op_to_reference_setting() #from_ref = '%s' % cob_to_ref.inverse().c() c2p_sg = gemmi.Op(cctbx_sg.z2p_op().c().inverse().as_xyz()) self.assertEqual(sg.centred_to_primitive(), c2p_sg) ops = gemmi.get_spacegroup_reference_setting(sg.number).operations() ops.change_basis_forward(sg.basisop) self.assertEqual(ops, sg.operations()) itb = gemmi.spacegroup_table_itb() if sgtbx: for s in sgtbx.space_group_symbol_iterator(): self.assertEqual(s.hall().strip(), next(itb).hall) with self.assertRaises(StopIteration): next(itb)
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)"]
def run(server_info, inp, status): sg_number = 0 if (len(inp.sgsymbol.strip()) != 0): sg_number = sgtbx.space_group_info( symbol=inp.sgsymbol, table_id=inp.convention).type().number() n_settings = 0 print "<table border=2 cellpadding=2>" print "<tr>" print "<th>Space group<br>No." print "<th>Schoenflies<br>symbol" print "<th>Hermann-Mauguin<br>symbol" print "<th>Hall<br>symbol" for symbols in sgtbx.space_group_symbol_iterator(): if (sg_number == 0 or symbols.number() == sg_number): print "<tr>" print "<td>(%d)<td>%s" % ( symbols.number(), symbols.schoenflies()) query = "target_module=explore_symmetry&sgsymbol=" \ + urllib.quote_plus(symbols.universal_hermann_mauguin()) print ("<td><a href=\"%s\">%s</a>") % ( server_info.script(query), symbols.universal_hermann_mauguin()) print "<td>%s" % (symbols.hall(),) n_settings += 1 print "</table>" if (sg_number == 0): print "<p>" print "Number of settings listed:", n_settings print "<p>"
def run(server_info, inp, status): sg_number = 0 if (len(inp.sgsymbol.strip()) != 0): sg_number = sgtbx.space_group_info( symbol=inp.sgsymbol, table_id=inp.convention).type().number() n_settings = 0 print "<table border=2 cellpadding=2>" print "<tr>" print "<th>Space group<br>No." print "<th>Schoenflies<br>symbol" print "<th>Hermann-Mauguin<br>symbol" print "<th>Hall<br>symbol" for symbols in sgtbx.space_group_symbol_iterator(): if (sg_number == 0 or symbols.number() == sg_number): print "<tr>" print "<td>(%d)<td>%s" % (symbols.number(), symbols.schoenflies()) query = "target_module=explore_symmetry&sgsymbol=" \ + urllib.quote_plus(symbols.universal_hermann_mauguin()) print("<td><a href=\"%s\">%s</a>") % ( server_info.script(query), symbols.universal_hermann_mauguin()) print "<td>%s" % (symbols.hall(), ) n_settings += 1 print "</table>" if (sg_number == 0): print "<p>" print "Number of settings listed:", n_settings print "<p>"
def list(self): for symbols in sgtbx.space_group_symbol_iterator(): sgi = sgtbx.space_group_info(group=sgtbx.space_group( space_group_symbols=symbols)) if self.comparator(sgi): if (self.chiral is None) or (self.chiral == sgi.group().is_chiral()): yield sgi
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]
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()
def run(): for symbols in sgtbx.space_group_symbol_iterator(): hm = html_markup(symbols.hermann_mauguin()) ext = symbols.extension() if ext == '\0': ext = '' uhm = html_markup(symbols.universal_hermann_mauguin()) print '%s,%s,%s,%s' % (symbols.number(), ''.join(hm), ext, ' '.join(uhm))
def get_test_space_group_symbols(flag_AllSpaceGroups, flag_ChiralSpaceGroups, flag_AllSettings, flag_UnusualSettings): if (flag_UnusualSettings): namespace = {} exec(open(os.path.join( libtbx.env.find_in_repositories( "phenix_regression"), "settings.py")).read(), 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 = range(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)"]
def exercise_space_group_contains(): g = sgtbx.space_group("P 2") for s in ["x,y,z", "-x,-y,z", "-x+1,-y-2,z+3"]: assert g.contains(sgtbx.rt_mx(s)) for s in ["x,y,-z", "x+1/2,y,z"]: assert not g.contains(sgtbx.rt_mx(s)) for symbols in sgtbx.space_group_symbol_iterator(): g = sgtbx.space_group(symbols.hall()) for s in g: assert g.contains(s) rnd = flex.mersenne_twister(seed=0) n_c = 0 n_nc = 0 for symbol in sgtbx.bravais_types.centric: g = sgtbx.space_group_info(symbol=symbol, space_group_t_den=144).group() for s in g.change_basis(sgtbx.change_of_basis_op("x+1/12,y-1/12,z+1/12")): if (rnd.random_double() < 0.9): continue # avoid long runtime gc = sgtbx.space_group(g) gc.expand_smx(s) if (gc.order_z() == g.order_z()): assert g.contains(s) n_c += 1 else: assert not g.contains(s) n_nc += 1 assert n_c == 11, n_c assert n_nc == 53, n_nc
def list(self): for symbols in sgtbx.space_group_symbol_iterator(): sgi = sgtbx.space_group_info(group=sgtbx.space_group( space_group_symbols=symbols)) if self.comparator(sgi): if (self.chiral is None) or (self.chiral == sgi.group().is_chiral()): yield sgi
def findEquivalentSgtbxSpaceGroup(sgmm): if not _equivsgtbx: for smbls in sgtbx.space_group_symbol_iterator(): uhm = smbls.universal_hermann_mauguin() grp = sgtbx.space_group_info(uhm).group() hgrp = hashSgtbxGroup(grp) _equivsgtbx.setdefault(hgrp, grp) hgmm = hashMMSpaceGroup(sgmm) return _equivsgtbx.get(hgmm)
def compare_ccp4_and_sgtbx(syminfo_data): for s in sgtbx.space_group_symbol_iterator(): sg = sgtbx.space_group(s.hall()) sg_type = sgtbx.space_group_type(sg) asu = sgtbx.reciprocal_space_asu(sg_type) sgtbx_hklasu = asu.reference_as_string().replace('==', '=') ccp4_hklasu = syminfo_data[s.number()] assert sgtbx_hklasu == ccp4_hklasu assert sgtbx_hklasu in hklasu_strings
def browse(self): for self.symbol in sgtbx.space_group_symbol_iterator(): self.sg = sgtbx.space_group(self.symbol.hall()).make_tidy() self.z2p_op = self.sg.z2p_op() self.sg_p = self.sg.change_basis(self.z2p_op) self.on_new_space_group() for self.op in self.sg_p: self.rot_info = self.op.r().info() self.tr_info = sgtbx.translation_part_info(self.op) if self.tr_info.origin_shift().is_zero(): continue self.on_new_symmetry()
def browse(self): for self.symbol in sgtbx.space_group_symbol_iterator(): self.sg = sgtbx.space_group(self.symbol.hall()).make_tidy() self.z2p_op = self.sg.z2p_op() self.sg_p = self.sg.change_basis(self.z2p_op) self.on_new_space_group() for self.op in self.sg_p: self.rot_info = self.op.r().info() self.tr_info = sgtbx.translation_part_info(self.op) if self.tr_info.origin_shift().is_zero(): continue self.on_new_symmetry()
def run(): all_flds = set() for symbols in sgtbx.space_group_symbol_iterator(): symbol = symbols.universal_hermann_mauguin() print symbol flds = symbol.split() all_flds.update(flds) with open('symops_530_html_markup.py', 'w') as f: print >> f, 'html_markup = {' for fld in sorted(all_flds): print >> f, " '%s': '%s'," % (fld, fld) print >> f, '}'
def exercise_inversion_centring(): cb = sgtbx.change_of_basis_op("x+1/12,y+1/12,z-1/12") for symb in sgtbx.space_group_symbol_iterator(): sg = sgtbx.space_group(space_group_symbols=symb) sg1 = sg.change_basis(cb) icb = sg1.change_of_origin_realising_origin_centricity() if sg1.is_centric(): assert not sg1.is_origin_centric() sg2 = sg1.change_basis(icb) assert sg2.is_origin_centric() else: assert str(icb) == "a,b,c"
def exercise_inversion_centring(): cb = sgtbx.change_of_basis_op("x+1/12,y+1/12,z-1/12") for symb in sgtbx.space_group_symbol_iterator(): sg = sgtbx.space_group(space_group_symbols=symb) sg1 = sg.change_basis(cb) icb = sg1.change_of_origin_realising_origin_centricity() if sg1.is_centric(): assert not sg1.is_origin_centric() sg2 = sg1.change_basis(icb) assert sg2.is_origin_centric() else: assert str(icb) == "a,b,c"
def exercise_ss_continuous_shifts_are_principal(): for i in range(1, 231): sgi = sgtbx.space_group_info(number=i) ss = sgi.structure_seminvariants() assert ss.continuous_shifts_are_principal() for symbols in sgtbx.space_group_symbol_iterator(): sgi = sgtbx.space_group_info(group=sgtbx.space_group( space_group_symbols=symbols)) ss = sgi.structure_seminvariants() if (not ss.continuous_shifts_are_principal()): assert symbols.universal_hermann_mauguin() in [ "R 3 :R", "R 3 m :R", "R 3 c :R" ]
def run(): for symbols in sgtbx.space_group_symbol_iterator(): symbol = symbols.universal_hermann_mauguin() print(symbol) space_group_info = sgtbx.space_group_info(symbol=symbol) for s in space_group_info.group(): print(s.as_xyz()) for s in space_group_info.group(): sr = s.as_rational() print(sr.r.elems, sr.t.elems) for s in space_group_info.group(): print(s.r().num(), s.r().den(), s.t().num(), s.t().den()) print()
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
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
def run(): groups = [] lookup_dict = {} for i_sg in range(1, 231): space_group_info = sgtbx.space_group_info(number=i_sg) space_group = space_group_info.group() group = {"symbol": str(space_group_info), "number": i_sg, "operators": []} for mx in space_group.smx(): group["operators"].append(str(mx)) groups.append(group) for symbol in sgtbx.space_group_symbol_iterator(): lookup_dict[str(symbol.hermann_mauguin())] = symbol.number() lookup_dict[str(symbol.hall())] = symbol.number() print json.dumps({"groups": groups, "lookup": lookup_dict})
def exercise_ss_continuous_shifts_are_principal(): for i in xrange(1, 231): sgi = sgtbx.space_group_info(number=i) ss = sgi.structure_seminvariants() assert ss.continuous_shifts_are_principal() for symbols in sgtbx.space_group_symbol_iterator(): sgi = sgtbx.space_group_info(group=sgtbx.space_group( space_group_symbols=symbols)) ss = sgi.structure_seminvariants() if (not ss.continuous_shifts_are_principal()): assert symbols.universal_hermann_mauguin() in [ "R 3 :R", "R 3 m :R", "R 3 c :R"]
def exercise_monoclinic_cell_choices(verbose=0): done = {} for space_group_number in xrange(3,16): done.update(exercise_monoclinic_cell_choices_core( space_group_number=space_group_number, verbose=verbose)) assert len(done) == 105 assert done.values().count(0) == 0 n = 0 for s in sgtbx.space_group_symbol_iterator(): if (s.number() < 3): continue if (s.number() > 15): break done[s.universal_hermann_mauguin()] = 0 n += 1 assert n == 105 assert done.values().count(0) == 105
def main(): duplicates = set() for smbls in sgtbx.space_group_symbol_iterator(): uhm = smbls.universal_hermann_mauguin() grp = sgtbx.space_group_info(uhm).group() if findEquivalentMMSpaceGroup(grp): continue shn = smbls.hermann_mauguin().replace(' ', '') if IsSpaceGroupIdentifier(shn): continue sg = mmSpaceGroupFromSymbol(uhm) hsg = hashMMSpaceGroup(sg) if hsg in duplicates: continue adjustMMSpaceGroupNumber(sg) duplicates.add(hsg) print SGCode(sg) return
def run () : groups = [] lookup_dict = {} for i_sg in range(1, 231) : space_group_info = sgtbx.space_group_info(number=i_sg) space_group = space_group_info.group() group = { "symbol" : str(space_group_info), "number" : i_sg, "operators" : [] } for mx in space_group.smx() : group["operators"].append(str(mx)) groups.append(group) for symbol in sgtbx.space_group_symbol_iterator() : lookup_dict[str(symbol.hermann_mauguin())] = symbol.number() lookup_dict[str(symbol.hall())] = symbol.number() print json.dumps({"groups" : groups, "lookup" : lookup_dict })
def exercise_monoclinic_cell_choices(verbose=0): done = {} for space_group_number in range(3, 16): done.update( exercise_monoclinic_cell_choices_core( space_group_number=space_group_number, verbose=verbose)) assert len(done) == 105 assert list(done.values()).count(0) == 0 n = 0 for s in sgtbx.space_group_symbol_iterator(): if (s.number() < 3): continue if (s.number() > 15): break done[s.universal_hermann_mauguin()] = 0 n += 1 assert n == 105 assert list(done.values()).count(0) == 105
def exercise_format_and_interpret_cryst1(): for symbols in sgtbx.space_group_symbol_iterator(): sgi = sgtbx.space_group_info(group=sgtbx.space_group(space_group_symbols=symbols)) cs = sgi.any_compatible_crystal_symmetry(volume=1000) pdb_str = iotbx.pdb.format_cryst1_record(crystal_symmetry=cs) cs2 = pdb.cryst1_interpretation.crystal_symmetry(cryst1_record=pdb_str) assert cs2.is_similar_symmetry(other=cs) # for pdb_str in """] CRYST1 1.000 1.000 1.000 90.00 90.00 90.00 P 1 CRYST1 1.000 1.000 1.000 0.00 0.00 0.00 P 1 CRYST1 0.000 0.000 0.000 90.00 90.00 90.00 P 1 CRYST1 1.000 0.000 0.000 0.00 90.00 90.00 P 1 """.splitlines(): cs = pdb.cryst1_interpretation.crystal_symmetry(cryst1_record=pdb_str) assert cs.unit_cell() is None assert cs.space_group_info() is None
def xtestCreateSpaceGroup(self): """Check all sgtbx space groups for proper conversion to SpaceGroup.""" try: from cctbx import sgtbx except ImportError: return for smbls in sgtbx.space_group_symbol_iterator(): shn = smbls.hermann_mauguin() short_name = shn.replace(' ', '') if SpaceGroups.IsSpaceGroupIdentifier(short_name): sg = SpaceGroups.GetSpaceGroup(shn) sgnew = self.getObjCrystParSetSpaceGroup(sg) # print "dbsg: " + repr(self.sgsEquivalent(sg, sgnew)) self.assertTrue(self.sgsEquivalent(sg, sgnew)) return
def exercise_format_and_interpret_cryst1(): for symbols in sgtbx.space_group_symbol_iterator(): sgi = sgtbx.space_group_info(group=sgtbx.space_group( space_group_symbols=symbols)) cs = sgi.any_compatible_crystal_symmetry(volume=1000) pdb_str = iotbx.pdb.format_cryst1_record(crystal_symmetry=cs) cs2 = pdb.cryst1_interpretation.crystal_symmetry(cryst1_record=pdb_str) assert cs2.is_similar_symmetry(other=cs) # for pdb_str in """] CRYST1 1.000 1.000 1.000 90.00 90.00 90.00 P 1 CRYST1 1.000 1.000 1.000 0.00 0.00 0.00 P 1 CRYST1 0.000 0.000 0.000 90.00 90.00 90.00 P 1 CRYST1 1.000 0.000 0.000 0.00 90.00 90.00 P 1 """.splitlines(): cs = pdb.cryst1_interpretation.crystal_symmetry(cryst1_record=pdb_str) assert cs.unit_cell() is None assert cs.space_group_info() is None
def generate_chiral_spacegroups(pointgroup): sg = space_group(space_group_symbols(pointgroup).hall()) pg = sg.build_derived_patterson_group() sg_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: if not sg_test in sg_list: sg_list.append(sg_test) return [ sg_test.type().lookup_symbol().replace(' ', '') \ for sg_test in sg_list]
def exercise_combine_symops_and_symbol(): for symbols in sgtbx.space_group_symbol_iterator(): space_group = sgtbx.space_group_info( symbol="Hall: %s" % symbols.hall()).group() space_group_from_ops = sgtbx.space_group() for s in list(space_group)[:space_group.order_p()]: space_group_from_ops.expand_smx(s) combined = combine_symops_and_symbol( space_group_from_ops=space_group_from_ops, space_group_symbol=symbols.universal_hermann_mauguin()) assert combined.group() == space_group if (symbols.extension() in ["R", "H"]): combined = combine_symops_and_symbol( space_group_from_ops=space_group_from_ops, space_group_symbol=symbols.hermann_mauguin()) assert combined.group() == space_group if (symbols.extension() == "H"): combined = combine_symops_and_symbol( space_group_from_ops=space_group_from_ops, space_group_symbol="H "+symbols.hermann_mauguin()[2:]) assert combined.group() == space_group
def exercise_combine_symops_and_symbol(): for symbols in sgtbx.space_group_symbol_iterator(): space_group = sgtbx.space_group_info( symbol="Hall: %s" % symbols.hall()).group() space_group_from_ops = sgtbx.space_group() for s in list(space_group)[:space_group.order_p()]: space_group_from_ops.expand_smx(s) combined = combine_symops_and_symbol( space_group_from_ops=space_group_from_ops, space_group_symbol=symbols.universal_hermann_mauguin()) assert combined.group() == space_group if (symbols.extension() in ["R", "H"]): combined = combine_symops_and_symbol( space_group_from_ops=space_group_from_ops, space_group_symbol=symbols.hermann_mauguin()) assert combined.group() == space_group if (symbols.extension() == "H"): combined = combine_symops_and_symbol( space_group_from_ops=space_group_from_ops, space_group_symbol="H "+symbols.hermann_mauguin()[2:]) assert combined.group() == space_group
def test_extensively( this_chunk ): n_chunks = 1 i_chunk = int(this_chunk) assert i_chunk <= n_chunks for i_sg, sg in enumerate(sgtbx.space_group_symbol_iterator()): if i_sg % n_chunks != i_chunk: continue buffer = StringIO() group = sgtbx.space_group(sg.hall()) #if group != sgtbx.space_group_info( symbol = 'I 21 21 21' ).group() : # continue unit_cell =sgtbx.space_group_info(group=group).any_compatible_unit_cell( volume=57*57*76) xs_in = crystal.symmetry(unit_cell=unit_cell, space_group=group) xs_in = xs_in.best_cell() # Just make sure we have the 'best cell' to start out with xs_minimum = xs_in.change_basis(xs_in.change_of_basis_op_to_niggli_cell()) sg_min = xs_minimum.space_group() sg_min_info = sgtbx.space_group_info(group = sg_min) sg_min_to_ref = sg_min_info.change_of_basis_op_to_reference_setting() sg_in_to_min = xs_in.change_of_basis_op_to_niggli_cell() xs_ref = xs_minimum.change_basis(sg_min_to_ref) best_cell_finder = fbc(xs_ref.unit_cell(), xs_ref.space_group()) xs_ref = best_cell_finder.return_best_xs() xs_lattice_pg = sgtbx.lattice_symmetry.group( xs_minimum.unit_cell(), max_delta=5.0) sg_in_ref_setting = sg_min.change_basis(sg_min_to_ref) # ----------- queue = [] if sg_in_ref_setting.is_chiral(): print "Testing : ",\ sgtbx.space_group_info(group=group),\ "( or ", sgtbx.space_group_info(group=sg_in_ref_setting),\ " in reference setting)" for s in sg_min: new_sg = sgtbx.space_group() new_sg.expand_smx(s) if new_sg in queue: continue else: queue.append(new_sg) xs_cheat = crystal.symmetry(xs_minimum.unit_cell(), space_group=new_sg) #print #print "Using symop", s xs_cheat_min = xs_cheat.change_basis( xs_cheat.change_of_basis_op_to_niggli_cell() ) #print "This results in space group: ", xs_cheat.space_group_info() sg_clues = pt.space_group_graph_from_cell_and_sg( xs_cheat_min.unit_cell(), xs_cheat_min.space_group() ) #sg_clues.show() found_it = False #print #print " --- Spacegroups consistent with input parameters ---" for sg_and_uc in sg_clues.return_likely_sg_and_cell(): check_sg = False check_uc = False xs = crystal.symmetry(sg_and_uc[1], space_group=sg_and_uc[0]) if approx_equal( sg_and_uc[1].parameters(), xs_ref.unit_cell().parameters(), eps=0.001, out=buffer): if sg_and_uc[0] == sg_in_ref_setting: found_it = True #print sgtbx.space_group_info( group=sg_and_uc[0] ), \ # sg_and_uc[1].parameters() if not found_it: print "FAILURE: ", sg.hall() assert found_it
def run(args): assert args in [[], ["python"], ["c++"]] # sgno_list_by_index_list_by_cs = {} from cctbx import sgtbx from cctbx import miller for symbols in sgtbx.space_group_symbol_iterator(): psgi = sgtbx.space_group_info(symbols.universal_hermann_mauguin()) \ .primitive_setting() p_indices = miller.index_generator(space_group_type=psgi.type(), anomalous_flag=False, max_index=[4] * 3).to_array() # 4 is the smallest value leading to correct results; any larger # value will work, too, but will make this procedure slower p1_indices = miller.expand_to_p1_iselection( space_group=psgi.group(), anomalous_flag=False, indices=p_indices, build_iselection=False).indices from cctbx.array_family import flex sort_perm = flex.sort_permutation( data=miller.index_span(p1_indices).pack(p1_indices)) p1_indices = p1_indices.select(sort_perm) index_list = tuple(p1_indices) sgno = psgi.type().number() sgno_list_by_index_list = sgno_list_by_index_list_by_cs \ .setdefault(symbols.crystal_system(), {}) sgno_list_by_index_list.setdefault(index_list, []).append(sgno) from scitbx.graph import tardy_tree cluster_manager = tardy_tree.cluster_manager(n_vertices=231) for cs, sgno_list_by_index_list in sgno_list_by_index_list_by_cs.items(): for sgno_list in sgno_list_by_index_list.values(): i = sgno_list[0] for j in sgno_list[1:]: cluster_manager.connect_vertices(i=i, j=j, optimize=True) cluster_manager.tidy() # # everything below is just to format the results # if (args == []): for cluster in cluster_manager.clusters: if (len(cluster) == 1): break print(cluster) else: note = ("""\ Output of: cctbx/examples/find_sys_abs_equiv_space_groups.py %s If you have to edit this table, please send email to: [email protected] """ % args[0]).splitlines() # if (args == ["python"]): print("space_group_numbers = [") for line in note: print(" #", line) ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for sgno in range(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): s = "None" else: s = str(tuple(cluster)) if (sgno == 230): comma = "" else: comma = "," print(" %s%s" % (s, comma)) print("]") else: print("""\ #ifndef CCTBX_SGTBX_SYS_ABS_EQUIV_H #define CCTBX_SGTBX_SYS_ABS_EQUIV_H namespace cctbx { namespace sgtbx { namespace sys_abs_equiv { """) data = [] ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for line in note: print(" //", line) for sgno in range(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): data.append("0") else: cid = "data_%03d" % sgno data.append(cid) print(" static const unsigned %s[] = {%d, %s};" % (cid, len(cluster), ", ".join( [str(i) for i in cluster]))) print("") print(" static const unsigned* space_group_numbers[] = {") print(" ", ",\n ".join(data)) print("""\ }; }}} #endif // GUARD""")
def run(args): assert args in [[], ["python"], ["c++"]] # sgno_list_by_index_list_by_cs = {} from cctbx import sgtbx from cctbx import miller for symbols in sgtbx.space_group_symbol_iterator(): psgi = sgtbx.space_group_info(symbols.universal_hermann_mauguin()) \ .primitive_setting() p_indices = miller.index_generator( space_group_type=psgi.type(), anomalous_flag=False, max_index=[4]*3).to_array() # 4 is the smallest value leading to correct results; any larger # value will work, too, but will make this procedure slower p1_indices = miller.expand_to_p1_iselection( space_group=psgi.group(), anomalous_flag=False, indices=p_indices, build_iselection=False).indices from cctbx.array_family import flex sort_perm = flex.sort_permutation( data=miller.index_span(p1_indices).pack(p1_indices)) p1_indices = p1_indices.select(sort_perm) index_list = tuple(p1_indices) sgno = psgi.type().number() sgno_list_by_index_list = sgno_list_by_index_list_by_cs \ .setdefault(symbols.crystal_system(), {}) sgno_list_by_index_list.setdefault(index_list, []).append(sgno) from scitbx.graph import tardy_tree cluster_manager = tardy_tree.cluster_manager(n_vertices=231) for cs,sgno_list_by_index_list in sgno_list_by_index_list_by_cs.items(): for sgno_list in sgno_list_by_index_list.values(): i = sgno_list[0] for j in sgno_list[1:]: cluster_manager.connect_vertices(i=i, j=j, optimize=True) cluster_manager.tidy() # # everything below is just to format the results # if (args == []): for cluster in cluster_manager.clusters: if (len(cluster) == 1): break print cluster else: note = ("""\ Output of: cctbx/examples/find_sys_abs_equiv_space_groups.py %s If you have to edit this table, please send email to: [email protected] """ % args[0]).splitlines() # if (args == ["python"]): print "space_group_numbers = [" for line in note: print " #", line ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for sgno in xrange(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): s = "None" else: s = str(tuple(cluster)) if (sgno == 230): comma = "" else: comma = "," print " %s%s" % (s, comma) print "]" else: print """\ #ifndef CCTBX_SGTBX_SYS_ABS_EQUIV_H #define CCTBX_SGTBX_SYS_ABS_EQUIV_H namespace cctbx { namespace sgtbx { namespace sys_abs_equiv { """ data = [] ci = cluster_manager.cluster_indices cl = cluster_manager.clusters for line in note: print " //", line for sgno in xrange(231): cluster = list(cl[ci[sgno]]) cluster.remove(sgno) if (len(cluster) == 0): data.append("0") else: cid = "data_%03d" % sgno data.append(cid) print " static const unsigned %s[] = {%d, %s};" % ( cid, len(cluster), ", ".join([str(i) for i in cluster])) print "" print " static const unsigned* space_group_numbers[] = {" print " ", ",\n ".join(data) print """\
for info in syminfo_data: # handle duplicates in syminfo.lib: pick the the one with ccp4 number if info['xhm'] not in syminfo_dict or info['ccp4'] != 0: syminfo_dict[info['xhm']] = info print('''\ // This table was generated by tools/gen_sg_table.py. // First 530 entries in the same order as in SgInfo, sgtbx and ITB. // Note: spacegroup 68 has three duplicates with different H-M names. ''') counter = 0 fmt = ' {%3d, %4d, %-12s, %s, %6s, %-16s, %-2d}, // %3d' def quot(s): return '"%s"' % s.replace('"', r'\"') for s in sgtbx.space_group_symbol_iterator(): xhm = s.hermann_mauguin() ext = ' 0' if s.extension() != '\0': xhm += ':%s' % s.extension() ext = "'%c'" % s.extension() info = syminfo_dict.pop(xhm) assert info['number'] == s.number() cctbx_sg = sgtbx.space_group(s.hall()) cctbx_info = sgtbx.space_group_info(group=cctbx_sg) from_ref, basisop_idx = get_basisop(cctbx_info) assert from_ref == info['basisop'], (from_ref, info['basisop']) if gemmi: assert (set(gemmi.symops_from_hall(s.hall())) == set(gemmi.symops_from_hall(info['hall']))), xhm print(fmt % (s.number(), info['ccp4'], quot(s.hermann_mauguin()),
def test_extensively(this_chunk): n_chunks = 1 i_chunk = int(this_chunk) assert i_chunk <= n_chunks for i_sg, sg in enumerate(sgtbx.space_group_symbol_iterator()): if i_sg % n_chunks != i_chunk: continue buffer = StringIO() group = sgtbx.space_group(sg.hall()) #if group != sgtbx.space_group_info( symbol = 'I 21 21 21' ).group(): # continue unit_cell = sgtbx.space_group_info( group=group).any_compatible_unit_cell(volume=57 * 57 * 76) xs_in = crystal.symmetry(unit_cell=unit_cell, space_group=group) xs_in = xs_in.best_cell() # Just make sure we have the 'best cell' to start out with xs_minimum = xs_in.change_basis( xs_in.change_of_basis_op_to_niggli_cell()) sg_min = xs_minimum.space_group() sg_min_info = sgtbx.space_group_info(group=sg_min) sg_min_to_ref = sg_min_info.change_of_basis_op_to_reference_setting() sg_in_to_min = xs_in.change_of_basis_op_to_niggli_cell() xs_ref = xs_minimum.change_basis(sg_min_to_ref) best_cell_finder = fbc(xs_ref.unit_cell(), xs_ref.space_group()) xs_ref = best_cell_finder.return_best_xs() xs_lattice_pg = sgtbx.lattice_symmetry.group(xs_minimum.unit_cell(), max_delta=5.0) sg_in_ref_setting = sg_min.change_basis(sg_min_to_ref) # ----------- queue = [] if sg_in_ref_setting.is_chiral(): print "Testing : ",\ sgtbx.space_group_info(group=group),\ "( or ", sgtbx.space_group_info(group=sg_in_ref_setting),\ " in reference setting)" for s in sg_min: new_sg = sgtbx.space_group() new_sg.expand_smx(s) if new_sg in queue: continue else: queue.append(new_sg) xs_cheat = crystal.symmetry(xs_minimum.unit_cell(), space_group=new_sg) #print #print "Using symop", s xs_cheat_min = xs_cheat.change_basis( xs_cheat.change_of_basis_op_to_niggli_cell()) #print "This results in space group: ", xs_cheat.space_group_info() sg_clues = pt.space_group_graph_from_cell_and_sg( xs_cheat_min.unit_cell(), xs_cheat_min.space_group()) #sg_clues.show() found_it = False #print #print " --- Spacegroups consistent with input parameters ---" for sg_and_uc in sg_clues.return_likely_sg_and_cell(): check_sg = False check_uc = False xs = crystal.symmetry(sg_and_uc[1], space_group=sg_and_uc[0]) if approx_equal(sg_and_uc[1].parameters(), xs_ref.unit_cell().parameters(), eps=0.001, out=buffer): if sg_and_uc[0] == sg_in_ref_setting: found_it = True #print sgtbx.space_group_info( group=sg_and_uc[0] ), \ # sg_and_uc[1].parameters() if not found_it: print "FAILURE: ", sg.hall() assert found_it
def test_with_sgtbx(self): if sgtbx is None: return for s in sgtbx.space_group_symbol_iterator(): self.compare_hall_symops_with_sgtbx(s.hall()) self.compare_hall_symops_with_sgtbx('C -4 -2b', existing_group=False)
def exercise_crystal_symmetry_utils(): as_rem = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_as_sg_uc as_inp = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_as_cns_inp_defines crystal_symmetry = crystal.symmetry(unit_cell=None, space_group_info=None) sg_uc = as_rem(crystal_symmetry=crystal_symmetry) assert sg_uc == "sg=None a=None b=None c=None alpha=None beta=None gamma=None" sg_uc = as_inp(crystal_symmetry=crystal_symmetry) assert not show_diff("\n".join(sg_uc), """\ {===>} sg="None"; {===>} a=None; {===>} b=None; {===>} c=None; {===>} alpha=None; {===>} beta=None; {===>} gamma=None;""") # crystal_symmetry = crystal.symmetry( unit_cell=(3,4,5,89,87,93), space_group_info=None) sg_uc = as_rem(crystal_symmetry=crystal_symmetry) assert sg_uc == "sg=None a=3 b=4 c=5 alpha=89 beta=87 gamma=93" sg_uc = as_inp(crystal_symmetry=crystal_symmetry) assert not show_diff("\n".join(sg_uc), """\ {===>} sg="None"; {===>} a=3; {===>} b=4; {===>} c=5; {===>} alpha=89; {===>} beta=87; {===>} gamma=93;""") # crystal_symmetry = crystal.symmetry( unit_cell=None, space_group_symbol=19) sg_uc = as_rem(crystal_symmetry=crystal_symmetry) assert sg_uc == \ "sg=P2(1)2(1)2(1) a=None b=None c=None alpha=None beta=None gamma=None" sg_uc = as_inp(crystal_symmetry=crystal_symmetry) assert not show_diff("\n".join(sg_uc), """\ {===>} sg="P2(1)2(1)2(1)"; {===>} a=None; {===>} b=None; {===>} c=None; {===>} alpha=None; {===>} beta=None; {===>} gamma=None;""") # for symbols in sgtbx.space_group_symbol_iterator(): cs1 = sgtbx.space_group_info( group=sgtbx.space_group(symbols)).any_compatible_crystal_symmetry( volume=1000) sg_uc = as_rem(crystal_symmetry=cs1) m = re.match(iotbx.cns.crystal_symmetry_utils.re_sg_uc, sg_uc) assert m is not None cs2 = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_from_re_match(m=m) assert cs1.is_similar_symmetry(cs2) # sg_uc = as_inp(crystal_symmetry=cs1) sio = StringIO() print >> sio, "\n".join(sg_uc) sio = StringIO(sio.getvalue()) cs2 = iotbx.cns.crystal_symmetry_from_inp.extract_from(file=sio) assert cs1.is_similar_symmetry(cs2) # uc_sg = """\ a= 82.901 b= 82.901 c= 364.175 alpha= 90 beta= 90 gamma= 120 sg= P6(5)22""" m = re.match(iotbx.cns.crystal_symmetry_utils.re_uc_sg, uc_sg) cs = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_from_re_match( m=m, i_uc=1, i_sg=7) assert cs is not None assert str(cs.unit_cell()) == "(82.901, 82.901, 364.175, 90, 90, 120)" assert str(cs.space_group().info()) == "P 65 2 2"
def exercise_crystal_symmetry_utils(): as_rem = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_as_sg_uc as_inp = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_as_cns_inp_defines crystal_symmetry = crystal.symmetry(unit_cell=None, space_group_info=None) sg_uc = as_rem(crystal_symmetry=crystal_symmetry) assert sg_uc == "sg=None a=None b=None c=None alpha=None beta=None gamma=None" sg_uc = as_inp(crystal_symmetry=crystal_symmetry) assert not show_diff( "\n".join(sg_uc), """\ {===>} sg="None"; {===>} a=None; {===>} b=None; {===>} c=None; {===>} alpha=None; {===>} beta=None; {===>} gamma=None;""") # crystal_symmetry = crystal.symmetry(unit_cell=(3, 4, 5, 89, 87, 93), space_group_info=None) sg_uc = as_rem(crystal_symmetry=crystal_symmetry) assert sg_uc == "sg=None a=3 b=4 c=5 alpha=89 beta=87 gamma=93" sg_uc = as_inp(crystal_symmetry=crystal_symmetry) assert not show_diff( "\n".join(sg_uc), """\ {===>} sg="None"; {===>} a=3; {===>} b=4; {===>} c=5; {===>} alpha=89; {===>} beta=87; {===>} gamma=93;""") # crystal_symmetry = crystal.symmetry(unit_cell=None, space_group_symbol=19) sg_uc = as_rem(crystal_symmetry=crystal_symmetry) assert sg_uc == \ "sg=P2(1)2(1)2(1) a=None b=None c=None alpha=None beta=None gamma=None" sg_uc = as_inp(crystal_symmetry=crystal_symmetry) assert not show_diff( "\n".join(sg_uc), """\ {===>} sg="P2(1)2(1)2(1)"; {===>} a=None; {===>} b=None; {===>} c=None; {===>} alpha=None; {===>} beta=None; {===>} gamma=None;""") # for symbols in sgtbx.space_group_symbol_iterator(): cs1 = sgtbx.space_group_info( group=sgtbx.space_group(symbols)).any_compatible_crystal_symmetry( volume=1000) sg_uc = as_rem(crystal_symmetry=cs1) m = re.match(iotbx.cns.crystal_symmetry_utils.re_sg_uc, sg_uc) assert m is not None cs2 = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_from_re_match( m=m) assert cs1.is_similar_symmetry(cs2) # sg_uc = as_inp(crystal_symmetry=cs1) sio = StringIO() print >> sio, "\n".join(sg_uc) sio = StringIO(sio.getvalue()) cs2 = iotbx.cns.crystal_symmetry_from_inp.extract_from(file=sio) assert cs1.is_similar_symmetry(cs2) # uc_sg = """\ a= 82.901 b= 82.901 c= 364.175 alpha= 90 beta= 90 gamma= 120 sg= P6(5)22""" m = re.match(iotbx.cns.crystal_symmetry_utils.re_uc_sg, uc_sg) cs = iotbx.cns.crystal_symmetry_utils.crystal_symmetry_from_re_match( m=m, i_uc=1, i_sg=7) assert cs is not None assert str(cs.unit_cell()) == "(82.901, 82.901, 364.175, 90, 90, 120)" assert str(cs.space_group().info()) == "P 65 2 2"