File size: 979 Bytes
792fe00
 
 
a8a0045
792fe00
a8a0045
 
 
 
 
 
 
 
 
 
792fe00
a8a0045
 
 
 
 
 
 
 
 
 
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
# 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