Atoms sit at arbitrary positions, a unit cell may hold 1 or 200 atoms, and the crystal repeats forever. A filter that slides over a fixed grid has nowhere to slide.
Shift the origin, rotate the axes or renumber the atoms: the file changes, the material does not. Lecture 3 showed that raw coordinates break these symmetries.
Why does a graph network give exactly the same energy when you renumber the atoms in a structure file, without ever being trained on renumbered copies?
Diamond and graphite are both pure carbon. Why can no composition-only model predict both band gaps, 5.5 and 0 eV?
Why must predicted forces turn when the crystal is rotated, while a predicted energy must not change at all?
Why can a graph network lose to a simple composition model on 500 structures, yet win clearly on 100 000?
| description | what the model sees | symmetries | features are… |
|---|---|---|---|
| Composition features (lecture 3) | element fractions, weighted means of elemental properties | invariant by construction | hand-made; blind to structure |
| Fixed structure descriptors (lecture 3) | radial distribution, Coulomb-matrix eigenvalues, SOAP | built into the formula | hand-made, fixed before training |
| Crystal graph + GNN (today) | atoms (nodes) and neighbour distances (edges) | built into the architecture | learned from the data |
It works in principle, but a rotation moves every voxel, fine grids are mostly empty space, and the periodic boundary must be handled by hand. A graph stores only what matters: who is next to whom, and how far.
Lecture 3 fixed the features first and then fitted a model. A graph neural network learns the features and the model together, while the symmetries stay exact.
The two matrices look different, but they describe the same three atoms. A model that reads the matrix as a flat list of numbers would give two answers. We need operations that do not care about the order: sums over neighbours and sums over atoms.
The weights wk trace a learned bond-strength curve. Beyond the last centre every ek ≈ 0: the model is blind there.
The crystal is infinite, but its graph is tiny: 2 nodes and 6 edges per Na. Periodicity lives in the edges, not in extra nodes.
| distance (Å) | neighbour | count | total |
|---|---|---|---|
| 2.82 | Cl | 6 | 6 |
| 3.99 | Na | 12 | 18 |
| 4.88 | Cl | 8 | 26 |
| 5.64 | Na | 6 | 32 |
| 6.31 | Cl | 24 | 56 |
Swap two neighbours: the sum is unchanged. An isolated atom gets no messages: hi stays as it was. The same Wf, Ws serve every atom, so a cell with 200 atoms needs no more weights than one with 2.
Given weights (scalar version of the last slide):
gate \(s_{ij} = \sigma(4u_{ij} - 2)\) · core \(c_{ij} = \text{ReLU}(0.5\,h_i + h_j)\)
ReLU instead of softplus keeps the arithmetic simple.
| atom | h before | h after one step |
|---|---|---|
| A | 1.0 | 2.119 |
| B | 0.5 | 1.601 |
| C | 1.5 | 1.709 |
C says more (core 2.0) but sits far away, so A gives it a small gate: A listens mostly to its close neighbour. In a trained network the weights, and so this preference, are learned from data.
| target | type | pooling |
|---|---|---|
| formation energy ΔHf (eV/atom), band gap Eg | intensive: per atom | mean |
| total energy of the cell (eV) | extensive: grows with size | sum |
A crystal described by a cell twice as large is the same material: its per-atom energy and its band gap must not change, and its total energy must double. The pooling choice encodes this physics. Summing per-atom energies, E = Σ Ei, is the starting point of next week's interatomic potentials.
| steps T | reach (Å) | atoms heard (3-D) |
|---|---|---|
| 1 | 2.82 | 7 |
| 2 | 5.64 | 25 |
| 3 | 8.46 | 63 |
| distances | energy E | force on atom 2 | |
|---|---|---|---|
| original | 1.200, 0.949, 1.273 | 0.0585 | (−0.393, 0.193) |
| rotated 40° | 1.200, 0.949, 1.273 | 0.0585 | (−0.425, −0.105) |
The energy belongs to the arrangement of atoms, not to the way we look at it. A force has a direction in space, so it must turn with the atoms. F = −∇E inherits that turning automatically.
Updates three kinds of features in turn: bonds, atoms and a global state vector for the whole crystal (for example temperature or pressure). Trained on Materials Project energies, band gaps and elastic moduli.
Builds a second graph, the line graph: every bond becomes a node, and two bonds that share an atom are joined by an edge carrying their angle. Messages alternate between the two graphs.
SchNet (Schütt et al., 2018): continuous distance filters, the same idea for molecules and crystals.
| formation energy ΔHf | band gap Eg (PBE) | |
|---|---|---|
| training data | several times 10⁴ (order 10⁵) DFT structures (Materials Project) | |
| spread of the labels | order of 1 eV/atom | 0 to about 8 eV, many metals at 0 |
| GNN test MAE (CGCNN, MEGNet, ALIGNN family) | about 0.02–0.04 eV/atom | about 0.2–0.4 eV |
| DFT versus experiment | about 0.1 eV/atom | PBE 25–80 % too small (lecture 1) |
Orders of magnitude and typical published values, rounded; exact numbers depend on dataset version and split.
The same task from composition alone (lecture 3 features, or ElemNet from lecture 9) typically gives a larger error and, by construction, one answer for all polymorphs of a formula. The graph adds what composition lacks: the structure.
The GNN now reproduces DFT more closely than DFT reproduces experiment. It learned the DFT label, bias included (lectures 1 and 6). For new chemistry, a random split hides polymorph and family leakage (lecture 6): expect larger errors on a grouped split.
A DFT calculation: hours of computer time. A trained GNN: milliseconds per structure. Screening millions of hypothetical crystals becomes possible, as long as they resemble the training data.
| diamond | graphite | |
|---|---|---|
| neighbours within 2 Å | 4, at 1.54 Å (109.5°) | 3, at 1.42 Å (120°) |
| band gap | 5.47 eV | 0 (semimetal) |
| enthalpy above graphite | +0.020 eV/atom | 0 |
The energy difference, 0.02 eV/atom (1.9 kJ/mol), is smaller than a typical GNN error of about 0.03 eV/atom. Seeing the structure is necessary, not sufficient, to rank close polymorphs.
Simulated learning curves with shapes like published ones (seeded; 5 % scatter).
Composition model: floor near 0.06 eV/atom (the structure it never sees); the GNN wins beyond about 8 000. The crossover is problem-dependent (about 500 in lecture 9): draw your own.
For comparison, the error of an average falls like N−1/2 (lecture 6): α = 0.5. Learning a whole function of structure is harder, so α is smaller. When data are the bottleneck, better labels, a better architecture or extra physics (bond angles, as in ALIGNN) may pay more than more of the same data.
import torch, numpy as np; nn = torch.nn from matminer.datasets import load_dataset df = load_dataset("matbench_mp_e_form").sample(4000, random_state=0) MU = np.arange(0, 5.0, 0.2) # Gaussian centres (Å) def to_graph(s, rc=5.0): i, j, _, d = s.get_neighbor_list(rc) # periodic images included e = np.exp(-((d[:, None] - MU) / 0.2) ** 2) z = torch.tensor([site.specie.Z for site in s]) return z, torch.tensor(np.array([i, j])), torch.tensor(e).float() class Conv(nn.Module): # one CGCNN step def __init__(self, F, E): super().__init__(); self.lin = nn.Linear(2 * F + E, 2 * F) def forward(self, h, ij, e): i, j = ij gate, core = self.lin(torch.cat([h[i], h[j], e], 1)).chunk(2, 1) m = torch.sigmoid(gate) * nn.functional.softplus(core) return h + torch.zeros_like(h).index_add(0, i, m) emb, head = nn.Embedding(100, 64), nn.Linear(64, 1) convs = nn.ModuleList([Conv(64, len(MU)) for _ in range(3)]) def predict(z, ij, e): h = emb(z) for conv in convs: h = conv(h, ij, e) return head(h.mean(0)) # mean pooling: eV/atom
Colab, CPU only. Notebook and training loop posted with this lecture.
Every step uses the same weights for every atom and sums over neighbours, so renumbering only reorders the atom features; the pooled mean is then unchanged. Invariance is built in, not learned.
Both have the input "C", so a composition model gives one answer: at best an MAE of 2.74 eV on the pair. A graph sees 4 versus 3 neighbours at different distances and angles.
Energy is a scalar: invariant. Forces are vectors: F(Rx) = R F(x). A distance-only network cannot turn its output; take F = −∇E, and add equivariant layers to describe directions better.
A GNN learns its features, so it needs data; its error keeps falling as N−α. A composition model learns fast but stops at the structure floor. In our curves they cross near 8 000 structures.
Lab 11: a crystal graph network in PyTorch. Problem set 3 (weeks 9–10) is due this week; problem set 4 (weeks 11–12) is due in week 13. Project progress check next week.
From one energy per crystal to energies and forces for every configuration: F = −∇E derived, locality E = Σ Ei, equivariant and universal potentials, and molecular dynamics that measures diffusion in a solid electrolyte.
All schematics and plots were drawn for this course. Rock-salt shells use a = 5.64 Å. The three-atom message-passing graph and the spring model are toy examples; the learning curves are simulated (seeded; script posted with Lab 11). Materials Project error levels are typical published values, rounded, given as orders of magnitude. Diamond–graphite enthalpy 1.9 kJ/mol; diamond band gap 5.47 eV.