This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution license (http://creativecommons.org/licenses/by/3.0/).
This paper invites the reader to learn more about time integrators for Molecular Dynamics simulation through a simple MATLAB implementation. An overview of methods is provided from an algorithmic viewpoint that emphasizes long-time stability and finite-time dynamic accuracy. The given software simulates Langevin dynamics using an explicit, second-order (weakly) accurate integrator that exactly reproduces the Boltzmann-Gibbs density. This latter feature comes from adding a Metropolis acceptance-rejection step to the integrator. The paper discusses in detail the properties of the integrator. Since these properties do not rely on a specific form of a heat or pressure bath model, the given algorithm can be used to simulate other bath models including, e.g., the widely used v-rescale thermostat.
Molecular Dynamics (MD) simulation refers to the time integration of Hamilton’s equations often coupled to a heat or pressure bath [1–5]. From its early use in computing equilibrium dynamics of homogeneous molecular systems [6–13] and pico- to nano-scale protein dynamics [14–23], the method has evolved into a general purpose tool for simulating statistical properties of heterogeneous molecular systems [24]. Accessible time horizons have increased remarkably: the time line in Figure 1 attempts to capture this nearly billion-fold improvement in capability over the last forty or so years. To put this speedup in perspective, though, computing power has increased by about eight powers of ten over this time period as predicted by Moore’s law.
To be clear, the selection of applications and methods shown in Figure 1 is not comprehensive and heavily biased towards the specific ideas and methods that inform this paper. The applications highlighted are simulations of liquid argon [6], water [11], protein dynamics without solvent [14,15] and biopolymer dynamics with solvent [25–31]. The methods include the following “upgrades” to MD simulation: Verlet integrator and neighbor lists [7], cell linked list [32], the SHAKE integrator for constraints [33], stochastic heat baths via Langevin dynamics [34,35], a library of empirical potentials [36], a deterministic heat bath via Nosé-Hoover dynamics [37,38], the fast multipole method [39], multiple time steps [40], splitting methods for Langevin dynamics [41–43], quasi-symplectic integrators [44,45], (fast) combined neighbor and cell lists [46], the v-rescale thermostat [47] and the stochastic Nosé-Hoover Langevin thermostat [48–50].
Near future applications of MD simulation include micro- to milli-scale simulations of biomolecular processes, like protein folding, ligand binding, membrane transport and biopolymer conformational changes [51–53]. In addition, atomistic MD simulations are used more sparingly in multiscale models [54–58] and rare event simulation, such as the finite temperature string method and milestoning [59–62]. Given this continuous development and generalization of MD, it is not a stretch to suppose that MD will play a transformative role in medicine, technology and education in the twenty-first century.
In its standard form, the method inputs a random initial condition, physical and numerical parameters and outputs a long discrete path of the molecular system. Statistical quantities, like velocity correlation or mean radius of gyration, are usually computed online, i.e., as points along this trajectory are produced. MD simulation is built atop a cheap forward Euler-like integrator that requires only a single interactomic force field evaluation per step. Even though MD seems straightforward, software implementations of MD are typically optimized for performance [36,63,64], and as a side effect, make it cumbersome for non-experts to learn and modify.
Also, besides this issue, due to the interplay between stochastic Brownian and molecular forces, infinitely long trajectories of existing MD integrators do not have the right distribution. What happens is that the Brownian force can cause the integrator to enter regions where its approximation to the molecular force is inaccurate and possibly destabilizing. In the latter case, the approximation spends a disproportionate amount of time at higher energies, and thus, the invariant measure of the approximation, if it even exists, is not correct. This phenomenon is a well-known shortcoming of explicit integrators for nonlinear diffusions [65–69].
Recently, a probabilistic approach was proposed to solve this problem, which questions the notion that Monte Carlo methods and MD have different aims: the former strictly samples probability distributions, and the latter estimates dynamics. The basic idea is to combine a standard MD integrator with a Metropolis-Hastings algorithm targeted to the Boltzmann-Gibbs distribution [70–72]. Because the scheme is a Monte Carlo method, it exactly preserves the desired distribution [71,72]. This property implies numerical stability over long-time simulations. However, the price to be paid for this stability is a loss of accuracy whenever a move is rejected and some overhead in evaluating the Metropolis acceptance-rejection step. Still, a Metropolized integrator is dynamically accurate on finite-time intervals [72,73], and so, even though a Metropolized integrator involves a Monte Carlo step, its aim and philosophy are very different from Monte Carlo methods, whose only goal is to sample a target distribution with no concern for the dynamics [71,74–82]. In principle, this approach offers a simple alternative to costly implicit integrators, but are Metropolized integrators ready for daily use in MD simulation? The answer to this question is unclear, since this approach is new and has not been tested on enough examples.
Motivated by these issues, this paper builds a software system for MD simulation with a Metropolis step built in and applies it to a homogeneous molecular system. The algorithm and its properties are introduced in a step-by-step fashion. In particular, we show that the integrator is second-order weakly accurate on finite-time intervals and converges to the Boltzmann-Gibbs distribution in the long-time limit. The software version of the algorithm is written in the latest version of MATLAB with plenty of comments, variables that are descriptively named and operations that can be easily translated into mathematical expressions [83]. Since MATLAB is widely available, this design ensures that the software will be easy-to-use and cross-platform. The following MATLAB-specific file formats will be used.
(F1) MATLAB script and function files are written in the MATLAB language and can be run from the MATLAB command line without ever compiling them.
(F2) MATLAB executable (MEX) files are written in the “C” language and compiled using the MATLAB mex function. The resulting executable is comparable in efficiency to a “C” code and can be called directly from the MATLAB command line. We will use MEX-files for performance-critical routines [84].
(F3) MATLAB binary (MAT) files will be used to store simulation data.
The paper is organized as follows. We begin with an overview of integrators that have been proposed in MD simulation in Section 2. We explain how to Metropolize each of these schemes to make them long-time stable in Section 3, and as an application, we use a Metropolized scheme to generate a long trajectory of a Lennard-Jones fluid in Section 4. Generalizations of corrected MD integrators to other molecular models are discussed in Section 5. The paper closes by discussing some potential pitfalls in high dimension and tricks to get the integrator to scale well in Section 6.
Algorithmic Introduction to Time Integrators for MD Simulation
For pedagogical reasons, we will start with Langevin dynamics of a system of N molecules. Then, we show in Section 5 how to simulate more general models of molecular systems. Denote by m_{j} > 0 and q_{j} the mass and position of the j-th molecule, respectively. The governing Langevin equation is given by:
{dqjdt(t)=mj−1pj(t),dpj(t)=−∂U∂qj(q(t))dt−γpj(t)dt+2kTγmjdwj,j=1,⋯,Nwhere q = (q_{1}, · · ·, q_{N}) and p = (p_{1}, · · ·, p_{N}) denote the positions and momenta of the particles, kT is the temperature factor, and
{wj}j=1N are N-independent Brownian motions. The last two terms in the second equation in (1) represent the effect of a heat bath with parameter γ. In Langevin dynamics, positions are differentiable, and due to the irregularity of the Brownian force, momenta are just continuous, but not differentiable. This difference in regularity explains why the first equation in (1) is written as an ordinary differential equation (ODE) and the second equation is written as a stochastic differential equation (SDE).
The bath-free dynamics is a Hamiltonian system with the following Hamiltonian energy function:
H(q,p)=∑j=1N12mj|pj|2+U(q)Since the masses are constant, this Hamiltonian nicely separates into a kinetic and potential energy that are purely functions of p and q, respectively. The stationary probability density of the solution to Equation (1) is the Boltzmann-Gibbs density given by:
ν(q,p)=Z−1exp(−1kTH(q,p)),Z=∫exp(−1kTH(q,p))dqdp
Let h be a given time step size and m = diag(m_{1}, · · ·, m_{N}). Let (Q_{0}, P_{0}) denote the position and momentum of the molecular system at time t > 0. The simplest approximation to Equation (1) is a forward Euler discretization or Euler-Maruyama scheme [85] that computes an updated position and momentum (Q_{1}, P_{1}) at t + h using:
Q1=Q0+hm−1P0P1=P0−h∇UQ0−hγP0+h2kTγm1/2ξHere, ξ ∈ ℝ^{n} denotes a Gaussian random vector with mean zero and covariance 𝔼(ξ_{i}ξ_{j}) = δ_{ij}. The problem with this approximation is that the forward Euler method is known to diverge in finite-time when the derivatives of the potential are unbounded, which is the norm in MD simulation. The precise statement and proof of divergence in a general setting can be found in [86]. By far the most computationally intensive part of the time-stepping algorithm is the evaluation of the potential force. Thus, we will restrict our discussion to schemes that, like Euler, only require a single force field evaluation per step.
An improvement to the forward Euler method is the following two-step scheme:
Q2=(1+e−γh)Q1−e−γhQ0+1−e−γhγm−1(−h∇U(Q1)+h2kTγm1/2ξ)In the limit, γ → 0, this scheme reduces to the well-known Verlet integrator for MD simulation [7]. Just like Verlet, this integrator defines a map on pairs of molecular system configurations. Substituting the approximation, e^{−γh} ≈ (1−γh/2)/(1+γh/2), into the above yields the Brünger-Brooks-Karplus (BBK) scheme, as appearing in [35]. Like the forward Euler method, this method is explicit and only requires one new force evaluation per step.
Second-order accurate schemes that generalize the Velocity Verlet integrator to Langevin dynamics were proposed in a sequence of papers [42–44,87,88]. Here, we mention two of these schemes that are both Strang splittings of Equation (1). The first was proposed by Ricci and Ciccotti [42] and consists of the following sub-steps:
(q˙(t)=m−1p(t)dp(t)=0)︸exactlyevolveby1/2astep°(q˙(t)=0dp(t)=−∇U(q(t))dt−γp(t)dt+2kTγm1/2dW)︸exactlyevolvebyastep°(q˙(t)=m−1p(t)dp(t)=0)︸exactlyevolveby1/2astepEach step in this decomposition can be exactly solved. Clearly, the half-steps are easy to solve, since momentum is constant over each of these half-steps. The SDE appearing in the inner step can also be exactly solved, since it is linear in momentum (see Chapter 5 in [89]). This splitting is quite natural, since it treats the heat bath forces in the same way as the potential forces.
A related, but different, splitting method was proposed by Bussi and Parinello in [43] and is given by:
(q˙(t)=0dp(t)=−γp(t)dt+2kTγm1/2dW)︸exactlyevolveby1/2astep°(q˙(t)=m−1p(t)p˙(t)=−∇U(q(t)))︸approximatelyevolveusingastepofVerlet°(q˙(t)=0dp(t)=−γp(t)dt+2kTγm1/2dW)︸exactlyevolveby1/2astepNotice that this decomposition splits the Langevin dynamics into its Hamiltonian and heat bath parts, which makes it easy to analyze the structural properties of the scheme. A Velocity Verlet integrator is used to approximate the Hamiltonian dynamics. This approximation exactly preserves phase space volume and preserves energy to third-order accuracy per step. Moreover, the solution to the SDE appearing in the half-steps exactly preserves the Boltzmann-Gibbs density.
Since the Velocity Verlet integrator does not exactly preserve energy, the composition above does not exactly preserve the stationary distribution with density in Equation (3). In [90], it was shown that if the derivatives of the potential are all bounded, the Bussi and Parinello integrator possesses an invariant measure that is 𝒪(h^{2}) close to the Boltzmann-Gibbs distribution. In this same context, the leading order error term in the integrator’s approximation to the invariant measure was explicitly determined [91]. Technically speaking, however, these results do not directly apply to MD simulation, since real MD simulation involves potentials whose derivatives are unbounded, e.g., Lennard-Jones forces. As a consequence of this irregularity in the force fields and discretization error, explicit schemes, like this one, may either not detect features of the potential energy properly, which leads to unnoticed, but large errors in dynamic quantities such as the mean first passage time, or may mishandle soft- or hard-core potentials, which leads to numerical instabilities; see the numerical examples in [92]. These numerical artifacts motivate adding a Metropolis accept/refusal sub-step to the integrator. In the next section, we show how to Metropolize all of the MD integrators presented in this section. In Section 5, we explain how to generalize the Metropolis-corrected Bussi and Parinello algorithm to a larger class of diffusion processes.
Metropolis-Corrected MD Integrators
Here, we show how to add a Metropolis acceptance-rejection step to a BBK-type scheme and the Bussi and Parinello splitting scheme and then precisely state the properties of these integrators. We start with a detailed description of each algorithm. Both algorithms require evaluating the acceptance probability given by the usual Metropolis ratio:
α(q,p,Q,P)=min(1,exp(−1kT(H(Q,P)−H(q,p,))))The procedure to Metropolize the Ricci and Ciccotti scheme can be found in Section 2 of [70].
Algorithm 3.1 (First-order BBK-type integrator). Given the current state (Q_{0}, P_{0}) at time t, the algorithm proposes a new state (
Q1★,
P1★) at time t + h for some time step h > 0 via:
(Q1★P1★)=(Q0+m−1(hP0−h22∇U(Q0))P0−h2(∇U(Q0)+∇U(Q1★)))This “proposal move” (
Q1★,
P1★) is then accepted or rejected:
(Q˜1P˜1)=x(Q1★P1★)+(1−x)(Q0−P0)where x is a Bernoulli random variable with parameter α(Q_{0}, P_{0},
Q1★,
P1★) given by Equation (4). The actual update of the system is taken to be:
(Q1P1)=(Q˜1exp(−γh)P˜1+kT1−exp(−2γh)m1/2ξ)Here, ξ ∈ ℝ^{n} denotes a Gaussian random vector with mean zero and covariance 𝔼(ξ_{i}ξ_{j}) = kTδ_{ij}.
The momenta of the molecules gets reversed if a move is rejected in Step 2 of Algorithm 3.1. This momentum flip is necessary for the algorithm to preserve the correct stationary distribution [70,71], but results in an O(1) error in dynamics. High acceptance rates are therefore needed to ensure that the time lag between successive rejections is frequently long enough for the approximation to capture the desired dynamics. Since the acceptance rate in Equation (4) is related to how well the Verlet integrator in (Step 1) preserves energy after a single step, this rejection rate is O(h^{3}). Thus, in practice, we find that the time step required to obtain a sufficiently high acceptance rate is often automatically fulfilled by a time step that sufficiently resolves the desired dynamics. Each step of this algorithm requires: evaluating the atomic force field once in the third equation of (Step 1), generating a Bernoulli random variable with parameter α in (Step 2) and generating an n-dimensional Gaussian vector in (Step 3). We stress that (Step 2) in Algorithm 3.1 is all that is needed to get MD integrators to exactly preserve the Boltzmann-Gibbs density in Equation (3).
Next, we show how to Metropolize the Bussi and Parinello splitting integrator.
Algorithm 3.2 (Second-order Bussi and Parinello integrator). Let ξ, η ∈ ℝ^{n} be two independent Gaussian random vectors with mean zero and covariance 𝔼(ξ_{i}ξ_{j}) = 𝔼 (η_{i}η_{j}) = δ_{ij}. Given a time step size h and the current state (Q_{0}, P_{0}) at time t, the algorithm takes a half-step of the heat bath dynamics:
(Q˜0P˜0)=(Q0exp(−γh/2)P˜0+kT1−exp(−γh)m1/2ξ)Followed by a full step of Verlet to compute a proposal move (
Q˜1★,
P˜1★):
(Q˜1★P˜1★)=(Q˜0+m−1(hP˜0−h22∇U(Q˜0))P0−h2(∇U(Q˜0)+∇U(Q˜1★)))This proposal move (
Q˜1★,
P˜1★) is then accepted or rejected:
(Q˜1P˜1)=x(Q˜1★P˜1★)+(1−x)(Q˜0−P˜0)where x is a Bernoulli random variable with parameter α(Q̃_{0}, P̃_{0},
Q˜1★,
P˜1★) given by Equation (4). The actual update of the system t + h is taken to be:
(Q1P1)=(Q˜1exp(−γh/2)P˜1+kT1−exp(−γh)m1/2η)
This algorithm requires generating two independent n-dimensional Gaussian vectors per step. Thus, it is more costly than Algorithm 3.1. However, the advantage of doing this is that the resulting Metropolis corrected algorithm is second-order weakly accurate, as the following Proposition states.
Proposition 3.3.Let (Q_{n},P_{n}) represent the numerical approximation produced by Algorithm 3.2 at time nh with the same initial condition as the true solution: (Q_{0}, P_{0}) = (q(0), p(0)). For every time interval T > 0 and for suitable observables f(q, p), there exists a C(T) > 0, such that:|𝔼f(q(⌊t/h⌋h),p(⌊t/h⌋h))−𝔼f(Q⌊t/h⌋,P⌊t/h⌋)|≤C(T)h2for all t < T.
This accuracy concept is sufficient for computing means and correlation functions at finite-time and equilibrium correlations. Figure 2 verifies this Proposition by checking the weak accuracy of Algorithms 3.1 and 3.2 on a harmonic oscillator test problem.
To be specific, Figure 2 plots the weak accuracy of the Metropolis-corrected MD integrators with respect to the true solution of the Langevin dynamics of a harmonic oscillator: q̇(t) = p(t),
dp(t)=−q(t)−p(t)+2dw(t), with initial condition q(0) = 1.0, p(0) = 0. The time steps tested are h = 2^{−n}, where n is given on the x-axis. The quantity monitored for the error is the estimate of 𝔼(q(1)^{2} + p(1)^{2}) = 1.699445410 computed analytically. The dashed and solid curves are the graphs of 2^{−n}(= h) and 2^{−2n}(= h^{2}) versus n, respectively.
Proof. The desired single-step error estimate can be obtained from an application of the triangle inequality:
|𝔼f(q(h),p(h))−𝔼f(Q1,P1)|≤|𝔼f(q(h),p(h))−𝔼f(Q^1,P^1)|+|𝔼f(Q^1,P^1)−𝔼f(Q1,P1)|where (Q̂_{1}, P̂_{1}) denotes one step of the uncorrected Bussi and Parinello scheme with (Q̂_{0}, P̂_{0}) = (q(0), p(0)). The first term in the upper bound in Equation (6) is O(h^{3}), since the unadjusted scheme is a Strang splitting of Equation (1). To bound the second term in Equation (6), note that:
𝔼f(Q1,P1)−𝔼f(Q^1,P^1)=𝔼{(f¯(Q˜1★,P˜1★)−f¯(Q˜0,−P˜0))(α(Q˜0,P˜0,Q˜1★,P˜1★)−1)}where we have introduced the auxilary function:
f¯(q,p)=𝔼f(q,exp(−γh/2)p+kT1−exp(−γh)m1/2η)Since the rejection rate is 𝒪(h^{3}), it follows from the above expression that the second term in the upper bound of Equation (6) is also O(h^{3}). Standard results in numerical analysis for SDEs then imply that the algorithm converges weakly on finite-time intervals with global order two; see, for instance, [93] (Chapter 2.2).
For completeness sake, we also provide a statement that both algorithms are ergodic.
Proposition 3.4.Let (Q_{n}, P_{n}) be the numerical approximation produced by Algorithms 3.1 or 3.2 at time nh. Then, for suitable observables f(q, p):
limT→∞1T∫0Tf(Q⌊t/h⌋,P⌊t/h⌋)dt→∫ℝ2nf(q,p)ν(q,p)dqdpHere, ν(q, p) denotes the Boltzmann-Gibbs density defined inEquation (3).
A proof of this Proposition can be found in [72].
Application to Lennard-Jones Fluid
Listing 1 translates Algorithm 3.2 into the MATLAB language. Intrinsically defined MATLAB functions appear in boldface. The algorithm uses MATLAB’s built in random number generators to carry out Step 1, Step 3 and Step 4. In particular, the Bernoulli random variable, x, in Step 3 is generated in Line 20, and the Gaussian vectors in Step 1 and Step 4 are generated on Line 9 and Line 29, respectively. In addition to updating the positions and momenta of the system, the program also stores the previous value of the potential energy and force, so that the force and potential energy is evaluated in Line 15 just once per simulation step. This evaluation calls a MEX function, which inputs the current position of the molecular system and outputs the force field and potential energy at that position. We use a MEX function, because the atomistic force field evaluation cannot be easily vectorized and is, by far, the most computationally demanding step in MD. The
PreProcessing script file called in Line 2 defines the physical and numerical parameters, sets the initial condition and allocates space for storing simulation data. Sample averages are updated as new points on the trajectory are produced in the
UpdateSampleAverages script file invoked in Line 35. Finally, the outputs produced by the algorithm are handled by the
PostProcessing script file in Line 39.
Let us consider a concrete example: a Lennard-Jones fluid that consists of N identical atoms [1–3]. The configuration space of this system is a fixed cubic box with periodic boundary conditions. The distance between the i-th and j-th particle is defined according to the minimum image convention, which states that the distance between q_{i} and q_{j} in a cubic box of length ℓ is:
dMD(qi,qj)=def|(qi,qj)−ℓ⌊(qi,qj)/ℓ⌉|where ⌊·⌉ is the nearest integer function. In terms of this distance, the total potential energy is a sum over all pairs:
U(q)=∑i=1n−1∑j=i+1nULJ(dMD(qi,qj))where U_{LJ}(r) is the following truncated Lennard-Jones potential function:
ULJ(r)={f(r)−f(rc),r<rc0,otherwise
Metropolized MD Integrator:
MDintegrator.m
Metropolized MD Integrator:
PreProcessing.m
Here, f(r) = 4(1/r^{12}− 1/r^{6}) and r_{c} is the cutoff radius, which is bounded above by the size of the simulation box; and we have used dimensionless units to describe this system, where energy is rescaled by the depth of the Lennard-Jones potential energy and length by the point where the potential energy is zero. The error introduced by the truncation in Equation (10) is proportional to the density of the molecular system and can be made arbitrarily small by selecting the cutoff distance to be sufficiently large. A direct evaluation of the potential force, ∇U(q), scales like O(N^{2}), and typically dominates the total computational cost. In practice, neighbor/cell lists, also called Verlet lists, are used in order to obtain a force evaluation that scales linearly with system size. Since the system we consider will have just a few hundred atoms, there is, however, little advantage to using these data structures, or using a fast force field evaluation, and thus,
ForceFieldmex evaluates the force and energy using a sum over all particle pairs.
Listing 2 shows the
PreProcessing script, which sets the parameters provided in Table 1 and constructs the initial condition, where the N atoms are assumed to be at rest and on the sites of a face-centered cubic lattice. The command,
rng(123), on Line 3 sets the seed of the random number generator functions,
RAND and
RANDN. The acceptance rates at every step and the velocity autocorrelation are updated in the
UpdateSampleAverages script shown in Listing 3. The mean acceptance rate, which is outputted in the
PostProcessing script shown in Listing 4, must be high enough to ensure that the dynamics is accurately represented. To compute the autocorrelation of an observable over a time interval of length T, the value of that observable along the entire trajectory is not needed. In fact, it suffices to use the values of this observable along a piece of trajectory over a moving time-window [t_{i}, t_{i} + T ], where t_{i} = i × h. This storage space is allocated in
PreProcessing and is updated in
UpdateSampleAverages. More precisely, the molecular velocities are stored in the pivot array from i − N_{a} to i, where i is the index of the current position and N_{a} = ⌈T/h⌉ + 1. Notice that velocity autocorrelations are not computed until after the index, i, exceeds 10^{4}. This equilibration time removes some of the statistical bias that may arise from using a non-random initial condition. Short-time trajectories of this molecular system are plotted in Figure 3 from an initial condition where atoms are placed on the sites of a face-centered cubic lattice and at rest. The trajectory is computed using the numerical and physical parameters indicated in Table 1, with the exception of the number of steps, which is set equal to N_{s} = 1000. Notice that at lower densities particle trajectories are more diffusive and less localized. Using the parameters provided in Table 1, we compute velocity autocorrelations for a range of density values in Figure 4. Since the heat bath parameter is set to a small value, these figures are in qualitative agreement with those obtained by simulating the molecular system with no heat bath as shown in Figure 5.2 of [3].
Here, we show how the preceding ideas extend to other molecular systems that obey stochastic differential equations. In the process, we generalize the Metropolized Bussi and Parinello integrator (Algorithm 3.2) to a big class of diffusion processes, including the v-rescale thermostat. We begin with the underlying Hamiltonian dynamics of a molecular system.
Bath-Free Dynamics
MD is based on Hamilton’s equations for a Hamiltonian H: ℝ^{2}^{d} → ℝ:
z˙(t)=J∇H(z(t)),z(0)∈ℝ2dwhere z(t) = (q(t), p(t)) is a vector of molecular positions q(t) ∈ ℝ^{d} and momenta p(t) ∈ ℝ^{d} and J is the 2d × 2d skew-symmetric matrix defined as:
J=(0d×dId×d−Id×d0d×d)The Hamiltonian, H(z), represents the total energy of the molecular system and is typically “separable”, meaning that it can be written as:
H(z)=K(p)+U(q),z=(q,p)where K(p) and U(q) are the kinetic and potential energy functions, respectively [94]. In MD, the kinetic energy function is a positive definite quadratic form, and the potential energy function involves “fudge factors” determined from experimental or quantum mechanical studies of pieces of the molecular system of interest [36]. The accuracy of the resulting energy function must be systematically verified by comparing MD simulation data to experimental data [95]. The flow that Equation (11) determines has the following structure:
(S1) volume-preserving (since the vector-field in Equation (11) is divergenceless); and
(S2) energy-preserving (since J is skew-symmetric and constant).
Explicit symplectic integrators, like the Verlet scheme, exploit these properties to obtain long-time stable schemes for Hamilton’s equations [96,97].
Governing Stochastic Dynamics
In order to mimic experimental conditions, Equation (11) is often coupled to a bath that puts the system at constant temperature and/or pressure. The standard way to do this is to assume that the system with a bath is governed by a stochastic ordinary differential equation (SDE) of the type:
dY(t)=A(Y(t))dt︸deterministicdrift+(divD)(Y(t))dt+2kTB(Y(t))dW(t)︸heatbathHere, we have introduced the following notation.
Y(t) ∈ ℝ^{n}
state of the (extended) system
A(x) ∈ ℝ^{n}
deterministic drift vector field
B(x) ∈ ℝ^{n}^{×}^{n}
noise-coefficient matrix
D(x) ∈ ℝ^{n}^{×}^{n}
diffusion matrix
W (t) ∈ ℝ^{n}
n-dimensional Brownian motion
kT
temperature factor
The n × n diffusion matrix, D(x), is defined in terms of the noise coefficient matrix, B(x), as:
D(x)=defkTB(x)B(x)T,forallx∈ℝnwhere B(x)^{T} denotes the transpose of the real matrix, B(x). The diffusion matrix is symmetric and nonnegative definite. Depending on the particular bath that is used, the dimension, n, of Y (t) in Equation (14) is related to the dimension, 2d, of z(t) in Equation (11) by the inequality: n ≥ 2d. For example, in Nosé-Hoover Langevin dynamics, a single bath degree of freedom is added to Equation (11), so that n = 2d + 1, while in Langevin dynamics, the effect of the bath is modeled by added friction and Brownian forces that keep n = 2d. The Langevin Equation (1) can be put in the form of Equation (14) by letting x = (q, p),
A(x)=(m−1p−∇U(q)−γp),B=γ(000m1/2),andW=(w1,⋯,wN)where m = diag(m_{1}, · · ·, m_{N}).
Equation (14) generates a stochastic process, Y (t), that is a Markov diffusion process. We assume that this diffusion process admits a stationary distribution μ(dx), i.e., a probability distribution preserved by the dynamics [98,99]. We denote by ν(x) the density of this distribution. Even though the diffusion matrix in Equation (15) is not necessarily positive definite, one can use the Hörmander’s condition to prove that the process, Y (t), is an ergodic process with a unique stationary distribution [100,101]. By the ergodic theorem, it then follows that:
1T∫0Tf(Y(t))dt→∫ℝnf(x)ν(x)dx,asT→∞,a.s.where f(x) is a suitable test function.
The evolution of the probability density of the law of Y (t) at time t, ρ(t, x), satisfies the Fokker-Planck equation:
−∂ρ∂t+Lρ=0where ρ(0, ·) is the density of the initial distribution, Y (0) ∼ ρ(0, ·), and L is defined as the following second-order partial differential operator:
(Lf)(x)=defdiv(div(D(x)f(x))−A(x)f(x))Since μ(dx) = ν(x)dx is a stationary distribution of Y (t), the probability density, ν(x), is a steady-state solution of Equation (18), i.e., it satisfies:
(Lν)(x)=0Define the probability current as the vector field:
j(x)=defdiv(D(x)ν(x))−A(x)ν(x)The stationarity condition in Equation (20) implies that j(x) is divergenceless. In the zero-current case, the diffusion process, Y (t), is reversible, and the stationary density ν(x) is called the equilibrium probability density of the diffusion [102].
In this case, the operator, L, is self-adjoint, in the sense that:
〈Lf,g〉ν=〈f,Lg〉νforallsuitabletestfunctionsf,gwhere 〈·, ·〉_{ν} denotes an L^{2} inner product weighted by the density, ν(x). This property implies that the diffusion is ν-symmetric [103]:
ν(x)pt(x,y)=ν(y)pt(y,x)forallt>0where p_{t}(x, y) denotes the transition probability density of Y (t). Indeed, Equation (22) is simply an infinitesimal version of Equation (23), which is referred to as the detailed balance condition. In the self-adjoint case, the drift is uniquely determined by the diffusion matrix and the stationary density ν(x):
j(x)=0⇒A(x)=1ν(x)div(D(x)ν(x))Long-time stable explicit schemes adapted to this structure have been recently developed [92].
Splitting Approach to MD Simulation
We are now in a position to explain our general approach for deriving a long-time stable scheme for Equation (14). Crucial to our approach is that in MD simulation, we usually have a formula for a function proportional to the stationary density ν(x). Following [90], we can split Equation (14) into:
dY=−D(Y)∇Hν(Y)dt+divD(Y)dt+2kTB(Y)dWY˙=A(Y)+D(Y)∇Hν(Y)where we have introduced H_{ν}(x) = −(log ν)(x). An exact splitting method preserves μ(dx). It is formed by taking the exact solution (in law) of Equation (25) in composition with the exact flow of Equation (26). The process produced by Equation (25) is self-adjoint with respect to ν(x). Moreover, the stationarity of ν(x) implies that the flow of the ODE (26) preserves it. Since each step is preservative, their composition is, too.
In place of the exact splitting, a Metropolized explicit integrator can be used for Equation (25) [92], and a measure-preserving scheme can be designed to solve the ODE [72,104]. In [92], explicit schemes are introduced for Equation (25) that: (i) sample the exact equilibrium probability density of the SDE when this density exists (i.e., whenever ν(x) is normalizable); (ii) generates a weakly accurate approximation to the solution of Equation (14) at constant kT ; (iii) acquire higher order accuracy in the small noise limit, kT → 0; and (iv) avoid computing the divergence of the diffusion matrix D(x). Compared to the methods in [72], the main novelty of these schemes stems from (iii) and (iv). The resulting explicit splitting method is accurate, since it is an additive splitting of Equation (14); and typically ergodic when the continuous process is ergodic [72].
This type of splitting of Equation (14) is quite natural and has been used before in MD [43,87], dissipative particle dynamics [105,106] and the simulation of inertial particles [107]. Other closely related schemes for Equation (14) include Brünger-Brooks-Karplus (BBK) [35], van Gunsteren and Berendsen (vGB) [108] and the Langevin-Impulse (LI) methods [41] and quasi-symplectic integrators [44]. However, for general MD force fields, none of these explicit integrators are long-time stable. Our framework to stabilize explicit MD integrators is the Metropolis-Hastings algorithm.
Metropolis-Hastings Algorithm
A Metropolis-Hastings method is a Monte Carlo method for producing samples from a probability distribution, given a formula for a function proportional to its density [74,75]. The algorithm consists of two sub-steps: firstly, a proposal move is generated according to a transition density, g(x, y); and secondly, this proposal move is accepted or rejected with a probability:
α(x,y)=1∧g(x,y)ν(y)g(x,y)ν(x)Standard results on Metropolis-Hastings methods can be used to classify this algorithm as ergodic [100,109,110].
Conclusions
This paper provided an algorithmic introduction to time integrators for MD simulation. A quick overview of existing algorithms was given. When the derivatives of the potential are bounded, it is well known that these integrators work just fine: they are convergent on finite-time intervals and possess an invariant measure that is nearby the Boltzmann-Gibbs density. However, in realistic MD simulation, the derivatives of the potential are unbounded. This lack of regularity can cause numerical instabilities or artifacts in explicit integrators. The paper demonstrated how a Metropolis acceptance-rejection step can be added to explicit MD integrators to mitigate some of these problems and, in principle, obtain long-time stable and finite-time accurate schemes. A MATLAB implementation of Metropolis-corrected MD integrators was provided and used to compute the velocity autocorrelation of a sea of Lennard-Jones particles at various densities between the solid and liquid phases. The paper did not provide an in-depth review of the theory of Metropolis integrators, which can be found elsewhere [72,73].
Calculating the force field at every step dominates the overall computational cost of MD simulation. These force fields involve: bonded interactions and non-bonded Lennard-Jones and electrostatic interactions. The calculation of bonded interactions is straightforward to vectorize and scales like O(N). In addition, Lennard-Jones forces rapidly decay with interatomic distance. To a good approximation, every atom interacts only with neighbors within a sufficiently large ball. By using data structures, like neighbor lists and cell linked lists, these interactions can be calculated in O(N) steps, and therefore, the Lennard-Jones interactions can be calculated in O(N) steps [46]. On the other hand, the electrostatic energy between particles decays, like 1/r, where r denotes an interatomic distance, which leads to long-range interactions between atoms. Unlike Lennard-Jones interaction, this interaction cannot be cutoff without introducing large errors. In this case, one can use sophisticated techniques, like the fast multipole method, to rigorously handle such interactions in 𝒪(N) steps [39,58].
However, the effect of these ‘mathematical tricks’ for fast calculation of the force field can become muted if the time step requirement for stability or accuracy becomes more severe in high dimension. This can happen in the Metropolis integrator, if the acceptance probability in Step 2 of Algorithm 3.1 or Step 3 of Algorithm 3.2 deteriorates in high dimension. The scaling of Metropolis algorithms has been quantified for the random walk Metropolis, hybrid Monte Carlo and Metropolis-adjusted Langevin algorithm (MALA) [111–115]. Since the acceptance probability is a function of an extensive quantity, the acceptance rate can artificially deteriorate with increasing system size, unless the time step is reduced. Because high acceptance rates are required to maintain dynamic accuracy, the dependence of the time step on system size limits the application of Metropolized schemes to large-scale systems. Fortunately, this scalability issue can often be resolved by using local, rather than global proposal moves, because the change in energy induced by a local move is typically an intensive quantity. For molecular dynamics calculations, this approach was pursued in [73]. Using dynamically consistent local moves (a so-called J-splitting [116]), it was shown that in certain situations, a scalable Metropolis integrator can be designed; however, the extent to which this strategy remedies the issue of high rejection rate in high dimension is not clear at this point and should be tested in applications.
The author wishes to acknowledge Eric Vanden-Eijnden for useful comments on an earlier version of this paper. The research that led to this paper was funded by the US National Science Foundation through Division of Mathematical Sciences (DMS) grant # DMS-1212058.
Conflicts of Interest
The authors declare no conflict of interest.
ReferencesAllenM.P.TildesleyD.J.FrenkelD.SmitBRapaportD.C.TuckermanMSchlickTRahmanACorrelations in the motion of atoms in liquid argonVerletLComputer “experiments” on classical fluids. I. Thermodynamical properties of Lennard-Jones moleculesAlderB.J.WainwrightT.E.Velocity autocorrelations for hard spheresAlderB.J.GassD.M.WainwrightT.E.Studies in molecular dynamics. VIII. The transport coefficients for a hard-sphere fluidHarpG.D.BerneB.J.Time-correlation functions, memory functions, and molecular dynamicsRahmanA.StillingerF.H.Molecular dynamics study of liquid waterStillingerF.H.RahmanAImproved simulation of liquid water by molecular dynamicsStillingerF.H.Water revisitedMcCammonA.J.GelinB.R.KarplusMDynamics of folded proteinsVan GunsterenW.F.BerendsenH.J.C.Algorithms for macromolecular dynamics and constraint dynamicsMcCammonJ.A.KarplusMSimulation of protein dynamicsVan GunsterenW.F.KarplusMProtein dynamics in solution and in a crystalline environment: A molecular dynamics studyKarplusM.McCammonA.J.Dynamics of proteins: Elements and functionVan GunsterenW.F.BerendsenH.J.C.Computer simulation of molecular dynamics: Methodology, applications, and perspectives in chemistryKarplusM.McCammonA.J.Molecular dynamics simulations of biomoleculesCaseD.A.Molecular dynamics and NMR spin relaxation in proteinsAdcockA.S.McCammonA.J.Molecular dynamics: Survey of methods for simulating the activity of proteinsVan GunsterenW.F.DolencJ.MarkA.E.Molecular simulation as an aid to experimentalistsKapralR.CiccottiGMolecular dynamics: An Account of its EvolutionLevittMMolecular dynamics of native protein: I. Computer simulation of trajectoriesLevittM.SharonRAccurate simulation of protein dynamics in solutionDaggettV.LevittMA model of the molten globule state from molecular dynamics simulationsLiA.DaggettVInvestigation of the solution structure of chymotrypsin inhibitor 2 using molecular dynamics: Comparison to X-Ray crystallographic and NMR dataDuanY.KollmanP.A.Pathways to a protein folding intermediate observed in a 1-microsecond simulation in aqueous solutionFreddolinoP.L.LiuF.GruebeleM.SchultenKTen-microsecond molecular dynamics simulation of a fast-folding WW domainShawD.E.MaragakisP.Lindorff-LarsenK.PianaS.DrorR.O.EastwoodM.P.BankJ.A.JumperJ.M.SalmonJ.K.ShanYAtomic-level characterization of the structural dynamics of proteinsQuentrecB.BrotCNew method for searching for neighbors in molecular dynamics computationsRyckaertJ.P.CiccottiG.BerendsenH.J.C.Numerical integration of the Cartesian equations of motion of a system with constraints: Molecular dynamics of n-AlkanesSchneiderT.StollEMolecular dynamics study of a three-dimensional one-component model for distortive phase transitionsBrüngerA.BrooksC.L.KarplusMStochastic boundary conditions for molecular dynamics simulations of ST2 waterBrooksB.R.BruccoleriR.E.OlafsonB.D.StatesD.J.SwaminathanS.KarplusMCHARMM: A program for macromolecular energy, minimization, and dynamics calculationsNoséSA unified formulation for constant temperature molecular dynamics methodsHooverW.G.Canonical dynamics: Equilibrium phase-space distributionsGreengardL.RokhlinVA fast algorithm for particle simulationsTuckermanM.E.BerneB.J.MartynaGReversible multiple time scale molecular dynamicsSkeelR.D.IzaguirreJAn impulse integrator for Langevin dynamicsRicciA.CiccottiGAlgorithms for Brownian dynamicsBussiG.ParrinelloMAccurate sampling using Langevin dynamicsMilsteinG.N.TretyakovM.V.Quasi-symplectic methods for Langevin-type equationsMilsteinG.N.TretyakovM.V.Computing ergodic limits for Langevin equationsYaoZ.WangJ.S.LiuG.R.ChengMImproved neighbor list algorithm in molecular simulations using cell decomposition and data sorting methodBussiG.DonadioD.ParrinelloMCanonical sampling through velocity rescalingSamoletovA.A.ChaplainM.A.DettmannC.P.Thermostats for “Slow” configurational modesLeimkuhlerB.NoorizadehE.TheilFA gentle stochastic thermostat for molecular dynamicsLeimkuhlerB.ReichS. AMetropolis adjusted Nosé-Hoover thermostatScheragaH.A.KhaliliM.LiwoAProtein-folding dynamics: Overview of molecular simulation techniquesDrorR.O.DirksR.M.GrossmanJ.P.XuH.ShawD.E.Biomolecular simulation: A computational microscope for molecular biologyLaneT.J.ShuklaD.BeauchampK.A.PandeV.S.To milliseconds and beyond: Challenges in the simulation of protein foldingNielsenS.O.LopezC.F.SrinivasG.KleinM.L.Coarse grain models and the computer simulation of soft materialsTozziniVCoarse-grained models for proteinsClementiCCoarse-grained models of protein folding: Toy models or predictive tools?SherwoodP.BrooksB.R.SansomM.S.P.Multiscale methods for macromolecular simulationsWeinanEWeinanE.Vanden-EijndenEMetastability Conformation Dynamics, and TransitionPathwaysin Complex SystemsVanden-EijndenE.VenturoliMMarkovian milestoning with Voronoi tessellationsJ. Chem. Phys2009130194101Vanden-EijndenE.VenturoliMExact rate calculations by trajectory parallelization and twistingJ. Chem. Phys2009131044120WeinanE.Vanden-EijndenETransition-path theory and path-finding algorithms for the study of rare eventsAnnu. Rev. Phys. Chem201061391420NelsonM.T.HumphreyW.GursoyA.DalkeA.KaléL.V.SkeelR.D.SchultenKNAMD: A parallel, object-oriented molecular dynamics programInt. J. High Perform. Comput. Appl199610251268ScottW.R.P.HünenbergerP.H.TironiI.G.MarkA.E.BilleterS.R.FennenJ.TordaA.E.HuberT.KrügerP.van GunsterenW.F.The GROMOS biomolecular simulation program packageJ. Phys. Chem. A199910335963607TalayDStochastic Hamiltonian systems: Exponential convergence to the invariant measure, and discretization by the implicit Euler schemeMarkov Process. Relat. Fields20028136HighamD.J.MaoX.StuartA.M.Strong convergence of Euler-type methods for nonlinear stochastic differential equationsIMA J. Num. Anal20024010411063MilsteinG.N.TretyakovM.V.Numerical integration of stochastic differential equations with nonglobally Lipschitz coefficientsIMA J. Num. Anal20054311391154HighamD.J.Stochastic ordinary differential equations in applied and computational mathematicsIMA J. Appl. Math201176449474HutzenthalerM.JentzenA.KloedenP.E.Strong convergence of an explicit numerical method for SDEs with non-globally Lipschitz continuous coefficientsAnn. Appl. Probab20122216111641ScemamaA.LelièvreT.StoltzG.CancésE.CaffarelMAn efficient sampling algorithm for variational Monte CarloJ. Chem. Phys2006125114105AkhmatskayaE.Bou-RabeeN.ReichSA comparison of generalized hybrid Monte Carlo methods with and without momentum flipJ. Comput. Phys200922822562265Bou-RabeeN.Vanden-EijndenEPathwise accuracy and ergodicity of Metropolized integrators for SDEsCommun. Pure Appl. Math201063655696Bou-RabeeN.Vanden-EijndenEA patch that imparts unconditional stability to explicit integrators for Langevin-like equationsJ. Comput. Phys201223125652580MetropolisN.RosenbluthA.W.RosenbluthM.N.TellerA.H.TellerEEquations of state calculations by fast computing machinesJ. Chem. Phys19532110871092HastingsW.K.Monte-Carlo methods using Markov chains and their applicationsBiometrika19705797109RosskyP.J.DollJ.D.FriedmanH.L.Brownian dynamics as smart Monte Carlo simulationJ. Chem. Phys1978694628DuaneS.KennedyA.D.PendletonB.J.RowethDHybrid Monte-CarloPhys. Lett. B1987195216222HorowitzA.M.A generalized guided Monte-Carlo algorithmPhys. Lett. B1991268247252KennedyA.D.PendletonBCost of the generalized hybrid Monte Carlo algorithm for free field theoryNucl. Phys. B2001607456510LiuJ.S.Monte Carlo Strategies in Scientific Computing2nd ed.SpringerBerlin/Heidelberg, Germany2008AkhmatskayaE.ReichSGSHMC: An efficient method for molecular simulationJ. Comput. Phys200822749374954LelièvreT.RoussetM.StoltzGFree Energy Computations: A Mathematical Perspective1st ed.Imperial College PressLondon, UK2010MATLAB, Version 8.0.0 (R2012b)The MathWorks IncNatick, MA, USA2012Introducing MEX-Files. Available online: http://www.mathworks.com/help/matlab/matlab_external/introducing-mex-files.html(accessed on 19 September 2013)KloedenP.E.PlatenENumerical Solution of Stochastic Differential EquationsSpringerBerlin, Germany1992HutzenthalerM.JentzenA.KloedenP.E.Strong and weak divergence in finite time of Euler’s method for stochastic differential equations with non-globally Lipschitz continuous coefficientsProc. R. Soc. A: Math. Phys. Eng. Sci201146715631576Vanden-EijndenE.CiccottiGSecond-order integrators for Langevin equations with holonomic constraintsChem. Phys. Lett2006429310316LeimkuhlerB.MatthewsCRobust and efficient configurational molecular sampling via Langevin dynamicsJ. Chem. Phys2013138174102EvansLAn Introduction to Stochastic Differential EquationsAmerican Mathematical SocietyProvidence, RI, USA2013Bou-RabeeN.OwhadiHLong-run accuracy of variational integrators in the stochastic contextSIAM J. Numer. Anal201048278297LeimkuhlerB.MatthewsC.StoltzGThe computation of averages from equilibrium and nonequilibrium Langevin molecular dynamics2013arXiv:1308.5814Bou-RabeeN.DonevA.Vanden-EijndenEMetropolized integration schemes for self-adjoint diffusions2013arXiv:1309.5037MilsteinG.N.TretyakovM.V.Stochastic Numerics for Mathematical PhysicsSpringerBerlin, Germany2004MarsdenJ.ERatiuT.S.Introduction to Mechanics and Symmetry: A Basic Exposition of Classical Mechanical SystemsSpringerBerlin/Heidelberg, Germany1999Van GunsterenW.F.MarkA.E.Validation of molecular dynamics simulationJ. Chem. Phys199810861096116LeimkuhlerB.ReichSSimulating Hamiltonian Dynamics; Cambridge Monographs on Applied and Computational MathematicsCambridge University PressCambridge, UK2004HairerE.LubichC.WannerGGeometric Numerical IntegrationSpringerBerlin/Heidelberg, Germany2010IkedaN.WatanabeSStochastic Differential Equations and Diffusion ProcessesNorth-HollandAmsterdam, The Netherlands1989KlebanerF.C.Introduction to Stochastic Calculus with ApplicationsImperial College PressLondon, UK2005MengersenK.L.TweedieR.L.Rates of convergence of the Hastings and Metropolis algorithmsAnn. Stat199624101121PratoG.D.ZabczykJErgodicity for Infinite Dimensional SystemsCambridge University PressCambridge, UK1996HaussmanU.G.PardouxETime reversal for diffusionsAnn. Probab19861411881205KentJTime-reversible diffusionsAdv. Appl. Prob197810819835EzraG.S.Reversible measure-preserving integrators for non-Hamiltonian systemsJ. Chem. Phys2006125034104ShardlowTSplitting for dissipative particle dynamicsSIAM J. Sci. Comput20032412671282SerranoM.de FabritiisG.EspanolP.CoveneyP.V.A stochastic Trotter integration scheme for dissipative particle dynamicsMath. Comput. Simulat200672190194PavliotisG.A.StuartA.M.ZygalakisK.C.Calculating effective diffusivities in the limit of vanishing molecular diffusionJ. Comput. Phys200822810301055Van GunsterenW.F.BerendsenH.J.C.Algorithms for Brownian dynamicsMol. Phys198245637647NummelinEGeneral Irreducible Markov Chains and Non-Negative OperatorsCambridge University PressNew York, NY, USA1984TierneyLMarkov chains for exploring posterior distributionsAnn. Stat19942217011728GelmanA.GilksW.R.RobertsG.O.Weak convergence and optimal scaling of random walk Metropolis algorithmsAnn. Appl. Probab19977110120RobertsG.O.RosenthalJ.S.Optimal scaling of discrete approximations to Langevin diffusionsJ. R. Stat. Soc. Ser. B199860255268BeskosA.RobertsG.O.StuartA.M.Optimal scalings for local Metropolis-Hastings chains on non-product targets in high dimensionsAnn. Appl. Probab200919863898BeskosA.PillaiN.S.RobertsG.O.Sanz-SernaJ.M.StuartA.M.Optimal tuning of hybrid Monte-Carlo algorithm2010arXiv:1001.4460MattinglyJ.C.PillaiN.S.StuartA.M.Diffusion limits of the random walk Metropolis algorithm in high dimensionsAnn. Appl. Probab201222881930KangF.Dao-LiuWDynamical Systems and Geometric Construction of AlgorithmsComputational Mathematics in China; Contemporary Mathmatics, Volume 163ShiZ.-C.YangC.C.American Mathmatical SocietyNew York, NY, USA1994132Figures and Table
A time line of selected developments in MD simulation.
Langevin dynamics of a harmonic oscillator.
Atomic trajectories in a simulation box.
Soft-sphere velocity autocorrelation functions. A reproduction of Figure 5.2 of [3] using Langevin dynamics with heat bath parameter γ = 0.01. The remaining parameters are set equal to those provided in Table 1. The negative correlations at higher densities are consistent with what has been found in the literature [6,8].