Skip to content

Atoms and forces: SchNet and NequIP

A machine-learned interatomic potential predicts a structure's energy, and forces come from its gradient. SchNet filters by distance, so it ignores rotation. NequIP carries vectors that rotate with the molecule. Compute both pieces.

Advanced ~14 min8 steps

What runs in CodeSplash

  • SPE011SchNet Needs a data type CodeSplash doesn't load yet
  • SPE012NequIP Needs a data type CodeSplash doesn't load yet

You will be able to

  • Explain why forces are taken as the negative gradient of one predicted energy
  • Compute SchNet-style distance-filtered messages and check they ignore rotation
  • Contrast an invariant message with NequIP's vector message that rotates
  • Plan an evaluation by held-out structures, energies and forces

Read first

01

Energy first, forces from it

Read

Simulating molecules and materials needs the energy of every arrangement of atoms, and accurate quantum calculations are slow. A machine-learned interatomic potentialMachine-learned interatomic potentialA network that predicts a structure's energy from atom types and positions, trained on reference calculations, to run simulations faster. is trained on those calculations to predict the energy EE from atom types and positions, much faster.

The forces then come from the gradient of that one energy, forces from an energyForces from an energyForces taken as the negative gradient of one predicted energy, F = −∇E, so they can't create energy in a closed loop.:

Fi=−∇riE.F_i = -\nabla_{r_i} E .

A separate force head could predict forces that don't belong to any energy, so a simulation could gain energy in a loop. Taking the gradient rules that out. Units and the energy/force loss weights decide which errors training cares about.

02

SchNet: filters from distances

Read

SchNetSchNetA molecule network whose filters are smooth functions of the distance between atoms, so its outputs ignore rotation. updates each atom's features with its neighbors' features, weighted by a learned function of their distance:

hil+1=hil+∑jhjl⊙Wl(∥ri−rj∥).h_i^{l+1} = h_i^l + \sum_j h_j^l \odot W_l\big(\lVert r_i - r_j \rVert\big).

The distances are expanded in radial basis functions and cut off smoothly beyond a radius. Because only distances enter, SchNet's features and energy ignore rotation.

In the reference's three-atom example the updated features are 2.216, 1.950 and 2.183, the same after rotating the atoms by 90°.

Reference · SPE011 · Needs a data type CodeSplash doesn't load yetSchNetSchNet learns molecular and material properties from atomic types and positions using continuous distance-dependent filters.
03

NequIP: features that rotate

Read

Distances alone can't tell some different shapes apart. NequIPNequIPAn interatomic potential whose atom features include vectors and higher-order tensors that rotate with the molecule. keeps richer atom features: scalars, vectors and higher-order tensors, each rotating in its own fixed way. Messages combine a neighbor's features with spherical harmonics of the bond direction, through tensor products that keep every rotation rule:

mijlo=∑li,lfR(rij)[hjli⊗Ylf(r^ij)]lo.m_{ij}^{l_o} = \sum_{l_i, l_f} R(r_{ij}) \big[h_j^{l_i} \otimes Y_{l_f}(\hat r_{ij})\big]_{l_o}.

Energy is still a sum of scalar atom energies, and forces still come from its gradient.

Reference · SPE012 · Needs a data type CodeSplash doesn't load yetNequIPNequIP learns interatomic potentials with E(3)-equivariant features, using geometric tensor information to improve data efficiency.
04

A vector message by hand

Explore

The reference builds the simplest vector message: neighbor directions weighted by e−re^{-r} and added. It comes out as (0.270, 0.357, 0.471), and rotating the inputs rotates this vector by the same rotation.

Python
import numpy as np
rel = np.array([[1., 0., 0.], [0., 1., .5], [-.3, .2, 1.]])     # neighbor offsets
def message(V):
    r = np.linalg.norm(V, axis=1)
    return (np.exp(-r)[:, None] * V / r[:, None]).sum(axis=0)
R = np.array([[0., -1., 0.], [1., 0., 0.], [0., 0., 1.]])
print(message(rel), np.allclose(message(rel @ R.T), message(rel) @ R.T))
R
rel <- rbind(c(1, 0, 0), c(0, 1, .5), c(-.3, .2, 1))           # neighbor offsets
message <- function(V) { r <- sqrt(rowSums(V^2)); colSums(exp(-r) * V / r) }
R <- rbind(c(0, -1, 0), c(1, 0, 0), c(0, 0, 1))
print(c(message(rel), isTRUE(all.equal(message(rel %*% t(R)), drop(message(rel) %*% t(R))))))

A SchNet message would give the same number before and after the rotation; this one turns with it.

DExplorable · Equivariance: rotate the input, check the output

Does a model's answer turn with its input, as physics says it must?

Rotate the input. Will this model's energy stay exactly the same?

How sure?

Model

Four small networks with fixed random weights. Each gives one number (an energy) and one arrow per point.

6

How many points (atoms, say) the model sees.

90

Rotate every point by this angle about the origin before asking the model again.

Move every point by (1, −0.5) after rotating.

Input and the model's arrowsRotated input: new arrows vs rotated originals1234561234560Energy, rotated0Arrows, rotated0Energy, reordered0Arrows, reordered

Red bars fail the check. Differences below 10⁻¹² are rounding and show as 0.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

05

Evaluating a potential

Predict

Predict first

Your training data are frames from simulation trajectories. How should you split for testing?

Random frames from all trajectoriesWhole held-out structures or trajectories
Reveal

Whole structures or trajectories. Neighboring frames are nearly identical, so random frames leak. Report energy and force errors in physical units, and run short simulations to check stability. Equivariance and a low training loss guarantee neither.

06

What runs here

Read
07

Check: atomistic models

Checkpoint

Check yourself

Why do potentials like SchNet compute forces as −∇E-\nabla E rather than with a separate force head?

Show the answer

Answer: b

A gradient field of a scalar energy is conservative. An unconstrained head may not be.

Check yourself

What makes SchNet's predicted energy unchanged when a molecule is rotated?

Show the answer

Answer: a

Distances don't change under rotation, so neither do the filtered messages or the energy.

Check yourself

SchNet uses a distance cutoff. What does that limit?

Show the answer

Answer: b

A cutoff keeps cost down and makes the model local. Long-range physics needs explicit handling.

Check yourself

What does NequIP carry that SchNet doesn't?

Show the answer

Answer: b

Directional features let NequIP tell apart shapes that distances alone confuse, while energy stays a scalar.

Check yourself

You rotate the neighbor offsets in the reference's vector message. What happens to the message?

Show the answer

Answer: b

The message is a weighted sum of direction vectors with distance-only weights, so it is equivariant.

Check yourself

A potential has tiny errors on random held-out frames from its training trajectories. What should you test next?

Show the answer

Answer: a

Neighboring frames leak. New environments and rollouts show whether the potential transfers and stays stable.

08

Recap

Recap
  • An interatomic potential predicts energy; forces come from its negative gradient.
  • SchNet filters by distance, so its outputs ignore rotation.
  • NequIP adds vectors and tensors that rotate with the structure.
  • Split by structure or trajectory. Both need molecular data, which CodeSplash doesn't load yet.

Concepts in this lesson