Histogram Reweighting

To further generalize our discussion of free-energy methods, it is convenient to introduce the concept of the “order parameter” $ z$ which is computed by a mapping function $ \theta({\boldsymbol r}^N)$, which is generally just any function of configuration (for example, $ \Delta\mathscr{U} = \mathscr{U}_1-\mathscr{U}_0$). For a system obeying the potential $ \mathscr{U}_0$, we can define the order parameter probability density as

$\displaystyle p_0 = \frac{\displaystyle \int {\boldsymbol r}^N e^{-\beta\mathscr{U}_0}\delta\left[z-\theta({\boldsymbol r}^N)\right]}{\displaystyle Z_0}$ (339)

where we are using the shorthand

$\displaystyle Z_0 = \int {\boldsymbol r}^N e^{-\beta\mathscr{U}_0}$ (340)

to represent (now the unscaled) configurational integral of the Boltzmann factor. The “Landau” free energy is then expressed as

$\displaystyle F_{\rm Landau}(z)=-k_BT\ln p_0(z)$ (341)

We'd generally like to be able to compute $ p_0$ or, alternatively, $ F_{\rm Landau}$, but as we have already seen, it is often impossible to perform adequate sampling over an entire range of order parameter. Suppose we restrict sampling to a region in order parameter space using a “bias potential” $ W_i(\theta({\boldsymbol r}^N))$. Under the action of this bias, we can compute directly a biased probability density:

$\displaystyle p_i(z) = \frac{\displaystyle \int {\boldsymbol r}^N e^{-\beta[\ma...
...U}_0+W_i(z)]}\delta\left[z-\theta({\boldsymbol r}^N)\right]}{\displaystyle Z_i}$ (342)

where we use the shorthand

$\displaystyle Z_i = \int {\boldsymbol r}^N e^{-\beta[\mathscr{U}_0+W_i(\theta({\boldsymbol r}^N))]}$ (343)

Note that in Eq. 340, we have made use of the fact that the Dirac delta function only permits $ \theta({\boldsymbol r}^N)$ to equal $ z$, so we do not need to express the argument of $ W_i$ as $ \theta({\boldsymbol r}^N)$ in the numerator. This is important, because it allows us to express the unbiased probability density:

$\displaystyle p_0(z) = \exp(+\beta W_i(z))\frac{Z_i}{Z_0}p_i(z)$ (344)

Let's now consider that we compute $ p_i$ by histogramming into bins of constant width $ \Delta z$. Let's call the histogram $ H_i$ and the total number of hits in the histogram $ M_i$. Then one way to write the relation between the approximate probability density and the histogram is

$\displaystyle p_i\Delta z = \frac{H_i}{M_i}$ (345)

Now we imagine we can use several different $ W_i$'s together, each of which focus sampling on a particular region of order-parameter space, and we propose that the unbiased probability density can be constructed by a superposition of the biased probabilities:

$\displaystyle p_0(z)$ $\displaystyle =\sum_{i=1}^n a_i(z)\exp(+\beta W_i(z))\frac{Z_i}{Z_0}p_i(z)$ (346)
$\displaystyle \Rightarrow p_0(z)\Delta z$ $\displaystyle = \sum_{i=1}^n a_i(z)\exp(+\beta W_i(z))\frac{Z_i}{Z_0}\frac{H_i(z)}{M_i}$ (347)

subject to

$\displaystyle \sum_{i=1}^n a_i(z) = 1  $   $\displaystyle \mbox{for all $z$}$ (348)

In Eq. 345, we have supposed that $ p_0\Delta z$ is a normalized histogram with the same bin size $ \Delta z$ as all $ H_i$.

Via minimization of the squared fluctuations of $ p_0(z)$ (since it will fluctuate in a simulation), one can arrive at an expression for $ a_i$ (math not shown):

$\displaystyle a_i(z) = \alpha(z)\exp[-\beta W_i(z)]M_i\frac{Z_0}{Z_i}$ (349)

where the normalization condition is met by

$\displaystyle \alpha(z) = \frac{1}{\displaystyle \sum_{i=1}^n \exp[-\beta W_i(z)]M_i\frac{Z_0}{Z_i}}$ (350)

This gives a reweighted histogram of

$\displaystyle p_0(z)\Delta z = \frac{\displaystyle \sum_{i=1}^n H_i}{\displaystyle \sum_{i=1}^n \exp[-\beta W_i(z)]M_i\frac{Z_0}{Z_i}}$ (351)

Now, let's define $ F_i$ via

$\displaystyle \exp\beta F_i$ $\displaystyle = -\frac{Z_i}{Z_0}$ (352)
  $\displaystyle = \frac{\displaystyle \int d{\boldsymbol r}^N e^{-\beta(\mathscr{U}_0+W_i)}}{\displaystyle Z_0}$ (353)
  $\displaystyle = \frac{\displaystyle \int dz \int {\boldsymbol r}^N e^{-\beta(\mathscr{U}_0+W_i)}\delta(\theta({\boldsymbol r}^N)-z)}{\displaystyle Z_0}$ (354)
  $\displaystyle = \int dz e^{-\beta W_i(z)}\frac{\displaystyle \int {\boldsymbol r}^N e^{-\beta\mathscr{U}_0}\delta\left[z-\theta({\boldsymbol r}^N)\right]}{Z_0}$ (355)
  $\displaystyle = \int dz p_0(z) e^{-\beta W_i(z)}$ (356)
$\displaystyle \Rightarrow F_i$ $\displaystyle = -\frac{1}{\beta}\ln\int dz p_0(z) e^{-\beta W_i(z)}$ (357)

This allows us to write the unbiased histogram as

$\displaystyle p_0(z)\Delta z = \frac{\displaystyle \sum_{i=1}^n H_i}{\displaystyle \sum_{j=1}^n \exp[-\beta (W_j(z)-F_j)]M_j}$ (358)

Given that we have a finite bin width, the integration in Eq. 355 can be approximated as

$\displaystyle F_j = -\frac{1}{\beta}\ln\sum_{k=0}^{n_{\rm bins}-1} p_0(z_k)\exp[-\beta W_j(z_k)]\Delta z$ (359)

where $ z_k = z_{\rm min}+(k+\frac{1}{2})\Delta z$, with $ z_{\rm min}$ the lower bound of the histogram domain and $ n_{\rm bins}$ is the number of bins.

Eq. 356 and 357 are called (by some) the WHAM equations (for Weighted Histogram Analysis Method [45]). They can be solved iteratively to yield an unbiased probability provided with a set of biased histograms $ H_i$ obtained from running MC simulations on $ \mathscr{U}_0+W_i$. The standard WHAM approach is

As an example, consider a single degree of freedom $ x$ (our “particle”) moving under Brownian dynamics (BD) on a quartic two-well potential:

$\displaystyle \dot{x} = -\frac{1}{\gamma}\frac{dV}{dx} + \sqrt{2k_BT/\gamma}\eta, $   where (360)
$\displaystyle V(x) = a(x^2-1)^2 + bx^2 + cx$ (361)

Here, $ \gamma$ is the BD friction, $ T$ is the temperature, and $ \eta$ is a random variate centered on zero with unit variance. A symmetrical two-well potential with a barrier at $ x=0$ of about 13 can be had by using $ a$ = 0.02, $ b$ = -1, and $ c$ = 0. Since there is only one degree of freedom, it can easily be shown that $ F(x) = V(x)$. So, if we run BD, sampling $ x$ and then histogramming it into $ p_0$, then we should see that $ F=-k_BT\ln p_0$ and $ V$ agree. Computing $ F$ from a directly histogrammed variable is sometimes called “Boltzmann inversion”.

Fig. 42 shows the calculation of $ F$ using this approach, with BD on $ V$ using the code bd-w.c. We show that sampling with a reduced temperature of 10 requires about 2 billion BD timesteps to reproduce $ V$. If we reduce the temperature to 1, the large barrier between the two wells is not surmounted and $ V$ is therefore not correctly reproduced.

Figure 42: Boltzmann inversion from 1-D Brownian dynamics simulations obeying the potential $ V$ in Eq. 359. (Left) BD run at $ T$ = 1.0; (right) BD run at $ T$ = 10.0. Each simulation was run for $ 2\times 10^9$ steps of length $ 1\times 10^{-3}$.
Image baseplot1 Image baseplot10

Fig. 43 shows that $ V$ can be reproduced at $ T$ of 1.0 using WHAM using 21 windows and harmonic bias potentials $ W_i$ spaced uniformly along $ z$, each with a $ k$ of 20. That is, each bias potential is of the form

$\displaystyle W_i(z) = \frac{1}{2}k(z-z_{0,i})^2$ (362)

where $ z_{0,i}$'s are uniformly spaced between -10 and 10. (Actually, -10 and 10 are the domain boundaries; this domain of size 20 is divided into 21 windows, and each $ z_0$ is in the center of its window. So, $ z_00 = -10+0.5(20/21) = -9.5238$, etc. An odd number of windows is a good idea so that we can better resolve the tippy top of the barrier.)

Here, only two million BD steps were run per window, for a total of 42 million steps. This means this WHAM dataset required more than twenty times less BD sampling at a temperature of 1.0 than the brute force sampling approach could at a temperature of 10.0.

Figure 43: WHAM results from BD simulations on $ V$ from Eq. 359. (Left) $ V(x)$ and all $ W_i(x)$; each $ z_0$ is uniformly spaced along $ z$, and $ k$ is 20. (Center) All biased histograms $ H_i(x)$ from BD simulations of $ 2\times 10^6$ steps at $ T$ = 1.0, with a scaled unbiased histogram $ p_0$ (scaled for visibility). (Right) Reconstructed $ F(x)$ and $ V(x)$ (again).
Image wham-bd-good

As a second example of WHAM, consider MD simulation of butane molecule in vacuum at $ T$ = 310 K. One order parameter we may consider here is the C$ _1$-C$ _4$ distance. When the molecule is in trans, the C$ _1$-C$ _4$ distance is about 4.5 Å, while when it is in gauche, the C$ _1$-C$ _4$ distance is about 3.2 Å. We expect there to be a small free-enegy barrier between these two states when characterized using the C$ _1$-C$ _4$ distance. Fig. 44 shows results of both WHAM and long MD simulations, showing indeed that the trans and gauche states are separated by a small barrier of about 2 kcal/mol at 310 K, easily surmountable in MD. WHAM reconstruction of $ F$ from 20 biased histograms generated from MD restrained using harmonic window potentials with spring constants of 100 kcal/mol-Å$ ^2$ shows perfect agreement with the Boltzmann-inverted result.

Figure 44: (Left) A butane molecule with the C$ _1$-C$ _4$ distance indicated by a purple line. (Center) Biased histograms from window-restrained MD simulations of butane in vacuum at 310 K. Windows are distributed uniformly along the C$ _1$-C$ _4$ distance variable. (Right) Free energy vs C$ _1$-C$ _4$ distance computed using Boltzmann inversion from a long MD simulation (grey dashes) and from WHAM (blue solid).
Image butane Image butane-wham

Butane is an almost trivially simple case; the C1-C4 distance is relatively easily sampled in standard MD at 310 K in few million time-steps. This is of course evident because we can generate a Boltzmann-inverted free energy directly from the histogram of this distance generated by MD. But it is important to note that the order parameter here, the C1-C4 distance, has a small amount of degeneracy: every value of this parameter except for its minimum and maximum has two major realizations determined by positive and negative senses of the dihedral angle. (There are of course some minor realizations due to angle stretching.) That means that each window's simulation should sample both the positive and negative regions of the order parameter space, and we must take care that the window potential is not so strong that these dihedral angle fluctuations cannot occur; if so, we would undersample the gauche states for sure. Fig. 45 shows traces of the C1-C4 distance for each window and corresponding traces of the dihedral angle; clearly for this value of $ k$, each window is indeed able to sample both positive and negative values of the dihedral angle.

Figure 45: (Left) C1-C4 distance vs. time for each of 16 windows. (Right) Dihedral angle vs. time for each of 16 windows.
Image window-traces Image angles

cfa22@drexel.edu