RDKit is an open-source cheminformatics toolkit for representing, manipulating, visualizing, and analyzing chemical structures. Its molecule objects store atoms, bonds, connectivity, and attributes such as atom type and formal charge, while its Python modules support chemical workflows and machine-learning integration. section 1.2.3
A practical RDKit workflow can include:
- Reading and writing molecules with rdkit.Chem. section 1.2.3
- Using AllChem for advanced chemical operations, Draw for visualization, and PandasTools for molecule columns in Pandas dataframes. section 1.2.3
- Converting molecules into numerical fingerprints for biological-activity prediction, toxicity assessment, compound prioritization, or optimization. section 1.2.3
Inspecting and visualizing caffeine
Chem.MolFromSmiles converts a caffeine SMILES string into a molecule object. The example counts 14 atoms and 15 bonds, then renders the molecule with Draw.MolsToGridImage. A larger workflow adds RDKit molecule columns to FDA-approved-drug data, generates ECFP6 fingerprints, reduces them with PCA, and applies logistic regression to classify USAN stems such as -cillin and -olol. section 1.2.3 section 1.2.3
Listing 1.1 Basic RDKit Functionality
from rdkit import Chem
from rdkit.Chem import (
AllChem, Descriptors, Draw, PandasTools,
)
smiles_string = "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" #A
mol = Chem.MolFromSmiles(smiles_string) #B
print("Number of atoms:", mol.GetNumAtoms()) #C
# Output -> Number of atoms: 14
print("Number of bonds:", mol.GetNumBonds())
# Output -> Number of bonds: 15
mol #D
img = Draw.MolsToGridImage( #E
mols=[mol], molsPerRow=1, useSVG=True, drawOptions=dopts,
)
with open("figures/ch01/caffeine.svg", "w") as f:
f.write(img.data)
Use the runnable listing to inspect imports, parse a SMILES string, count molecular components, and generate a grid image. section 1.2.3
