SMILES Randomization Augmentation
Overview
A single molecule can be written as many valid SMILES strings depending on the atom traversal order — CCO, OCC, and C(O)C all represent ethanol. For sequence-based models (LSTM, Transformer) that process SMILES character-by-character, each randomized SMILES is a distinct training example with the same label. This effectively multiplies the dataset size by N without changing the chemistry. RDKit's Chem.MolToSmiles(mol, doRandom=True) generates these variants. Typical augmentation factors of 3-10x improve model generalization on small molecular datasets.
Quick Start
from rdkit import Chem
import numpy as np
def augment_smiles(smiles_list, labels, n_augments=3):
"""Generate randomized SMILES variants for data augmentation."""
aug_smiles, aug_labels = [], []
for smi, label in zip(smiles_list, labels):
mol = Chem.MolFromSmiles(smi)
if mol is None:
continue
aug_smiles.append(Chem.MolToSmiles(mol, canonical=True))
aug_labels.append(label)
for _ in range(n_augments):
rand_smi = Chem.MolToSmiles(mol, doRandom=True)
aug_smiles.append(rand_smi)
aug_labels.append(label)
return aug_smiles, np.array(aug_labels)
# 3x augmentation: 1000 molecules → 4000 training examples
train_smi, train_y = augment_smiles(df['SMILES'], df['target'], n_augments=3)
Workflow
- Parse each SMILES to an RDKit Mol object
- Always include the canonical form as the base example
- Generate N random SMILES variants with
doRandom=True - Duplicate labels for each variant
- Train sequence model on augmented dataset
Key Decisions
- n_augments: 3-5 for moderate datasets; 10+ for very small (<500 molecules)
- Canonical always included: Ensures the standard representation is always in training
- Train only: Only augment training set — use canonical SMILES for validation/test
- Best for: Sequence models (LSTM, Transformer); fingerprint models see identical features regardless