Skip to main content
NIHPA Author Manuscripts logoLink to NIHPA Author Manuscripts
. Author manuscript; available in PMC: 2008 Jul 1.
Published in final edited form as: J Comput Phys. 2007 Jul 1;225(1):1–5. doi: 10.1016/j.jcp.2007.03.010

Correcting Mesh-Based Force Calculations to Conserve Both Energy and Momentum in Molecular Dynamics Simulations

Robert D Skeel a,, David J Hardy b, James C Phillips b
PMCID: PMC2346486  NIHMSID: NIHMS28162  PMID: 18591998

The high cost of evaluating forces in molecular dynamics makes it necessary to use approximations. The most effective approximations for nonbonded 2-body interactions, such as particle–particle particle–mesh, particle–mesh Ewald, and multilevel summation, split the potential into a short-range part which is evaluated directly and a long-range part which is interpolated from a mesh. This results in a force that, though still conservative, is not translation-invariant, resulting in drift in the linear momentum. A common remedy is to apply a uniform correction to all forces to conserve linear momentum, but this results in a force that is not conservative. Described here is a mass-weighted correction, based on the simple idea of constraining the center of mass, which does yield a conservative force.

Consider a system of N particles with masses mi and positions r⃗i = r⃗i(t), i = 1, 2, . . . , N, which evolve in time t as dictated by Newton’s second law of motion

mir¨i=Fi(R,R˙,t), (1)

where R denotes r⃗1, r⃗2,…, r⃗N,. Often linear momentum Σimi r⃗i is conserved, which is equivalent to ΣiF⃗i = 0⃗. In particular, a translation-invariant potential energy function

U(r1+d,,rN+d)=U(r1,,rN)

yields forces F⃗i = −∇iU(R) that sum up to zero.

For a computer simulation the cost of evaluating forces can be very high. In particular, 2-body nonbonded interactions require 𝒪(N2) operations unless approximations are used. The most efficient approximations are obtained with methods such as particle–particle particle–mesh [1], particle–mesh Ewald (PME) [2], and multilevel summation [35], which split the potential into a short-range part calculated directly and a long-range part interpolated from a mesh. The use of a mesh yields an approximation Ua(R) to the long-range part of the potential energy which is not translation-invariant. This leads not only to a violation of Newton’s third law but causes particles to exert forces on themselves [6]! (Methods based on a hierarchical clustering of interactions, such as the fast multipole method [7], do not have this problem; however, they compute forces that are not conservative [8] and appear to be otherwise less efficient for molecular dynamics [9,4], though these studies are based on older versions of the methods.)

Failure to conserve linear momentum is at best a nuisance, since it means that even if the center of mass is initially at rest, it will start moving as the simulation progresses. A common remedy [2,10,11] is to subtract out the average net force (1/N) kFka from each force Fia. However, the resulting force is not conservative even if the original approximate force is conservative. For a conservative force, the Jacobian matrix of F⃗i with respect to r⃗j must equal the transpose of the Jacobian matrix of F⃗j with respect to r⃗i. However, such is not the case for the adjusted force Fia(R)(1/N)kFka(R), whose Jacobian matrix with respect to position r⃗j is given by

rj(Fia1NkFka)=ija+1Nkkja,

Where ija is the (i, j)th 3 × 3 block of the Hessian of the potential energy function Ua.

The negative effect of this simple force correction on conservation of energy is observed in [12, p. 30]. A system of 216 rigid SPC waters is simulated for 10 ns in a cube of side length 18.7 Å. PME is used with a 18 × 18 × 18 grid, a direct sum cutoff of 8 Å, and the Verlet integrator with a 2 fs time step. The use of the force correction produces a drift of −0.14 kcal/mol amidst fluctuations of ±0.05 kcal/mol. Without the force correction the drift is not discernible.

A mass-weighted correction to the force is conservative, however. Assume that the initial linear momentum is zero:

imir˙i(0)=0

(which is attained by subtracting a constant velocity from each velocity).

Denote the displacement of the center of mass by

g(R)=1mtotkmk(rkrk(0)),

where mtot = Σkmk, and conservation of linear momentum is equivalent to the holonomic constraint

g(R)=0.

This can be combined with the equations of motion (1) by adding constraint forces

mir¨i=Fi()+mimtotλ,

where λ⃗ is a set of Lagrange multipliers and its coefficient is obtained from the Jacobian matrix of g⃗(R) with respect to r⃗i. Eliminating λ⃗ (by twice differentiating the constraints and substituting in the equations of motion) leads to

mir¨i=Fi()mimtotkFk().

A direct proof that the corrected force is conservative is obtained by defining a corrected potential energy function

Uc(R)=Ua(r1g(R),,rNg(R)).

This is translation-invariant, and the use of a potential leads to conservative forces

Fic(r1,,rN)=iUc(r1,,rN)=Fia(r1g(R),,rNg(R))mimtotkFka(r1g(R),,rNg(R)). (2)

The assumption of zero initial linear momentum together with conservation of linear momentum implies g⃗(R(t)) ≡ 0⃗. Practical numerical integrators also exactly conserve linear momentum, so the corrected force simplifies to

Fic(R)=Fia(R)mimtotkFka(R).

Extension of this technique to nonzero initial linear momentum is possible using Eq. (2), but the calculations become more complicated and time consuming. If the term g⃗(R) is omitted, the force will not be conservative.

To test the value of the mass-weighted correction, a system of 826 TIP3 water molecules in a cubic box of length 29.08 Å was simulated for 10 ns. Three simulations were performed with the same (equilibrated) initial positions and velocities: one with no force correction, one with a uniform correction, and one with a mass-weighted correction. The simulation was performed with NAMD [13] using PME with cubic B-spline interpolation from a 24 × 24 × 24 grid and the Verlet integrator with a time step of 2 fs. A tolerance of 10−6 was used for the direct part of the Ewald sum, which dictates the choice of the parameter in the Ewald splitting. A switching distance of 7 Å and a cutoff of 8 Å was used for Lennard-Jones interactions with an XPLOR switching function (which is continuously differentiable). Rigid water constraints were solved analytically using SETTLE [14]. Figure 1 confirms that the force-corrected simulations conserve momentum whereas the uncorrected simulation terminates with a speed of 0.26 Å/ps and a displacement of 1180 Å for the center of mass. (The reason that the plot shows momentum not to be exactly conserved for the two force-corrected simulations is that NAMD, for parallel performance reasons, outputs the linear momentum before applying the force correction.) The values plotted in this graph, and the one that follows, are block-averaged over 50-ps intervals. Figure 2 shows total energy as a function of time. The simulations without a force correction and with a mass-weighted correction each experience a little energy drift. Theoretical and empirical evidence [15] indicates that some drift occurs for the Verlet integrator even with a conservative force and a modest stepsize. However, the simulation with the uniform correction experiences an energy drift that is an order of magnitude greater. Similar results were also obtained for two other 10-ns simulations. Hence, a simulation with the weighted correction can be run an order of magnitude longer before temperature change becomes problematic. (The Verlet integrator is symplectic for a conservative force but merely preserves volume in phase space for a nonconservative force.)

Fig. 1.

Fig. 1

Speed of center of mass (Å/ps) vs. time (ns) for a periodic cube of 826 TIP3P water molecules with a 2 fs time step. The solid line is for uncorrected forces, the dashed line for a mass-weighted correction, and the dotted line for a uniform correction to forces.

Fig. 2.

Fig. 2

Time-averaged total energy (kcal/mol) vs. time (ns) for a periodic cube of 826 TIP3P water molecules with a 2 fs time step. The solid line is for uncorrected forces, the dashed line for a mass-weighted correction, and the dotted line for a uniform correction to forces.

Implementation of a force correction on a parallel distributed-memory computer requires a reduction operation followed by a broadcast. Fortunately, the mass-weighted correction is latency tolerant—unlike the uniform correction. Practical integrators such as the Verlet scheme and its extension to constraints [16] and to multiple time stepping [17,18] incorporate force evaluations as impulses and exactly integrate these impulses. Hence force corrections (mi/mtot)λ⃗n introduced at time t = n Δ t change the positions by an amount (tn Δ t) Δtλ⃗n/mtot for t = n Δ t, which is the same for all particles. More-over, this remains true as long as only translation-invariant forces are applied. Hence the correction to positions and velocities need not be applied until just before the next evaluation of forces that are not translation-invariant. In practice, these forces are long-range nonbonded electrostatic forces, evaluated using the largest time step. Such a technique is implemented in version 2.6 of NAMD [19].

Acknowledgments

This material is based upon work supported by NIH Grant P41-RR05969.

Footnotes

Publisher's Disclaimer: This is a PDF file of an unedited manuscript that has been accepted for publication. As a service to our customers we are providing this early version of the manuscript. The manuscript will undergo copyediting, typesetting, and review of the resulting proof before it is published in its final citable form. Please note that during the production process errors may be discovered which could affect the content, and all legal disclaimers that apply to the journal pertain.

References

  • 1.Hockney RW, Eastwood JW. Computer Simulation Using Particles. McGraw-Hill; New York: 1981. [Google Scholar]
  • 2.Essmann U, Perera L, Berkowitz ML, Darden T, Lee H, Pederson L. A smooth particle mesh Ewald method. J Chem Phys. 1995;103:8577–8593. [Google Scholar]
  • 3.Brandt A, Lubrecht AA. Multilevel matrix multiplication and fast solution of integral equations. J Comput Phys. 1990;90:348–370. [Google Scholar]
  • 4.Skeel RD, Tezcan I, Hardy DJ. Multiple grid methods for classical molecular dynamics. J Comput Chem. 2002;23(6):673–684. doi: 10.1002/jcc.10072. [DOI] [PubMed] [Google Scholar]
  • 5.Hardy DJ. Ph.D. thesis, Univ. of Illinois at Urbana-Champaign, also Department of Computer Science Report No. UIUCDCS-R-2006-2546. [May 2006]. Multilevel summation for the fast evaluation of forces for the simulation of biomolecules. Available online at http://www.cs.uiuc.edu/research/techreports.php?year=2006. [Google Scholar]
  • 6.Sandak B. Multiscale fast summation of long range charge and dipolar interactions. J Comput Chem. 2001;22(7):717–731. [Google Scholar]
  • 7.Greengard L, Rokhlin V. A fast algorithm for particle simulations. J Comput Phys. 1987;73:325–348. [Google Scholar]
  • 8.Bishop T, Skeel RD, Schulten K. Difficulties with multiple timestepping and the fast multipole algorithm in molecular dynamics. J Comput Chem. 1997;18(14):1785–1791. [Google Scholar]
  • 9.Pollock EL, Glosli J. Comments on P3M, FMM, and the Ewald method for large periodic Coulombic systems. Computer Phys Commun. 1996;95(2 and 3):93–110. [Google Scholar]
  • 10.Deserno M, Holm C. How to mesh up Ewald sums. I. A theoretical and numerical comparison of various particle mesh routines. J Chem Phys. 1998;109(18):7678–7693. [Google Scholar]
  • 11.Toukmaji A, Sagui C, Board J, Darden T. Efficient particle-mesh Ewald based approach to fixed and induced dipolar interactions. J Chem Phys. 2000;113(24):10913–10927. [Google Scholar]
  • 12.Wang W. Ph.D. thesis, Univ. of Illinois at Urbana-Champaign, also Department of Computer Science Report No. UIUCDCS-R-2005-2522. 2005. Fast polarizable force field computation in biomolecular simulations. Available online at http://www.cs.uiuc.edu/research/techreports.php?year=2005. [Google Scholar]
  • 13.Phillips JC, Braun R, Wang W, Gumbart J, Tajkhorshid E, Villa E, Chipot C, Skeel RD, Kalé L, Schulten K. Scalable molecular dynamics with NAMD. J Comput Chem. 2005;26(16):1781–1802. doi: 10.1002/jcc.20289. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 14.Miyamoto S, Kollman PA. SETTLE: An analytical version of the SHAKE and RATTLE algorithm for rigid water molecules. J Comput Chem. 1992;13(8):952–962. [Google Scholar]
  • 15.Engle RD, Skeel RD, Drees M. Monitoring energy drift with shadow Hamiltonians. J Comput Phys. 2005;206(2):432–452. [Google Scholar]
  • 16.Ryckaert J, Ciccotti G, Berendsen H. Numerical integration of the cartesian equation of motion of a system with constraints: molecular dynamics of n-alkanes. J Comput Phys. 1977;23:327–341. [Google Scholar]
  • 17.Tuckerman M, Berne BJ, Martyna GJ. Reversible multiple time scale molecular dynamics. J Chem Phys. 1992;97(3):1990–2001. [Google Scholar]
  • 18.Grubmüller H, Heller H, Windemuth A, Schulten K. Generalized Verlet algorithm for efficient molecular dynamics simulations with long-range interactions. Molecular Simulation. 1991;6:121–142. [Google Scholar]
  • 19.http://www.ks.uiuc.edu/Research/namd/.

RESOURCES