### Install ChEMBL Webresource Client Source: https://github.com/chembl/chembl_webresource_client/blob/master/README.md Install the library using pip. This is the first step to using the client. ```bash pip install chembl_webresource_client ``` -------------------------------- ### Get Tissue by Name using ChEMBL Client Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Filters tissues by a starting name pattern. Requires the 'chembl_webresource_client' library. ```python from chembl_webresource_client.new_client import new_client tissue = new_client.tissue res = tissue.filter(pref_name__istartswith='blood') res ``` -------------------------------- ### Get tissue by BTO ID Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Demonstrates how to retrieve tissue information using its BTO ( বায়োমেডিকেল টার্মস Ontology) ID. ```APIDOC ## Get tissue by BTO ID ### Description This function retrieves detailed information about a specific tissue when provided with its unique BTO identifier. ### Method ```python tissue.filter(bto_id="BTO:0001073") ``` ### Parameters - **bto_id** (string) - Required - The BTO identifier for the tissue (e.g., "BTO:0001073"). ``` -------------------------------- ### Get tissue by Uberon ID Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Queries for tissue information using the Uberon ID. Make sure to import `new_client`. ```python from chembl_webresource_client.new_client import new_client tissue = new_client.tissue res = tissue.filter(uberon_id="UBERON:0000173") res ``` -------------------------------- ### Get all biotherapeutic molecules Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves all molecules classified as biotherapeutics. Use this to find protein-based drugs. ```python from chembl_webresource_client.new_client import new_client Molecule = new_client.molecule biotherapeutics = molecule.filter(biotherapeutic__isnull=False) len(biotherapeutics) ``` -------------------------------- ### Get tissue by Uberon ID Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Illustrates how to obtain tissue information using its Uberon ID. ```APIDOC ## Get tissue by Uberon id ### Description This function enables users to query for tissue data using the Uberon ontology identifier. ### Method ```python tissue.filter(uberon_id="UBERON:0000173") ``` ### Parameters - **uberon_id** (string) - Required - The Uberon identifier for the tissue (e.g., "UBERON:0000173"). ``` -------------------------------- ### Full-Text Search on Molecules Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Performs a free-text search on the molecule resource, for example, to find molecules by their brand name or synonym. Requires importing `new_client`. ```python from chembl_webresource_client.new_client import new_client # Search molecules by brand name / synonym molecule = new_client.molecule results = molecule.search('viagra') print(len(results)) # 2 synonyms = [s['molecule_synonym'] for r in results for s in r['molecule_synonyms']] print('Sildenafil' in ' '.join(synonyms)) # True ``` -------------------------------- ### Map Compounds to Targets and UniProt Accessions Source: https://context7.com/chembl/chembl_webresource_client/llms.txt This example demonstrates how to map ChEMBL compound IDs to UniProt accessions through intermediate activity data. It processes data in chunks for efficiency and involves two main steps: compound to target mapping, and target to UniProt mapping. ```python from chembl_webresource_client.new_client import new_client chembl_ids = ['CHEMBL819', 'CHEMBL820', 'CHEMBL821'] chunk_size = 50 compounds2targets = {cid: set() for cid in chembl_ids} keys = list(compounds2targets.keys()) # Step 1: compound → target (via activities) for i in range(0, len(keys), chunk_size): acts = new_client.activity.filter( molecule_chembl_id__in=keys[i:i + chunk_size] ).only(['molecule_chembl_id', 'target_chembl_id']) for act in acts: compounds2targets[act['molecule_chembl_id']].add(act['target_chembl_id']) # Step 2: target ChEMBL ID → UniProt accession for key, val in compounds2targets.items(): lval = list(val) uniprots = set() for i in range(0, len(lval), chunk_size): targets = new_client.target.filter( target_chembl_id__in=lval[i:i + chunk_size] ).only(['target_components']) uniprots |= set( sum([[comp['accession'] for comp in t['target_components']] for t in targets], []) ) compounds2targets[key] = uniprots print({'A1E3K9', 'P35695'}.issubset(compounds2targets['CHEMBL819'])) # True print(len(compounds2targets['CHEMBL819'])) # 14 ``` -------------------------------- ### UniChem Client: Get All Database Identifiers for a Compound Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Use the UniChem client to retrieve all database identifiers for a given compound name. The result is a dictionary where keys are source database names and values are lists of compound IDs. ```python from chembl_webresource_client.unichem import unichem_client as unichem # Get all database identifiers for aspirin (by name "AIN") ret = unichem.get('AIN') all_ids = [x['src_compound_id'] for x in ret[list(ret.keys())[0]]] print({'aspirin', 'CHEMBL25', 'SCHEMBL1353'}.issubset(set(all_ids))) # True ``` -------------------------------- ### Full-Text Search on Targets Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Performs a free-text search on the target resource, for example, to find targets by gene name. Requires importing `new_client`. ```python from chembl_webresource_client.new_client import new_client # Search targets by gene name target = new_client.target brd4_targets = target.search('BRD4') print(len(brd4_targets)) # 2 ``` -------------------------------- ### Get Molecule by Standard InChI Key Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves detailed information about a single molecule using its standard InChI key. ```APIDOC ## Get Molecule by Standard InChI Key ### Description Fetches a molecule's details, including its ChEMBL ID, preferred name, and structures, using its standard InChI key. ### Method ```python molecule = new_client.molecule mol = molecule.filter(molecule_structures__standard_inchi_key='BSYNRYMUTXBXSQ-UHFFFAOYSA-N').only(['molecule_chembl_id', 'pref_name', 'molecule_structures']) ``` ### Parameters - **molecule_structures__standard_inchi_key** (string) - Required - The standard InChI key of the molecule to search for. ### Response Example ```json [ { "molecule_chembl_id": "CHEMBL25", "molecule_structures": { "canonical_smiles": "CC(=O)Oc1ccccc1C(=O)O", "molfile": "\n RDKit 2D\n\n 13 13 0 0 0 0 0 0 0 0999 V2000\n 8.8810 -2.1206 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 8.8798 -2.9479 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 9.5946 -3.3607 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 10.3110 -2.9474 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 10.3081 -2.1170 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 9.5928 -1.7078 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 11.0210 -1.7018 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 11.7369 -2.1116 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 11.0260 -3.3588 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 11.0273 -4.1837 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 11.7423 -4.5949 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 10.3136 -4.5972 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 11.0178 -0.8769 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 2 0\n 5 7 1 0\n 3 4 2 0\n 7 8 2 0\n 4 9 1 0\n 4 5 1 0\n 9 10 1 0\n 2 3 1 0\n 10 11 1 0\n 5 6 2 0\n 10 12 2 0\n 6 1 1 0\n 7 13 1 0\nM END\n\n> \nCHEMBL25\n\n> \nASPIRIN\n\n", "standard_inchi": "InChI=1S/C9H8O4/c1-6(10)13-8-5-3-2-4-7(8)9(11)12/h2-5H,1H3,(H,11,12)", "standard_inchi_key": "BSYNRYMUTXBXSQ-UHFFFAOYSA-N" }, "pref_name": "ASPIRIN" } ] ``` ``` -------------------------------- ### UniChem Client: Cross-Database Identifier Mapping Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Provides examples of using the UniChem client to resolve compound identifiers across multiple chemical databases, translate identifiers between sources, and list available data sources. ```APIDOC ## UniChem client — cross-database identifier mapping `unichem_client` resolves compound identifiers across 40+ chemical databases (ChEMBL, PubChem, ChemSpider, DrugBank, etc.). ```python from chembl_webresource_client.unichem import unichem_client as unichem # Get all database identifiers for aspirin (by name "AIN") ret = unichem.get('AIN') all_ids = [x['src_compound_id'] for x in ret[list(ret.keys())[0]]] print({'aspirin', 'CHEMBL25', 'SCHEMBL1353'}.issubset(set(all_ids))) # True # Resolve InChI Key → InChI inchi_data = unichem.inchiFromKey('AAOVKJBEBIDNHE-UHFFFAOYSA-N') print(inchi_data[0]['standardinchi']) # InChI=1S/C16H13ClN2O/c1-19-14... # Translate a compound from one source database (src_id=1 = ChEMBL) to another mapping = unichem.get('CHEMBL25', src_id=1, to_src_id=22) # 22 = PubChem print(mapping) # List all UniChem data sources sources = unichem.src() print(sources[:2]) # [{'src_id': '1', 'src_url': 'https://www.ebi.ac.uk/chembl', ...}, ...] # Map between two sources cross_map = unichem.map(src=1, dst=22) # ChEMBL → PubChem SID # Connectivity search (advanced — find structurally identical compounds across sources) connectivity_results = unichem.connectivity('CHEMBL25', src_id=1, sources=1) ``` ``` -------------------------------- ### Get Approved Drugs Sorted by Molecular Weight Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves all approved drugs (max_phase=4) and sorts them in ascending order based on their free base molecular weight. Requires importing the new_client from chembl_webresource_client. ```python from chembl_webresource_client.new_client import new_client Molecule = new_client.molecule approved_drugs = molecule.filter(max_phase=4).order_by('molecule_properties__mw_freebase') approved_drugs ``` -------------------------------- ### Get ChEMBL Sources Table Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves a list of all available ChEMBL sources. This is useful for understanding the origin of data within the ChEMBL database. ```python sources = new_client.source sources ``` -------------------------------- ### Get tissue by BTO ID Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves tissue information using its BTO ( বায়োমেডিকেল টার্মস Ontology) ID. Ensure `new_client` is imported. ```python from chembl_webresource_client.new_client import new_client tissue = new_client.tissue res = tissue.filter(bto_id="BTO:0001073") res ``` -------------------------------- ### Get tissue by Caloha ID Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Fetches tissue details using the Caloha ID. The `new_client` must be imported prior to use. ```python from chembl_webresource_client.new_client import new_client tissue = new_client.tissue res = tissue.filter(caloha_id="TS-0490") res ``` -------------------------------- ### Get Molecule by Standard InChI Key Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Fetches molecule details including ChEMBL ID, preferred name, and structures using its standard InChI key. The result is a list containing a dictionary of molecule information. ```python from chembl_webresource_client.new_client import new_client molecule = new_client.molecule mol = molecule.filter(molecule_structures__standard_inchi_key='BSYNRYMUTXBXSQ-UHFFFAOYSA-N').only(['molecule_chembl_id', 'pref_name', 'molecule_structures']) mol ``` -------------------------------- ### Get molecules with MW <= 300 and pref_name ending with 'nib' Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Finds molecules with a molecular weight less than or equal to 300 and whose preferred name ends with 'nib'. This query is specific to kinase inhibitors or similar drug classes. ```python from chembl_webresource_client.new_client import new_client Molecule = new_client.molecule light_nib_molecules = molecule.filter(molecule_properties__mw_freebase__lte=300, pref_name__iendswith="nib").only(['molecule_chembl_id', 'pref_name']) light_nib_molecules ``` -------------------------------- ### Access Drug and Drug-Indication Resources Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Retrieves information about drugs, cell lines, tissues, and documents. Examples include finding drugs approved in a specific year with a certain stem, identifying cell lines by ID, and searching for documents related to a keyword. ```python from chembl_webresource_client.new_client import new_client # Drug approved in 1976 with USAN stem "-azosin" drug = new_client.drug res = drug.filter(first_approval=1976).filter(usan_stem="-azosin") print(res[0]['synonyms']) # includes 'Prazosin' # Cell line by Cellosaurus ID cell_line = new_client.cell_line mcf7 = cell_line.filter(cellosaurus_id="CVCL_0417") print(mcf7[0]['cell_chembl_id']) # CHEMBL3307686 # Tissue by BTO, CALOHA, or UBERON ontology ID tissue = new_client.tissue t1 = tissue.filter(bto_id="BTO:0001073") print(t1[0]['tissue_chembl_id']) # CHEMBL3638173 t2 = tissue.filter(pref_name__istartswith='blood') print([t['pref_name'] for t in t2]) # ['Blood', 'Blood/Brain', 'Blood/Uterus', ...] # Documents about cytokines document = new_client.document docs = document.search('cytokine') print(len(docs)) # 300–400 ``` -------------------------------- ### Get Cell Line by Cellosaurus ID using ChEMBL Client Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves cell line information using its Cellosaurus ID. Ensure the 'chembl_webresource_client' is installed. ```python from chembl_webresource_client.new_client import new_client cell_line = new_client.cell_line res = cell_line.filter(cellosaurus_id="CVCL_0417") res ``` -------------------------------- ### List Available Data Entities Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Import the new_client and use dir() to list all available data resources. This helps in understanding the scope of data accessible through the client. ```python from chembl_webresource_client.new_client import new_client available_resources = [resource for resource in dir(new_client) if not resource.startswith('_')] print(available_resources) ``` -------------------------------- ### Get tissue by name Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves tissue information based on a partial or full name match. It filters tissues where the preferred name starts with the provided string. ```APIDOC ## Get tissue by name ### Description Retrieves tissue information based on a partial or full name match. It filters tissues where the preferred name starts with the provided string. ### Method GET ### Endpoint /tissue ### Parameters #### Query Parameters - **pref_name__istartswith** (string) - Required - The prefix to search for in the tissue's preferred name (case-insensitive). ### Response #### Success Response (200) - **bto_id** (string) - The BTO identifier for the tissue. - **caloha_id** (string) - The CALOHA identifier for the tissue. - **efo_id** (string) - The EFO identifier for the tissue. - **pref_name** (string) - The preferred name of the tissue. - **tissue_chembl_id** (string) - The ChEMBL identifier for the tissue. - **uberon_id** (string) - The UBERON identifier for the tissue. ### Request Example ```python from chembl_webresource_client.new_client import new_client tissue = new_client.tissue res = tissue.filter(pref_name__istartswith='blood') ``` ### Response Example ```json [ { "bto_id": null, "caloha_id": null, "efo_id": null, "pref_name": "Blood brain barrier", "tissue_chembl_id": "CHEMBL3987461", "uberon_id": "UBERON:0000120" }, { "bto_id": "BTO:0000089", "caloha_id": "TS-0079", "efo_id": "EFO:0000296", "pref_name": "Blood", "tissue_chembl_id": "CHEMBL3638178", "uberon_id": "UBERON:0000178" } ] ``` ``` -------------------------------- ### Paginate Molecule Results (First 10) Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Fetches the first 10 approved molecules (max_phase=4) using slicing. This demonstrates efficient pagination by only retrieving the requested subset. Requires importing `new_client`. ```python from chembl_webresource_client.new_client import new_client molecule = new_client.molecule all_approved = molecule.filter(max_phase=4) # First 10 records first_page = list(all_approved[:10]) print(len(first_page)) # 10 ``` -------------------------------- ### UniChem Client: List All Data Sources Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Retrieve a list of all supported data sources within UniChem, including their IDs and URLs. This is useful for understanding the scope of cross-database mapping. ```python # List all UniChem data sources sources = unichem.src() print(sources[:2]) # [{'src_id': '1', 'src_url': 'https://www.ebi.ac.uk/chembl', ...}, ...] ``` -------------------------------- ### Get Single Molecule by ChEMBL ID Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieve a single molecule's details using its ChEMBL ID with the `filter` method. Specify desired fields using the `only` method. This example retrieves the molecule's ID, preferred name, and structure. ```python from chembl_webresource_client.new_client import new_client Molecule = new_client.molecule m1 = molecule.filter(chembl_id='CHEMBL192').only(['molecule_chembl_id', 'pref_name', 'molecule_structures']) m1 ``` -------------------------------- ### Import and Configure Settings Source: https://github.com/chembl/chembl_webresource_client/blob/master/README.md Import the Settings object to configure client behavior such as caching and request timeouts. Settings are applied globally. ```python from chembl_webresource_client.settings import Settings ``` ```python Settings.Instance().TIMEOUT = 10 ``` -------------------------------- ### Molecule Client: SDF / XML Output Format Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Demonstrates how to set the output format for molecule queries to SDF for binary molfile chunks, and how to reset it back to JSON. ```APIDOC ## SDF / XML output format The format of a QuerySet can be switched before data retrieval; `sdf` returns binary molfile chunks suitable for cheminformatics pipelines. ```python from chembl_webresource_client.new_client import new_client molclient = new_client.molecule # Return natural product drugs as SDF molclient.set_format('sdf') natural_drugs = molclient.filter(natural_product=1) sdf_data = b'$$$$'.join([n for n in natural_drugs if n]) print(len(natural_drugs)) # ~1950 # Reset to JSON molclient.set_format('json') # Inspect the underlying URL that would be used molclient.set_format('json') qs = molclient.filter(max_phase=4).order_by('-molecule_properties__mw_freebase') print(qs.url()) # https://www.ebi.ac.uk/chembl/api/data/molecule?max_phase=4&order_by=... ``` ``` -------------------------------- ### Get all biotherapeutic molecules Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves a list of all molecules that are classified as biotherapeutics. ```APIDOC ## Get all biotherapeutic molecules ### Description Retrieves all molecules that are classified as biotherapeutics. ### Method ```python molecule = new_client.molecule biotherapeutics = molecule.filter(biotherapeutic__isnull=False) ``` ### Response Example ```json 22963 ``` ``` -------------------------------- ### Utils Client: Image Round-trip (SMILES to PNG to CTAB to SMILES) Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Demonstrates a round-trip conversion: SMILES to an image (PNG), then image to CTAB, and finally CTAB back to SMILES. This verifies the integrity of the image conversion process. ```python # Image round-trip: SMILES → PNG → CTAB → SMILES img_bytes = utils.smiles2image('CC(=O)Oc1ccccc1C(=O)O') ctab_from_img = utils.image2ctab(img_bytes) recovered_smiles = utils.ctab2smiles(ctab_from_img).split()[2] print(recovered_smiles[-10:]) # ...C(=O)O (tail matches) ``` -------------------------------- ### Get tissue by Caloha ID Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Shows how to fetch tissue details using its Caloha ID. ```APIDOC ## Get tissue by Caloha id ### Description This function allows retrieval of tissue information using its associated Caloha ID. ### Method ```python tissue.filter(caloha_id="TS-0490") ``` ### Parameters - **caloha_id** (string) - Required - The Caloha identifier for the tissue (e.g., "TS-0490"). ``` -------------------------------- ### Settings Configuration Source: https://context7.com/chembl/chembl_webresource_client/llms.txt The Settings singleton controls caching, timeouts, retries, and API endpoints. Adjust these before creating client objects. ```APIDOC ## Settings Configuration `Settings` is a singleton that controls caching, timeouts, retries, and API endpoints. Import and adjust it before creating any client objects. ```python from chembl_webresource_client.settings import Settings s = Settings.Instance() # Disable caching entirely (useful for testing) s.CACHING = False # Extend the per-request timeout (seconds) s.TIMEOUT = 10 # Cache entries expire after 48 hours instead of the default 24 s.CACHE_EXPIRE = 60 * 60 * 48 # Limit concurrent HTTP connections (default 50) s.CONCURRENT_SIZE = 20 # Clear the local SQLite cache s.clear_cache() print(s) # ChEMBL API client settings: # 'CACHE_EXPIRE': 172800, # 'CACHING': False, # 'CONCURRENT_SIZE': 20, # ... ``` **Key settings reference** | Setting | Default | Description | |---|---|---| | `CACHING` | `True` | Enable local SQLite caching of results | | `CACHE_EXPIRE` | `86400` | Cache TTL in seconds (24 h) | | `CACHE_NAME` | `'.chembl_ws_client__'` | SQLite file name (stored in `~`) | | `TOTAL_RETRIES` | `3` | HTTP retry attempts per request | | `CONCURRENT_SIZE` | `50` | HTTP connection pool size | | `FAST_SAVE` | `True` | Up-to-50× faster cache writes (minor data-loss risk on crash) | | `TIMEOUT` | `3.0` | Request timeout in seconds (`None` = no timeout) | | `MAX_LIMIT` | `20` | Page size for paginated API responses | | `PROXIES` | `None` | Dict of proxies forwarded to `requests` | ``` -------------------------------- ### Get all molecules with no Rule-of-Five violations Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves all molecules in the ChEMBL database that have zero Rule-of-Five violations. ```APIDOC ## Get all molecules in ChEMBL with no Rule-of-Five violations ### Description Retrieves all molecules in ChEMBL that have no Rule-of-Five violations. ### Method ```python molecule = new_client.molecule no_violations = molecule.filter(molecule_properties__num_ro5_violations=0) ``` ### Response Example ```json 1441706 ``` ``` -------------------------------- ### Utils Client: Generate Morgan Fingerprints Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Generate Morgan fingerprints (a type of circular fingerprint) from a CTAB representation of a molecule using the `utils` client. The output is in FPS format. ```python # Generate Morgan fingerprints (FPS format) fps = utils.sdf2fps(ctab) print(fps.startswith('#FPS')) # True ``` -------------------------------- ### UniChem Client: Map Between Two Sources Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Perform a direct mapping between two specified source databases (e.g., ChEMBL to PubChem SIDs) using the UniChem client. ```python # Map between two sources cross_map = unichem.map(src=1, dst=22) # ChEMBL → PubChem SID ``` -------------------------------- ### Utils Client: Convert CTAB to InChI and InChI Key Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Perform a two-step conversion: first, convert a CTAB to an InChI string, and then convert that InChI string to its corresponding InChI Key using the `utils` client. ```python # CTAB → InChI, then InChI → InChI Key inchi = utils.ctab2inchi(ctab) inchi_key = utils.inchi2inchiKey(inchi) print(inchi_key) # BSYNRYMUTXBXSQ-UHFFFAOYSA-N ``` -------------------------------- ### Get cell line by cellosaurus id Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves cell line information using its Cellosaurus ID. ```APIDOC ## Get cell line by cellosaurus id ### Description Retrieves cell line information using its Cellosaurus ID. ### Method GET ### Endpoint /cell_line ### Parameters #### Query Parameters - **cellosaurus_id** (string) - Required - The Cellosaurus identifier for the cell line. ### Response #### Success Response (200) - **cell_chembl_id** (string) - The ChEMBL identifier for the cell line. - **cell_description** (string) - A description of the cell line. - **cell_id** (integer) - The internal ChEMBL ID for the cell line. - **cell_name** (string) - The name of the cell line. - **cell_source_organism** (string) - The organism from which the cell line was derived. - **cell_source_tax_id** (integer) - The taxonomic ID of the source organism. - **cell_source_tissue** (string) - The tissue from which the cell line was derived. - **cellosaurus_id** (string) - The Cellosaurus identifier for the cell line. - **cl_lincs_id** (string) - The LINCS ID for the cell line. - **clo_id** (string) - The CLO identifier for the cell line. - **efo_id** (string) - The EFO identifier for the cell line. ### Request Example ```python from chembl_webresource_client.new_client import new_client cell_line = new_client.cell_line res = cell_line.filter(cellosaurus_id="CVCL_0417") ``` ### Response Example ```json [ { "cell_chembl_id": "CHEMBL3307686", "cell_description": "MDA-MB-435 (Breast metastasis of melanoma cells", "cell_id": 687, "cell_name": "MDA-MB-435", "cell_source_organism": "Homo sapiens", "cell_source_tax_id": 9606, "cell_source_tissue": "Breast metastasis of melanoma cells", "cellosaurus_id": "CVCL_0417", "cl_lincs_id": null, "clo_id": null, "efo_id": "EFO_0001213" } ] ``` ``` -------------------------------- ### Get all activities with a pChEMBL value for a molecule Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves all activities for a specific molecule (CHEMBL25) that have a non-null pChEMBL value. ```APIDOC ## Get all activities with a pChEMBL value for a molecule ### Description Retrieves all activities for a molecule (CHEMBL25) that have a pChEMBL value. ### Method ```python activities = new_client.activity res = activities.filter(molecule_chembl_id="CHEMBL25", pchembl_value__isnull=False) ``` ### Response Example ```json 138 ``` ``` -------------------------------- ### Configure ChEMBL Client Settings Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Import and adjust settings for caching, timeouts, retries, and API endpoints before creating client objects. Caching can be disabled, timeouts extended, cache expiration adjusted, and concurrent connection limits modified. ```python from chembl_webresource_client.settings import Settings s = Settings.Instance() # Disable caching entirely (useful for testing) s.CACHING = False # Extend the per-request timeout (seconds) s.TIMEOUT = 10 # Cache entries expire after 48 hours instead of the default 24 s.CACHE_EXPIRE = 60 * 60 * 48 # Limit concurrent HTTP connections (default 50) s.CONCURRENT_SIZE = 20 # Clear the local SQLite cache s.clear_cache() print(s) # ChEMBL API client settings: # 'CACHE_EXPIRE': 172800, # 'CACHING': False, # 'CONCURRENT_SIZE': 20, # ... ``` -------------------------------- ### Initialize New ChEMBL Client Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Create a new client object to access ChEMBL REST API endpoints. Available resources include molecule, target, activity, and more. ```python from chembl_webresource_client.new_client import new_client # Available resources (attributes on new_client): # molecule, target, activity, assay, document, drug, drug_indication, # compound_record, molecule_form, similarity, substructure, # cell_line, tissue, mechanism, metabolism, ... ``` -------------------------------- ### Get all IC50 activities related to the hERG target Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves all IC50 activities associated with the hERG target (KCNH2). ```APIDOC ## Get all IC50 activities related to the hERG target ### Description Retrieves all IC50 activities related to the hERG target (Voltage-gated inwardly rectifying potassium channel KCNH2). ### Method ```python target = new_client.target activity = new_client.activity herg = target.filter(pref_name__iexact='Voltage-gated inwardly rectifying potassium channel KCNH2').only('target_chembl_id')[0] herg_activities = activity.filter(target_chembl_id=herg['target_chembl_id']).filter(standard_type="IC50") ``` ### Response Example ```json 13200 ``` ``` -------------------------------- ### UniChem Client: Resolve InChI Key to InChI Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Convert an InChI Key to its corresponding InChI string representation using the UniChem client. ```python # Resolve InChI Key → InChI inchi_data = unichem.inchiFromKey('AAOVKJBEBIDNHE-UHFFFAOYSA-N') print(inchi_data[0]['standardinchi']) # InChI=1S/C16H13ClN2O/c1-19-14... ``` -------------------------------- ### new_client — Main Data API Source: https://context7.com/chembl/chembl_webresource_client/llms.txt `new_client` provides a pre-built client object with attributes corresponding to ChEMBL REST endpoints. Each attribute is a `QuerySet` supporting filtering, ordering, field selection, and slicing. ```APIDOC ## new_client — Main Data API `new_client` is a pre-built client object whose attributes correspond to every ChEMBL REST endpoint. Each attribute is a `QuerySet` that supports Django-style filtering, ordering, field selection, and slicing. ```python from chembl_webresource_client.new_client import new_client # Available resources (attributes on new_client): # molecule, target, activity, assay, document, drug, drug_indication, # compound_record, molecule_form, similarity, substructure, # cell_line, tissue, mechanism, metabolism, ... ``` ``` -------------------------------- ### CLI tools: chembl_sim Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Documentation for the `chembl_sim` command-line tool, which performs similarity searches based on ChEMBL IDs or SMILES, with options for similarity threshold, input/output formats, and data sources. ```APIDOC ### `chembl_sim` — Similarity search ```bash # Similarity search at default 95% threshold echo "CHEMBL25" | chembl_sim -s chembl_id # Custom threshold (70%), SMILES input, SDF output echo "CC(=O)Oc1ccccc1C(=O)O" | chembl_sim -s smi -t 70 -d sdf -o results.sdf # Human-readable tab-separated output chembl_sim -i compounds.smi -s smi -t 80 -d chembl_id -H ``` ``` -------------------------------- ### Sort Molecules by Molecular Weight (Ascending) Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Retrieves molecules with `max_phase` equal to 4 and sorts them in ascending order based on their molecular weight. Requires importing `new_client`. ```python from chembl_webresource_client.new_client import new_client molecule = new_client.molecule # Ascending by molecular weight by_mw = molecule.filter(max_phase=4).order_by('molecule_properties__mw_freebase') print(by_mw[0]['molecule_properties']['mw_freebase']) # smallest MW first ``` -------------------------------- ### Retrieve ChEMBL Molecules in SDF Format Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Set the output format to 'sdf' to retrieve binary molfile chunks. Remember to reset the format to 'json' for subsequent JSON-based requests. ```python from chembl_webresource_client.new_client import new_client Molecule = new_client.molecule # Return natural product drugs as SDF Molecule.set_format('sdf') natural_drugs = Molecule.filter(natural_product=1) sdf_data = b'$$$$'.join([n for n in natural_drugs if n]) print(len(natural_drugs)) # ~1950 # Reset to JSON Molecule.set_format('json') ``` -------------------------------- ### Get molecules with molecular weight <= 300 Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves a list of molecules whose free base molecular weight is less than or equal to 300. ```APIDOC ## Get molecules with molecular weight <= 300 ### Description Retrieves molecules with a free base molecular weight less than or equal to 300. ### Method ```python molecule = new_client.molecule light_molecules = molecule.filter(molecule_properties__mw_freebase__lte=300) ``` ### Response Example ```json 367682 ``` ``` -------------------------------- ### Sort Molecules by Molecular Weight (Descending) Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Retrieves molecules with `max_phase` equal to 4 and sorts them in descending order based on their molecular weight. Requires importing `new_client`. ```python from chembl_webresource_client.new_client import new_client molecule = new_client.molecule # Descending by_mw_desc = molecule.filter(max_phase=4).order_by('-molecule_properties__mw_freebase') ``` -------------------------------- ### Paginate Molecule Results (Records 100-110) Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Fetches records 100 through 110 of approved molecules (max_phase=4) using slicing. This demonstrates offset-based pagination for accessing specific data windows. Requires importing `new_client`. ```python from chembl_webresource_client.new_client import new_client molecule = new_client.molecule all_approved = molecule.filter(max_phase=4) # Records 100-110 second_window = list(all_approved[100:110]) print(len(second_window)) # 10 ``` -------------------------------- ### Get IC50 activities for hERG target Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Fetches all IC50 binding activities associated with the hERG target (KCNH2). This is useful for assessing potential cardiotoxicity. ```python from chembl_webresource_client.new_client import new_client Target = new_client.target Activity = new_client.activity herg = Target.filter(pref_name__iexact='Voltage-gated inwardly rectifying potassium channel KCNH2').only('target_chembl_id')[0] herg_activities = Activity.filter(target_chembl_id=herg['target_chembl_id']).filter(standard_type="IC50") len(herg_activities) ``` -------------------------------- ### UniChem Client: Connectivity Search Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Perform an advanced connectivity search to find structurally identical compounds across specified sources. This requires providing the compound identifier, its source ID, and the target sources for the search. ```python # Connectivity search (advanced — find structurally identical compounds across sources) connectivity_results = unichem.connectivity('CHEMBL25', src_id=1, sources=1) ``` -------------------------------- ### Get Many Molecules by IDs Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves data for multiple molecules by providing a list of their ChEMBL IDs. You can specify the fields to return using the `only` method. ```APIDOC ## Get Many Molecules by IDs ### Description Retrieves data for multiple molecules by providing a list of their ChEMBL IDs. The `only` method can be used to specify which fields to include in the response. ### Method `molecule.filter()` ### Parameters #### Query Parameters - **molecule_chembl_id__in** (list of strings) - Required - A list of ChEMBL IDs to search for. #### Request Body None ### Request Example ```python from chembl_webresource_client.new_client import new_client molecule = new_client.molecule mols = molecule.filter(molecule_chembl_id__in=['CHEMBL25', 'CHEMBL192', 'CHEMBL27']).only(['molecule_chembl_id', 'pref_name']) ``` ### Response #### Success Response (200) - **molecule_chembl_id** (string) - The ChEMBL ID of the molecule. - **pref_name** (string) - The preferred name of the molecule. #### Response Example ```json [ {'molecule_chembl_id': 'CHEMBL25', 'pref_name': 'ASPIRIN'}, {'molecule_chembl_id': 'CHEMBL27', 'pref_name': 'PROPRANOLOL'}, {'molecule_chembl_id': 'CHEMBL192', 'pref_name': 'SILDENAFIL'} ] ``` ``` -------------------------------- ### UniChem Client: Map Compound Between Databases Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Translate a compound identifier from one source database (e.g., ChEMBL) to another (e.g., PubChem) using the UniChem client's mapping functionality. ```python # Translate a compound from one source database (src_id=1 = ChEMBL) to another mapping = unichem.get('CHEMBL25', src_id=1, to_src_id=22) # 22 = PubChem print(mapping) ``` -------------------------------- ### Get all activities for a specific target with assay type B (binding) Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves all binding activities (assay type 'B') for a given target ChEMBL ID. ```APIDOC ## Get all activities for a specific target with assay type B (binding): ### Description Retrieves all activities for a specific target (CHEMBL3938) with assay type B (binding). ### Method ```python activity = new_client.activity res = activity.filter(target_chembl_id='CHEMBL3938', assay_type='B') ``` ### Response Example ```json 860 ``` ``` -------------------------------- ### Utils Client: Convert SMILES to CTAB (MDL Molfile) Source: https://context7.com/chembl/chembl_webresource_client/llms.txt Use the `utils` client to convert a SMILES string into a CTAB (MDL Molfile) format. This is a fundamental step for many cheminformatics operations. ```python from chembl_webresource_client.utils import utils import json # SMILES → CTAB (MDL molfile) ctab = utils.smiles2ctab('O=C(Oc1ccccc1C(=O)O)C') print('V2000' in ctab) # True ``` -------------------------------- ### Get molecules with no Rule-of-Five violations Source: https://github.com/chembl/chembl_webresource_client/blob/master/demo_wrc.ipynb Retrieves all molecules in the ChEMBL database that satisfy Lipinski's Rule of Five (0 violations). This is a common filter for drug-likeness. ```python from chembl_webresource_client.new_client import new_client Molecule = new_client.molecule no_violations = molecule.filter(molecule_properties__num_ro5_violations=0) len(no_violations) ```