Python quickstart
Install DeepMedChem, authenticate once, and search chemical space as a Python library.
Install the chemistry-thin SDK. It contains no RDKit, model weights, or local chemical-space data.
python -m pip install deepmedchem
deepmedchem logindeepmedchem login approves the device in your browser and stores the key in the OS keychain (or a
0600 credentials file on hosts without one). In automation, set DEEPMEDCHEM_API_KEY instead. The
compatibility variables DMC_API_KEY and CHEESE_API_KEY remain supported during migration.
The examples below are shown as they appear in a Jupyter notebook. End a cell with a bare expression
(hits, not print(hits)) to see the compact result representation.
1. Import and check the key
import deepmedchem as dmc
dmc.usage()Usage(plan='premium', credits=unlimited)usage() returns the plan and remaining daily credits. It needs no database, so it is the cheapest
way to confirm that authentication works.
2. Which chemical spaces exist?
import pandas as pd
libraries = dmc.catalog()["libraries"]
pd.DataFrame(
{
"database_id": l["database_id"],
"name": l["name"],
"molecules": f"{l['product_count']:,}",
"prices": l["pricing"]["available"],
}
for l in libraries
) database_id name molecules prices
0 cheminfinita-2026-02 ChemInfinita 2026-02 794,249,963,054 False
1 d2b-spacem1 D2B SpaceM1 1,489,758,122 False
2 enamine-real-v5a Enamine REAL v5a 93,407,931,591 True
3 freedom-space-5 Freedom Space 5 296,350,180,179 True
4 synple-explore-2025-10 Synple eXplore 9,532,882,668,261 True
5 synple-synple-2025-10 Synple 7,606,081,396,275 True
6 vast-2026-h2 VAST 2026 H2 6,798,511,197 TrueThe catalog is the source of truth for what each space supports. See chemical spaces and capabilities.
3. First search
aspirin = "CC(=O)Oc1ccccc1C(=O)O"
hits = dmc.search(aspirin, database="enamine-real-v5a", method="shape", limit=9)
hitsSearchResult(9 molecules, method='shape', database='enamine-real-v5a')method is "morgan" (the default), "shape", or "esp"; see
choosing a search method.
Use the bare result, not print()
print(hits) writes the whole raw response. A bare hits (or repr(hits)) gives the one-line
summary above.
The result is a list of SMILES
SearchResult is an ordered sequence of SMILES. Iteration, indexing, slicing, and smiles all use
the same ranking.
len(hits), hits[0], hits[:3](9,
'O=C(O)Oc1ccccc1C(=O)O',
['O=C(O)Oc1ccccc1C(=O)O', 'COC(=O)Oc1ccccc1C(=O)O', 'COC(=O)Oc1ccccc1C(C)=O'])Aligned columns are available without another request:
pd.DataFrame({"smiles": hits.smiles, "score": hits.scores, "price_usd": hits.prices}) smiles score price_usd
0 O=C(O)Oc1ccccc1C(=O)O 0.972565 245
1 COC(=O)Oc1ccccc1C(=O)O 0.971898 163
2 COC(=O)Oc1ccccc1C(C)=O 0.955080 163
3 CC(=O)c1ccccc1OC(=O)O 0.924291 245
4 O=C(O)COc1ccccc1C(=O)O 0.871286 245
5 CC(C)(C)OC(=O)Oc1ccccc1C(=O)O 0.807577 163
6 O=C(O)c1ccccc1Oc1ccc(F)cc1 0.739560 163
7 O=C(O)NCCOc1ccccc1C(=O)O 0.728522 163
8 O=C(O)CCCOc1ccccc1C(=O)O 0.721572 245Prices are positive whole US dollars for US delivery and default to 1 mg where the vendor uses pack
sizes. An unavailable price is None. See
chemical spaces and capabilities for database support.
Typed rows and provenance
Typed row access and provenance come from the original response and require no further request:
best = hits.hits[0]
best.rank, best.smiles, best.score, best.price, best.product_id(1, 'O=C(O)Oc1ccccc1C(=O)O', 0.9725648164749146, 245, 'd72ff65eda257ec576fbbefd')hits.metaSearchMeta(request_id='8c88948b-c223-4ff8-9c3e-f1f3b3608da7', database='enamine-real-v5a', release='2026-09-06.2', method='shape', metric='CHEESE shape cosine', returned=9, elapsed_ms=583.7)hits.request_id, hits.database_release, and the complete forward-compatible response in
hits.raw are also available. Keep the release when you need to reproduce a result.
See the molecules
With RDKit installed (it is not an SDK dependency), draw the query and the top hits:
from rdkit import Chem
from rdkit.Chem import Draw
mols = [Chem.MolFromSmiles(s) for s in [aspirin, *hits.smiles[:5]]]
labels = ["query"] + [f"{s:.2f} ${p}" for s, p in zip(hits.scores[:5], hits.prices[:5])]
Draw.MolsToGridImage(mols, molsPerRow=3, legends=labels, subImgSize=(260, 200))
4. Search methods: Morgan/ECFP4 vs shape vs electrostatics
method= decides what “similar” means. The same query, database, and limit give different
rankings.
morgan (default) | shape | esp | |
|---|---|---|---|
| Compares | 2D structure: shared circular atom neighbourhoods (radius 2, ECFP4) | 3D shape of the molecule's conformers | 3D electrostatic potential (partial-charge distribution) |
| Score | ECFP4 Tanimoto, 0–1 | CHEESE shape cosine | CHEESE electrostatic cosine |
| Model in response | rdkit-ecfp4-r2-n2048 (2048-bit fingerprint) | shapesim | espsim |
| Finds | Close analogues with the same chemotype and substituent patterns | Molecules that fill space like the query, even with a different scaffold | Molecules that present a similar charge pattern, such as polar or hydrogen-bonding motifs |
| Typical use | SAR expansion, quick first look | Scaffold hopping, shape-based ligand design | Bioisostere ideas, when interactions matter more than the skeleton |
| Cost | Fastest | Slower, separate capacity | Slower, separate capacity |
Keep these points in mind:
- All three methods start from the same pool of constructible products.
shapeandespthen exactly rerank that pool with the CHEESE model, so rankings overlap and no method returns a molecule the proposal step never assembled. - Scores are not comparable across methods or model versions. A shape score of 0.9 does not mean “more similar” than an ECFP4 score of 0.7. Compare ranks, or use one method per question.
- Shape and electrostatic scores depend on the conformer and partial-charge assumptions of the
pinned model release. Record
model_versionanddatabase_releaseto reproduce a run. - For small queries such as ethanol the methods mostly agree. Differences grow with size and flexibility.
Start with morgan. Switch to shape when you want different scaffolds with a similar 3D
footprint, and to esp when the interaction pattern, rather than the skeleton, is the point.
Compare the methods on one query
Celecoxib, top 20 from Enamine REAL. The RDKit ECFP4 similarity to the query puts the three rankings on one 2D yardstick.
from rdkit import DataStructs
from rdkit.Chem import rdFingerprintGenerator
celecoxib = "Cc1ccc(-c2cc(C(F)(F)F)nn2-c2ccc(S(N)(=O)=O)cc2)cc1"
ecfp4 = rdFingerprintGenerator.GetMorganGenerator(radius=2, fpSize=2048)
fp_query = ecfp4.GetFingerprint(Chem.MolFromSmiles(celecoxib))
def ecfp4_to_query(smiles):
return DataStructs.TanimotoSimilarity(fp_query, ecfp4.GetFingerprint(Chem.MolFromSmiles(smiles)))
runs = {m: dmc.search(celecoxib, database="enamine", method=m, limit=20) for m in ["morgan", "shape", "esp"]}
pd.DataFrame(
{
"method": m,
"metric": r.metric,
"model_version": r.raw["model_version"],
"score range": f"{min(r.scores):.2f}-{max(r.scores):.2f}",
"mean ECFP4 to query": round(sum(map(ecfp4_to_query, r.smiles)) / len(r), 2),
"server time (ms)": round(r.timing_ms["total"]),
}
for m, r in runs.items()
) method metric model_version score range mean ECFP4 to query server time (ms)
0 morgan ECFP4 Tanimoto rdkit-ecfp4-r2-n2048 0.46-0.53 0.48 364
1 shape CHEESE shape cosine shapesim 0.64-0.77 0.46 672
2 esp CHEESE electrostatic cosine espsim 0.64-0.79 0.47 671How many molecules do two top-20 lists share?
names = list(runs)
pd.DataFrame(
[[len(set(runs[a].smiles) & set(runs[b].smiles)) for b in names] for a in names],
index=names, columns=names,
) morgan shape esp
morgan 20 7 8
shape 7 20 7
esp 8 7 20Top three hits per method, labelled with the method score and the ECFP4 similarity to the query:

For this query the mean ECFP4 similarity is nearly the same for all three methods, yet only 7–8 of 20 molecules are shared between any two. Each method reorders the same candidate pool, so they choose different molecules from similar neighbourhoods. Morgan ranks by 2D fragments alone (note the tied 0.53 scores). Shape and electrostatic hits often have lower ECFP4 similarity but a high 3D score, such as a different linker or rearranged core with a similar footprint. This is one query: judge the methods on your own target.
Client.search_cheese(..., scorer="shape" | "esp") is the same call restricted to the CHEESE
methods, and Client.search() accepts the same method=.
5. Database shorthands
Wherever a database is expected, a short alias such as "enamine" resolves to the full ID
(enamine-real-v5a). Aliases exist only for make-on-demand spaces; full IDs always work.
a = dmc.search("CCO", database="enamine", limit=1)
b = dmc.search("CCO", database="enamine-real-v5a", limit=1)
a.database_id, a.database_release, a.database_id == b.database_id('enamine-real-v5a', '2026-09-06.2', True)6. Substructure
Substructure search finds exact containment, so scores are None. The default query language is
SMARTS; pass format="smiles" for SMILES.
motif = dmc.substructure("C(=O)N1CCC1", database="enamine", limit=5) # N-acyl azetidine
pd.DataFrame({"smiles": motif.smiles, "score": motif.scores, "price_usd": motif.prices}) smiles score price_usd
0 NC(=O)N1CC(C(=O)N2CCCc3cccc(Br)c3C2)C1 None 163
1 CN(C(=O)C1CC2(C1)CN(C(=O)OCc1ccccc1)C2)[C@H]1[... None 163
2 COc1nc(CN(C[C@@H]2CCC[C@H]2CF)C(=O)C2CN(C(C)=O... None 245
3 CCC(CC)CSCC(C)C(=O)N1CCC1 None 163
4 CC(C)(C)OC(=O)N1CC(c2ocnc2CNCC2(OCCO)CCOC2)C1 None 163Demanding motifs can take tens of seconds; see
substructure search for timeout_seconds, coverage, and
partial results.
7. Random sample
The same seed on the same database release and sampling version returns the same molecules.
s1 = dmc.sample(database="enamine", count=5, seed=42)
s2 = dmc.sample(database="enamine", count=5, seed=42)
s1.smiles == s2.smiles, s1.sampling_method, s1.seed(True, 'route_product_tuple', 42)The SDK never invents a numeric similarity for an exact or random result. See random sampling for the distribution semantics.
8. One client for several calls
Use an explicit client when several calls should share one connection, or when working with selections and durable runs:
from deepmedchem import Client
with Client() as client:
first = client.search("CCO", database="enamine", method="morgan", limit=3)
second = client.search("CCN", database="enamine", method="morgan", limit=3)
first.smiles, second.smiles(['CCCCO', 'CCCCCO', 'CCC(CC)CO'], ['CCCC', 'CCCCF', 'CCCCC'])9. Save results
to_file infers the format from the suffix: .csv, .sdf (requires RDKit), .smi, or .json. It
returns the number of molecules written. to_pandas(), to_csv(), to_sdf(), and to_records() are
also available.
import tempfile, pathlib
out = pathlib.Path(tempfile.mkdtemp())
hits.to_file(out / "aspirin_shape.csv"), hits.to_file(out / "aspirin_shape.smi")(9, 9)The CSV starts with rank, smiles, score, price, product_id, database_id, database_release, reaction_id, metric and then any further populated fields.
10. Errors
Every API failure raises DeepMedChemError with code, status_code, retryable, and
request_id. The client already retries transient 429, 503, and 504 responses twice, honouring
Retry-After.
from deepmedchem import DeepMedChemError
for bad in [dict(smiles="not-a-smiles", database="enamine"), dict(smiles="CCO", database="no-such-space")]:
try:
dmc.search(**bad)
except DeepMedChemError as e:
print(f"{e.code:22} HTTP {e.status_code} retryable={e.retryable} {e}")worker_error HTTP 400 retryable=False invalid SMILES
unavailable_library HTTP 400 retryable=False library not loaded: no-such-spaceRetry only when retryable is true. Quote request_id when contacting support. A missing
credential raises the code missing_api_key. See errors for the status
mapping.
11. Async
deepmedchem.aio provides matching short-lived async operations, and AsyncClient supports explicit
connection reuse. Jupyter allows top-level await:
from deepmedchem import aio
(await aio.search("CCO", database="enamine", limit=3)).smiles['CCCCO', 'CCCCCO', 'CCC(CC)CO']12. From hits to a vendor request
prepare_order turns a results CSV into a reviewable quote or order request for each vendor. It
sends nothing: it only writes files (and the CLI can open your mail client with the draft). Price
estimates are deliberately left out of the request.
from deepmedchem import prepare_order
bundle = prepare_order(out / "aspirin_shape.csv", get_quote=True, output_dir=out / "quote")
print((bundle.directory / "summary.txt").read_text())DeepMedChem quote request bundle
Source: aspirin_shape.csv
Molecules: 9
Vendor requests: 1
Enamine: 9 molecules -> info@enamine.net (enamine/)
If an email draft did not open, copy the matching email.txt and attach or paste molecules.csv.13. The same from a terminal
The package installs the deepmedchem command, also available as dmc.
deepmedchem usage
deepmedchem databases --detailed
deepmedchem search CCO -d enamine -n 3 -o hits.csv
deepmedchem substructure 'C(=O)N1CCC1' -d enamine -n 20
deepmedchem sample -d enamine -n 100 --seed 12345
deepmedchem order hits.csv --get-quote --no-opendeepmedchem search CCO -d enamine -n 3 prints a table and a one-line summary (-o also saves the file and reports Saved 3 molecules to hits.csv (csv).):
rank score price smiles
---- ------ ----- ---------
1 0.4167 $245 CCCCO
2 0.3846 $245 CCCCCO
3 0.3846 $245 CCC(CC)CO
Searched ~93.4B source combinations (Enamine REAL v5a) in 693 ms.
Similarity range: 0.38-0.42 ECFP4 Tanimoto.See the Python reference for profiles, credential precedence, and every result field.