Spaces:
Sleeping
Sleeping
Update genesis/structures.py
Browse files- genesis/structures.py +34 -27
genesis/structures.py
CHANGED
@@ -1,33 +1,40 @@
|
|
1 |
# genesis/structures.py
|
|
|
|
|
|
|
|
|
|
|
2 |
import requests
|
3 |
-
from typing import List, Dict
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
structures = []
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
"title": title,
|
27 |
-
"pdbe_url": f"https://www.ebi.ac.uk/pdbe/entry/pdb/{pdb_id}",
|
28 |
-
"rcsb_url": f"https://www.rcsb.org/structure/{pdb_id}"
|
29 |
-
})
|
30 |
-
except Exception as e:
|
31 |
-
print(f"[Structures] Failed to fetch for {term}: {e}")
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# genesis/structures.py
|
2 |
+
"""
|
3 |
+
Structure Fetching for GENESIS-AI
|
4 |
+
Integrates PDBe (PDB) and ChEMBL molecule lookups.
|
5 |
+
"""
|
6 |
+
|
7 |
import requests
|
|
|
8 |
|
9 |
+
PDBe_API = "https://www.ebi.ac.uk/pdbe/api/pdb/entry/summary/"
|
10 |
+
CHEMBL_API = "https://www.ebi.ac.uk/chembl/api/data/molecule/"
|
|
|
11 |
|
12 |
+
def fetch_pdb_structure(pdb_id):
|
13 |
+
"""Fetch PDB structure summary from PDBe."""
|
14 |
+
try:
|
15 |
+
r = requests.get(f"{PDBe_API}{pdb_id.lower()}")
|
16 |
+
r.raise_for_status()
|
17 |
+
return r.json()
|
18 |
+
except Exception as e:
|
19 |
+
return {"error": str(e)}
|
20 |
|
21 |
+
def fetch_chembl_molecule(chembl_id):
|
22 |
+
"""Fetch ChEMBL molecule data."""
|
23 |
+
try:
|
24 |
+
r = requests.get(f"{CHEMBL_API}{chembl_id}.json")
|
25 |
+
r.raise_for_status()
|
26 |
+
return r.json()
|
27 |
+
except Exception as e:
|
28 |
+
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
def fetch_structures_for_terms(terms):
|
31 |
+
"""
|
32 |
+
Searches for possible PDB or ChEMBL IDs in terms and fetches details.
|
33 |
+
"""
|
34 |
+
results = []
|
35 |
+
for term in terms:
|
36 |
+
if term.upper().startswith("CHEMBL"):
|
37 |
+
results.append({"term": term, "data": fetch_chembl_molecule(term)})
|
38 |
+
elif len(term) == 4 and term.isalnum():
|
39 |
+
results.append({"term": term, "data": fetch_pdb_structure(term)})
|
40 |
+
return results
|