Spaces:
Sleeping
Sleeping
File size: 1,233 Bytes
3b4e96a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# genesis/structures.py
import requests
from typing import List, Dict
def fetch_structures_for_terms(terms: List[str]) -> List[Dict[str, str]]:
"""Fetch PDB structures from PDBe or RCSB for given search terms."""
structures = []
for term in terms:
try:
# PDBe search
pdbe_url = f"https://www.ebi.ac.uk/pdbe/search/pdb/select"
params = {"q": term, "rows": 2, "wt": "json"}
r = requests.get(pdbe_url, params=params, timeout=10)
r.raise_for_status()
data = r.json()
docs = data.get("response", {}).get("docs", [])
for doc in docs:
pdb_id = doc.get("pdb_id")
title = doc.get("title", term)
if pdb_id:
structures.append({
"term": term,
"pdb_id": pdb_id,
"title": title,
"pdbe_url": f"https://www.ebi.ac.uk/pdbe/entry/pdb/{pdb_id}",
"rcsb_url": f"https://www.rcsb.org/structure/{pdb_id}"
})
except Exception as e:
print(f"[Structures] Failed to fetch for {term}: {e}")
return structures
|