Alterlab chembl

From AlterLab-IEU/AlterLab-Academic-Skills · View interactive version

Alterlab chembl is an AI agent skill from the GitHub repository AlterLab-IEU/AlterLab-Academic-Skills. Query ChEMBL via the chembl_webresource_client Python client for curated bioactive molecules and drug-like compound libraries at scale — search compounds by structure or physicochemical properties, retrieve bioactivity measurements (IC50, Ki, EC50), and find inhibitors of a target. Use when screenin

How to use this skill

Skill file

ChEMBL Database

Overview

ChEMBL is a manually curated database of bioactive molecules maintained by the European Bioinformatics Institute (EBI). Release ChEMBL 37 (May 2026) holds ~2.9 million distinct compounds, ~24.5 million bioactivity measurements, ~18,500 targets, and data on approved drugs and clinical candidates (live counts: https://www.ebi.ac.uk/chembl/api/data/status.json). Access and query this data programmatically using the ChEMBL Python client for drug discovery and medicinal chemistry research.

When to Use This Skill

This skill should be used when:

Does NOT Trigger

| Scenario | Use Instead |

|----------|-------------|

| Measured binding constants (Ki/Kd) from BindingDB, or its full TSV dump | alterlab-bindingdb |

| General compound lookup, name↔CID/SMILES conversion, PubChem BioAssay | alterlab-pubchem |

| Drug–drug interactions, drug labels, detailed pharmacology records | alterlab-drugbank |

| Purchasable compounds / docking-ready 3D libraries | alterlab-zinc-db |

| Computing descriptors or fingerprints locally from structures | alterlab-rdkit |

Hand-off rule. When the request matches a row above, open your answer by naming that skill by its exact id (for example alterlab-bindingdb) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.

Installation and Setup

Python Client

Run the ChEMBL Python client install-free — uv resolves it for each run (a bare

uv pip install outside a virtual environment fails with "No virtual environment found"):

uv run --with chembl_webresource_client python query.py
uv run --with chembl_webresource_client --with pandas python scripts/example_queries.py

Without Python, the same data comes from the REST API, e.g.

curl "https://www.ebi.ac.uk/chembl/api/data/mechanism.json?molecule_chembl_id=CHEMBL25"

and .../drug_indication.json?molecule_chembl_id=CHEMBL25 (checked 2026-10-23: 1 mechanism,

cyclooxygenase inhibitor; 167 indication records).

Large result sets — count first, then page in 1,000s. Broad activity filters match

thousands of records: EGFR (CHEMBL203) IC50 ≤ 100 nM is 10,665 activities (checked

2026-11-02). Iterating a client queryset fetches them about 20 per request, which takes many

minutes. Read page_meta.total_count first, then either page the REST API at its maximum

limit=1000 with only= fields (one page took about 4 s), or slice the queryset

(activity.filter(...).only([...])[:1000]) and say how many were left out:

curl -s "https://www.ebi.ac.uk/chembl/api/data/activity.json?target_chembl_id=CHEMBL203&standard_type=IC50&standard_relation=%3D&standard_units=nM&standard_value__lte=100&limit=1000&only=molecule_chembl_id,standard_value,pchembl_value"

Basic Usage Pattern

from chembl_webresource_client.new_client import new_client

# Access different endpoints
molecule = new_client.molecule
target = new_client.target
activity = new_client.activity
drug = new_client.drug

Core Capabilities

1. Molecule Queries

Retrieve by ChEMBL ID:

molecule = new_client.molecule
aspirin = molecule.get('CHEMBL25')

Search by name:

results = molecule.filter(pref_name__icontains='aspirin')

Filter by properties:

# Find small molecules (MW <= 500) with favorable LogP
results = molecule.filter(
    molecule_properties__mw_freebase__lte=500,
    molecule_properties__alogp__lte=5
)

2. Target Queries

Retrieve target information:

target = new_client.target
egfr = target.get('CHEMBL203')

Search for specific target types:

# Find all kinase targets
kinases = target.filter(
    target_type='SINGLE PROTEIN',
    pref_name__icontains='kinase'
)

3. Bioactivity Data

Query activities for a target:

activity = new_client.activity
# Find potent EGFR inhibitors
results = activity.filter(
    target_chembl_id='CHEMBL203',
    standard_type='IC50',
    standard_value__lte=100,
    standard_units='nM'
)

Get all activities for a compound:

compound_activities = activity.filter(
    molecule_chembl_id='CHEMBL25',
    pchembl_value__isnull=False
)

4. Structure-Based Searches

Similarity search:

similarity = new_client.similarity
# Find compounds similar to aspirin
similar = similarity.filter(
    smiles='CC(=O)Oc1ccccc1C(=O)O',
    similarity=85  # 85% similarity threshold
)

Substructure search:

substructure = new_client.substructure
# Find compounds containing benzene ring
results = substructure.filter(smiles='c1ccccc1')

5. Drug Information

Retrieve drug data:

drug = new_client.drug
drug_info = drug.get('CHEMBL25')

Get mechanisms of action:

mechanism = new_client.mechanism
mechanisms = mechanism.filter(molecule_chembl_id='CHEMBL25')

Query drug indications:

drug_indication = new_client.drug_indication
indications = drug_indication.filter(molecule_chembl_id='CHEMBL25')

Query Workflow

Workflow 1: Finding Inhibitors for a Target

  1. Identify the target — most reliably by UniProt accession, because name

search is fuzzy (pref_name__icontains='EGFR' returns chimeras and

protein–protein-interaction targets first, and CHEMBL203's pref_name is

"Epidermal growth factor receptor", so gene symbols only match synonyms):

```python

targets = new_client.target.filter(

target_components__accession='P00533', # human EGFR

target_type='SINGLE PROTEIN',

)

target_id = targets[0]['target_chembl_id'] # CHEMBL203

# By symbol instead: target_synonym__icontains='EGFR' plus organism='Homo sapiens',

# then check pref_name — substring matches also hit VEGFR1/2/3.

```

  1. Query bioactivity data for that target:

```python

activities = new_client.activity.filter(

target_chembl_id=target_id,

standard_type='IC50',

standard_value__lte=100

)

```

  1. Extract compound IDs and retrieve details:

```python

compound_ids = [act['molecule_chembl_id'] for act in activities]

compounds = [new_client.molecule.get(cid) for cid in compound_ids]

```

Workflow 2: Analyzing a Known Drug

  1. Get drug information:

```python

drug_info = new_client.drug.get('CHEMBL1234')

```

  1. Retrieve mechanisms:

```python

mechanisms = new_client.mechanism.filter(molecule_chembl_id='CHEMBL1234')

```

  1. Find all bioactivities:

```python

activities = new_client.activity.filter(molecule_chembl_id='CHEMBL1234')

```

Workflow 3: Structure-Activity Relationship (SAR) Study

  1. Find similar compounds:

```python

similar = new_client.similarity.filter(smiles='query_smiles', similarity=80)

```

  1. Get activities for each compound:

```python

for compound in similar:

activities = new_client.activity.filter(

molecule_chembl_id=compound['molecule_chembl_id']

)

```

  1. Analyze property-activity relationships using molecular properties from results.

Filter Operators

ChEMBL supports Django-style query filters:

Data Export and Analysis

Convert results to pandas DataFrame for analysis:

import pandas as pd

activities = new_client.activity.filter(target_chembl_id='CHEMBL203')
df = pd.DataFrame(list(activities))

# Analyze results
print(df['standard_value'].describe())
print(df.groupby('standard_type').size())

Performance Optimization

Caching

The client automatically caches results for 24 hours. Configure caching:

from chembl_webresource_client.settings import Settings

# Disable caching
Settings.Instance().CACHING = False

# Adjust cache expiration (seconds)
Settings.Instance().CACHE_EXPIRE = 86400

Lazy Evaluation

Queries execute only when data is accessed. Convert to list to force execution:

# Query is not executed yet
results = molecule.filter(pref_name__icontains='aspirin')

# Force execution
results_list = list(results)

Pagination

Results are paginated automatically. Iterate through all results:

for activity in new_client.activity.filter(target_chembl_id='CHEMBL203'):
    # Process each activity
    print(activity['molecule_chembl_id'])

Common Use Cases

Find Kinase Inhibitors

# Identify kinase targets
kinases = new_client.target.filter(
    target_type='SINGLE PROTEIN',
    pref_name__icontains='kinase'
)

# Get potent inhibitors
for kinase in kinases[:5]:  # First 5 kinases
    activities = new_client.activity.filter(
        target_chembl_id=kinase['target_chembl_id'],
        standard_type='IC50',
        standard_value__lte=50
    )

Explore Drug Repurposing

# Get approved drugs (the drug endpoint also lists clinical candidates,
# so filter on max_phase=4; ~3,000 approved of ~16,000 drug records)
drugs = new_client.drug.filter(max_phase=4)

# For each drug, find all targets
for drug in drugs[:10]:
    mechanisms = new_client.mechanism.filter(
        molecule_chembl_id=drug['molecule_chembl_id']
    )

Virtual Screening

# Find compounds with desired properties
candidates = new_client.molecule.filter(
    molecule_properties__mw_freebase__range=[300, 500],
    molecule_properties__alogp__lte=5,
    molecule_properties__hba__lte=10,
    molecule_properties__hbd__lte=5
)

Resources

scripts/example_queries.py

Ready-to-use Python functions demonstrating common ChEMBL query patterns:

Consult this script for implementation details and usage examples.

references/api_reference.md

Comprehensive API documentation including:

Refer to this document when detailed API information is needed or when troubleshooting queries.

Important Notes

Data Reliability

Units and Standards

Rate Limiting

Chemical Structure Formats

Additional Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.