mgbam's picture
Update genesis/api_clients/chembl_api.py
a8a0045 verified
raw
history blame
979 Bytes
# genesis/api_clients/chembl_api.py
import requests
CHEMBL_BASE = "https://www.ebi.ac.uk/chembl/api/data"
def search_chembl(molecule_name: str, max_results: int = 10):
"""
Search ChEMBL database for a molecule by name or identifier.
Returns a list of dicts with molecule name, ChEMBL ID, and other details.
"""
url = f"{CHEMBL_BASE}/molecule"
params = {"molecule_synonyms__icontains": molecule_name, "limit": max_results, "format": "json"}
res = requests.get(url, params=params)
res.raise_for_status()
data = res.json()
results = []
for mol in data.get("molecules", []):
results.append({
"name": mol.get("pref_name"),
"chembl_id": mol.get("molecule_chembl_id"),
"max_phase": mol.get("max_phase"),
"molecule_type": mol.get("molecule_type"),
"link": f"https://www.ebi.ac.uk/chembl/compound_report_card/{mol.get('molecule_chembl_id')}/"
})
return results