AI for Materials Science · Lecture 10 (Complete Beginner-to-Research Edition)
Graph Neural Networks & Machine Learning Interatomic Potentials:
Molecular GNNs, Chemprop D-MPNN, Crystal CGCNN & Equivariant MLIPs
Zesheng Liu
Laboratory of Organic Electronics, Linköping University
Modules 10a–10c | 50-Line PyTorch GNN, Full-Course AqSolDB Leaderboard, CGCNN & Energy-Conserving MD
Lecture 10 roadmap: from molecular graphs to universal potentials
Unifying the entire semester's themes—inductive bias, symmetry, extrapolation, and physical conservation (
10a–10c)PART 1 · MODULE 10a
50-Line Molecular GNN
Representing molecules as (x, edge_index) graphs, message passing with index_add_, permutation invariance, Sum vs. Mean readout, and acene extrapolation.
PART 2 · MODULE 10b
Chemprop & Course Finale
Directed bond message passing (D-MPNN) avoiding tottering echoes, one-line CLI training on the exact same AqSolDB split, and our full-course model leaderboard.
PART 3 · MODULE 10c
Crystal CGCNN & MLIPs
Periodic crystal multi-graphs & Gaussian radial basis (GBF), gated CGCNN invariance, autograd conservative forces (F = −∇E) in NVE MD, and MACE equivariant potentials.
Graphs are the native data structure of matter—encoding atoms, bonds, and physical symmetries directly into neural network message passing.
Message passing: a GNN is a learnable Morgan fingerprint
Each GNN layer expands an atom's receptive field by one bond hop—turning local neighborhoods into end-to-end learned embeddings
Just like Morgan fingerprint radius r = 2 hashes 2-hop neighborhoods, an L-layer GNN aggregates L-hop chemical environments—with learnable PyTorch weights!
Zero magic: a complete PyTorch GNN layer in 8 lines
No PyG black boxes required—
index_add_ gives exact, permutation-invariant neighborhood aggregation1
msg = self.W_msg(torch.cat([h[src], h[dst], e_attr], -1))
Compute one message vector per directed bond from neighbor atom + bond features.
2
agg.index_add_(0, src, msg)
Sum all incoming bond messages per atom—guaranteed permutation invariant!
3
h_mol = global_sum_pool(h, batch_idx)
Batching multiple molecules = one big disconnected graph +
batch_idx vector.SYMMETRY BUILT IN
Why Graphs Beat SMILES Strings
- No arbitrary atom numbering: Shuffling atom indices produces the exact same output (diff = 0).
- No syntax errors: Bonds and ring closures are explicit edges, never fragile parentheses.
- Determinism note: Enable
torch.use_deterministic_algorithms(True)for reproducibleindex_add_!
A GNN is simply repeated 'gather neighbor messages -> permutation-invariant sum -> MLP update', followed by graph readout.
Closing Lecture 02's acene cliffhanger: Sum Readout extrapolates!
Random Forests flatline on unseen pentacene; a Sum-Readout GNN naturally continues the physical hydrophobicity trend
Readout physics matters: Sum Readout preserves extensive molecular size (enabling size extrapolation), whereas Mean Readout throws away atom count!
Chemprop D-MPNN: directed bond messages eliminate tottering
Standard atom-based MPNNs bounce messages back and forth across the same bond; D-MPNN updates directed bond states instead
Chemprop (Yang et al., JCIM 2019) is the industry-standard molecular property GNN—requiring just one CLI command (chemprop train) with scaffold splits.
Full-course AqSolDB leaderboard (identical 1,896-molecule test set)
Every model from Lectures 02, 07, and 10 evaluated head-to-head on the exact same test split
End-to-end graph learning (RMSE 1.04–1.05) decisively beats both 17-descriptor MLPs (1.17) and descriptor+fingerprint Random Forests (1.11)!
GNN oversmoothing & the Cell 2020 Halicin discovery funnel
Why 3–5 message-passing layers hit the sweet spot—and how Chemprop united our entire course toolkit to discover a novel antibiotic
Deep vanilla GNNs blur all atoms together (oversmoothing); pairing a 3–5 layer D-MPNN with RDKit descriptors, BO & Tanimoto < 0.4 filtering unlocked Halicin!
From molecules to periodic crystals: Multi-Graphs & GBF distances
Inorganic crystals have no discrete covalent bonds—edges connect periodic neighbor images weighted by Gaussian radial basis functions
Expanding interatomic distances d_ij into K smooth Gaussian basis functions gives CGCNN sub-0.05 Å sensitivity while preserving exact E(3) translation & rotation invariance.
Machine Learning Potentials (MLIPs): autograd forces conserve energy!
Predict scalar total energy E(R) with smooth activations (
SiLU), then compute Fi = −∂E/∂Ri via torch.autograd.gradNever predict MD forces directly—differentiating a smooth scalar energy network guarantees a curl-free conservative force field and stable NVE trajectories!
The MLIP frontier: E(3)-equivariant universal potentials (MACE / CHGNet)
Retaining directional tensor features (spherical harmonics Ylm) delivers near-DFT accuracy at 10,000× speed across the periodic table
Pre-trained universal MLIPs (MACE-MP-0, MatterSim, SevenNet) plug directly into ASE—turning hours of DFT crystal relaxation into milliseconds on a laptop.
Summary (Take home notes)
- Graphs match the physics of matter: Molecular GNNs learn end-to-end representations directly from atoms & bonds, with built-in permutation invariance.
- Readout & directed edges matter: Sum Readout unlocks size extrapolation (acenes), and Chemprop's D-MPNN removes tottering—achieving our best AqSolDB RMSE (1.04–1.05).
- Periodic crystals need multi-graphs + GBF: CGCNN encodes periodic boundary images and continuous distances, preserving translation, rotation, and supercell invariance.
- Conservative MLIPs via autograd: Differentiating a smooth scalar energy network (F = −∇E) with Force Matching ensures strict NVE MD energy conservation.
- Universal equivariant MLIPs are here: MACE and CHGNet bring near-DFT accuracy at O(N) speed across the entire periodic table.
Thanks for your listening
Zesheng Liu · zesheng.liu@liu.se
AI for Materials Science · Lecture 10 | Final Practice:
10d_exercises.ipynb · Wishing you great discoveries in Materials AI!