def run(args): if (len(args) != 2): raise Usage("""\ cctbx.python space_subgroups.py max_index space_group_symbol Example: cctbx.python space_subgroups.py 2 P41212""") # max_index = int(args[0]) print("max_index:", max_index) assert max_index >= 1 print() space_group_t_den = 144 sginfo = sgtbx.space_group_info(symbol=args[1], space_group_t_den=space_group_t_den) sginfo.show_summary() print() cb_op_to_p = sginfo.change_of_basis_op_to_primitive_setting() sginfo_p = sginfo.change_basis(cb_op=cb_op_to_p) if (sginfo_p.group() != sginfo.group()): print("Primitive setting:") sginfo_p.show_summary() print() # all_subgroups = dict_with_default_0() sg_p = sginfo_p.group() sg_p_a = sg_p.build_derived_acentric_group() if (sg_p.is_centric()): inv_mx = sg_p(0, 1, 0).t() else: inv_mx = None for symx1 in sg_p_a: subgr1 = sgtbx.space_group(hall_symbol="P1", t_den=space_group_t_den) subgr1.expand_smx(symx1) for symx2 in sg_p_a: subgr2 = sgtbx.space_group(subgr1) subgr2.expand_smx(symx2) loop_over_super_cells(max_index=max_index, all_subgroups=all_subgroups, subgroup=subgr2) if (inv_mx is not None): subgr3 = sgtbx.space_group(subgr2) subgr3.expand_inv(inv_mx) loop_over_super_cells(max_index=max_index, all_subgroups=all_subgroups, subgroup=subgr3) # show_sorted_by_counts(label_count_pairs=list(all_subgroups.items()))
def run(args): if (len(args) != 2): raise Usage("""\ cctbx.python space_subgroups.py max_index space_group_symbol Example: cctbx.python space_subgroups.py 2 P41212""") # max_index = int(args[0]) print "max_index:", max_index assert max_index >= 1 print space_group_t_den = 144 sginfo = sgtbx.space_group_info( symbol=args[1], space_group_t_den=space_group_t_den) sginfo.show_summary() print cb_op_to_p = sginfo.change_of_basis_op_to_primitive_setting() sginfo_p = sginfo.change_basis(cb_op=cb_op_to_p) if (sginfo_p.group() != sginfo.group()): print "Primitive setting:" sginfo_p.show_summary() print # all_subgroups = dict_with_default_0() sg_p = sginfo_p.group() sg_p_a = sg_p.build_derived_acentric_group() if (sg_p.is_centric()): inv_mx = sg_p(0, 1, 0).t() else: inv_mx = None for symx1 in sg_p_a: subgr1 = sgtbx.space_group(hall_symbol="P1", t_den=space_group_t_den) subgr1.expand_smx(symx1) for symx2 in sg_p_a: subgr2 = sgtbx.space_group(subgr1) subgr2.expand_smx(symx2) loop_over_super_cells( max_index=max_index, all_subgroups=all_subgroups, subgroup=subgr2) if (inv_mx is not None): subgr3 = sgtbx.space_group(subgr2) subgr3.expand_inv(inv_mx) loop_over_super_cells( max_index=max_index, all_subgroups=all_subgroups, subgroup=subgr3) # show_sorted_by_counts(label_count_pairs=all_subgroups.items())
def exercise(): from libtbx.test_utils import show_diff, Exception_expected from six.moves import cPickle as pickle # from libtbx.str_utils import split_keeping_spaces assert split_keeping_spaces(s="") == [] assert split_keeping_spaces(s=" ") == [" "] assert split_keeping_spaces(s="a") == ["a"] assert split_keeping_spaces(s="abc") == ["abc"] assert split_keeping_spaces(s=" a") == [" ", "a"] assert split_keeping_spaces(s=" a") == [" ", "a"] assert split_keeping_spaces(s=" abc") == [" ", "abc"] assert split_keeping_spaces(s=" abc ") == [" ", "abc", " "] assert split_keeping_spaces(s=" abc ") == [" ", "abc", " "] assert split_keeping_spaces(s="a ") == ["a", " "] assert split_keeping_spaces(s="a ") == ["a", " "] assert split_keeping_spaces(s="abc ") == ["abc", " "] assert split_keeping_spaces(s="a b") == ["a", " ", "b"] assert split_keeping_spaces(s="a b") == ["a", " ", "b"] assert split_keeping_spaces(s=" a b c d ") == [ " ", "a", " ", "b", " ", "c", " ", "d", " " ] # from libtbx.str_utils import size_as_string_with_commas assert size_as_string_with_commas(0) == "0" assert size_as_string_with_commas(1) == "1" assert size_as_string_with_commas(-1) == "-1" assert size_as_string_with_commas(10) == "10" assert size_as_string_with_commas(100) == "100" assert size_as_string_with_commas(1000) == "1,000" assert size_as_string_with_commas(12345) == "12,345" assert size_as_string_with_commas(12345678) == "12,345,678" assert size_as_string_with_commas(-12345678) == "-12,345,678" # from libtbx.str_utils import show_string assert show_string("abc") == '"abc"' assert show_string("a'c") == '"a\'c"' assert show_string('a"c') == "'a\"c'" assert show_string('\'"c') == '"\'\\"c"' # from libtbx.str_utils import prefix_each_line assert prefix_each_line(prefix="^", lines_as_one_string="""\ hello world""") == """\ ^hello ^world""" # from libtbx.str_utils import prefix_each_line_suffix assert prefix_each_line_suffix(prefix="^", lines_as_one_string="""\ hello world""", suffix=" ") == """\ ^hello ^world""" assert prefix_each_line_suffix(prefix="^", lines_as_one_string="""\ hello world""", suffix=" ", rstrip=False) == """\ ^hello%s ^world """ % " " # from libtbx.str_utils import show_sorted_by_counts from six.moves import cStringIO out = cStringIO() assert show_sorted_by_counts(label_count_pairs=[("b", 3), ("a", 3), ("c", -2)], out=out, prefix="%") assert not show_diff(out.getvalue(), """\ %"a" 3 %"b" 3 %"c" -2 """) out = cStringIO() assert show_sorted_by_counts(label_count_pairs=[("b", -3), ("a", -3), ("c", 2)], reverse=False, out=out, prefix="%", annotations=[None, "", "x"]) assert not show_diff(out.getvalue(), """\ %"a" -3 %"b" -3 %"c" 2 x """) # from libtbx.str_utils import line_breaker for string, expected_result in [ ("", [""]), ("this is", ["this is"]), ("this is a", ["this is", "a"]), ("this is a sentence", ["this is", "a", "sentence"]), ("this is a longer sentence", ["this is", "a", "longer", "sentence"]), ("this is a very long sentence indeed", ["this is", "a very", "long", "sentence", "indeed"]) ]: assert [block for block in line_breaker(string, width=7)] == expected_result # from libtbx.str_utils import StringIO out1 = cStringIO() out2 = StringIO() out3 = StringIO("Hello world!\n") print("Hello world!", file=out1) print("Hello world!", file=out2) try: print("Hello world!", file=out3) except AttributeError: pass else: raise Exception_expected out4 = pickle.loads(pickle.dumps(out2)) out5 = pickle.loads(pickle.dumps(out3)) assert out4.getvalue() == out1.getvalue() == out2.getvalue( ) == out5.getvalue() # from libtbx.str_utils import reformat_terminal_text txt1 = """ This is some terminal-formatted text which needs to be reset. """ assert (reformat_terminal_text(txt1) == "This is some terminal-formatted text which needs to be reset.") txt2 = """ This is more terminal-formatted text which needs to be reset. """ # from libtbx.str_utils import strip_lines, rstrip_lines lines = [" This is more ", " terminal-formatted ", " text "] assert ( strip_lines(txt2) == "\nThis is more\nterminal-formatted\ntext which needs\nto be reset.") assert ( rstrip_lines(txt2) == "\n This is more\n terminal-formatted\n text which needs\n to be reset." ) # from libtbx.str_utils import expandtabs_track_columns def check(s): es, js = expandtabs_track_columns(s=s) assert len(js) == len(s) assert es == s.expandtabs() sr = "".join([es[j] for j in js]) assert sr == s.replace("\t", " ") check("") check("\t") check("\t\t") check("\ty") check("x\ty") check("x\ty\tz") check("\txy\t\tz") check("abcdefg\txy\t\tz") check("ab defgh\txyz\t\tu") # from libtbx.str_utils import format_value assert format_value("%.4f", 1.2345678) == "1.2346" assert format_value("%.4f", None) == " None" assert format_value("%.4f", None, replace_none_with="---") == " ---" # from libtbx.str_utils import make_header out = StringIO() make_header("Header 1", out=out) assert (out.getvalue() == """ =================================== Header 1 ================================== """) out = StringIO() make_header("Header 2", out=out) assert (out.getvalue() == """ =================================== Header 2 ================================== """) # import sys from libtbx.str_utils import string_representation iset = list(range(130)) + list(range(250, 256)) for i in iset: s = chr(i) for j in iset: ss = s + chr(j) sr = string_representation(string=ss, preferred_quote="'", alternative_quote='"') if sys.hexversion < 0x03000000: assert sr == repr(ss) else: assert eval(sr) == ss from libtbx.str_utils import framed_output out = StringIO() box = framed_output(out, frame='#') print("Hello, world!", file=box) box.close() assert (out.getvalue() == """ ################# # Hello, world! # ################# """) out = StringIO() box = framed_output(out, frame='-', width=80, center=True, title="Refinement stats") box.write("r_free = 0.1234") box.write(" ") box.write("r_work = 0.1567") box.close() assert (out.getvalue() == """ |--------------------------------Refinement stats------------------------------| | r_free = 0.1234 r_work = 0.1567 | |------------------------------------------------------------------------------| """) out = StringIO() box = framed_output(out, frame='-', width=72, prefix=" ", title="Validation summary") print("Overall MolProbity score: 2.56", file=box) box.add_separator() print("""\ Ramachandran favored: 97.5 % outliers: 2.5 % Rotamer outliers: 5.9 % Clashscore: 10.9""", file=box) assert (out.getvalue() == "") del box assert (out.getvalue() == """ |-Validation summary---------------------------------------------------| | Overall MolProbity score: 2.56 | |----------------------------------------------------------------------| | Ramachandran favored: 97.5 % | | outliers: 2.5 % | | Rotamer outliers: 5.9 % | | Clashscore: 10.9 | |----------------------------------------------------------------------| """) from libtbx.str_utils import print_message_in_box out = StringIO() print_message_in_box( message="This is some terminal-formatted text which needs to be reset.", out=out, width=32, center=True, prefix=" ", frame='*') assert (out.getvalue() == """ ******************************** * This is some * * terminal-formatted text * * which needs to be reset. * ******************************** """) from libtbx.str_utils import make_big_header out = StringIO() make_big_header("Section title", out=out) assert (out.getvalue() == """ ################################################################################ # Section title # ################################################################################ """)
def run(args): assert len(args) in [0,2], "n_sites, n_trials" if (len(args) == 0): n_sites, n_trials = 3, 2 out = null_out() else: n_sites, n_trials = [int(arg) for arg in args] out = sys.stdout # show_times_at_exit() class type_info(object): def __init__(O, type, use_analytical_gradients): O.type = type O.use_analytical_gradients = use_analytical_gradients def __str__(O): return "%s(use_analytical_gradients=%s)" % ( O.type.__name__, str(O.use_analytical_gradients)) spherical_types = [ type_info(euler_params, False), type_info(euler_params, True), type_info(euler_angles_xyz, False), type_info(euler_angles_xyz, True), type_info(euler_angles_zxz, False), type_info(euler_angles_zxz, True), type_info(euler_angles_yxyz, False), type_info(euler_angles_xyzy, False), type_info(inf_euler_params, False), type_info(inf_axis_angle, False)] nfun_accu = {} n_failed = {} for ti in spherical_types: nfun_accu[str(ti)] = flex.size_t() n_failed[str(ti)] = 0 mersenne_twister = flex.mersenne_twister(seed=0) for i_trial in xrange(n_trials): sites = [matrix.col(s) for s in flex.vec3_double( mersenne_twister.random_double(size=n_sites*3)*2-1)] c = center_of_mass_from_sites(sites) r = matrix.sqr(mersenne_twister.random_double_r3_rotation_matrix()) wells = [r*(s-c)+c for s in sites] for ti in spherical_types: r = refinery(spherical_type_info=ti, sites=sites, wells=wells, out=out) nfun_accu[str(ti)].append(r.nfun) if (r.failed): n_failed[str(ti)] += 1 nfun_sums = [] annotations = [] for ti in spherical_types: print >> out, ti nfuns = nfun_accu[str(ti)] stats = nfuns.as_double().min_max_mean() stats.show(out=out, prefix=" ") nfun_sums.append((str(ti), flex.sum(nfuns))) if (n_failed[str(ti)] == 0): annotations.append(None) else: annotations.append("failed: %d" % n_failed[str(ti)]) print >> out show_sorted_by_counts( label_count_pairs=nfun_sums, reverse=False, out=out, annotations=annotations) print >> out print "OK"
def run(args): assert len(args) in [0, 2], "n_sites, n_trials" if (len(args) == 0): n_sites, n_trials = 3, 2 out = null_out() else: n_sites, n_trials = [int(arg) for arg in args] out = sys.stdout # show_times_at_exit() class type_info(object): def __init__(O, type, use_analytical_gradients): O.type = type O.use_analytical_gradients = use_analytical_gradients def __str__(O): return "%s(use_analytical_gradients=%s)" % ( O.type.__name__, str(O.use_analytical_gradients)) spherical_types = [ type_info(euler_params, False), type_info(euler_params, True), type_info(euler_angles_xyz, False), type_info(euler_angles_xyz, True), type_info(euler_angles_zxz, False), type_info(euler_angles_zxz, True), type_info(euler_angles_yxyz, False), type_info(euler_angles_xyzy, False), type_info(inf_euler_params, False), type_info(inf_axis_angle, False) ] nfun_accu = {} n_failed = {} for ti in spherical_types: nfun_accu[str(ti)] = flex.size_t() n_failed[str(ti)] = 0 mersenne_twister = flex.mersenne_twister(seed=0) for i_trial in xrange(n_trials): sites = [ matrix.col(s) for s in flex.vec3_double( mersenne_twister.random_double(size=n_sites * 3) * 2 - 1) ] c = center_of_mass_from_sites(sites) r = matrix.sqr(mersenne_twister.random_double_r3_rotation_matrix()) wells = [r * (s - c) + c for s in sites] for ti in spherical_types: r = refinery(spherical_type_info=ti, sites=sites, wells=wells, out=out) nfun_accu[str(ti)].append(r.nfun) if (r.failed): n_failed[str(ti)] += 1 nfun_sums = [] annotations = [] for ti in spherical_types: print >> out, ti nfuns = nfun_accu[str(ti)] stats = nfuns.as_double().min_max_mean() stats.show(out=out, prefix=" ") nfun_sums.append((str(ti), flex.sum(nfuns))) if (n_failed[str(ti)] == 0): annotations.append(None) else: annotations.append("failed: %d" % n_failed[str(ti)]) print >> out show_sorted_by_counts(label_count_pairs=nfun_sums, reverse=False, out=out, annotations=annotations) print >> out print "OK"
def exercise(): from libtbx.test_utils import show_diff, Exception_expected import cPickle # from libtbx.str_utils import split_keeping_spaces assert split_keeping_spaces(s="") == [] assert split_keeping_spaces(s=" ") == [" "] assert split_keeping_spaces(s="a") == ["a"] assert split_keeping_spaces(s="abc") == ["abc"] assert split_keeping_spaces(s=" a") == [" ", "a"] assert split_keeping_spaces(s=" a") == [" ", "a"] assert split_keeping_spaces(s=" abc") == [" ", "abc"] assert split_keeping_spaces(s=" abc ") == [" ", "abc", " "] assert split_keeping_spaces(s=" abc ") == [" ", "abc", " "] assert split_keeping_spaces(s="a ") == ["a", " "] assert split_keeping_spaces(s="a ") == ["a", " "] assert split_keeping_spaces(s="abc ") == ["abc", " "] assert split_keeping_spaces(s="a b") == ["a", " ", "b"] assert split_keeping_spaces(s="a b") == ["a", " ", "b"] assert split_keeping_spaces(s=" a b c d ") == [ " ", "a", " ", "b", " ", "c", " ", "d", " "] # from libtbx.str_utils import size_as_string_with_commas assert size_as_string_with_commas(0) == "0" assert size_as_string_with_commas(1) == "1" assert size_as_string_with_commas(-1) == "-1" assert size_as_string_with_commas(10) == "10" assert size_as_string_with_commas(100) == "100" assert size_as_string_with_commas(1000) == "1,000" assert size_as_string_with_commas(12345) == "12,345" assert size_as_string_with_commas(12345678) == "12,345,678" assert size_as_string_with_commas(-12345678) == "-12,345,678" # from libtbx.str_utils import show_string assert show_string("abc") == '"abc"' assert show_string("a'c") == '"a\'c"' assert show_string('a"c') == "'a\"c'" assert show_string('\'"c') == '"\'\\"c"' # from libtbx.str_utils import prefix_each_line assert prefix_each_line(prefix="^", lines_as_one_string="""\ hello world""") == """\ ^hello ^world""" # from libtbx.str_utils import prefix_each_line_suffix assert prefix_each_line_suffix(prefix="^", lines_as_one_string="""\ hello world""", suffix=" ") == """\ ^hello ^world""" assert prefix_each_line_suffix(prefix="^", lines_as_one_string="""\ hello world""", suffix=" ", rstrip=False) == """\ ^hello%s ^world """ % " " # from libtbx.str_utils import show_sorted_by_counts import cStringIO out = cStringIO.StringIO() assert show_sorted_by_counts( label_count_pairs=[("b", 3), ("a", 3), ("c", -2)], out=out, prefix="%") assert not show_diff(out.getvalue(), """\ %"a" 3 %"b" 3 %"c" -2 """) out = cStringIO.StringIO() assert show_sorted_by_counts( label_count_pairs=[("b", -3), ("a", -3), ("c", 2)], reverse=False, out=out, prefix="%", annotations=[None, "", "x"]) assert not show_diff(out.getvalue(), """\ %"c" 2 x %"a" -3 %"b" -3 """) # from libtbx.str_utils import line_breaker for string, expected_result in [ ("", [""]), ("this is", ["this is"]), ("this is a", ["this is", "a"]), ("this is a sentence", ["this is", "a", "sentence"]), ("this is a longer sentence", ["this is", "a", "longer", "sentence"]), ("this is a very long sentence indeed", ["this is", "a very", "long", "sentence", "indeed"])]: assert [block for block in line_breaker(string, width=7)]==expected_result # from libtbx.str_utils import StringIO out1 = cStringIO.StringIO() out2 = StringIO() out3 = StringIO("Hello world!\n") print >> out1, "Hello world!" print >> out2, "Hello world!" try : print >> out3, "Hello world!" except AttributeError : pass else : raise Exception_expected out4 = cPickle.loads(cPickle.dumps(out2)) out5 = cPickle.loads(cPickle.dumps(out3)) assert out4.getvalue()==out1.getvalue()==out2.getvalue()==out5.getvalue() # from libtbx.str_utils import reformat_terminal_text txt1 = """ This is some terminal-formatted text which needs to be reset. """ assert (reformat_terminal_text(txt1) == "This is some terminal-formatted text which needs to be reset.") txt2 = """ This is more terminal-formatted text which needs to be reset. """ # from libtbx.str_utils import strip_lines, rstrip_lines lines = [" This is more ", " terminal-formatted ", " text "] assert (strip_lines(txt2) == "\nThis is more\nterminal-formatted\ntext which needs\nto be reset.") assert (rstrip_lines(txt2) == "\n This is more\n terminal-formatted\n text which needs\n to be reset." ) # from libtbx.str_utils import expandtabs_track_columns def check(s): es,js = expandtabs_track_columns(s=s) assert len(js) == len(s) assert es == s.expandtabs() sr = "".join([es[j] for j in js]) assert sr == s.replace("\t", " ") check("") check("\t") check("\t\t") check("\ty") check("x\ty") check("x\ty\tz") check("\txy\t\tz") check("abcdefg\txy\t\tz") check("ab defgh\txyz\t\tu") # from libtbx.str_utils import format_value assert format_value("%.4f", 1.2345678) == "1.2346" assert format_value("%.4f", None) == " None" assert format_value("%.4f", None, replace_none_with="---") == " ---" # from libtbx.str_utils import make_header out = StringIO() make_header("Header 1", out=out) assert (out.getvalue() == """ =================================== Header 1 ================================== """) out = StringIO() make_header("Header 2", out=out) assert (out.getvalue() == """ =================================== Header 2 ================================== """) # from libtbx.str_utils import string_representation iset = range(130) + range(250,256) for i in iset: s = chr(i) for j in iset: ss = s + chr(j) assert string_representation( string=ss, preferred_quote="'", alternative_quote='"') == repr(ss) from libtbx.str_utils import framed_output out = StringIO() box = framed_output(out, frame='#') print >> box, "Hello, world!" box.close() assert (out.getvalue() == """ ################# # Hello, world! # ################# """) out = StringIO() box = framed_output(out, frame='-', width=80, center=True, title="Refinement stats") box.write("r_free = 0.1234") box.write(" ") box.write("r_work = 0.1567") box.close() assert (out.getvalue() == """ |--------------------------------Refinement stats------------------------------| | r_free = 0.1234 r_work = 0.1567 | |------------------------------------------------------------------------------| """) out = StringIO() box = framed_output(out, frame='-', width=72, prefix=" ", title="Validation summary") print >> box, "Overall MolProbity score: 2.56" box.add_separator() print >> box, """\ Ramachandran favored: 97.5 % outliers: 2.5 % Rotamer outliers: 5.9 % Clashscore: 10.9""" assert (out.getvalue() == "") del box assert (out.getvalue() == """ |-Validation summary---------------------------------------------------| | Overall MolProbity score: 2.56 | |----------------------------------------------------------------------| | Ramachandran favored: 97.5 % | | outliers: 2.5 % | | Rotamer outliers: 5.9 % | | Clashscore: 10.9 | |----------------------------------------------------------------------| """) from libtbx.str_utils import print_message_in_box out = StringIO() print_message_in_box( message="This is some terminal-formatted text which needs to be reset.", out=out, width=32, center=True, prefix=" ", frame='*') assert (out.getvalue() == """ ******************************** * This is some * * terminal-formatted text * * which needs to be reset. * ******************************** """)
def check_comp(file_name): result = 0 print "file name:", file_name cif_object = mmtbx.monomer_library.server.read_cif(file_name) for comp_comp_id in mmtbx.monomer_library.server.convert_comp_list( source_info=file_name, cif_object=cif_object): result += 1 atom_names = set() for atom in comp_comp_id.atom_list: atom_name = atom.atom_id assert atom_name.count(" ") == 0 if (atom_name in atom_names): raise RuntimeError("Duplicate atom name: %s" % show_string(atom_name)) atom_names.add(atom_name) print " number of atoms:", len(atom_names) # bond_atom_ids = set() for bond in comp_comp_id.bond_list: atom_ids = [bond.atom_id_1, bond.atom_id_2] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError("Unknown bond atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in bond_atom_ids): raise RuntimeError("Duplicate bond: %s - %s" % tuple([show_string(s) for s in atom_ids])) bond_atom_ids.add(atom_ids) print " number of bonds:", len(bond_atom_ids) # angle_atom_ids = set() for angle in comp_comp_id.angle_list: atom_ids = [angle.atom_id_1, angle.atom_id_2, angle.atom_id_3] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError("Unknown angle atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in angle_atom_ids): raise RuntimeError("Duplicate angle: %s - %s - %s" % tuple([show_string(s) for s in atom_ids])) angle_atom_ids.add(atom_ids) print " number of angles:", len(angle_atom_ids) # tor_atom_ids = set() for tor in comp_comp_id.tor_list: atom_ids = [ tor.atom_id_1, tor.atom_id_2, tor.atom_id_3, tor.atom_id_4 ] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError("Unknown tor atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in tor_atom_ids): raise RuntimeError("Duplicate tor: %s - %s - %s - %s" % tuple([show_string(s) for s in atom_ids])) tor_atom_ids.add(atom_ids) print " number of tors:", len(tor_atom_ids) tor_atom_ids = {} for tor in comp_comp_id.tor_list: atom_ids = tuple(sorted([tor.atom_id_2, tor.atom_id_3])) tor_atom_ids.setdefault(atom_ids, []).append(tor) for atom_ids, tors in tor_atom_ids.items(): if (len(tors) != 1): print " redundant tors:", ", ".join( [tor.id for tor in tors]) # chir_atom_ids = set() for chir in comp_comp_id.chir_list: atom_ids = [ chir.atom_id_1, chir.atom_id_2, chir.atom_id_3, chir.atom_id_centre ] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError("Unknown chir atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in chir_atom_ids): raise RuntimeError("Duplicate chir: %s - %s - %s - %s" % tuple([show_string(s) for s in atom_ids])) chir_atom_ids.add(atom_ids) print " number of chirs:", len(chir_atom_ids) # plane_atom_counts = dict_with_default_0() for plane_atom in comp_comp_id.plane_atom_list: if (plane_atom.atom_id not in atom_names): raise RuntimeError("Unknown plane atom name: %s" % show_string(plane_atom.atom_id)) plane_atom_counts[plane_atom.plane_id] += 1 print " number of planes:", len(plane_atom_counts) if (len(plane_atom_counts) != 0): show_sorted_by_counts(label_count_pairs=plane_atom_counts.items(), prefix=" ") assert min(plane_atom_counts.values()) >= 3 # rotamer_info = comp_comp_id.rotamer_info() if (rotamer_info is not None): print " rotamer_info.tor_ids:", rotamer_info.tor_ids for tor_id in rotamer_info.tor_ids: assert tor_id.strip() == tor_id assert tor_id.split() == [tor_id] for tor_atom_ids in rotamer_info.tor_atom_ids: assert len(tor_atom_ids) == 5 assert tor_atom_ids[0] in rotamer_info.tor_ids for atom_id in tor_atom_ids[1:]: assert atom_id.strip() == atom_id assert atom_id.split() == [atom_id] atom_ids = rotamer_info.atom_ids_not_handled if (atom_ids is not None): for atom_id in atom_ids: assert atom_id.strip() == atom_id assert atom_id.split() == [atom_id] assert ( rotamer_info. constrain_dihedrals_with_sigma_less_than_or_equal_to is None or rotamer_info. constrain_dihedrals_with_sigma_less_than_or_equal_to > 0) print " number of rotamers:", len(rotamer_info.rotamer) n_missing_frequencies = 0 for rotamer in rotamer_info.rotamer: assert rotamer.id is not None assert len(rotamer.id.strip()) == len(rotamer.id) assert len(rotamer.id.split()) == 1 if (rotamer.frequency is None): if (rotamer.frequency_annotation != "for more uniform sampling"): n_missing_frequencies += 1 else: assert rotamer.frequency > 0 assert rotamer.frequency < 1 assert rotamer.angles is not None assert len(rotamer.angles) == len(rotamer_info.tor_ids) for angle in rotamer.angles: assert angle is None or -180 < angle <= 180 if (n_missing_frequencies != 0): print " WARNING: number of missing frequencies:", \ n_missing_frequencies return result
def check_comp(file_name): result = 0 print "file name:", file_name cif_object = mmtbx.monomer_library.server.read_cif(file_name) for comp_comp_id in mmtbx.monomer_library.server.convert_comp_list( source_info=file_name, cif_object=cif_object): result += 1 atom_names = set() for atom in comp_comp_id.atom_list: atom_name = atom.atom_id assert atom_name.count(" ") == 0 if (atom_name in atom_names): raise RuntimeError( "Duplicate atom name: %s" % show_string(atom_name)) atom_names.add(atom_name) print " number of atoms:", len(atom_names) # bond_atom_ids = set() for bond in comp_comp_id.bond_list: atom_ids = [bond.atom_id_1, bond.atom_id_2] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError( "Unknown bond atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in bond_atom_ids): raise RuntimeError( "Duplicate bond: %s - %s" % tuple([show_string(s) for s in atom_ids])) bond_atom_ids.add(atom_ids) print " number of bonds:", len(bond_atom_ids) # angle_atom_ids = set() for angle in comp_comp_id.angle_list: atom_ids = [angle.atom_id_1, angle.atom_id_2, angle.atom_id_3] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError( "Unknown angle atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in angle_atom_ids): raise RuntimeError( "Duplicate angle: %s - %s - %s" % tuple([show_string(s) for s in atom_ids])) angle_atom_ids.add(atom_ids) print " number of angles:", len(angle_atom_ids) # tor_atom_ids = set() for tor in comp_comp_id.tor_list: atom_ids = [tor.atom_id_1, tor.atom_id_2, tor.atom_id_3, tor.atom_id_4] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError( "Unknown tor atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in tor_atom_ids): raise RuntimeError( "Duplicate tor: %s - %s - %s - %s" % tuple([show_string(s) for s in atom_ids])) tor_atom_ids.add(atom_ids) print " number of tors:", len(tor_atom_ids) tor_atom_ids = {} for tor in comp_comp_id.tor_list: atom_ids = tuple(sorted([tor.atom_id_2, tor.atom_id_3])) tor_atom_ids.setdefault(atom_ids, []).append(tor) for atom_ids,tors in tor_atom_ids.items(): if (len(tors) != 1): print " redundant tors:", ", ".join([tor.id for tor in tors]) # chir_atom_ids = set() for chir in comp_comp_id.chir_list: atom_ids = [ chir.atom_id_1, chir.atom_id_2, chir.atom_id_3, chir.atom_id_centre] for atom_name in atom_ids: if (atom_name not in atom_names): raise RuntimeError( "Unknown chir atom name: %s" % show_string(atom_name)) atom_ids = tuple(sorted(atom_ids)) if (atom_ids in chir_atom_ids): raise RuntimeError( "Duplicate chir: %s - %s - %s - %s" % tuple([show_string(s) for s in atom_ids])) chir_atom_ids.add(atom_ids) print " number of chirs:", len(chir_atom_ids) # plane_atom_counts = dict_with_default_0() for plane_atom in comp_comp_id.plane_atom_list: if (plane_atom.atom_id not in atom_names): raise RuntimeError( "Unknown plane atom name: %s" % show_string(plane_atom.atom_id)) plane_atom_counts[plane_atom.plane_id] += 1 print " number of planes:", len(plane_atom_counts) if (len(plane_atom_counts) != 0): show_sorted_by_counts( label_count_pairs=plane_atom_counts.items(), prefix=" ") assert min(plane_atom_counts.values()) >= 3 # rotamer_info = comp_comp_id.rotamer_info() if (rotamer_info is not None): print " rotamer_info.tor_ids:", rotamer_info.tor_ids for tor_id in rotamer_info.tor_ids: assert tor_id.strip() == tor_id assert tor_id.split() == [tor_id] for tor_atom_ids in rotamer_info.tor_atom_ids: assert len(tor_atom_ids) == 5 assert tor_atom_ids[0] in rotamer_info.tor_ids for atom_id in tor_atom_ids[1:]: assert atom_id.strip() == atom_id assert atom_id.split() == [atom_id] atom_ids = rotamer_info.atom_ids_not_handled if (atom_ids is not None): for atom_id in atom_ids: assert atom_id.strip() == atom_id assert atom_id.split() == [atom_id] assert ( rotamer_info.constrain_dihedrals_with_sigma_less_than_or_equal_to is None or rotamer_info.constrain_dihedrals_with_sigma_less_than_or_equal_to > 0) print " number of rotamers:", len(rotamer_info.rotamer) n_missing_frequencies = 0 for rotamer in rotamer_info.rotamer: assert rotamer.id is not None assert len(rotamer.id.strip()) == len(rotamer.id) assert len(rotamer.id.split()) == 1 if (rotamer.frequency is None): if (rotamer.frequency_annotation != "for more uniform sampling"): n_missing_frequencies += 1 else: assert rotamer.frequency > 0 assert rotamer.frequency < 1 assert rotamer.angles is not None assert len(rotamer.angles) == len(rotamer_info.tor_ids) for angle in rotamer.angles: assert angle is None or -180 < angle <= 180 if (n_missing_frequencies != 0): print " WARNING: number of missing frequencies:", \ n_missing_frequencies return result