Ismail Ben Alla

GNN Molecular

Seven GNNs for Molecular Properties

Research · Oct 2024 · Completed

Comparing seven graph neural networks at predicting how well molecules dissolve.

Built withPyTorchPyTorch GeometricRDKitMoleculeNet (ESOL)pytest

GNN Molecular — overview

Overview

A molecule is naturally a graph: atoms are nodes and bonds are edges. I wanted to see how different graph neural network designs use that structure to predict a real chemical property, aqueous solubility, from the MoleculeNet ESOL benchmark.

I first implemented three architectures by hand in notebooks: a graph convolutional network (GCN), a message-passing neural network (MPNN) that also uses bond features, and a diffusion-convolutional network (DCNN) that spreads information over several hops. I later turned them into a tested Python package and added four standard models built from PyTorch Geometric layers: GIN, GAT (v2), GraphSAGE and AttentiveFP.

All seven run on the same seeded split with the same metrics. AttentiveFP (test RMSE 0.498, R² 0.926) and GIN (0.528, 0.916) lead, followed by the MPNN (0.645), GAT (0.769), GraphSAGE (0.816), DCNN (0.907) and GCN (0.981). The four models that read bond types come out ahead of the three that only see atoms.

The question

How do seven graph neural network designs compare at predicting molecular solubility (ESOL) directly from molecular graphs?

Key features

How it works

  1. Molecules to graphs

    ESOL molecules are loaded from MoleculeNet and represented as graphs of atoms and bonds, with molecules that contain isolated atoms filtered out where needed.

  2. Batch the graphs

    PyTorch Geometric merges many small molecular graphs into one disconnected graph per batch and keeps track of which atom belongs to which molecule.

  3. Propagate information

    Each architecture updates atom representations in its own way: graph convolution, learned messages over bonds, multi-hop diffusion, sum-and-MLP (GIN), attention over neighbours (GAT, AttentiveFP) or separate self and neighbour weights (GraphSAGE).

  4. Pool and predict

    Atom representations are pooled into one vector per molecule, which a regression head maps to a solubility value, trained with mean squared error.

Examples

AttentiveFP, the best of the seven: the best-validation checkpoint (epoch 222) scores test RMSE 0.498 and R² 0.926.
AttentiveFP, the best of the seven: the best-validation checkpoint (epoch 222) scores test RMSE 0.498 and R² 0.926.
GIN with bond features: test RMSE 0.528 and R² 0.916, close to AttentiveFP with 25 times fewer parameters.
GIN with bond features: test RMSE 0.528 and R² 0.916, close to AttentiveFP with 25 times fewer parameters.
MPNN training (left) and validation (right) metrics on ESOL. The best-validation checkpoint (epoch 195) scores test RMSE 0.645 and R² 0.875.
MPNN training (left) and validation (right) metrics on ESOL. The best-validation checkpoint (epoch 195) scores test RMSE 0.645 and R² 0.875.
The first ESOL molecule (amygdalin), rendered with RDKit: 32 atoms become 32 graph nodes with 9 features each.
The first ESOL molecule (amygdalin), rendered with RDKit: 32 atoms become 32 graph nodes with 9 features each.

Input

mgnn-predict --checkpoint checkpoints/mpnn/best.pt "CCO" "c1ccccc1"

Output

1.195 log(mol/L) CCO -1.633 log(mol/L) c1ccccc1

Real output of the trained MPNN for ethanol and benzene. Their measured values are 1.10 and -1.64; both molecules are part of ESOL, so this shows the tool working, not generalisation.

Tech stack

What I learned

Limitations

Keywords

graph neural networks · GNN · GCN · graph convolutional network · MPNN · message passing neural network · DCNN · AttentiveFP · GraphSAGE · graph attention network · GAT · graph isomorphism network · GIN · diffusion convolutional neural network · PyTorch Geometric · PyTorch · RDKit · cheminformatics · molecular property prediction · molecular graphs · SMILES · MoleculeNet · ESOL · aqueous solubility prediction · drug discovery · deep learning