def run(args): list_cif = server.mon_lib_list_cif() srv = server.server(list_cif=list_cif) for comp_id in args: comp_comp_id = srv.get_comp_comp_id_direct(comp_id=comp_id) motif = comp_comp_id.as_geometry_restraints_motif() motif.show()
def main(): list_cif = mon_lib_list_cif() geostd_list_cif_obj = geostd_list_cif() list_cif = merge_and_overwrite_cifs(geostd_list_cif_obj, list_cif, ) print(dir(list_cif)) print(dir(list_cif.cif)) cif = list_cif.cif print(list(cif.blocks.keys())) j=0 tmp = [] for i, block in enumerate(cif.blocks): if block in ['link_list']: continue if block.startswith('link_'): j+=1 tmp.append([]) tmp[-1].append(block) tmp[-1].append('Taken from Monomer Library or GeoStd') #tmp[-1].append('') #tmp[-1].append([block]*6) #tmp[-1].append([0,1,2,3,4,5]) print(i, j, block) outl = 'standard_cif_links = [\n' for block in sorted(tmp): outl += ' %s,\n' % block outl += ']\n' print(outl)
def exercise(): verbose = "--verbose" in sys.argv[1:] list_cif = server.mon_lib_list_cif() srv = server.server(list_cif=list_cif) open("tmp.cif", "w").write(tmp_cif) srv.process_cif(file_name="tmp.cif") comp_comp_id = srv.get_comp_comp_id_direct(comp_id="tst") motif = comp_comp_id.as_geometry_restraints_motif() out = StringIO() motif.show(out=out) if (verbose): sys.stdout.write(out.getvalue()) assert not show_diff(out.getvalue(), expected_out_tst_comp) for link_link_id in srv.link_link_id_list: out = StringIO() link_link_id.as_geometry_restraints_motif_manipulation().show(out=out) if (verbose): sys.stdout.write(out.getvalue()) if (link_link_id.chem_link.id == "tst_lnk"): assert not show_diff(out.getvalue(), expected_out_tst_lnk) for mod_mod_id in srv.mod_mod_id_list: out = StringIO() mod_mod_id.as_geometry_restraints_motif_manipulation().show(out=out) if (verbose): sys.stdout.write(out.getvalue()) if (mod_mod_id.chem_mod.id == "tst_mod"): assert not show_diff(out.getvalue(), expected_out_tst_mod) print "OK"
def exercise(): list_cif = server.mon_lib_list_cif() srv = server.server(list_cif=list_cif) print("srv.root_path:", srv.root_path) table_of_contents = [] n_get_comp_comp_id_successes = 0 unknown_type_energy_counts = dict_with_default_0() missing_angle_definitions_counts = dict_with_default_0() missing_bond_values_counts = dict_with_default_0() missing_angle_values_counts = dict_with_default_0() for first_char in string.lowercase + string.digits: sub_dir = os.path.join(srv.root_path, first_char) if (not os.path.isdir(sub_dir)): continue for node in os.listdir(sub_dir): if (not node.lower().endswith(".cif")): continue comp_id = node[:-4] if (comp_id.endswith("_EL")): continue if (comp_id in ["CON_CON", "PRN_PRN"]): comp_id = comp_id[:3] if (comp_id.upper() != comp_id): print("Mixed case:", os.path.join(first_char, node)) comp_comp_id = srv.get_comp_comp_id_direct(comp_id=comp_id) if (comp_comp_id is None): print("Error instantiating comp_comp_id %s (%s)" % (comp_id, os.path.join(sub_dir, node))) else: n_get_comp_comp_id_successes += 1 table_of_contents.append(" ".join( [comp_id.upper(), os.path.join(first_char, node)])) status = detect_unknown_type_energy(comp_id=comp_id, comp_comp_id=comp_comp_id) unknown_type_energy_counts[status] += 1 status = detect_missing_angle_definitions( comp_id=comp_id, comp_comp_id=comp_comp_id) missing_angle_definitions_counts[status] += 1 status = detect_missing_bond_values(comp_id=comp_id, comp_comp_id=comp_comp_id) missing_bond_values_counts[status] += 1 status = detect_missing_angle_values(comp_id=comp_id, comp_comp_id=comp_comp_id) missing_angle_values_counts[status] += 1 if (1 and status != "ok"): print('svn rm "%s"' % os.path.join(first_char, node)) print("number of cif files read successfully:", n_get_comp_comp_id_successes) print("unknown type_energy counts:", unknown_type_energy_counts) print("missing bond angle definitions counts:", \ missing_angle_definitions_counts) print("missing bond values counts:", missing_bond_values_counts) print("missing angle values counts:", missing_angle_values_counts) print("writing file table_of_contents") open("table_of_contents", "w").write("\n".join(table_of_contents) + "\n")
def exercise(): list_cif = server.mon_lib_list_cif() srv = server.server(list_cif=list_cif) print "srv.root_path:", srv.root_path table_of_contents = [] n_get_comp_comp_id_successes = 0 unknown_type_energy_counts = dict_with_default_0() missing_angle_definitions_counts = dict_with_default_0() missing_bond_values_counts = dict_with_default_0() missing_angle_values_counts = dict_with_default_0() for first_char in string.lowercase+string.digits: sub_dir = os.path.join(srv.root_path, first_char) if (not os.path.isdir(sub_dir)): continue for node in os.listdir(sub_dir): if (not node.lower().endswith(".cif")): continue comp_id = node[:-4] if (comp_id.endswith("_EL")): continue if (comp_id in ["CON_CON", "PRN_PRN"]): comp_id = comp_id[:3] if (comp_id.upper() != comp_id): print "Mixed case:", os.path.join(first_char, node) comp_comp_id = srv.get_comp_comp_id_direct(comp_id=comp_id) if (comp_comp_id is None): print "Error instantiating comp_comp_id %s (%s)" % ( comp_id, os.path.join(sub_dir, node)) else: n_get_comp_comp_id_successes += 1 table_of_contents.append( " ".join([comp_id.upper(), os.path.join(first_char, node)])) status = detect_unknown_type_energy( comp_id=comp_id, comp_comp_id=comp_comp_id) unknown_type_energy_counts[status] += 1 status = detect_missing_angle_definitions( comp_id=comp_id, comp_comp_id=comp_comp_id) missing_angle_definitions_counts[status] += 1 status = detect_missing_bond_values( comp_id=comp_id, comp_comp_id=comp_comp_id) missing_bond_values_counts[status] += 1 status = detect_missing_angle_values( comp_id=comp_id, comp_comp_id=comp_comp_id) missing_angle_values_counts[status] += 1 if (1 and status != "ok"): print 'svn rm "%s"' % os.path.join(first_char, node) print "number of cif files read successfully:", n_get_comp_comp_id_successes print "unknown type_energy counts:", unknown_type_energy_counts print "missing bond angle definitions counts:", \ missing_angle_definitions_counts print "missing bond values counts:", missing_bond_values_counts print "missing angle values counts:", missing_angle_values_counts print "writing file table_of_contents" open("table_of_contents", "w").write("\n".join(table_of_contents)+"\n")
def run () : from mmtbx.monomer_library import server from libtbx.utils import Sorry try : cif1 = server.mon_lib_list_cif() cif2 = server.geostd_list_cif() cif3 = server.mon_lib_ener_lib_cif() assert (not None in [cif1, cif2, cif3]) except server.MonomerLibraryServerError : raise Sorry("The monomer library installation could not be found. If "+ "you are using a Phenix installer, we recommend downloading the "+ "installer again and reinstalling.") else : print "OK"
def run(): from mmtbx.monomer_library import server from libtbx.utils import Sorry try: cif1 = server.mon_lib_list_cif() cif2 = server.geostd_list_cif() cif3 = server.mon_lib_ener_lib_cif() assert (not None in [cif1, cif2, cif3]) except server.MonomerLibraryServerError: raise Sorry( "The monomer library installation could not be found. If " + "you are using a Phenix installer, we recommend downloading the " + "installer again and reinstalling.") else: print("OK")
def exercise(): verbose = "--verbose" in sys.argv[1:] quick = "--quick" in sys.argv[1:] list_cif = server.mon_lib_list_cif() srv = server.server(list_cif=list_cif) print("srv.root_path:", srv.root_path) default_switch = "--default_off" not in sys.argv[1:] if (False or default_switch): monomers_with_commas = {} atom_id_counts = dicts.with_default_value(0) for row_id in list_cif.cif["comp_list"]["_chem_comp.id"]: if (quick and random.random() < 0.95): continue if (verbose): print("id:", row_id) comp_comp_id = srv.get_comp_comp_id_direct(comp_id=row_id) if (comp_comp_id is None): print("Could not instantiating comp_comp_id(%s)" % row_id) else: has_primes = False has_commas = False for atom in comp_comp_id.atom_list: atom_id_counts[atom.atom_id] += 1 if (atom.atom_id.find("'") >= 0): has_primes = True if (atom.atom_id.find(",") >= 0): has_commas = True if (has_commas): monomers_with_commas[ comp_comp_id.chem_comp.id] = has_primes print(monomers_with_commas) atom_ids = flex.std_string(list(atom_id_counts.keys())) counts = flex.size_t(list(atom_id_counts.values())) perm = flex.sort_permutation(data=counts, reverse=True) atom_ids = atom_ids.select(perm) counts = counts.select(perm) for atom_id, count in zip(atom_ids, counts): print(atom_id, count) if (False or default_switch): for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): if (quick and random.random() < 0.95): continue if (verbose): print("id:", row["_chem_comp.id"]) comp_comp_id = srv.get_comp_comp_id_direct( comp_id=row["_chem_comp.id"]) check_chem_comp(cif_types.chem_comp(**row), comp_comp_id) if ("--pickle" in sys.argv[1:]): easy_pickle.dump("mon_lib.pickle", srv) if (False or default_switch): comp = srv.get_comp_comp_id_direct("GLY") comp.show() mod = srv.mod_mod_id_dict["COO"] comp.apply_mod(mod).show() if (False or default_switch): comp = srv.get_comp_comp_id_direct("LYS") comp.show() mod = srv.mod_mod_id_dict["B2C"] comp.apply_mod(mod).show() if (False or default_switch): for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): if (quick and random.random() < 0.95): continue comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"]) if (comp_comp_id is not None): if (comp_comp_id.classification == "peptide"): print(comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, end=' ') print(row["_chem_comp.group"], end=' ') grp = row["_chem_comp.group"].lower().strip() if (grp not in ("l-peptide", "d-peptide", "polymer")): print("LOOK", end=' ') #if (not os.path.isdir("look")): os.makedirs("look") #open("look/%s.cif" % row["_chem_comp.id"], "w").write( #open(comp_comp_id.file_name).read()) print() elif (row["_chem_comp.group"].lower().find("peptide") >= 0 or comp_comp_id.chem_comp.group.lower().find("peptide") >= 0): print(comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, end=' ') print(row["_chem_comp.group"], "MISMATCH") if (comp_comp_id.classification in ("RNA", "DNA")): print(comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, end=' ') print(row["_chem_comp.group"], end=' ') if (comp_comp_id.classification != row["_chem_comp.group"].strip()): print(comp_comp_id.classification, "MISMATCH", end=' ') print() elif (row["_chem_comp.group"].lower().find("NA") >= 0 or comp_comp_id.chem_comp.group.lower().find("NA") >= 0): print(comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, end=' ') print(row["_chem_comp.group"], "MISMATCH") if (False or default_switch): for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): if (quick and random.random() < 0.95): continue comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"]) if (comp_comp_id is not None): planes = comp_comp_id.get_planes() for plane in planes: dist_esd_dict = {} for plane_atom in plane.plane_atoms: dist_esd_dict[str(plane_atom.dist_esd)] = 0 # FIXME: might break compat for py2/3 because indexing a values call if (len(dist_esd_dict) != 1 or list(dist_esd_dict.keys())[0] != "0.02"): print(comp_comp_id.chem_comp.id, plane.plane_id, end=' ') print(list(dist_esd_dict.keys())) if (False or default_switch): standard_amino_acids = [ "GLY", "VAL", "ALA", "LEU", "ILE", "PRO", "MET", "PHE", "TRP", "SER", "THR", "TYR", "CYS", "ASN", "GLN", "ASP", "GLU", "LYS", "ARG", "HIS" ] for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): is_standard_aa = row["_chem_comp.id"] in standard_amino_acids if (1 and not is_standard_aa): continue comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"]) if (is_standard_aa): assert comp_comp_id is not None assert comp_comp_id.chem_comp.group.strip() == "L-peptide" if (comp_comp_id is not None): print(comp_comp_id.chem_comp.id.strip(), end=' ') print(comp_comp_id.chem_comp.name.strip(), end=' ') print(comp_comp_id.chem_comp.group.strip()) for tor in comp_comp_id.tor_list: print(" tor:", tor.atom_id_1, tor.atom_id_2, end=' ') print(tor.atom_id_3, tor.atom_id_4, tor.value_angle, end=' ') print(tor.value_angle_esd, tor.period) for chir in comp_comp_id.chir_list: print(" chir:", chir.atom_id_centre, chir.atom_id_1, end=' ') print(chir.atom_id_2, chir.atom_id_3, chir.volume_sign) if (False or default_switch): elib = server.ener_lib() if (False or default_switch): for syn in elib.lib_synonym.items(): print(syn) if (False or default_switch): for vdw in elib.lib_vdw: vdw.show() print("OK")
def exercise(): verbose = "--verbose" in sys.argv[1:] quick = "--quick" in sys.argv[1:] list_cif = server.mon_lib_list_cif() srv = server.server(list_cif=list_cif) print "srv.root_path:", srv.root_path default_switch = "--default_off" not in sys.argv[1:] if (False or default_switch): monomers_with_commas = {} atom_id_counts = dicts.with_default_value(0) for row_id in list_cif.cif["comp_list"]["_chem_comp.id"]: if (quick and random.random() < 0.95): continue if (verbose): print "id:", row_id comp_comp_id = srv.get_comp_comp_id_direct(comp_id=row_id) if (comp_comp_id is None): print "Error instantiating comp_comp_id(%s)" % row_id else: has_primes = False has_commas = False for atom in comp_comp_id.atom_list: atom_id_counts[atom.atom_id] += 1 if (atom.atom_id.find("'") >= 0): has_primes = True if (atom.atom_id.find(",") >= 0): has_commas = True if (has_commas): monomers_with_commas[comp_comp_id.chem_comp.id] = has_primes print monomers_with_commas atom_ids = flex.std_string(atom_id_counts.keys()) counts = flex.size_t(atom_id_counts.values()) perm = flex.sort_permutation(data=counts, reverse=True) atom_ids = atom_ids.select(perm) counts = counts.select(perm) for atom_id,count in zip(atom_ids, counts): print atom_id, count if (False or default_switch): for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): if (quick and random.random() < 0.95): continue if (verbose): print "id:", row["_chem_comp.id"] comp_comp_id = srv.get_comp_comp_id_direct(comp_id=row["_chem_comp.id"]) check_chem_comp(cif_types.chem_comp(**row), comp_comp_id) if ("--pickle" in sys.argv[1:]): easy_pickle.dump("mon_lib.pickle", srv) if (False or default_switch): comp = srv.get_comp_comp_id_direct("GLY") comp.show() mod = srv.mod_mod_id_dict["COO"] comp.apply_mod(mod).show() if (False or default_switch): comp = srv.get_comp_comp_id_direct("LYS") comp.show() mod = srv.mod_mod_id_dict["B2C"] comp.apply_mod(mod).show() if (False or default_switch): for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): if (quick and random.random() < 0.95): continue comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"]) if (comp_comp_id is not None): if (comp_comp_id.classification == "peptide"): print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, print row["_chem_comp.group"], grp = row["_chem_comp.group"].lower().strip() if (grp not in ("l-peptide", "d-peptide", "polymer")): print "LOOK", #if (not os.path.isdir("look")): os.makedirs("look") #open("look/%s.cif" % row["_chem_comp.id"], "w").write( #open(comp_comp_id.file_name).read()) print elif (row["_chem_comp.group"].lower().find("peptide") >= 0 or comp_comp_id.chem_comp.group.lower().find("peptide") >= 0): print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, print row["_chem_comp.group"], "MISMATCH" if (comp_comp_id.classification in ("RNA", "DNA")): print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, print row["_chem_comp.group"], if (comp_comp_id.classification != row["_chem_comp.group"].strip()): print comp_comp_id.classification, "MISMATCH", print elif (row["_chem_comp.group"].lower().find("NA") >= 0 or comp_comp_id.chem_comp.group.lower().find("NA") >= 0): print comp_comp_id.chem_comp.id, comp_comp_id.chem_comp.name, print row["_chem_comp.group"], "MISMATCH" if (False or default_switch): for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): if (quick and random.random() < 0.95): continue comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"]) if (comp_comp_id is not None): planes = comp_comp_id.get_planes() for plane in planes: dist_esd_dict = {} for plane_atom in plane.plane_atoms: dist_esd_dict[str(plane_atom.dist_esd)] = 0 if (len(dist_esd_dict) != 1 or dist_esd_dict.keys()[0] != "0.02"): print comp_comp_id.chem_comp.id, plane.plane_id, print dist_esd_dict.keys() if (False or default_switch): standard_amino_acids = [ "GLY", "VAL", "ALA", "LEU", "ILE", "PRO", "MET", "PHE", "TRP", "SER", "THR", "TYR", "CYS", "ASN", "GLN", "ASP", "GLU", "LYS", "ARG", "HIS"] for row in list_cif.cif["comp_list"]["_chem_comp"].iterrows(): is_standard_aa = row["_chem_comp.id"] in standard_amino_acids if (1 and not is_standard_aa): continue comp_comp_id = srv.get_comp_comp_id_direct(row["_chem_comp.id"]) if (is_standard_aa): assert comp_comp_id is not None assert comp_comp_id.chem_comp.group.strip() == "L-peptide" if (comp_comp_id is not None): print comp_comp_id.chem_comp.id.strip(), print comp_comp_id.chem_comp.name.strip(), print comp_comp_id.chem_comp.group.strip() for tor in comp_comp_id.tor_list: print " tor:", tor.atom_id_1, tor.atom_id_2, print tor.atom_id_3, tor.atom_id_4, tor.value_angle, print tor.value_angle_esd, tor.period for chir in comp_comp_id.chir_list: print " chir:", chir.atom_id_centre, chir.atom_id_1, print chir.atom_id_2, chir.atom_id_3, chir.volume_sign if (False or default_switch): elib = server.ener_lib() if (False or default_switch): for syn in elib.lib_synonym.items(): print syn if (False or default_switch): for vdw in elib.lib_vdw: vdw.show() print "OK"
def _generate_restraints(self, res_ids): list = server.mon_lib_list_cif() self._residues = [ row["_chem_comp.id"] for row in list.cif["comp_list"]["_chem_comp"].iterrows() ] self._srv = server.server(list_cif=list) bonds = {} output = [] for r in res_ids: if not r in self._residues: self._generate_ligand_restraints() break for r in res_ids: res = self._srv.get_comp_comp_id_direct(r) if res is not None: for b in res.bond_list: if not (b.atom_id_1.startswith('H') or b.atom_id_2.startswith('H')): if not b.atom_id_1 in bonds: bonds[b.atom_id_1] = {} bonds[b.atom_id_1][b.atom_id_2] = b.value_dist output.append('DFIX_%s %.3f %s %s' % (r, b.value_dist, b.atom_id_1, b.atom_id_2)) for a in res.angle_list: if not (a.atom_id_1.startswith('H') or a.atom_id_2.startswith('H') or a.atom_id_3.startswith('H')): ang = None dist1 = None dist2 = None if a.atom_id_1 in bonds: if a.atom_id_2 in bonds[a.atom_id_1]: dist1 = bonds[a.atom_id_1][a.atom_id_2] if a.atom_id_2 in bonds: if a.atom_id_1 in bonds[a.atom_id_2]: dist1 = bonds[a.atom_id_2][a.atom_id_1] if a.atom_id_2 in bonds: if a.atom_id_3 in bonds[a.atom_id_2]: dist2 = bonds[a.atom_id_2][a.atom_id_3] if a.atom_id_3 in bonds: if a.atom_id_2 in bonds[a.atom_id_3]: dist2 = bonds[a.atom_id_3][a.atom_id_2] if a.value_angle is not None and dist1 is not None and dist2 is not None: dang = math.sqrt(math.pow(dist1,2)+math.pow(dist2,2)-(2*dist1*dist2*math.cos((math.pi/180)*a.value_angle))) output.append('DANG_%s %.3f %s %s' % (r, dang, a.atom_id_1, a.atom_id_3)) for p in res.get_planes(): atoms = [] for a in p.plane_atoms: if not a.atom_id.startswith('H'): atoms.append(a.atom_id) if len(atoms) > 2: output.append('FLAT_' + r + ' ' + ' '.join(atoms)) output.append('CHIV_%s C' % r) for c in res.chir_list: output.append('CHIV_%s %.3f %s' % (r, res.get_chir_volume_ideal(c) * (1 if c.volume_sign == 'positiv' else -1), c.atom_id_centre)) for t in res.tor_list: if t.id.startswith('chi'): output.append('RTAB_%s %s %s %s %s %s' % (r, t.id.capitalize(), t.atom_id_1, t.atom_id_2, t.atom_id_3, t.atom_id_4)) output.append('\n') return '\n'.join(output)