### Motivation

Perhaps the most well-known and widely-used algorithm for calculating free energies on the fly from molecular simulation is metadynamics (1) and its flavors (2). It really was a game changer, as evidenced by the 2500+ citations the original paper has amassed since its publication in 2002. It also helped that it was elegant in its simplicity and a public implementation was made available through PLUMED which greatly improved its adoption; free energy calculations have now become an indispensable tool for the molecular modeler. Lurking in the shadows however was another algorithm which, though proposed *earlier* than metadynamics (3) and in my opinion superior in nearly every way, is not nearly as popular. This of course is the adaptive biasing force method, or ABF for short.

Now there are a number of contributing factors as to why I believe ABF never really caught on. But before I proceed, I want to make clear my expectations of the reader: I assume in this blog post that you are generally familiar with advanced free energy sampling and its concepts/jargon, basic statistical mechanics and are at least moderately comfortable with multivariable calculus and linear algebra. If you’re not, feel free to read on and pick up what you can, or wait until I write a future post introducing free energy sampling methods (which I plan on doing). Anyways, where were we? Some reasons I think prevented kept ABF from reaching rock-star status: First, ABF is not as simple to implement as metadynamics. Second, I also feel that the authors shot themselves in the foot by not writing the paper in a more simple “implementation-oriented” fashion. Third, ABF requires second derivatives of the collective variables with respect to the atomic coordinates, which gets nasty very quickly (more on this later). Finally, it just wasn’t available in a nice portable package like PLUMED.

This post will focus on describing a later development on the original ABF method (4). This paper solves problems 2 and 3, and various implementations of ABF are now available in many packages. As lead developer of SSAGES, an advanced sampling suite, and co-author of its ABF module, I wanted to step through various aspects of Darve’s 2008 paper (4) and discuss certain implementation choices. I’ll wrap up by using it to resolve the free energy surface of a simple system. Hopefully I will make a strong case for why ABF is currently my go-to method for estimating free energies, with some minor exceptions. Let’s begin!

### Preliminary

Advanced sampling methods such as adaptive umbrella sampling, metadynamics and Wang-Landau sampling can be categorized as *adaptive biasing potentials*. That is, there is an underlying biasing potential which acts on a set of collective variables, . This bias is propagated to the atomic coordinates via the chain rule,

All of these methods adjust the shape of the bias over the course of the simulation in order to achieve uniform sampling along . You can watch the video below which illustrates this principle.

ABF on the other hand is an *adaptive biasing force* (duh) method. What this means is that instead of adapting a potential to the underlying free energy surface, it seeks to estimate the *mean force * at specific points along the order parameter. Practically speaking, the order parameter is divided into discrete bins and a running estimate of the average force in each bin is refined over time, which converges to negative the free energy () gradient,

The consequence of converging to the mean force is that it eliminates the energetic barrier along the collective variable; the system should be able to freely diffuse along .

So why bother at all with ABF? Isn’t metadynamics good enough? Well, in adaptive biasing potential methods, the quantity being estimated is the free energy, , which is essentially the underlying probability distribution. This is an inherently *global* measure. A probability at a given point is only meaningful if it is known relative to another point along the collective variable. In other words, free energy is arbitrary up to an additive constant, hence it is only makes sense to discuss it in relative terms. Consequently, repeated sampling of the entire interval (or up to an relative free energy) is required to converge the free energy surface. Additionally, if for some reason there are sampling issues at any point along the collective variable it may affect the rest of the surface; this type of problem is especially prominent at the edges of bounded intervals.

Because ABF estimates a force, or gradient, it is an inherently *local* property. The derivative at a single point can be estimated locally without visiting other parts of the collective variable. This leads to faster convergence, and is less prone to boundary problems. Furthermore, since the estimation occurs on a discrete basis over a series of bins, one does not have to worry about the many parameters that go into metadynamic-type simulations such as Gaussian widths, height, deposition rate, etc…

### Derivation

So far we’ve just been discussing things at a high-level. At the end of the day, what exactly is ABF? What mathematical expression(s) do we plan on representing? We begin with the concept of thermodynamic integration. Given two states, and , the difference in free energy between them can be expresses as,

where

This is a classical result. Here is the Hamiltonian of the system, is the potential energy, and the derivatives are evaluated in a *constrained* ensemble . The limitation in using this expression is that the presence of multiple reactive pathways along the collective variable may give rise to quasi-nonergodicity. Another statistical mechanical result is the expression for the mean force in an unconstrained ensemble,

Here we can think of the first term on the RHS as the mechanical force acting along , and the second term as the entropic contribution. The appearance of the Jacobian in this expression is because of the transformation from a set of generalized coordinates to the desired collective variable. This next bit is really where the magic happens; as a reminder you can look back to the references below, in particular (3, 4) for more details. First let’s take to be an arbitrary vector field – literally any arbitrary vector. Subject to the condition that , it can be shown that

Let’s take this another step. If we make a choice of such that , then the above expression simplifies to

At this point I’ve just thrown a bunch of equations at you. I’ll try to break things down a bit. First, is just the gradient of the collective variable with respect to our atomic coordinates, . This is a standard requirement for the definition of any collective variable if we wish to sample along it in molecular dynamics. is just a vector of the atomic forces. It may seem that we have a fine expression that we can use in an algorithm, but there’s somewhat of an issue. To satisfy the condition we can take . However, in the equation for (negative) the mean force, we have a divergence term which necessitates second order spatial derivatives – yuck!

The main development of Darve (4) was to derive an equivalent expression that is first order in space, but introduces an additional first order in time derivative,

Here is a vector of the atomic momenta. Cool huh? That’s really it. No matter what our choice of instantaneous vector field is, subject to the condition given, we will eventually converge to the mean force. One final point is that the ABF method is one of the few methods for which there is proven (exponential) convergence. Though in practice many adaptive biasing methods were in wide use well before proofs of their convergence were published (and they worked just fine), it’s still an added bonus. Armed with this final equation, let’s proceed to implementing the ABF algorithm in practice and hopefully that will help clear up any lingering questions.

### Implementation

The first step in implementing ABF is to define a grid over the set of collective variable(s) which will be sampled. The number of bins should be chosen to accommodate the width of the finest features you are interested in resolving. There are two quantities which will be stored on the grid: the total accumulated force, and the number of hits at each grid point. The ratio of these two quantities will converge to the mean force of interest. Within a molecular dynamics simulation, we can define an iterative procedure for the algorithm.

- The interatomic forces are computed by the MD engine at timestep .
- The collective variable(s) are computed and the gradient are calculated from the atomic coordinates at timestep .
- Compute the arbitrary vector field from . This is where we have to take things a bit slow. Recall the condition which needs to be satisfied? Well, there are a number of ways of finding a vector (or matrix) to fulfill that condition. Let’s go over some of those.

First let’s establish some notation. will represent the Jacobian matrix of the collective variable(s), containing the gradient of each respective CV along the rows. Thus the entries of are where are the degrees of freedom, typically the x,y,z coordinates of the atoms. Our arbitrary vector field matrix will then have columns and rows such that . The first thing that came to my mind when I saw that condition was the Moore-Pensorse pseudoinverse.

Linear algebra interludeSuppose we have a matrix which is square (not necessarily the case above) and we are interested in finding a matrix such that . The clear answer would be to compute the inverse of , . The Moore-Penrose pseudoinverse is a generalized notion of an inverse for non-square matrices. In our case we are looking for a

right inverse. We first define a symmetric basis as (all entries are real), and take as . In other words, .

Darve (4) suggests the choice where . Here is the diagonal mass matrix, containing the atomic masses. This can be thought of as a “mass weighted” pseudoinverse. Making this choice actually results in another ABF equation which can also be used, but I prefer to compute in the manner described above. Notice as well how, if the mass matrix was the identity matrix, it is actually equivalent to the pseudoinverse. The reason for choosing the pseudoinverse (SSAGES implements both) is that in the case where a simulation contains virtual sites, as is often the case in many water models, the mass matrix will contain a zero along the diagonal rendering it singular. In either case, the user is free to choose whichever they please.

Will that choice make a difference? I previously mentioned that no matter the choice of , we will always converge to the mean force. This is true, but our choice of affects the rate at which we converge. Choosing it wisely means we converge very rapidly, while a poor results in slow convergence. In the numerical experiments I’ve run, I did not notice a significant difference in performance between the mass-weighted and pure pseudoinverse. One last note before returning the program is that can also be computed using the expression *if and only if * the collective variables are orthogonal. Otherwise, . However, it’s usually not too much trouble to compute it in the manner I’ve previously described, so we just stick with that. Now, back to the program.

- Once is computed, we calculate where is a vector of the atomic momenta.
- The time derivative is calculated using finite difference. This is perfectly fine since the MD engine is taking finite steps in time anyways. So long as the finite difference scheme is of the same or greater order of accuracy, then things should be fine. In SSAGES we choose a second order accurate finite difference scheme so . This means we need to store the two previous dot products and start biasing only after the third iteration, which is fine.
- Subtract the previous mean force estimate at the current point from the time derivative we just computed. This is important since as the simulation proceeds, we need to account for the bias due to the external force we have been applying to the system.
- Sum into our grid at , and increment the number of hits at that grid point.
- Update the finite difference time derivatives.
- Compute the external bias that we are going to sum into the atomic forces as . Here arises another practical implementation issue. Early on, this force estimate will fluctuate wildly and can easily cause the simulation to blow up. So what is suggested (and what we do), is to have a minimum number of hits in each bin such that the force is turned on in a linear ramp. To do this simply divide by instead of just .
- Update the atomic forces and let the MD engine integrate the forces.
- Return to step 1.

And there you have it, a breakdown of ABF’s mechanics. I do recommend you take a look at the source file for our implementation if you’re a bit more interested, because we implement a scalable strategy for multiple walkers that I did not discuss in this post. That wraps things up with respect to the ABF algorithm itself. What still remains however, is the post-processing.

### Analysis

Once a simulation is complete (or you simply run out of CPU time on your cluster) we need to extract the free energy corresponding to the mean force we just estimated. For a one-dimensional surface, this is as simple as integrating the force along the collective variable by calling “cumtrapz(x,F)” in MATLAB or Numpy. However, for multi-dimensional surfaces, things get a bit more complicated. It turns out that due to statistical fluctuations in the force vector field, the path chosen to integrate along affects the resulting free energy surface. In other words, the free energy is no longer a conserving potential! We all know that as a state function, the free energy difference between two points should be independent of the path chosen. Dealing with this issue is the subject of another post entirely – or you can just go on and read the discussion in Darve (4) if you’d like.

### Conclusion

I’d like to leave you with a video I made using ABF to estimate the potential of mean force between an NaCl ion pair in water. It just gives you a feel for how the method converges (quickly!) and is nice to watch. I hope I’ve been able to demystify ABF a bit for you. If I haven’t then I apologize. In either case, Enjoy!

*Proceedings of the National Academy of Sciences*99(20):12562–12566. [Source]

*Phys Rev Lett*100(2). doi: 10.1103/physrevlett.100.020603

*The Journal of Chemical Physics*115(20):9169–9183. [Source]

*The Journal of Chemical Physics*128(14):144120. [Source]

## 0 Comments