RDKit
What this library is for
RDKit is the standard open-source cheminformatics toolkit for molecule parsing,
molecular graph operations, fingerprints, descriptors, substructure matching,
reaction handling, conformer generation, standardization, and 2D/3D molecular
depictions. Its core object is a chemically perceived Mol.
When to use this vs. alternatives
- Use RDKit for SMILES/SMARTS/SDF/MOL workflows, molecular descriptors,
fingerprints, similarity search, substructure search, reactions,
stereochemistry, standardization, and conformer generation.
- Use OpenMM for molecular simulation after chemistry preparation has produced a
force-field-ready topology/coordinates; RDKit is not an MD engine.
- Use pymatgen for inorganic/periodic materials structures and phase-stability
analysis; RDKit's molecule graph model is not a replacement for periodic
crystallographic analysis.
- Use ASE when coordinates are ready for an atomistic calculator workflow.
Convert carefully and validate atom order, coordinates, charge, spin, and
bonding assumptions.
- Do not parse SMILES with regexes or manipulate atom/bond tables by hand unless
the user is explicitly developing a new cheminformatics algorithm.
Canonical workflow
Start from sanitized molecules, check failures explicitly, then use RDKit's
graph-aware operations for descriptors, fingerprints, similarity, substructure
search, or conformers.
from rdkit import Chem, DataStructs
from rdkit.Chem import AllChem, Descriptors, Draw, rdFingerprintGenerator
smiles = ["c1ccccc1C(=O)O", "CCOC(=O)c1ccccc1", "bad_smiles"]
mols = []
for smi in smiles:
mol = Chem.MolFromSmiles(smi)
if mol is None:
print("failed_to_parse", smi)
continue
mols.append(mol)
for mol in mols:
print(Chem.MolToSmiles(mol), Descriptors.MolWt(mol), Descriptors.MolLogP(mol))
pattern = Chem.MolFromSmarts("c1ccccc1")
hits = [mol for mol in mols if mol.HasSubstructMatch(pattern)]
fpgen = rdFingerprintGenerator.GetMorganGenerator(radius=2, fpSize=2048)
fps = [fpgen.GetFingerprint(mol) for mol in mols]
print(DataStructs.TanimotoSimilarity(fps[0], fps[1]))
mol3d = Chem.AddHs(mols[0])
AllChem.EmbedMolecule(mol3d, AllChem.ETKDGv3())
AllChem.MMFFOptimizeMolecule(mol3d)
Draw.MolsToGridImage(mols, legends=[Chem.MolToSmiles(m) for m in mols])
For deeper examples, read:
Key conventions and gotchas
Chem.MolFromSmiles() returns None on parse or sanitization failure. Always
check before passing molecules into descriptor, fingerprint, or drawing code.
- Sanitization assigns valence, aromaticity, conjugation, hybridization, rings,
and related chemistry perception.
sanitize=False is an advanced escape hatch;
many RDKit functions will be unreliable until partial or full sanitization is
performed deliberately.
- RDKit is strict about allowed valences by default. Explicit valence,
kekulization, and aromaticity failures often indicate bad input chemistry,
missing charges, or a representation outside RDKit's default model.
- Hydrogens are often implicit. Add explicit hydrogens before 3D embedding,
force-field optimization, many charge workflows, or export to tools that need
explicit atoms; remove them only when the downstream representation expects it.
- Stereochemistry is representation-sensitive. Preserve isomeric SMILES,
assign/check stereochemistry when it matters, and do not assume all
non-tetrahedral stereochemistry is fully represented.
MolToSmiles() canonicalizes by default and can change atom order in the text
representation. Keep atom indices and properties on the Mol, not in a
parallel SMILES string table.
- SDF suppliers can return
None records for bad molecules. Filter records and
keep source identifiers so failures are auditable.
Anti-patterns
- Do not regex-parse SMILES for atoms, rings, branches, charges, or aromaticity.
Use
Mol, SMARTS, substructure matching, and RDKit atom/bond APIs.
- Do not ignore
None molecules and let downstream descriptor code fail with a
confusing attribute error. Report failed inputs and, if useful, diagnose with
DetectChemistryProblems().
- Do not disable sanitization just to make errors disappear. If you must read an
unusual molecule, use
sanitize=False, inspect chemistry problems, run
partial sanitization deliberately, and document the assumptions.
- Do not generate 3D conformers without hydrogens and force-field cleanup unless
the user explicitly wants raw distance-geometry coordinates.
- Do not treat fingerprint similarity as chemical truth. State the fingerprint,
radius, bit length/count representation, and similarity metric.
- Do not mix RDKit molecules with pymatgen/ASE/OpenMM objects without validating
atom order, coordinates, formal charge, stereochemistry, and bond perception.
Diagnostic checks
Before trusting outputs, the agent should:
- Count and report parse failures from SMILES/SDF/MOL inputs.
- Canonicalize or standardize molecules only when the workflow calls for it, and
record the chosen standardization steps.
- For descriptor/fingerprint tables, include molecule identifiers and note the
RDKit version, fingerprint type, radius, size, and chirality setting.
- For substructure searches, test the SMARTS on positive and negative examples
and verify whether chirality/query features are intended.
- For conformers, report whether hydrogens were added, the embedding method,
force field, convergence status, and number of conformers retained.
- For stereochemistry-sensitive work, compare isomeric SMILES before and after
transformations.
Pointers to deeper material
1---2name: rdkit3description: Use when the user is working with cheminformatics: SMILES, SMARTS, SDF/MOL files, molecular graphs, substructure search, fingerprints, descriptors, similarity, reactions, standardization, stereochemistry, conformers, or molecule drawing. Prefer RDKit over generic NetworkX, regexes, pandas string parsing, or ad hoc chemistry code when molecular graph semantics matter.4---56# RDKit78## What this library is for910RDKit is the standard open-source cheminformatics toolkit for molecule parsing,11molecular graph operations, fingerprints, descriptors, substructure matching,12reaction handling, conformer generation, standardization, and 2D/3D molecular13depictions. Its core object is a chemically perceived `Mol`.1415## When to use this vs. alternatives1617- Use RDKit for SMILES/SMARTS/SDF/MOL workflows, molecular descriptors,18 fingerprints, similarity search, substructure search, reactions,19 stereochemistry, standardization, and conformer generation.20- Use OpenMM for molecular simulation after chemistry preparation has produced a21 force-field-ready topology/coordinates; RDKit is not an MD engine.22- Use pymatgen for inorganic/periodic materials structures and phase-stability23 analysis; RDKit's molecule graph model is not a replacement for periodic24 crystallographic analysis.25- Use ASE when coordinates are ready for an atomistic calculator workflow.26 Convert carefully and validate atom order, coordinates, charge, spin, and27 bonding assumptions.28- Do not parse SMILES with regexes or manipulate atom/bond tables by hand unless29 the user is explicitly developing a new cheminformatics algorithm.3031## Canonical workflow3233Start from sanitized molecules, check failures explicitly, then use RDKit's34graph-aware operations for descriptors, fingerprints, similarity, substructure35search, or conformers.3637```python38from rdkit import Chem, DataStructs39from rdkit.Chem import AllChem, Descriptors, Draw, rdFingerprintGenerator4041smiles = ["c1ccccc1C(=O)O", "CCOC(=O)c1ccccc1", "bad_smiles"]42mols = []43for smi in smiles:44 mol = Chem.MolFromSmiles(smi)45 if mol is None:46 print("failed_to_parse", smi)47 continue48 mols.append(mol)4950for mol in mols:51 print(Chem.MolToSmiles(mol), Descriptors.MolWt(mol), Descriptors.MolLogP(mol))5253pattern = Chem.MolFromSmarts("c1ccccc1")54hits = [mol for mol in mols if mol.HasSubstructMatch(pattern)]5556fpgen = rdFingerprintGenerator.GetMorganGenerator(radius=2, fpSize=2048)57fps = [fpgen.GetFingerprint(mol) for mol in mols]58print(DataStructs.TanimotoSimilarity(fps[0], fps[1]))5960mol3d = Chem.AddHs(mols[0])61AllChem.EmbedMolecule(mol3d, AllChem.ETKDGv3())62AllChem.MMFFOptimizeMolecule(mol3d)6364Draw.MolsToGridImage(mols, legends=[Chem.MolToSmiles(m) for m in mols])65```6667For deeper examples, read:6869- Getting started: https://www.rdkit.org/docs/GettingStartedInPython.html70- Cookbook: https://www.rdkit.org/docs/Cookbook.html71- RDKit Book: https://www.rdkit.org/docs/RDKit_Book.html72- Python API reference: https://www.rdkit.org/docs/api-docs.html7374## Key conventions and gotchas7576- `Chem.MolFromSmiles()` returns `None` on parse or sanitization failure. Always77 check before passing molecules into descriptor, fingerprint, or drawing code.78- Sanitization assigns valence, aromaticity, conjugation, hybridization, rings,79 and related chemistry perception. `sanitize=False` is an advanced escape hatch;80 many RDKit functions will be unreliable until partial or full sanitization is81 performed deliberately.82- RDKit is strict about allowed valences by default. Explicit valence,83 kekulization, and aromaticity failures often indicate bad input chemistry,84 missing charges, or a representation outside RDKit's default model.85- Hydrogens are often implicit. Add explicit hydrogens before 3D embedding,86 force-field optimization, many charge workflows, or export to tools that need87 explicit atoms; remove them only when the downstream representation expects it.88- Stereochemistry is representation-sensitive. Preserve isomeric SMILES,89 assign/check stereochemistry when it matters, and do not assume all90 non-tetrahedral stereochemistry is fully represented.91- `MolToSmiles()` canonicalizes by default and can change atom order in the text92 representation. Keep atom indices and properties on the `Mol`, not in a93 parallel SMILES string table.94- SDF suppliers can return `None` records for bad molecules. Filter records and95 keep source identifiers so failures are auditable.9697## Anti-patterns9899- Do not regex-parse SMILES for atoms, rings, branches, charges, or aromaticity.100 Use `Mol`, SMARTS, substructure matching, and RDKit atom/bond APIs.101- Do not ignore `None` molecules and let downstream descriptor code fail with a102 confusing attribute error. Report failed inputs and, if useful, diagnose with103 `DetectChemistryProblems()`.104- Do not disable sanitization just to make errors disappear. If you must read an105 unusual molecule, use `sanitize=False`, inspect chemistry problems, run106 partial sanitization deliberately, and document the assumptions.107- Do not generate 3D conformers without hydrogens and force-field cleanup unless108 the user explicitly wants raw distance-geometry coordinates.109- Do not treat fingerprint similarity as chemical truth. State the fingerprint,110 radius, bit length/count representation, and similarity metric.111- Do not mix RDKit molecules with pymatgen/ASE/OpenMM objects without validating112 atom order, coordinates, formal charge, stereochemistry, and bond perception.113114## Diagnostic checks115116Before trusting outputs, the agent should:117118- Count and report parse failures from SMILES/SDF/MOL inputs.119- Canonicalize or standardize molecules only when the workflow calls for it, and120 record the chosen standardization steps.121- For descriptor/fingerprint tables, include molecule identifiers and note the122 RDKit version, fingerprint type, radius, size, and chirality setting.123- For substructure searches, test the SMARTS on positive and negative examples124 and verify whether chirality/query features are intended.125- For conformers, report whether hydrogens were added, the embedding method,126 force field, convergence status, and number of conformers retained.127- For stereochemistry-sensitive work, compare isomeric SMILES before and after128 transformations.129130## Pointers to deeper material131132- Documentation: https://www.rdkit.org/docs/133- Getting started: https://www.rdkit.org/docs/GettingStartedInPython.html134- Cookbook: https://www.rdkit.org/docs/Cookbook.html135- RDKit Book: https://www.rdkit.org/docs/RDKit_Book.html136- FAQ: https://github.com/rdkit/rdkit/wiki/FrequentlyAskedQuestions137- Source repository: https://github.com/rdkit/rdkit138- Paper: Landrum, "RDKit: Open-source cheminformatics".139 https://www.rdkit.org/