mgbam commited on
Commit
3b4e96a
·
verified ·
1 Parent(s): 6e9bb07

Create structures.py

Browse files
Files changed (1) hide show
  1. genesis/structures.py +33 -0
genesis/structures.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # genesis/structures.py
2
+ import requests
3
+ from typing import List, Dict
4
+
5
+ def fetch_structures_for_terms(terms: List[str]) -> List[Dict[str, str]]:
6
+ """Fetch PDB structures from PDBe or RCSB for given search terms."""
7
+ structures = []
8
+
9
+ for term in terms:
10
+ try:
11
+ # PDBe search
12
+ pdbe_url = f"https://www.ebi.ac.uk/pdbe/search/pdb/select"
13
+ params = {"q": term, "rows": 2, "wt": "json"}
14
+ r = requests.get(pdbe_url, params=params, timeout=10)
15
+ r.raise_for_status()
16
+ data = r.json()
17
+
18
+ docs = data.get("response", {}).get("docs", [])
19
+ for doc in docs:
20
+ pdb_id = doc.get("pdb_id")
21
+ title = doc.get("title", term)
22
+ if pdb_id:
23
+ structures.append({
24
+ "term": term,
25
+ "pdb_id": pdb_id,
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
+ return structures