Search

Search papers and lessons

Boltzmann Generators: Sampling Equilibrium States with Deep Learning

Frank Noé, Simon Olsson, Jonas Köhler et al. · 2018

Noé and colleagues train an invertible neural network to turn a Gaussian into one-shot equilibrium samples of molecular systems, then reweight them to the exact Boltzmann distribution.

On this page

  • Colour = topic mix
  • Linear algebra
  • Probability
  • Calculus
  • Discrete math
  • Sampling
  • Generative models
  • ReadReady to readNot yet

TL;DR

Chemists want samples from the equilibrium state of a molecule, the configurations it is likely to be found in at a given temperature. Getting them by simulation is slow, because the molecule gets stuck in one shape for a long time before it jumps to another. This paper trains a neural network that maps simple random numbers to molecular configurations, with the probabilities of those configurations known exactly. The method, called a Boltzmann Generator, produces independent samples in one shot, then reweights them so that averages match the true equilibrium distribution.

Builds on: Boltzmann Distribution, Normalizing Flow, Kullback–Leibler Divergence, Importance Sampling · Leads to: Molecular Dynamics alternatives for sampling and free energy calculations; Generative Model methods that are unbiased by construction

Why it mattered

Free energy differences decide which of two molecular states is favored, which drug binds a protein, and how a reaction proceeds. Computing them needs many samples from both states. Standard molecular dynamics and Markov chain Monte Carlo can take an enormous number of steps to cross between two metastable states, and the paper estimates that folding or unfolding a protein can need around 10910^{9} to 101510^{15} simulation steps. A method that produces independent samples in one shot, and can compute free energies without a predefined reaction coordinate, targets exactly that bottleneck. The paper reports samples for a protein with 892 atoms, which was a large system for this kind of method.

History

The Boltzmann distribution, which gives each configuration a weight that falls off with its energy, has been the basis of statistical mechanics since the late nineteenth century. Simulation methods for sampling it, such as Metropolis Monte Carlo and molecular dynamics, developed over the decades that followed. Enhanced sampling methods, which bias a chosen reaction coordinate, became the standard fix for rare events. Normalizing flows, neural networks built from invertible maps whose densities can be computed, came out of machine learning in the mid-2010s. This paper joined the two lines: the invertible networks of machine learning, trained against a physical energy function instead of a dataset.

The problem

A molecule's equilibrium behavior is set by its energy function u(x)u(\mathbf{x}), where x\mathbf{x} holds all the atomic positions. At a given temperature the probability of a configuration is proportional to e−u(x)\mathrm{e}^{-u(\mathbf{x})}. Two configurations of very different energy can be separated by a barrier that only a rare thermal fluctuation crosses. Simulation spends almost all its time inside one basin.

Dense systems make it worse. In a crowded liquid of repelling particles, the low-energy arrangements are a vanishingly small fraction of all arrangements. Designing a sampler by hand, one that places all the particles without clashes and with low energy, looks unfeasible. The paper's aim is a machine that learns the sampler from the energy function, without knowing in advance which coordinates matter.

How it works

The idea is traced on a one-dimensional toy, with a single invertible map and a standard normal prior. The prior is a random number zz from a Gaussian. The network is the map x=Fzx(z)=2z+1x = F_{zx}(z) = 2z + 1, which is invertible with derivative 2. The energy is u(x)=x2/2u(x) = x^2 / 2.

  1. Draw a latent sample. Draw z=0.5z = 0.5 from the Gaussian prior. This is the "simple" distribution the sampler starts from.
  2. Map it to configuration space. x=Fzx(0.5)=2⋅0.5+1=2x = F_{zx}(0.5) = 2 \cdot 0.5 + 1 = 2. The configuration is x=2x = 2.
  3. Compute its energy. u(2)=22/2=2u(2) = 2^2 / 2 = 2. High energy means the configuration is unlikely under the target.
  4. Account for stretching. The map stretches space by a factor R=2R = 2. The density of the generated samples picks up the same factor, and the log term log⁡R=log⁡2≈0.693\log R = \log 2 \approx 0.693 records it.
  5. Score the sample with the loss. The contribution of this sample to the training loss is u(x)−log⁡R=2−0.693=1.307u(x) - \log R = 2 - 0.693 = 1.307. Training lowers the average of this quantity over many samples.
  6. Reweight to the Boltzmann distribution. The density of the generated sample is pX(x)=φ(z)/Rp_X(x) = \varphi(z) / R, where φ\varphi is the Gaussian density. Here φ(0.5)≈0.352\varphi(0.5) \approx 0.352, so pX(2)≈0.176p_X(2) \approx 0.176. The weight is w=e−u(x)/pX(x)=0.135/0.176≈0.77w = \mathrm{e}^{-u(x)} / p_X(x) = 0.135 / 0.176 \approx 0.77.
  7. Average with weights. Any average is taken as ∑iwiA(xi)/∑iwi\sum_i w_i A(x_i) / \sum_i w_i, which corrects for the fact that the network did not sample the target exactly.

The diagram shows the flow of one training step.

flowchart LR
  Z[Latent sample z from Gaussian] --> F[Invertible network F_zx]
  F --> X[Configuration x]
  X --> E[Energy u of x]
  X --> J[Log stretch factor]
  E --> L[Loss: energy minus log stretch]
  J --> L
  L --> U[Update network parameters]
  X --> W[Weight e to minus u over p_X]

Training uses two signals. Training by energy is the loss in step 5, which needs no samples, only the energy function. Training by example uses a few configurations from short simulations or from an experimental structure: these are mapped back to the Gaussian space and their likelihood is maximized. The energy term alone tends to focus on the most stable state, so the example term is used early on to get the network into the right region of configuration space.

Worked examples

Example
1. Two latent samples (tiny)

Use the same toy: x=2z+1x = 2z + 1, u(x)=x2/2u(x) = x^2 / 2, R=2R = 2. Take two latent samples, z=−1z = -1 and z=0.5z = 0.5.

  1. For z=−1z = -1: x=2⋅(−1)+1=−1x = 2 \cdot (-1) + 1 = -1. Energy u(−1)=0.5u(-1) = 0.5.
  2. Loss contribution: u(−1)−log⁡2=0.5−0.693=−0.193u(-1) - \log 2 = 0.5 - 0.693 = -0.193.
  3. For z=0.5z = 0.5: x=2x = 2, u(2)=2u(2) = 2, loss contribution 1.3071.307 (from How it works).
  4. The loss contribution is lower for the first sample, which is the one with lower energy. This is the sense in which the loss pushes the network toward low-energy configurations.

Interpretation: a sample with a negative loss contribution pulls the average down. Training favors maps that send probable latent points to low-energy configurations.

Example
2. Reweighting a biased average (standard)

Continue with the two samples above. For z=−1z = -1, the density is pX(−1)=φ(−1)/2=0.242/2=0.121p_X(-1) = \varphi(-1) / 2 = 0.242 / 2 = 0.121, and the weight is w=e−0.5/0.121=0.607/0.121≈5.01w = \mathrm{e}^{-0.5} / 0.121 = 0.607 / 0.121 \approx 5.01. For z=0.5z = 0.5, w≈0.77w \approx 0.77 as before.

  1. The unweighted mean of xx over the two samples is (−1+2)/2=0.5(-1 + 2) / 2 = 0.5.
  2. The weighted sum is 5.01⋅(−1)+0.77⋅2=−5.01+1.54=−3.475.01 \cdot (-1) + 0.77 \cdot 2 = -5.01 + 1.54 = -3.47.
  3. The total weight is 5.01+0.77=5.785.01 + 0.77 = 5.78.
  4. The weighted mean is −3.47/5.78≈−0.60-3.47 / 5.78 \approx -0.60.

Interpretation: the generator undersampled the low-energy point x=−1x = -1, and reweighting moves the estimate from 0.5 to about −0.60-0.60, toward the configuration the Boltzmann distribution prefers.

Example
3. Budget of a training run (realistic)

The paper states that the loss is estimated from a batch of around 1000 samples, that a few hundred to a few thousand iterations train the network for its examples, and that this costs a few million energy evaluations. Each energy evaluation is a full molecular energy, which is the expensive part. Taking the paper's own figures:

  1. A batch of 1000 samples costs 1000 energy evaluations per iteration.
  2. Across 300 iterations, that is 300⋅1000=300,000300 \cdot 1000 = 300{,}000 evaluations, about 0.3 million.
  3. Across 3000 iterations, that is 3,000⋅1000=3,000,0003{,}000 \cdot 1000 = 3{,}000{,}000, about 3 million.
  4. So the paper's "few million" describes the range of the budget. The paper gives between one minute and a few hours of computation for the present systems.
  5. Once trained, the network draws new samples at the cost of one forward pass each, with no further energy calls needed to get them, except for the reweighting.

Interpretation: the expensive work is front-loaded into training. The payoff is that the cost of each additional independent sample is small, while a molecular dynamics run would need very many steps for each one.

Try it: a run uses batches of 1000 samples and 2500 iterations. How many energy evaluations does training take? Answer: 2500⋅1000=2,500,0002500 \cdot 1000 = 2{,}500{,}000, about 2.5 million, which sits inside the paper's stated range.

The math

The target is the Boltzmann density pB(x)=e−u(x)/Zp_B(\mathbf{x}) = \mathrm{e}^{-u(\mathbf{x})} / Z, where ZZ is the partition function. The generator is an invertible map x=Fzx(z)\mathbf{x} = F_{zx}(\mathbf{z}) applied to a Gaussian prior pZ(z)=N(z;0,I)p_Z(\mathbf{z}) = \mathcal{N}(\mathbf{z}; 0, I). Its inverse is FxzF_{xz}.

Definition: Boltzmann Generator

A Boltzmann Generator is an invertible neural network FzxF_{zx} together with a Gaussian prior, such that the density pXp_X of the generated configurations is known at every sample point. Its training losses approximate the difference between pXp_X and pBp_B, and its samples are reweighted to pBp_B for any average.

Step 1 in symbols: the density of a generated sample

Let Rzx(z)=∣det⁡JFzx(z)∣R_{zx}(\mathbf{z}) = \left|\det J_{F_{zx}}(\mathbf{z})\right| be the absolute determinant of the Jacobian, the factor by which the map stretches volume. The change of variables formula gives

log⁡pX(Fzx(z))=log⁡pZ(z)−log⁡Rzx(z)\log p_X\big(F_{zx}(\mathbf{z})\big) = \log p_Z(\mathbf{z}) - \log R_{zx}(\mathbf{z})

so the density of the generated sample is known exactly, as long as RzxR_{zx} is cheap to compute. The invertible layers are designed so that it is.

Step 2 in symbols: the energy loss

The Kullback-Leibler divergence from the generated distribution to the Boltzmann distribution is

DKL(pX ∥ pB)=Ex∼pX[log⁡pX(x)−log⁡pB(x)]D_{KL}(p_X \,\|\, p_B) = \mathbb{E}_{\mathbf{x} \sim p_X}\big[\log p_X(\mathbf{x}) - \log p_B(\mathbf{x})\big]

Substituting Step 1 and log⁡pB=−u−log⁡Z\log p_B = -u - \log Z, and dropping terms that do not depend on the network (the constant log⁡pZ\log p_Z and log⁡Z\log Z), gives the energy loss

JKL=Ez[u(Fzx(z))−log⁡Rzx(z)]J_{KL} = \mathbb{E}_{\mathbf{z}}\big[u\big(F_{zx}(\mathbf{z})\big) - \log R_{zx}(\mathbf{z})\big]

This is the loss from How it works, step 5. The first term is the mean energy of the generated configurations. The second term is an entropy-like term that keeps the generator from collapsing onto one minimum-energy configuration. The paper notes that the value of JKLJ_{KL} also equals a free energy difference, up to a constant, which is why a difference of two such values gives a free energy difference between two states.

Step 3 in symbols: the example loss

For a configuration x\mathbf{x} taken from a simulation, the network maps it back to latent space with z=Fxz(x)\mathbf{z} = F_{xz}(\mathbf{x}). Maximizing the likelihood under the Gaussian gives

JML=Ex[12∥Fxz(x)∥2−log⁡Rxz(x)]J_{ML} = \mathbb{E}_{\mathbf{x}}\Big[\tfrac{1}{2}\left\|F_{xz}(\mathbf{x})\right\|^2 - \log R_{xz}(\mathbf{x})\Big]

The first term is the energy of a harmonic oscillator, the Gaussian's negative log-density. The second term is the log-determinant of the inverse map. This is standard maximum likelihood, the same principle used for any density model.

Step 4 in symbols: reweighting

Each sample xi\mathbf{x}_i from the generator gets weight wi=e−u(xi)/pX(xi)w_i = \mathrm{e}^{-u(\mathbf{x}_i)} / p_X(\mathbf{x}_i), and an average of an observable AA under the Boltzmann distribution is estimated by

⟨A⟩≈∑iwi A(xi)∑iwi\langle A \rangle \approx \frac{\sum_i w_i \, A(\mathbf{x}_i)}{\sum_i w_i}

This is importance sampling, with the generator's density as the proposal. Its accuracy depends on how close pXp_X is to pBp_B, which is what the training losses push toward.

Results

The main findings, with the paper's own numbers.

  • Model systems. On two-dimensional double-well and Mueller potentials, a Boltzmann Generator trained from two short, disconnected simulations produces samples from both states and across the barrier. Its free energy differences match the reference values. For the double well, the paper estimates that direct simulation needs about 4⋅1064 \cdot 10^{6} steps per return trip and about 100 crossings, while training costs about 10610^{6} steps. It calls the generator about a factor of 100 more efficient for this simple system.
  • Dense solvated dimer. With 38 particles in a two-dimensional crowded box, the generator learns a latent space in which the configurations form a concentrated 76-dimensional ball. Free energy profiles agree with umbrella sampling across temperatures. The paper estimates that direct simulation would need at least 101210^{12} steps to sample one transition from closed to open and back, and that training uses about 3⋅1073 \cdot 10^{7} energy evaluations, giving a speedup of at least seven orders of magnitude over MD.
  • Exploration. Starting from a single configuration, an exploration method that runs Metropolis steps in latent space finds new metastable states within a few 10510^{5} energy calls.
  • Protein. For the bovine pancreatic trypsin inhibitor, in an implicit solvent, a generator with 8 invertible blocks produces one-shot samples of all 892 atoms. Its energy distribution overlaps the simulation data, and it samples a near-crystal structure and an open structure, the latter a transition that was seen only once in a millisecond simulation. The reported mean backbone deviation of the near-crystal samples from the crystal structure is 1.4 Å.
  • Disconnected states. Two independently trained generators, each seeded with disconnected simulations, give free energy differences. For the dimer, the paper reports 50 times fewer energy calls than umbrella sampling at five temperatures.

What the results do not show: a generator is trained on one specific system, not on many, so each new molecule needs its own training. The paper's Discussion says the method may not be ergodic, meaning it can miss some configurations, and it recommends combining it with MD or MCMC moves. The statistical efficiency of the samples falls as dimension grows, and the authors describe divide-and-conquer approaches for systems with hundreds of thousands of coordinates as future work.

Common mistakes and tradeoffs

It is tempting to think a Boltzmann Generator is just an image generator for molecules. In fact it is trained against the energy function and its samples are reweighted, because its density is known. An image generator learns from examples and has no exact density to reweight with.

It is tempting to think the raw samples are already unbiased. In fact they come from the generator's density, not the Boltzmann distribution, so averages need the weights from Step 4. Skipping reweighting gives biased free energies.

It is tempting to think training by energy alone is enough. In fact the paper found it focuses on the most stable state, so training by example is used as well, especially early on.

It is tempting to think the method needs no physical knowledge. In fact the representation matters: the paper whitens the backbone atoms with principal component analysis and describes side-chain atoms in internal coordinates, and it removes permutations of identical solvent molecules. Without these, the learning problem is much harder.

When to use it: when you need independent equilibrium samples or free energies, the energy function is known, and the system is too large or too rare-event-prone for direct simulation to be practical. When not to use it: when a clear reaction coordinate already makes umbrella sampling cheap, when the system is huge and the sample efficiency falls, or when you need ergodic exploration without any extra moves. Alternatives include umbrella sampling, metadynamics and replica exchange, which the paper suggests can also be reformulated in the generator's latent space.

Reading guide

The paper's sections in order, with the lessons each one needs.

Recap

  • The Boltzmann distribution gives probabilities of configurations, but drawing independent samples from it is hard for rare-event systems.
  • A Boltzmann Generator is an invertible network with a Gaussian prior. Its generated density is known exactly by the change of variables formula.
  • Its energy loss, the KL divergence to the Boltzmann distribution, needs only the energy function. Its example loss, a maximum likelihood term, uses a few configurations from simulation.
  • Samples are reweighted by the ratio of Boltzmann weight to generated density, which gives unbiased averages and free energy differences.
  • The paper applies this to model potentials, a crowded dimer and a protein with 892 atoms. Its main limits are per-system training and reduced efficiency in high dimension.

Read next: Molecular Dynamics for the baseline the paper improves on, and Normalizing Flow for the architecture family.

Check yourself

QuestionRecall: what is the role of the reweighting step in a Boltzmann Generator?Show answer

Samples come from the generator's density, not the Boltzmann distribution. Each sample is weighted by the Boltzmann weight divided by the generated density, so that averages and free energy differences estimate the true equilibrium values.

QuestionComputation: for the toy x=2z+1x = 2z + 1 and u(x)=x2/2u(x) = x^2 / 2, with R=2R = 2, what is the loss contribution of the latent sample z=0z = 0?Show answer

Then x=1x = 1, u(1)=0.5u(1) = 0.5, and the loss contribution is u(1)−log⁡2=0.5−0.693=−0.193u(1) - \log 2 = 0.5 - 0.693 = -0.193.

QuestionWhy: why does the energy loss include the log-determinant term, and what would happen without it?Show answer

The log-determinant term rewards the generator for spreading samples across configuration space rather than concentrating them. Without it, the loss is only the mean energy, which is minimized by collapsing onto one minimum-energy configuration, the mode collapse the paper describes.

QuestionApplied: a group has a single protein whose two states are separated by a rare transition, and they can afford about one million energy evaluations. Which parts of the paper's approach apply, and what should they check before trusting the free energies?Show answer

Training by energy and reweighting apply, with the energy function as the only input the energy loss needs. They should check that the generator covers both states, which the paper addresses with training by example from each state, and that the reweighted estimates converge, for example by watching the loss and the effective sample size across training.

Sources

Read the full paper

Frank Noé, Simon Olsson, Jonas Köhler et al., 2018. arXiv:1812.01729