# Molecular property prediction

> Predict a molecule's properties from its atom–bond graph with a GNN and a permutation-invariant readout; benchmarks are MoleculeNet, QM9 and OGB, and scaffold splits test generalisation to unseen chemotypes, which random splits overstate.

Source: https://www.mlfoundry.in/learn/molecular-property-prediction  
Section: Deep Learning › Graph Neural Networks (GNNs)  
Level: advanced · 8 min read · updated 2026-10-21

**Molecular property prediction:** is the supervised task of mapping a molecule to a measured or computed property: a quantum-chemical energy, solubility, lipophilicity, binding to a protein target, or toxicity. With graph neural networks the molecule is a graph of atoms (nodes) and bonds (edges), and the prediction is made at **graph level**. The standard benchmark suites are MoleculeNet (Wu et al., Chemical Science 2018) and the molecular datasets of the Open Graph Benchmark (Hu et al., NeurIPS 2020).

The input usually arrives as a SMILES string such as `Oc1ccccc1` (phenol). A toolkit like RDKit parses it into heavy atoms and bonds. Hydrogens are normally kept only as a per-atom count. The output is one number per task: a regression value, or a logit for each of several binary assays.

The task is hard for four reasons. Labelled sets are small: hundreds to tens of thousands of molecules, because every label is an experiment or a DFT calculation. Multi-task assay data has missing labels. Tiny structural edits can flip activity ("activity cliffs"). And the molecules a chemist wants scored next usually come from new chemical series, not the ones already measured.

Before GNNs the standard approach was a fixed **fingerprint** fed to a random forest or SVM. The most used is ECFP (extended-connectivity fingerprints, Rogers and Hahn, 2010), which hashes circular atom neighbourhoods of radius 2 or 3 into a bit vector. ECFP plus a random forest is still the baseline that every new model must beat.

## From molecule to prediction

Each atom gets a feature vector: element (one-hot), degree, formal charge, number of hydrogens, hybridisation, aromaticity, ring membership and chirality. Each bond gets its type (single, double, triple, aromatic), conjugation, ring membership and stereo. A GNN runs $T$ rounds of message passing (see **Message Passing Neural Networks (MPNN)**), a readout pools the atoms, and an MLP head outputs one value per task:

$$
\hat{\mathbf y}=\mathrm{MLP}\Big(\sum_{v\in G} h_v^T\Big)\in\mathbb R^{K},\qquad \mathcal L=\frac{1}{\sum_{i,k} m_{ik}}\sum_{i}\sum_{k=1}^{K} m_{ik}\,\mathrm{BCE}\big(y_{ik},\,\sigma(\hat y_{ik})\big)
$$

- $h_v^T$: state of atom $v$ after $T$ message-passing rounds; the sum may be replaced by a mean or set2set
- $K$: number of tasks, e.g. 12 assays in Tox21
- $m_{ik}$: 1 if molecule $i$ has a label for task $k$, else 0; missing labels contribute no loss

> Figure: Top: phenol (SMILES Oc1ccccc1) becomes a graph of 7 heavy atoms and 7 bonds. Each atom and bond carries a feature vector. A GNN encoder, a permutation-invariant readout and an MLP head give one output per task. Bottom: the scaffold split groups molecules by Bemis–Murcko scaffold and assigns whole groups, largest first, to train, then validation, then test. No test scaffold is ever seen in training.

Model choices are covered in their own articles. **Message Passing Neural Networks (MPNN)** were designed for QM9. The directed MPNN of Chemprop (Yang et al., 2019) passes messages along directed bonds and never sends a message straight back along the bond it arrived on. **Graph Isomorphism Network (GIN)** is the usual backbone for pre-training. On QM9, 3D models such as SchNet (Schütt et al., 2017) add interatomic distances. Energies depend on geometry, so this helps a lot there.

## Splits and metrics

A **random split** puts close analogues of each test molecule in the training set. It measures interpolation within known chemical series. A **scaffold split** removes side chains to get each molecule's Bemis–Murcko scaffold (Bemis and Murcko, 1996): its ring systems plus the linkers between them. It then sorts the scaffold groups by size and fills train (80%) with the largest groups, then validation (10%), then test (10%). The test set therefore holds rare, unseen scaffolds. This is harder and closer to prospective use.

$$
\mathrm{MAE}=\frac1n\sum_i|\hat y_i-y_i|,\qquad \mathrm{AUC}=\frac{1}{|P|\,|N|}\sum_{i\in P}\sum_{j\in N}\Big(\mathbb 1[s_i>s_j]+\tfrac12\,\mathbb 1[s_i=s_j]\Big)
$$

- $P,\ N$: labelled positives and negatives of one task; AUC is computed per task and then averaged
- $s_i$: predicted score of molecule $i$

For energies, "chemical accuracy" means an error below 1 kcal/mol (about 0.043 eV). For sparse, highly imbalanced assays such as PCBA, average precision is reported instead of ROC-AUC, because a ROC-AUC near 1 can hide poor precision on the rare actives.

Common benchmarks (MoleculeNet unless noted) with their standard metric and split

| Dataset | Molecules | Tasks | Target | Metric | Split |
| --- | --- | --- | --- | --- | --- |
| QM9 | 133,885 | 12 | DFT quantum properties | MAE | random |
| ESOL | 1,128 | 1 | aqueous solubility | RMSE | random |
| FreeSolv | 642 | 1 | hydration free energy | RMSE | random |
| Lipophilicity | 4,200 | 1 | octanol/water distribution | RMSE | random |
| Tox21 | 7,831 | 12 | toxicity assays | ROC-AUC | random |
| HIV | 41,127 | 1 | inhibits HIV replication | ROC-AUC | scaffold |
| BACE | 1,513 | 1 | BACE-1 inhibition | ROC-AUC | scaffold |
| ogbg-molpcba (OGB) | 437,929 | 128 | bioassays | AP | scaffold |
| ZINC subset | 12,000 | 1 | constrained solubility | MAE | fixed 10k/1k/1k |

> Figure: A synthetic library of 100 molecules in 20 scaffold families, scored by a 3-nearest-neighbour regressor on Tanimoto similarity. Default (random split, seed 1): all 20 test molecules have their scaffold in training, the mean similarity to the nearest training molecule is 0.66, and the test MAE is 0.70, against 1.50 for predicting the training mean. Over seeds 1–10 the random-split MAE ranges from 0.49 to 1.11. Switch to the scaffold split: the 20 test molecules come from 10 unseen scaffolds, the similarity drops to 0.25, and the MAE rises to 1.70. That is worse than the 0.94 of the training mean.

## Worked example: masked loss and per-task AUC

Six molecules, two assays (A, B); a dash marks a missing label

| Molecule | y_A | p_A | BCE_A | y_B | p_B | BCE_B |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | 1 | 0.90 | 0.105 | – | 0.30 | – |
| 2 | 0 | 0.20 | 0.223 | 1 | 0.80 | 0.223 |
| 3 | 1 | 0.60 | 0.511 | 0 | 0.40 | 0.511 |
| 4 | 0 | 0.70 | 1.204 | 0 | 0.20 | 0.223 |
| 5 | – | 0.50 | – | 1 | 0.35 | 1.050 |
| 6 | 0 | 0.10 | 0.105 | – | 0.60 | – |

1. Masked loss: 9 of 12 entries are labelled. Their BCE terms sum to 4.155, so $\mathcal L=4.155/9=0.462$. Predictions 0.50, 0.30 and 0.60 get no gradient.
2. AUC, task A: positives {0.90, 0.60}, negatives {0.20, 0.70, 0.10}. Of the 6 pairs, 5 rank the positive higher; only 0.60 < 0.70 fails. AUC = 5/6 = 0.833.
3. AUC, task B: positives {0.80, 0.35}, negatives {0.40, 0.20}. 3 of the 4 pairs are ordered correctly, since 0.35 < 0.40. AUC = 3/4 = 0.750.
4. The reported score is the mean over tasks: (0.833 + 0.750)/2 = 0.792.

```python
from collections import defaultdict
from rdkit.Chem.Scaffolds import MurckoScaffold

def scaffold_split(smiles, frac_train=0.8, frac_valid=0.1):
    groups = defaultdict(list)
    for i, s in enumerate(smiles):
        groups[MurckoScaffold.MurckoScaffoldSmiles(smiles=s, includeChirality=False)].append(i)
    fams = sorted(groups.values(), key=lambda g: (len(g), g[0]), reverse=True)   # largest first
    n = len(smiles)
    train, valid, test = [], [], []
    for g in fams:
        if len(train) + len(g) <= frac_train * n:
            train += g
        elif len(train) + len(valid) + len(g) <= (frac_train + frac_valid) * n:
            valid += g
        else:
            test += g
    return train, valid, test

smiles = ["Oc1ccccc1", "Cc1ccccc1", "Nc1ccccc1", "OC(=O)c1ccccc1",   # benzene scaffold
          "OC1CCCCC1", "Cc1cccnc1", "NC(Cc1c[nH]c2ccccc12)C(=O)O", "O=Cc1ccco1"]
print(scaffold_split(smiles))   # ([0, 1, 2, 3, 7, 6], [5], [4])
```

A Bemis–Murcko scaffold split with RDKit, using the same ordering rule as DeepChem's ScaffoldSplitter. Not run here, since RDKit was not available; the split logic was checked separately on these scaffold groups.

> **Random splits flatter the model:** With a random split, nearly every test molecule has a close analogue in training, so a model that only memorises series looks strong. The interactive figure shows the effect: the same model goes from 0.70 to 1.70 MAE when the scaffolds are held out. Report scaffold-split results (or time splits, where dates exist) for any claim about new chemistry. Average over several seeds, because results on sets of 1–4k molecules vary a lot from split to split.

**Strengths**

- GNNs learn task-specific substructure features instead of a fixed hash.
- One encoder can serve many tasks through a multi-task head with masked loss.
- Self-supervised pre-training on unlabelled molecules (Hu et al., ICLR 2020) helps on small datasets.

**Limitations**

- On small datasets, ECFP plus a random forest is often as good or better.
- 2D graphs ignore conformation, and 3D models need reliable geometries.
- Out-of-distribution generalisation to new scaffolds remains the main gap.

- **Virtual screening:** rank millions of purchasable compounds for activity before any are made
- **ADMET filters:** solubility, permeability, toxicity and metabolic stability flags in lead optimisation
- **DFT surrogates:** QM9-style models predict energies and orbital gaps far faster than the DFT calculation

**Question:** Why does a scaffold split usually give a lower score than a random split on the same dataset?

- A. It uses a smaller training set
- B. Test molecules have ring scaffolds absent from training, so close analogues cannot be memorised
- C. It changes the metric from ROC-AUC to MAE
- D. It removes hydrogens from the molecules

**Answer:** B. Test molecules have ring scaffolds absent from training, so close analogues cannot be memorised — Both splits are 80/10/10. The scaffold split puts whole scaffold groups on one side, so the model must extrapolate to new chemical series. A random split leaves analogues of the test molecules in training.

**Question:** In multi-task Tox21 training, how should missing assay labels be handled?

- A. Treat them as negatives
- B. Drop every molecule with any missing label
- C. Mask them out of the loss and out of each task's AUC
- D. Impute them with the task's mean label

**Answer:** C. Mask them out of the loss and out of each task's AUC — Untested is not inactive. The mask $m_{ik}$ removes those terms from the loss. AUC is computed per task on that task's labelled molecules only, then averaged.

**Key points**

- Molecule → RDKit graph (atom and bond features) → GNN → permutation-invariant readout → one output per task.
- Multi-task assays use a masked BCE: $\sum m_{ik}\,\mathrm{BCE}/\sum m_{ik}$. Regression uses MAE or RMSE; classification uses ROC-AUC, or AP when actives are rare.
- Benchmarks: QM9 (133,885 molecules), ESOL, FreeSolv, Lipophilicity, Tox21, HIV, BACE, OGB molhiv and molpcba, ZINC.
- A scaffold split groups by Bemis–Murcko scaffold and fills train with the largest groups, so test scaffolds are unseen.
- Random splits overstate accuracy for new chemistry. Average over seeds on small sets.
- ECFP plus a random forest is a strong baseline. 3D models such as SchNet matter for quantum targets.

---

From MLFoundry (https://www.mlfoundry.in). The web page adds interactive figures and diagrams.
