Commit 5d7922db authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add the possibility to automatically retrieve PDB Ligand cross-links

It is part of the admin tasks, but not automated yet upon
compound creation.
parent 8aba3960
Pipeline #31140 failed with stages
in 13 minutes and 24 seconds
......@@ -32,6 +32,7 @@ from .ws import (
get_doi_info,
get_chembl_id,
get_pubchem_id,
get_ligand_id,
EntryNotFoundError,
)
......@@ -1034,6 +1035,17 @@ class Compound(AutoFillableModel):
except EntryNotFoundError:
pass
def set_ligand_link(self):
"""
Set Ligand ID by looking up SMILES
with the PDB REST service
"""
try:
self.ligand_id = get_ligand_id(self.canonical_smile)
except EntryNotFoundError:
pass
def compute_fsp3(self):
"""
Compute FSP3 from CSP3 and number of carbons
......
......@@ -438,6 +438,7 @@ def set_compound_links(compound_ids: List[int]) -> List[int]:
c.set_drugbank_link()
c.set_chembl_link()
c.set_pubchem_link()
c.set_ligand_link()
c.save()
return [c.id for c in qs]
......
......@@ -520,3 +520,19 @@ def get_pubchem_id(inchikey: str) -> str:
return str(json_data["PC_Compounds"][0]["id"]["id"]["cid"])
except KeyError as ke:
print(ke, json_data)
def get_ligand_id(smiles: str) -> str:
endpoint = f"http://www.rcsb.org/pdb/rest/smilesQuery?"
text = requests.get(
endpoint, params={"smiles": smiles, "search_type": "exact"}
).text
doc = ET.fromstring(text)
ligandInfoEls = doc.findall("ligandInfo")
if len(ligandInfoEls) > 0:
for ligandEl in ligandInfoEls[0].findall("ligand"):
if "chemicalID" in ligandEl.attrib:
return ligandEl.attrib["chemicalID"]
raise EntryNotFoundError(
smiles, msg=str(f"ligand for smiles {smiles} not found in PDB Ligand")
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment