A molecule object is an in-memory data structure representing a chemical compound. In RDKit, the Mol, also called a ROMol, stores atoms, bonds, connectivity, and associated molecular information rather than a picture. section 1.2.3 section 2.2.1
Use the molecule object as the central representation for cheminformatics operations:
- Store chemical structure as atoms, bonds, and their connectivity. section 1.2.3 section 2.2.1
- Retain atom and bond attributes such as atom type and formal charge. section 1.2.3
- Enable substructure searching, molecular analysis, visualization, and conversion into numerical representations for machine learning. section 1.2.3 section 2.2.1
- Connect molecular strings or structure files to tabular workflows by storing Mol objects in Pandas DataFrame columns. section 2.2.1
From SMILES to a molecular object
Convert a SMILES string with Chem.MolFromSmiles(smiles_string), then inspect the resulting object or count its atoms and bonds. A caffeine example produces a Mol with 14 atoms and 15 bonds; drawing it creates a visualization derived from the object, not the object itself. section 1.2.3
Loading a compound collection
Load an SDF into a Pandas DataFrame and use PandasTools.AddMoleculeColumnToFrame() to convert its SMILES column into a column of RDKit Mol objects. The resulting objects can support fingerprints, similarity analysis, and downstream machine-learning workflows. section 2.2.1
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)
Run the compact RDKit example to construct a Mol from SMILES, inspect atom and bond counts, and render the molecule. section 1.2.3
