Search

Search papers and lessons

Directional Message Passing for Molecular Graphs

Johannes Gasteiger, Janek Groß, Stephan Günnemann · 2020

DimeNet predicts molecular energies and forces by passing messages between pairs of atoms and using the angles between bonds, not only the distances, and it beats earlier graph networks on QM9 and MD17.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Classical mechanics
  • Linear algebra
  • Architectures
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

DimeNet is a graph neural network that predicts molecular properties such as energy from the three-dimensional positions of the atoms. Earlier graph networks only saw the distance between each pair of bonded atoms, so two molecules with the same bond lengths but different bond angles looked the same to them. DimeNet passes messages along pairs of bonds and mixes in the angle between them, using a basis built from spherical Bessel functions and spherical harmonics. On the QM9 benchmark it set the state of the art on 11 of 12 targets, and on MD17 it outperformed earlier graph networks by 76% on average.

Builds on: Message Passing Neural Network, Equivariance, Spherical Harmonics, Radial Basis Function, Bessel Function · Leads to: no dependents in the graph yet

Why it mattered

Predicting a molecule's energy from its atoms used to mean expensive quantum calculations. Machine learning models that learn from examples are fast, and they had started to replace those calculations for simulation and screening. The paper calls the rise of graph neural networks a small revolution, because they learn their own features from atom types and coordinates, with no hand-made descriptors.

DimeNet mattered because it fixed a specific blind spot. Standard graph networks depend only on distances, which keeps them invariant to rotation, translation and reflection, and those are necessary physical properties. But the classical description of a molecule's energy also has terms for bond angles and for rotations around bonds, and a distance-only model can capture those only indirectly, through many layers of higher-order interaction. DimeNet models the angles directly. The paper also gives a physically motivated way to represent distances and angles, which uses fewer parameters than the Gaussian functions the field had been using.

The model is also built for simulation, not only for static predictions. It is twice continuously differentiable, which means the forces on the atoms can be taken as the gradient of its energy. That makes it usable in molecular dynamics, where the forces drive the motion of the atoms over time.

The problem

Classical molecular models write a molecule's energy as a sum of four parts: bond stretching, bond angles, rotation around bonds, and interactions between atoms that are not bonded. A standard graph neural network updates each atom from its neighbours' states, and each message depends on the pairwise distance. That is enough to get the first and fourth parts roughly right. The second and third parts depend on directions, and the network can get them only by stacking many layers.

The paper gives a concrete failure case. Take a hexagonal molecule, such as cyclohexane, and two triangular molecules, such as cyclopropane, with the same bond lengths. At a cutoff of about 2 Å, every atom in each has exactly the same neighbourhood of distances, so a distance-only graph network cannot tell them apart. The angles differ, and the angles are what the network needs.

Simply adding direction is not straightforward. Filters applied in fixed global directions, as in equivariant convolutional networks, only respect a discrete set of rotations, and local coordinate frames per atom break permutation invariance. The paper needs a representation that keeps the rotational and permutation symmetries the physics requires, is smooth enough for forces, and does not blow up the parameter count. The solution has three parts: messages attached to directed bonds, a joint basis for distance and angle, and an envelope that makes the cutoff smooth.

How it works

Here is one tiny case, followed from input to output. Take three atoms A, B and C in a chain, where A and B are bonded and B and C are bonded, and both bonds are 1 Å long. Place them in two shapes: a straight chain, with the angle at B equal to 180°, and a bent chain, with the angle at B equal to 90°. A distance-only network sees the same numbers for both. DimeNet should give them different predictions.

flowchart LR
  A[Atom positions and types] --> B[Embedding block: a message on each directed bond]
  B --> C[Interaction block: update each message from messages on neighbouring bonds]
  C --> D[Angle and distance mixed into one joint basis]
  C --> E[Output block: sum messages per atom]
  E --> F[Energy: sum over atoms and layers]
  F --> G[Forces: gradient of the energy]
  1. Start from positions and atom types. Each atom has a type, such as carbon or oxygen, and a position. Atoms within a cutoff distance of 5 Å are connected. Check: in the example, A, B and C are all within the cutoff of one another, so every pair is connected.

  2. Give each directed bond a distance representation. The distance d between two atoms is expanded into a fixed set of basis values, using spherical Bessel functions, so the network sees a smooth description of how far apart they are. Check: 1 Å in the example gives the same basis values in both shapes, because the bond lengths match.

  3. Create a message on each directed bond. A message m_ji travels from atom j to atom i. It is built from the two atom types and the distance representation. In the example there are four directed bonds: A to B, B to A, B to C and C to B. Check: there are four messages, one per direction of each bond.

  4. Gather the messages that reach the bond's start. To update the message from B to A, DimeNet collects the messages that arrive at B from its other neighbours, here the message from C to B. It does not use the message from A itself. Check: the update for B to A uses exactly one incoming message, the one from C.

  5. Measure the angle between the two bonds. The angle at B, between the bond to C and the bond to A, is the quantity a distance-only model does not see. In the straight chain it is 180°, and in the bent chain it is 90°. Check: the two shapes have different angles and identical distances.

  6. Mix distance and angle into one basis, then update the message. The distance of the incoming bond and the angle are combined into one joint basis. A learned filter applies that basis to the incoming message, and the result is added to the message from B to A. Check: the two shapes now produce different updates to the same message.

  7. Read out energy and forces. After several interaction blocks, each atom sums the messages that arrive at it, and a small network turns each atom's sum into a number. The energy is the sum over atoms. The forces on the atoms are the negative gradient of the energy with respect to their positions. Check: the forces are not a separate output; they come from the same energy, so they are consistent with it.

The math

The baseline: messages on atoms

A standard graph network updates each atom's state hi\mathbf{h}_i from its neighbours, through an interaction function fintf_{\text{int}} and an update function fupdatef_{\text{update}}:

hi(l+1)=fupdate(hi(l),∑j∈Nifint(hj(l),e(ij)(l))).\mathbf{h}_i^{(l+1)} = f_{\text{update}}\left(\mathbf{h}_i^{(l)}, \sum_{j \in \mathcal{N}_i} f_{\text{int}}\left(\mathbf{h}_j^{(l)}, \mathbf{e}_{(ij)}^{(l)}\right)\right).

Here Ni\mathcal{N}_i is the set of neighbours of atom ii, and e(ij)\mathbf{e}_{(ij)} is an edge embedding that usually depends only on distance. The Message Passing Neural Network framework is this recipe in general form.

Step 3 in symbols: messages on directed bonds

DimeNet keeps a message mji\mathbf{m}_{ji} on each directed bond, and updates it from messages arriving at jj, except the one from ii:

mji(l+1)=fupdate(mji(l),∑k∈Nj∖{i}fint(mkj(l),eRBF(ji),aSBF(kj,ji))).\mathbf{m}_{ji}^{(l+1)} = f_{\text{update}}\left(\mathbf{m}_{ji}^{(l)}, \sum_{k \in \mathcal{N}_j \setminus \{i\}} f_{\text{int}}\left(\mathbf{m}_{kj}^{(l)}, \mathbf{e}_{\text{RBF}}^{(ji)}, \mathbf{a}_{\text{SBF}}^{(kj,ji)}\right)\right).

Here eRBF(ji)\mathbf{e}_{\text{RBF}}^{(ji)} is the distance representation of the bond jiji, and aSBF(kj,ji)\mathbf{a}_{\text{SBF}}^{(kj,ji)} is the joint distance-and-angle representation of the pair of bonds kjkj and jiji. The angle is α(kj,ji)=∠xkxjxi\alpha_{(kj,ji)} = \angle \mathbf{x}_k \mathbf{x}_j \mathbf{x}_i, the angle at atom jj between atoms kk and ii. Atom states are recovered by summing the messages that arrive at each atom: hi=∑jmji\mathbf{h}_i = \sum_j \mathbf{m}_{ji}.

Step 2 in symbols: the radial basis

For a distance dd between two atoms, with cutoff cc and frequency index nn, the basis is

e~RBF,n(d)=2c⋅sin⁡(nπcd)d.\tilde{e}_{\text{RBF},n}(d) = \sqrt{\frac{2}{c}} \cdot \frac{\sin\left(\frac{n\pi}{c} d\right)}{d}.

These functions are orthogonal on the interval up to the cutoff. The paper argues that this reduces redundancy, so it needs 16 of them where PhysNet uses 64 Gaussians and SchNet uses 300.

Step 5 and 6 in symbols: the joint angle-distance basis

The joint basis for a distance dd and an angle α\alpha comes from separating variables in the Schrödinger-type equation for a particle in a sphere of radius cc. It is built from spherical Bessel functions jlj_l and spherical harmonics Yl0Y_l^0:

a~SBF,ln(d,α)=2c3jl+12(zln)  jl(zlncd)Yl0(α),\tilde{a}_{\text{SBF},ln}(d,\alpha) = \sqrt{\frac{2}{c^{3} j_{l+1}^{2}(z_{ln})}} \; j_l\left(\frac{z_{ln}}{c} d\right) Y_l^{0}(\alpha),

where zlnz_{ln} is the nnth root of the order-ll Bessel function. The index ll runs over the angular frequencies and nn over the radial ones.

Making the cutoff smooth

A sharp cutoff would make the energy jump when an atom crosses it, so the forces would be undefined there. The paper multiplies each basis function by an envelope u(d)u(d) that goes to zero at the cutoff, with its first and second derivatives:

u(d)=1−(p+1)(p+2)2dp+p(p+2)dp+1−p(p+1)2dp+2.u(d) = 1 - \frac{(p+1)(p+2)}{2} d^{p} + p(p+2) d^{p+1} - \frac{p(p+1)}{2} d^{p+2}.

Here dd is the distance divided by the cutoff, so d=1d = 1 is the cutoff itself. The paper uses p=6p = 6, and the envelope is what makes the model twice continuously differentiable.

Forces and the training loss

The forces are the negative gradient of the predicted energy with respect to each atom's coordinates:

Fi=−∂∂xifθ(X,z).\mathbf{F}_i = -\frac{\partial}{\partial \mathbf{x}_i} f_{\theta}(\mathbf{X}, \mathbf{z}).

For molecular dynamics the loss combines the energy error with the force error, weighted by ρ\rho:

LMD=∣fθ(X,z)−E^∣+ρ3N∑i=1N∑α=13∣−∂fθ∂xiα−F^iα∣.\mathcal{L}_{\text{MD}} = \left|f_{\theta}(\mathbf{X}, \mathbf{z}) - \hat{E}\right| + \frac{\rho}{3N} \sum_{i=1}^{N} \sum_{\alpha=1}^{3} \left| -\frac{\partial f_{\theta}}{\partial x_{i\alpha}} - \hat{F}_{i\alpha} \right|.

Here NN is the number of atoms, E^\hat{E} and F^\hat{F} are the reference energy and forces, and α\alpha indexes the three coordinates. The paper sets the force weight ρ\rho high, because the forces drive the simulated dynamics.

Worked examples

Example
1. The same bond lengths, two angles
  1. Put atom B at the origin: B = (0, 0, 0). Put A at (−1, 0, 0) so the bond from B to A has length 1.
  2. Straight chain: put C at (1, 0, 0). The bond from B to C has length 1, and the vectors from B are BA = (−1, 0, 0) and BC = (1, 0, 0).
  3. The cosine of the angle is their dot product over the product of their lengths: (−1 × 1 + 0 + 0) / (1 × 1) = −1. The angle is 180°.
  4. Bent chain: put C at (0, 1, 0). The bond from B to C still has length 1. The vectors are BA = (−1, 0, 0) and BC = (0, 1, 0).
  5. The dot product is 0, so the cosine is 0 and the angle is 90°.
  6. Interpretation: both shapes have bond lengths of exactly 1 Å, so any model that sees only distances gives them the same input. The angle is the one number that separates them, and DimeNet's angle basis carries that number into the message update.
Example
2. Evaluating the radial basis at one distance

Use a cutoff c = 5 Å and a distance d = 1 Å, and evaluate the first two basis functions.

  1. For n = 1: the prefactor is √(2/5) ≈ 0.6325. The sine argument is π × 1 / 5 = 36°, and sin 36° ≈ 0.5878.
  2. Multiply and divide by d = 1: 0.6325 × 0.5878 ≈ 0.372.
  3. For n = 2: the sine argument is 2π / 5 = 72°, and sin 72° ≈ 0.9511.
  4. Multiply: 0.6325 × 0.9511 ≈ 0.602.
  5. Interpretation: the two basis values are 0.372 and 0.602 at the same distance. Together they describe the distance from two frequencies, and higher n would add finer detail. The paper finds that a few such functions are enough.
Example
3. A realistic comparison on QM9, with the last step left to you

The QM9 table reports the mean absolute error for each target. For the energy gap Δε, the second-best model, PhysNet, has an error of 42.5 meV, and DimeNet has 34.8 meV.

  1. The absolute improvement is 42.5 − 34.8 = 7.7 meV.
  2. The relative improvement is that gap divided by the old error: 7.7 / 42.5.
  3. Work out the quotient: 7.7 / 42.5 is about 0.181.
  4. Interpretation: the gain is real but not uniform. Relative improvements vary across targets, and the paper's headline figure of 31% is a mean over the targets of errors that were first standardised by each target's own spread.
  5. Try it: a reader compares the HOMO energy error, which is 32.9 meV for PhysNet and 27.8 meV for DimeNet. What is the relative improvement? Answer: (32.9 − 27.8) / 32.9 = 5.1 / 32.9, about 15.5%.

Results

The numbers below come from the paper's text and its QM9 table.

QM9. The benchmark has about 130,000 small molecules with up to nine heavy atoms of C, O, N and F. The paper trains on 110,000, validates on 10,000 and tests on 10,831. DimeNet sets the state of the art on 11 of the 12 targets. Its mean standardised error is 31% lower than the second-best model, and its mean standardised log error is 0.22 lower. On individual targets, DimeNet's energy error for U0 is 8.02 meV, against 8.15 for PhysNet and 14 for SchNet. Its dipole-moment error is 0.0286 D, against 0.033 for SchNet.

MD17. This benchmark asks for energies and atomic forces of eight small organic molecules, with one model per molecule. The paper says DimeNet matches the best published results on the standard setup, and that the remaining error is far below the error of the reference DFT calculations, so the benchmark is near its limit. On a harder setup with only 1,000 training samples, DimeNet beats SchNet by a large margin and is roughly on par with sGDML, a method with hand-made descriptors.

Headline. On average DimeNet outperforms previous graph networks by 76% on MD17 and by 31% on QM9.

Ablations. The paper removes one piece at a time. Using 64 Gaussian functions in place of the 16 radial and 6 Bessel functions raises the error by about 10%. Setting the number of angular functions to one, so that angles are ignored, raises it by about 26%. Using node embeddings in place of message embeddings, which drops the directional information entirely, raises the error by about 68%, and then DimeNet is worse than SchNet. Both the directional scheme and the basis contribute, and removing the directional messages hurts most.

Learned filters. The paper shows that some learned filters respond to distance and angle in ways that match chemistry, for example to the 120° angle and 1.39 Å spacing of a benzene ring.

Limits. The model needs atomic positions, so it does not apply to a molecular graph alone. The paper's experiments are on molecules of up to about nine heavy atoms and on small organic molecules, and the authors note that the remaining terms of the classical energy, torsions and non-bonded interactions, are left for future work. Accuracy on MD17 is limited by the reference calculations, not the model. Each message aggregates over pairs of bonds, so each step costs more than a distance-only layer.

Reading guide

The paper runs in eight parts. Each one leans on the lessons below.

Check yourself

QuestionWhy can a distance-only graph network fail to tell apart two molecules with identical bond lengths?Show answer

Distance-only messages depend only on how far apart bonded atoms are. If two molecules have the same bond lengths and the same neighbour structure, every message is the same, so the network produces identical features. The difference lies in the angles between bonds, which a distance-only model does not use.

QuestionTwo bonds are 1 Å long and the angle between them at the shared atom is 60°. What is the cosine of that angle, and what does the cosine mean for the basis?Show answer

The cosine of 60° is 0.5. For the case m = 0 used here, the spherical harmonic Y_l^0(α) is a polynomial in the cosine of the angle, so the basis depends on the angle through cos α. The network evaluates the basis at 0.5 for a 60° angle, and a different value for every other angle.

QuestionWhy do DimeNet's forces come from the gradient of the energy, and not from a separate output?Show answer

The forces must satisfy energy conservation, and the easiest way to guarantee that is to define them as the negative gradient of one scalar energy. A separate force output would have no such guarantee, and the simulated dynamics could then gain or lose energy in ways the physics does not allow.

QuestionOn QM9 the paper reports a 31% average improvement over the second-best model. A colleague says that means every target improved by 31%. What is wrong with that reading?Show answer

The 31% is the mean of standardised errors across the 12 targets, after each error is divided by that target's own typical size. The gain differs from target to target. For example, the energy gap improves by about 18% and HOMO by about 15%, and some targets improve more. An average hides that spread, so the per-target table is the right place to check a claim about one property.

Sources

Read the full paper

Johannes Gasteiger, Janek Groß, Stephan Günnemann, 2020. arXiv:2003.03123