liveBook · Manning

Molecule object

As explained in Build AI Drug Discovery Pipelines

An RDKit Mol is an in-memory molecular graph object representing atoms, bonds, and associated molecular information.

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

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines stored graph information and demonstrates construction and inspection, while deferring broader RDKit functionality to later treatment.
Examples
Uses caffeine construction, SDF-to-DataFrame conversion, molecule visualization, atom-bond counts, and drug-stem classification workflows.
What it assumes
Assumes basic Python and chemical-structure notation while introducing RDKit objects, SMILES conversion, SDF loading, and molecular graphs.
What you can do after
Apply it via RDKit to convert SMILES or SDF records into analyzable molecular objects and prepare them for cheminformatics workflows.
How it connects
Connects RDKit, SMILES, SDF files, Pandas DataFrames, molecular graphs, fingerprints, and machine-learning models.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.