Reproducible cheminformatics notebooks, a practical checklist
A cheminformatics notebook is reproducible when inputs are identified, the environment pinned, randomness seeded and outputs carry provenance. Here is how.
A cheminformatics notebook is reproducible when a colleague can rerun it next year and get the same molecules, the same numbers and the same plots. That takes four habits. Identify every molecule by something stable, pin the software environment, seed every random step and attach provenance to every output. None of them is hard, and all of them are easier to adopt at the first cell than to retrofit after a result has been shared. This guide lists each habit with the one or two lines of code it takes.
Identify every molecule by something stable
A name is not an identifier. The same drug has brand names, generic names and vendor codes, and a name lookup can return a salt one day and the parent the next. A SMILES string is better but is not unique unless canonicalised, and canonicalisation depends on the toolkit and its version. Store three things for each compound. First, an identifier that is stable across tools, such as the InChIKey or the PubChem CID. Second, the canonical SMILES as your toolkit writes it, next to the toolkit version. Third, the source and the date of the lookup.
The guide on canonical SMILES explains why one molecule needs one string, and the guide on InChI and InChIKey covers when the hashed key is the right join column. When you resolve a compound on Molecule Analysis, copy the identifiers into the notebook rather than the name you typed.
Pin the environment
Record the exact versions of RDKit, numpy, pandas and any model library, and store them in an environment file next to the notebook. Then print the versions inside the notebook, so the record travels with the output even when the environment file is lost.
import rdkit, numpy, pandas
print("rdkit", rdkit.__version__)
print("numpy", numpy.__version__)
print("pandas", pandas.__version__)
RDKit matters most. Canonical SMILES, aromaticity perception, descriptor definitions and the default conformer generator have all changed across releases. A deduplication by SMILES done under one version and repeated under another can split or merge records. If you must upgrade in the middle of a project, rerun the standardisation step on the raw inputs rather than mixing strings from two versions.
Seed everything that is random
Several common steps are stochastic. Conformer generation with ETKDG starts from random distance geometry, so pass an explicit seed. Train and test splitting, model initialisation, library sampling and any embedding such as UMAP all draw random numbers. Set a seed for each and record it in the manifest. The guide on train and test splits in chemistry explains why the split itself, not just its seed, is part of the result.
from rdkit import Chem
from rdkit.Chem import AllChem
mol = Chem.AddHs(Chem.MolFromSmiles("Cn1cnc2c1c(=O)n(C)c(=O)n2C")) # caffeine
params = AllChem.ETKDGv3()
params.randomSeed = 20261128
AllChem.EmbedMolecule(mol, params)
A seeded run is reproducible on the same software and hardware. Across machines, floating-point differences can still change the last digits of an energy or the shape of an embedding, so compare with a tolerance rather than byte for byte.
Separate data acquisition from analysis
Every call to an external resource, whether a public database or an API, belongs in a cell that writes the raw response to disk with a timestamp, and every later cell reads from that file. Three benefits follow. The notebook reruns without a network. The analysis cannot silently change because a record upstream was corrected. And the raw file is evidence, since it shows exactly what the service returned on that day. Keep a raw directory that is never edited and a derived directory that is rebuilt from it. When a lookup is free and cheap, the temptation is to call it inline. Resist it, because the second rerun is where the discrepancy appears.
Run top to bottom before sharing
Notebooks accumulate hidden state. A variable defined in a cell that was later deleted still lives in the kernel, and a cell run out of order produces a result that the saved file does not explain. Before sharing, restart the kernel and run every cell from the top. If it fails, the notebook was not reproducible, and the failure is the cheapest one you will have. Convert long-lived logic into a small module imported by the notebook, and keep the notebook for the narrative and the figures. The guide on exporting and sharing results covers what the files you write at the end should contain.
Write a manifest at the end
A manifest is a small JSON file that names the inputs, the versions, the seeds and the outputs. It costs ten lines and answers most questions a reviewer will ask.
import json, datetime, rdkit
from rdkit import Chem
mol = Chem.MolFromSmiles("Cn1cnc2c1c(=O)n(C)c(=O)n2C")
manifest = {
"date": datetime.date.today().isoformat(),
"rdkit_version": rdkit.__version__,
"seed": 20261128,
"inputs": [{"name": "caffeine", "cid": 2519,
"inchikey": Chem.MolToInchiKey(mol),
"canonical_smiles": Chem.MolToSmiles(mol)}],
"outputs": ["derived/caffeine_conformers.sdf"],
}
with open("manifest.json", "w") as f:
json.dump(manifest, f, indent=2)
The InChIKey written here is the standard key for caffeine, RYYVLZVUVIJVGH-UHFFFAOYSA-N, and the CID is PubChem's. A colleague who finds a different key when rerunning knows at once that the structure, not the analysis, has changed.
Key points
- Identify molecules by InChIKey or CID, and store canonical SMILES next to the toolkit version that wrote them.
- Pin and print software versions. RDKit releases change canonical strings and descriptors.
- Seed conformer generation, splits, models and embeddings, and record the seeds.
- Save raw responses to disk with a date and analyse only from those files.
- Restart and run all before sharing, and write a manifest of inputs, versions, seeds and outputs.
Questions people ask
- Why does the RDKit version matter for reproducibility?
- Canonical SMILES, descriptor values and conformer generation can change between RDKit releases. A notebook that writes canonical SMILES or computed properties to disk without recording the version may produce different strings or numbers when rerun, and a deduplication by SMILES may then disagree with the original.
- What should a cheminformatics notebook record about each molecule?
- A stable identifier such as the InChIKey or the PubChem CID, the canonical SMILES together with the toolkit version that produced it, the source of the record and the date it was retrieved. With those four, anyone can re-resolve the molecule and check that the structure has not drifted.
- Which random seeds need fixing in a chemistry notebook?
- Conformer embedding, train and test splitting, model initialisation, any dimensionality reduction such as UMAP, and any sampling of a library. Set an explicit seed for each and record it. A notebook that gives different results on rerun is not wrong, but it cannot be checked.
Further reading
- RDKit documentation
- Riniker and Landrum, Better informed distance geometry (2015)
- Wikipedia, Reproducibility
- Wikipedia, Project Jupyter
In practice: Everything on MolForge is reachable from the browser, the REST API and the MCP server. Lookups are free; a paid tool shows its price in credits before it runs.