Graph Neural Networks for Molecules Explained
10 min read · updated August 11, 2026
A molecule is already a graph. Atoms are nodes, bonds are edges, and every property a chemist reasons about is a statement about local environments and how they connect. A graph neural network is the model class that consumes that object without flattening it first.
Why the graph is the natural object
The alternatives all lose something specific. A SMILES string imposes an arbitrary traversal order, so a sequence model must learn that CC(=O)O and OC(C)=O are the same molecule — a symmetry that is free in a graph and expensive in a sequence. A fingerprint fixes the notion of “local environment” in advance, at a radius you chose, with a hash you cannot invert. A graph network keeps the adjacency and learns the environment function instead.
The correspondence goes further than convenience. Chemical intuition is local: an ester behaves like an ester largely regardless of what is on the far side of the molecule, and the exceptions — conjugation, steric hindrance, intramolecular hydrogen bonding — are exactly the cases where information has to travel further along the graph. A model whose depth controls how far information travels is a model whose main hyperparameter means something chemical.
What goes into a node and an edge
Node features are hand-specified and shorter than people expect. A typical set: atomic number as a one-hot vector over the elements that occur in your data, degree, formal charge, number of attached hydrogens, hybridisation, aromatic flag, ring-membership flag, chiral tag, and mass scaled down to keep magnitudes comparable. Edge features: bond order, conjugation flag, ring flag, and the stereo descriptor for double bonds.
None of this is learned, and the choice matters. Omit the chiral tag and your model cannot distinguish enantiomers, exactly as an unchiral Morgan fingerprint cannot. Omit the ring flag and the network has to infer ring membership from connectivity, which it is provably bad at.
Worked: one atom over three rounds
Take the carbonyl carbon of acetic acid, CC(=O)O. Its neighbours are the methyl carbon, the carbonyl oxygen and the hydroxyl oxygen.
round 0 h(C2) = features(C2)
= [C, degree 3, charge 0, 0 H, sp2, not aromatic, not in ring, ...]
the atom knows only itself
round 1 m(C2) = AGGREGATE over neighbours of MESSAGE(h(nbr), h(edge))
h(C2) = UPDATE(h(C2), m(C2))
C2 now encodes: an sp2 carbon bonded to a methyl,
a double-bonded O and a single-bonded O -> a carboxyl carbon
round 2 the same step again, but neighbours' vectors already
summarise their own neighbours
C2 now encodes the whole 2-bond environment, including
the three hydrogens implied on the methyl carbon
round 3 C2 sees the entire molecule; acetic acid has only 4 heavy atoms,
so further rounds add no new information and begin to mix
every atom's vector toward the same valueThis is the same neighbourhood-expansion idea as the Morgan iteration, with two differences that matter. The aggregation is a learned differentiable function rather than a hash, so chemically similar environments can land near each other instead of on unrelated bits. And the whole thing is trained end to end against your label, so the notion of “similar environment” is defined by the property you care about.
The formalism was unified by Justin Gilmer and colleagues in “Neural Message Passing for Quantum Chemistry” (2017), which showed that several then-current molecular architectures were the same message-passing skeleton with different message, update and readout functions. A widely used variant, the directed MPNN behind Chemprop, passes messages along directed bonds rather than atoms so that a message cannot immediately return down the bond it arrived on; Kevin Yang and colleagues describe it in “Analyzing Learned Molecular Representations for Property Prediction” (2019).
Readout, and why pooling choice matters
After the message-passing rounds you have one vector per atom and need one vector per molecule. The readout is usually a sum, a mean, or a learned attention-weighted pool.
Sum and mean are not interchangeable, and the distinction is physical. An extensive property scales with molecular size — atomisation energy, molar refractivity — and sum pooling can represent that because a bigger molecule contributes more terms. An intensive property does not scale — a pKa, a melting point — and mean pooling gives the model a size-invariant starting point. Choosing sum for an intensive target means the network must spend capacity learning to divide by atom count, and it will do so imperfectly on molecules larger than anything in training.
Why more layers make it worse
Two independent limits bite, and both show up around the same depth.
The first is oversmoothing. Each round replaces an atom’s vector with a function of its neighbours’ vectors, which is a smoothing operation on the graph. Iterated enough times, all node representations converge toward a common value determined by the graph’s structure rather than by the individual atom — Qimai Li, Zhichao Han and Xiao-Ming Wu analysed this for graph convolutional networks in “Deeper Insights into Graph Convolutional Networks for Semi-Supervised Learning” (2018). The atoms become indistinguishable, and a network that cannot tell its atoms apart cannot tell a carbonyl from an ether.
The second is that molecules are small. A drug-like molecule has roughly 20 to 40 heavy atoms and a graph diameter often under 15 bonds. Three to six rounds already reach most of the molecule from most starting atoms; beyond that there is nothing left to propagate. This is why molecular GNNs are shallow while image networks are deep, and why adding layers is almost never the fix for underfitting here.
There is a third limit that depth does not touch at all. Standard message passing is bounded above by the one-dimensional Weisfeiler-Lehman graph isomorphism test, shown by Keyulu Xu and colleagues in “How Powerful are Graph Neural Networks?” (2019). Practically, that means it cannot count cycles: there exist pairs of distinct molecular graphs with identical WL colourings that no amount of message passing distinguishes. The standard remedy is not a deeper network but better input features — explicit ring-size flags, substructure counts, or a small fingerprint concatenated to the pooled vector.
When a fingerprint still wins
On small datasets — and most experimental chemistry datasets are small, a few hundred to a few thousand measurements — a gradient boosted model on Morgan fingerprints and a handful of physicochemical descriptors is a serious baseline that graph networks frequently fail to beat. It has no representation to learn, so it spends all its data on the structure-property relationship.
Graph networks pull ahead when there is enough data to learn a representation, when the label is something the fixed representation genuinely cannot express, or when you want to transfer a pretrained encoder across related tasks. Run the fingerprint baseline first, with the same scaffold split and error metric you intend to report; a graph network that beats it on a random split and loses on a scaffold split has learned your dataset, not your chemistry.