Chemical Physics Letters 429 (2006) 310–316 www.elsevier.com/locate/cplett Second-order integrators for Langevin equations with holonomic constraints Eric Vanden-Eijnden a a,* , Giovanni Ciccotti b,1 Courant Institute of Mathematical Sciences, New York University, New York, NY 10012, United States b Dipartimento di Fisica, Università ‘La Sapienza’, Piazzale A. Moro 2, 00185 Roma, Italy Received 22 May 2006; in final form 24 July 2006 Available online 5 August 2006 Abstract We propose a numerical scheme for the integration of the Langevin equation which is second-order accurate. More importantly, we indicate how to generalize this scheme to situations where holonomic constraints are added and show that the resulting scheme remains second-order accurate. ! 2006 Elsevier B.V. All rights reserved. 1. Introduction The evolution of a system of interacting particles in the presence of a thermal bath at temperature T can be described by the Langevin equation pffiffiffiffiffiffiffiffiffiffiffiffi M€xðtÞ ¼ F ðxðtÞÞ $ cM x_ ðtÞ þ 2k B T cM 1=2 gðtÞ ð1Þ where xðtÞ 2 R3N denotes the position of the N particles, M the diagonal mass tensor, F(x) the force, c > 0 the friction coefficient and gðtÞ ¼ W_ ðtÞ is a white-noise (W(t) being a Wiener process). As a result, the Langevin Eq. (1) is an useful tool to sample the Boltzmann–Gibbs distribution R q(x,v) = Z$1e$bH(x,v) where Z ¼ R3N &R3N e$bH ðx;vÞ dxdv is the partition function and H ðx; vÞ ¼ 12 hv; Mvi þ V ðxÞ is the Hamiltonian (here we assumed that F = $$V). The question that we investigate here is how to generate an accurate approximation of a trajectory (x(t), v(t)) via time-discretization of (2). This question has been addressed by many authors. Among the most popular integrators are the one of van Gunsteren and Berendsen (vGB) proposed in [1], the one of Brooks–Brünger–Karplus (BBK) pro* Corresponding author. Fax: +1 212 995 4121. E-mail addresses: eve2@cims.nyu.edu (E. Vanden-Eijnden), giovanni. ciccotti@roma1.infn.it (G. Ciccotti). 1 Fax: +39 06 4957697. 0009-2614/$ - see front matter ! 2006 Elsevier B.V. All rights reserved. doi:10.1016/j.cplett.2006.07.086 posed in [2] and the Langevin impulse ðLbIÞ integrator proposed in [3]. These various integrators have been recently reviewed and compared in [4], and it has been shown that BBK is first-order accurate, whereas both vGB and LbI are second-order accurate. More recently, a class of integrators which are up to third-order accurate and also have some additional nice properties have been proposed in [5]. While all of these integrators have been derived for Langevin equations subject to no constraints, they have been often used to integrate systems in which holonomic constraints are present: this is usually done by simply applying an extra step of SHAKE [6] at every time-step. To the best of our knowledge, however, nobody has ever addressed the question of whether such a generalization of these integrators to simulate systems with constraints affect their numerical accuracy. This question is pertinent since higher-order accurate integrators allow for bigger time-steps and thereby permit to simulate the systems over longer timeintervals. In the deterministic context, because SHAKE does not affect the general structure of second-order integrators such as Verlet, one can easily show that it must preserve the order of accuracy of the integrator. The situation is more complex for Langevin integrators, however, because the structure of these integrators is more complicated and there is a nontrivial interplay between the force and the random noise at every time-step. 311 E. Vanden-Eijnden, G. Ciccotti / Chemical Physics Letters 429 (2006) 310–316 In this Letter, we investigate the issue of the accuracy of a Langevin integrator used with SHAKE. Our main results are: (i) the integrator (21) and its quasi-symplectic version (23) in Section 2, which give simple and, to the best of our knowledge, new second-order accurate integrators for Langevin equations without constraints and (ii) the integrators (34) and (39) in Section 3, which show that SHAKE can be applied to (21) and (23) to impose holonomic constraints without loosing the second-order accuracy of the integrator. While we do not do so here, the method used in Section 3 can in principle be applied to prove (or disprove) that the popular integrators such as vGB, BBK or LbI keep their order of accuracy when applied in conjunction with SHAKE. 2. Basic algorithms Written componentwise as a stochastic differential equation, (1) becomes ( dxi ðtÞ ¼ vi ðtÞdt pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi dvi ðtÞ ¼ ðm$1 2k B T ci m$1 i dW i ðtÞ i F i ðxðtÞÞ $ ci vi ðtÞÞdt þ ð2Þ where (x1, x2, x3) are the x, y and z components of particle 1 (v1, v2, v3) are the components of its velocity, m1 = m2 = m3 > 0 is its mass and c1 = c2 = c3 > 0 is the friction coefficient it is subject to, and similarly for (x4, x5, x6), etc. To simplify the formula, it will be convenient to write (2) as " dxi ðtÞ ¼ vi ðtÞdt ð3Þ dvi ðtÞ ¼ ðfi ðxðtÞÞ $ ci vi ðtÞÞdt þ ri dW i ðtÞ; pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi 2k B T ci m$1 where we defined fi ðxÞ ¼ m$1 i . i F i ðxÞ and ri ¼ Going back to vectorial notations, this equation can be written as the system of integral equations 8 R tþh > < xðt þ hÞ ¼ xðtÞ þ t vðsÞds R tþh R tþh ð4Þ vðt þ hÞ ¼ vðtÞ þ t f ðxðsÞÞds $ c t vðsÞds > : þrðW ðt þ hÞ $ W ðhÞÞ pffiffi Using x(s) = x(t) + O(h) and pffiffi vðsÞ ¼ vðtÞ þ Oð hÞ (recall that W ðt þ hÞ $ W ðhÞ ¼ Oð hÞ) under the integrals and neglecting the corrections of order h3/2 and higher, we arrive at the Euler–Maruyama scheme [7,8]: " nþ1 x ¼ xn þ hvn pffiffi ð5Þ vnþ1 ¼ vn þ hf ðxn Þ $ hcvn þ hrnn : n n where x is the numerical approximation of x(nh), v that of v(nh) and nn are independent (for different n) Gaussian variables with mean zero and covariance Eðnni nnj Þ ¼ dij (here we d pffiffi n d used W ðt þ hÞ $ W ðtÞ ¼ hn , where ¼ denotes equality in law or distribution). It can be shown [7,8] that the scheme (5) is first-order accurate, meaning that, given any suitable observable /, sup jE/ðxðnhÞ; vðnhÞÞ $ E/ðxn ; vn Þj 6 Ch 06n6T =h ð6Þ where (x(nh), v(nh)) is the (exact) solution of (2) evaluated at t = nh, (xn, vn) is its numerical approximation by (5) and it is assumed that (x(0), v(0)) = (x0, v0); E denotes expectation with respect to the noises in (2) and (5), and the constant C depends on T < 1 and the observable /(x, v) but not on h. Note that (6) is a finite-time error estimate, hence it says little about the error in computing equilibrium averages, but it indicates that it may be necessary to use (5) with a very small time-step h when the force field is stiff. Hence (5) may be insufficient in applications (Fig. 1). To doR better than (5), go back to (4), and for v(s) in the tþh integral t vðsÞds use Rs Rs vðsÞ ¼ vðtÞ þ t f ðxðuÞÞdu $ c t vðuÞdu þ rðW ðsÞ $ W ðtÞÞ ð7Þ pffiffi Using x(u) = x(t) + O(h) and vðuÞ ¼ vðtÞ þ Oð hÞ at this level we deduce that (recall that s 2 [t, t + h] and hence s $ t = O(h)) vðsÞ ¼ vðtÞ þ ðs $ tÞðf ðxðtÞÞ $ cvðtÞÞ þ rðW ðsÞ $ W ðtÞÞ þ Oðh3=2 Þ ð8Þ and hence R tþh vðsÞds ¼ hvðtÞ þ 12 h2 ðf ðxðtÞÞ $ cvðtÞÞ t R tþh þ r t ðW ðsÞ $ W ðtÞÞds þ Oðh5=2 Þ ð9Þ R tþh Similarly, for f(x(s)) in the integral t f ðxðsÞÞds, use Rs f ðxðsÞÞ ¼ f ðxðtÞÞ þ t vðuÞ ' rf ðxðuÞÞdu ð10Þ pffiffi then x(u) = x(t) + O(h) and vðuÞ ¼ vðtÞ þ Oð hÞ to arrive at 0 10 –1 10 –2 10 –3 10 –4 10 –5 10 2 3 4 5 6 Fig. 1. Numerical errors of the integratorsp(5), ffiffi (21) and (23) on the example of x_ ðtÞ ¼ vðtÞ; v_ ðtÞ ¼ $xðtÞ $ vðtÞ þ 2gðtÞ, x(0) = v(0) = 0. The times steps are h = 2$n for n = 2,3,4,5,6. The quantity monitored for the error is the estimate of Eðx2 ð1Þ þ v2 ð1ÞÞ ¼ 0:9796111900 . . . computed by ensemble averaging over 108 independent realizations. The dashed curves are the graphs of the functions 2$n(=h) and 2$2n(=h2) versus n. The circles are the errors obtained using the first-order integrator (5) and they are consistent with the error estimate (6); the diamonds are the errors obtained using the second-order integrator (21) and they are consistent with the error estimate (18); the squares are the errors obtained using the quasi-symplectic second-order integrator (23). 312 E. Vanden-Eijnden, G. Ciccotti / Chemical Physics Letters 429 (2006) 310–316 f ðxðsÞÞ ¼ f ðxðtÞÞ þ ðt $ sÞvðtÞ ' rf ðxðtÞÞ þ Oðh3=2 Þ ð11Þ and R tþh ð12Þ t f ðxðsÞÞds ¼ hf ðxðtÞÞ þ 12 h2 vðtÞ ' rf ðxðtÞÞ þ Oðh5=2 Þ Recalling that EðWRi ðsÞW j ðs0 ÞÞ ¼ dij minðs; s0 Þ, one sees that tþh for fixed t and h, t ðW ðsÞ $ W ðtÞÞds is a Gaussian variable with mean zero and such that #R $#R $ tþh tþh E t ðW i ðsÞ $ W i ðtÞÞds ðW j ðsÞ $ W j ðtÞÞds ¼ 13 h3 dij t R tþh EððW i ðt þ hÞ $ W i ðtÞÞ t ðW j ðsÞ $ W j ðtÞÞdsÞ ¼ 12 h2 dij ð13Þ Since (W(t + h) $ W(t)) is also a Gaussian variable with mean zero and covariance hdij, this means that d pffiffi W ðt þ hÞ $ W ðtÞ ¼ hnn # $ ð14Þ R tþh d ðW ðsÞ $ W ðtÞÞds ¼ h3=2 12 nn þ 2p1 ffi3ffi gn t where (nn, gn) are independent Gaussian variables with mean zero and covariance Eðnni nnj Þ ¼ Eðgni gnj Þ ¼ dij ; Eðnni gnj Þ ¼ 0 ð15Þ 5/2 Inserting (9) and (12) into (4), neglecting terms of order h and higher and using (14) we arrive at the integrator ( xnþ1 ¼ xn þ hvn þ An pffiffi vnþ1 ¼ vn þ hf ðxn Þ $ hcvn þ hrnn þ 12 h2 vn ' rf ðxn Þ $ cAn ð16Þ where An ¼ 12 h2 ðf ðxn Þ $ cvn Þ þ rh3=2 # 1 n n 2 þ 2p1 ffi3ffi gn $ ð17Þ This integrator is in fact a special case of Milstein’s scheme [7,8] and it is second-order accurate, i.e. we now have (compare (6)) sup jE/ðxðnhÞ; vðnhÞÞ $ E/ðxn ; vn Þj 6 Ch2 ð18Þ 06n6T =h where (xn, vn) is the solution of (16). However, (16) is unpleasant because it involves the term vn Æ $f(xn). To get rid of the latter, notice that (16) implies that f ðxnþ1 Þ ¼ f ðxn Þ þ hvn ' rf ðxn Þ þ Oðh3=2 Þ or, equivalently, that 1 2 n hv 2 n ' rf ðx Þ ¼ 1 hðf ðxnþ1 Þ 2 n $ f ðx ÞÞ þ Oðh ð19Þ 5=2 Þ: ð20Þ Using (20) in (16) we can rewrite this integrator as ( xnþ1 ¼ xn þ hvn þ An pffiffi vnþ1 ¼ vn þ 12 hðf ðxnþ1 Þ þ f ðxn ÞÞ $ hcvn þ hrnn $ cAn ð21Þ To the best of our knowledge, the integrator (21) is new: it is explicit and, like (16), it is second-order accurate, i.e. (18) still holds now with (xn, vn) being the solution of (21). It is a generalization to the Langevin equation of the familiar velocity-Verlet algorithm, which is obtained from (21) by setting c = r = 0 (in which case (2) reduces to Hamilton’s equation of motion) ( xnþ1 ¼ xn þ hvn þ 12 h2 f ðxn Þ ð22Þ vnþ1 ¼ vn þ 12 hðf ðxnþ1 Þ þ f ðxn ÞÞ Notice that (21) requires no more force field evaluation than (22), and no more than (5). There is another way to modify the integrator (21) without losing either accuracy or simplicity (i.e. such that the computation of $f(xn) is avoided and each time step requires only one force field evaluation): pffiffi 8 nþ1=2 v ¼ vn þ 12 hf ðxn Þ $ 12 hcvn þ 12 hrnn > > > # $ > > 1 2 n n 1 3=2 1 n > p1ffiffi gn > $ h cðf ðx Þ $ cv Þ $ h cr n þ > 8 4 2 3 > < nþ1=2 3=2 nþ1 n 1 n x ¼ x þ hv þ h r 2pffi3ffi g > > pffiffi > > vnþ1 ¼ vnþ1=2 þ 1 hf ðxnþ1 Þ $ 1 hcvnþ1=2 þ 1 hrnn > > 2 2 2 > # $ > > : $ 18 h2 cðf ðxnþ1 Þ $ cvnþ1=2 Þ $ 14 h3=2 cr 12 nn þ p1ffi3ffi gn n+1 ð23Þ It can be checked by direct comparison that x and vn+1 from (23) agree up to order h2 with xn+1 and vn+1 from either (16) or (21). To the best of our knowledge, the integrator (23) is also new: it is a second-order generalization of the BBK integrator [2]. Setting c = r = 0 in (23), this integrator also reduces to velocity-Verlet, now written as 8 nþ1=2 ¼ vn þ 12 hf ðxn Þ > <v ð24Þ xnþ1 ¼ xn þ hvnþ1=2 > : nþ1 nþ1=2 1 nþ1 v ¼v þ 2 hf ðx Þ The integrator (23) may have some advantage over (21) because, unlike (21), (23) is quasi-symplectic in the sense of [5]: it reduces to a symplectic integrator when c = r = 0 and the Jacobian J of the transformation from (xn, vn) to (xn+1, vn+1) is independent of (xn, vn). A direct calculation &2 Q3N % gives J ¼ i¼1 1 $ 12 hci þ 18 h2 c2i , to be compared with P3N the exact value expð$h i¼1 ci Þ. 3. Generalizations to situations with constraints Many situations require to generalize the Langevin Eq. (2) to include hard constraints. Let us assume that K constraints are given in the form of h1(x) = ' ' ' = hK(x) = 0. Then (2) becomes 8 < x_ ðtÞ ¼ vðtÞ K P ð25Þ : v_ ðtÞ ¼ f ðxðtÞÞ $ cvðtÞ þ rgðtÞ $ ka ðtÞrha ðxðtÞÞ a¼1 where k1(t), . . . , kK(t) are Lagrange multiplier added to satisfy the constraints. Since ha(x(t)) = 0 for all a = 1, . . . , K and all t, it follows that 313 E. Vanden-Eijnden, G. Ciccotti / Chemical Physics Letters 429 (2006) 310–316 0 ¼ h_ a ðxðtÞÞ ¼ vðtÞ ' rha ðxðtÞÞ ð26Þ which indicates that at all times v(t) must be orthogonal to all the $ha(x(t)) (and so the initial velocity v(0) must also satisfy this condition). Similarly, we must have 0 ¼ €ha ðxðtÞÞ ¼ vðtÞvðtÞ : rrha ðxðtÞÞ þ v_ ðtÞ ' rha ðxðtÞÞ ¼ vðtÞvðtÞ : rrha ðxðtÞÞ þ ðf ðxðtÞÞ $ cvðtÞ þ rgðtÞÞ ' rha ðxðtÞÞ K X $ kb ðtÞrhb ðxðtÞÞ ' rha ðxðtÞÞ; ð27Þ b¼1 where, given a; b 2 R3N , ab : rr ¼ is an equation for ka(t). Letting P3N ı;j¼1 ai bj o 2 =oxi oxj (27) K ab ðxÞ ¼ rha ðxÞ ' rhb ðxÞ 2 RK & RK ð28Þ and assuming that this matrix is invertible (27) can be solved in ka(t) as ka ðtÞ ¼ K X b¼1 þ K $1 ab ðxðtÞÞrhb ðxðtÞÞ K X b¼1 ' ðf ðxðtÞÞ $ cvðtÞ þ rgðtÞÞ K $1 ab ðxðtÞÞrrhb ðxðtÞÞ : vðtÞvðtÞ ð29Þ Inserting (29) into (25), one sees that this equation can be written explicitly as 8 x_ ðtÞ ¼ vðtÞ > > > < v_ ðtÞ ¼ P ðxðtÞÞðf ðxðtÞÞ $ cvðtÞ þ rgðtÞÞ K P > > > $ rha ðxðtÞÞK $1 : ab ðxðtÞÞrrhb ðxðtÞÞ : vðtÞvðtÞ a;b¼1 ð30Þ where P(x) is the orthogonal projector unto the manifold h1(x) = ' ' ' = hK(x) = 0: componentwise, it is given by K X oha ðxÞ ohb ðxÞ K $1 ð31Þ P ij ðxÞ ¼ dij $ ab ðxÞ oxi oxj a;b¼1 Since the noise g(t) is multiplied by a function of x(t) alone in (30), there is no problem of interpretation with this equation and the heuristic way we arrived at (30) can be justified rigorously. Notice that ka(t) contains a martingale part, K X K $1 ð32Þ dkma ðtÞ ¼ r ab ðxðtÞÞrhb ðxðtÞÞ ' dW ðtÞ: b¼1 and a bounded variation part K X dkba ðtÞ ¼ K $1 ab ðxðtÞÞrhb ðxðtÞÞ ' ðf ðxðtÞÞ $ cvðtÞÞdt b¼1 þ K X b¼1 K $1 ab ðxðtÞÞrrhb ðxðtÞÞ : vðtÞvðtÞdt ð33Þ We could write down directly a numerical integrator for (30) by proceeding as in Section 2. This, however, would have two disadvantages. First, the resulting integrator would be rather complicated and, e.g. involve second-order derivatives of ha(x), which are cumbersome to compute. Second, and more importantly, even if we write down a second-order accurate integrator, this integrator would only conserve the constraints h1(x(t)) = . . . = hK(x(t)) = 0 to O(h2). This is very unsatisfactory since over long times, the constraints would then drift away. In the spirit of SHAKE [6], it is much more convenient to write down an integrator which is accurate to second-order but conserves the constraints exactly. Below, we show that the following integrator satisfies these conditions: 8 K P > > > xnþ1 ¼ xn þ hvn þ An $ lna rha ðxn Þ > > > a¼1 < pffiffi vnþ1 ¼ vn þ 12 hðf ðxnþ1 Þ þ f ðxn ÞÞ $ hcvn þ hrnn $ cAn > > > K > P > > $h$1 ðl(a rha ðxnþ1 Þ þ lna rha ðxn ÞÞ : a¼1 n Here A is given in (17) ha ðxnþ1 Þ ¼ 0; and ðln1 ; . . . ; lnK Þ ð34Þ are chosen so that a ¼ 1; . . . ; K ðl(1 ; . . . ; l(K Þ ð35Þ are chosen so that vnþ1 ' rha ðxnþ1 Þ ¼ 0; a ¼ 1; . . . ; K ð36Þ (34) simply means that we can apply RATTLE to (21), remain second-order accurate and satisfy the constraints (26) exactly. The multipliers lna can be obtained via SHAKE; the multipliers l(a can be obtained via solution of a linear system. For future reference, notice that the updating step for the velocities in (34) can be written as vnþ1 ¼ P ðxnþ1 Þv( where v( ¼ vn þ 12 hðf ðxnþ1 Þ þ f ðxn ÞÞ $ hcvn þ $ h$1 K P a¼1 lna rha ðxn Þ: ð37Þ pffiffi n hrn $ cAn ð38Þ In the same way, we can apply RATTLE to (23), remain second-order accurate and satisfy the constraints (26) exactly. In this case, the integrator reads: 8 nþ1=2 pffiffi ¼ vn þ 12 hf ðxn Þ $ 12 hcvn þ 12 hrnn v > > > # $ > > > 1 2 n n 1 3=2 1 n p1ffiffi gn > $ h cðf ðx Þ $ cv Þ $ h cr g þ > 8 4 2 3 > > > > K > P n > > $h$1 la rha ðxn Þ > > > a¼1 > < xnþ1 ¼ xn þ hvnþ1=2 þ h3=2 r 2p1 ffi3ffi gn > > pffiffi > > vnþ1 ¼ vnþ1=2 þ 12 hf ðxnþ1 Þ $ 12 hcvnþ1=2 þ 12 hrnn > > > # $ > > > 1 2 nþ1 nþ1=2 1 3=2 1 n p1ffiffi gn > $ h cðf ðx Þ $ cv Þ $ h cr g þ > 8 4 2 3 > > > > K > P > > : l(a rha ðxnþ1 Þ $h$1 a¼1 ð39Þ where the Lagrange multipliers and ðl(1 ; . . . ; l(K Þ are chosen so that (35) and (37) are satisfied. It can be checked by direct comparison that xn+1 and vn+1 from (39) agree up to order h2 with xn+1 and vn+1 from (34). ðln1 ; . . . ; lnK Þ 314 E. Vanden-Eijnden, G. Ciccotti / Chemical Physics Letters 429 (2006) 310–316 The remainder of this Letter is devoted to show the consistency of (34) with respect to (30) and establish that it is second-order accurate; this also establishes the consistency and second-order accuracy of (39) since this integrator coincide with (34) to O(h2). Since we were unable to find a soft argument establishing this claim, we will proceed the hard way, write down an integrator for (30) which is second-order accurate and show that, to O(h2) this integrator is equivalent to (34). For simplicity, we will treat the simpler case where there is a single constraint, K = 1 and h1(x) = h(x) (the general case can be treated similarly but the algebra become even more tedious). Under this assumption, (30) can be written as the following integral equation (using P(x(t))v(t) = v(t) which follows from (26)) 8 R tþh xðt þ hÞ ¼ xðtÞ þ t vðsÞds > > > > R tþh > > > < vðt þ hÞ ¼ vðtÞ þ t ðP ðxðsÞÞf ðxðsÞÞ $ cvðsÞÞds R tþh ð40Þ þr t P ðxðsÞÞdW ðsÞ > > R > tþh $2 > > $ t rhðxðtÞÞjrhðxðsÞÞj rrhðxðsÞÞ > > : : vðsÞvðsÞds: Proceeding as in Section 2, we can integrate once and replace v(s), etc. by their value according to (40), then expand and keep only the term of order h2 or lower. The relevant expressions are (here for simplicity we denote x(t) ” x and v(t) ” v) R tþh t vðsÞds ¼ hv þ 12 h2 ðP ðxÞf ðxÞ $ cvÞ R tþh þ rP ðxÞ t ðW ðsÞ $ W ðtÞÞds $ 12 h2 jrhðxÞj$2 ðrrhðxÞ : vvÞrhðxÞ R tþh t R tþh t þ Oðh5=2 Þ ð41Þ P ðxðsÞÞf ðxðsÞÞds ¼ hP ðxÞf ðxÞ þ 12 h2 v ' rðP ðxÞf ðxÞÞ þ Oðh5=2 Þ rhðxðsÞÞjrhðxðsÞÞj$2 rrhðxðsÞÞ : vðsÞvðsÞds ð42Þ $2 ¼ hjrhðxÞj ðrrhðxÞ : vvÞrhðxÞ þ 12 h2 v ' rðrhðxÞjrhðxÞj$2 rrhðxÞÞ : vv þ h2 jrhðxÞj$2 ðrrhðxÞ : vðP ðxÞf ðxÞ $ cvÞrhðxÞÞ R tþh þ 2rjrhðxÞj$2 ðrrhðxÞ : vP ðxÞ t ðW ðsÞ $ W ðtÞÞdsÞrhðxÞ $ h2 jrhðxÞj$4 ðrrhðxÞ : vrhðxÞÞðrrhðxÞ : vvÞrhðxÞ þ 12 h2 r2 jrhðxÞj$2 ðP ðxÞ 5=2 ð43Þ where we used (this identity holds almost surely under iterations within the scheme) Rs Rs rrhðxðsÞÞ : ðP ðxðsÞÞ t dW ðuÞÞðP ðxðsÞÞ t dW ðuÞÞ : rrhðxÞÞrhðxÞ þ Oðh ¼ ðs $ tÞP ðxðsÞÞ : rrhðxðsÞÞ Þ ð44Þ and, finally, R tþh P ðxðsÞÞdW ðsÞ ¼ P ðxÞðW ðt þ hÞ $ W ðtÞÞ t R tþh þ v ' rP ðxÞ t ðs $ tÞdW ðsÞ þ Oðh5=2 Þ ð45Þ R tþh R tþh Using t ðs $ tÞdW ðsÞ ¼ hðW ðt þ hÞ $ W ðtÞÞ$ t ðW ðsÞ $W ðtÞÞds together with (14), inserting these expressions in (40) and neglecting terms of order h5/2 and higher gives the following integrator 8 nþ1 $2 x ¼ xn þ hvn þ P n An $ 12 h2 jrhn j ðvn vn : rrhn Þrhn > > > p ffi ffi > > > vnþ1 ¼ vn þ hP n f n $ hcvn þ hrP n nn > > > > > $hjrhn j$2 ðvn vn : rrhn Þrhn þ 12 h2 vn ' rðP n f n Þ > > > > $2 > > $cP n An þ 12 h2 cjrhn j ðvn vn : rrhn Þrhn > > < # $ þh3=2 rðvn ' rP n Þ 12 nn $ 2p1 ffi3ffi gn > > > $2 > > $ 12 h2 vn ' rðjrhn j ðvn vn : rrhn Þrhn Þ > > > > > > $2jrhn j$2 ðvn ðP n An Þ : rrhn Þrhn > > > > $4 > þh2 jrhn j ðvn vn : rrhn Þðvn rhn : rrhn Þrhn > > > : $ 12 h2 r2 jrhn j$2 ðP n : rrhn Þrhn ð46Þ where fn = f(xn), hn = h(xn), Pn = P(xn). Notice that (46) is second-order accurate, but unlike (34), this integrator does not preserve the constraints exactly: in fact hn = O(h2) and Pnvn = vn + O(h2). Let us now show that (34) is identical to (46) to O(h2). To this end, notice first that, using (34) and (35) implies that (using hn = 0 and vn Æ $hn = 0) 0 ¼ hðxnþ1 Þ ¼ hðxn þ hvn þ An $ ln rhn Þ ¼ An ' rhn $ ln jrhn j2 þ 12 ðhvn $ ln rhn Þðhvn $ ln rhn Þ : rrhn þ Oðh5=2 Þ As a result $2 $2 ln ¼ jrhn j An ' rhn þ 12 jrhn j ðhvn $ ln rhn Þ ð47Þ & ðhvn $ ln rhn Þ : rrhn þ Oðh5=2 Þ ¼ jrhn j An ' rhn þ 12 h2 jrhn j vn vn : rrhn þ Oðh5=2 Þ $2 $2 ð48Þ (Notice for later use that even though ln is divided by h in the equation for vn+1 in (34), we do not need to compute terms up to O(h3) because vn+1 is obtained via (37) and Pn+1$hn = O(h).) (48) implies that the way the positions are updated in (34) is explicitly xnþ1 ¼ xn þ hvn þ An $ jrhn j An ' rhn rhn $ 12 h2 jrhn j & ðvn vn : rrhn Þrhn þ Oðh5=2 Þ $2 ¼ xn þ hvn þ P n An $ 12 h2 jrhn j ðvn vn : rrhn Þrhn þ Oðh5=2 Þ $2 $2 ð49Þ which is consistent to second-order with the equation for xn+1 in (46). Consider next the way the velocities are updated in (34). In the present case where K = 1 (38) is explicitly (using (48)) pffiffi v( ¼ vn þ 12 hðf nþ1 þ f n Þ $ hcvn þ hrnn $ cAn $ h$1 ln rhn pffiffi ¼ vn þ hf n þ 12 h2 vn ' rf n $ hcvn þ hrnn $ cAn $ h$1 jrhn j ðrhn ' An Þrhn $ 12 hjrhn j $2 $2 & ðvn vn : rrhn Þrhn þ Oðh3=2 Þ 3/2 2 ð50Þ $1 n where the terms of order h and h come from $ h l $hn and hence do not contribute to vn+1 since Pn+1$hn = O(h) 315 E. Vanden-Eijnden, G. Ciccotti / Chemical Physics Letters 429 (2006) 310–316 (see the remark after (48)). On the other hand, using (49), we also have that P nþ1 v( ¼ P n v( þ hvn ' rP n v( þ P n An ' rP n v( $ 12 h2 jrhn j ðvn vn : rrhn Þrhn ' rP n v( $2 þ 12 h2 vn vn : rrP n v( þ Oðh5=2 Þ ð51Þ Combining (48), (50) and (51), we deduce that pffiffi vnþ1 ¼ vn þ hP n f n þ 12 h2 P n vn ' rf n $ hcvn þ hrP n nn þh n n n n $2 n n n n rv ' rP n $ jrh j ðrh ' A Þv ' rP rh n $ 12 h2 jrhn j$2 ðvn vn : rrhn Þvn ' rP n rhn þ P n An ' rP n vn # $ $2 þ h2 r2 P n 12 nn þ 2p1 ffi3ffi gn ' rP n nn $ h2 r2 jrhn j ## $ $ # $ & 12 nn þ 2p1 ffi3ffi gn ' rhn P n 12 nn þ 2p1 ffi3ffi gn ' rP n rhn $ 12 h2 jrhn j ðvn vn : rrhn Þrhn ' rP n vn $2 þ 12 h2 vn vn : rrP n vn þ Oðh5=2 Þ ð52Þ To simplify this expression, let us derive first a few useful identities. Given any two vectors a; b 2 R3N , we have a ' rP n b ¼ $jrhn j ðab : rrhn Þrhn $2 $ jrhn j ðb ' rhn Þa ' rrhn þ 2jrhn j ðarhn : rrhn Þðb ' rhn Þrhn $4 ð53Þ when b is perpendicular to $hn (e.g. when b = vn), this expression simplifies into ðb ? rhn Þ ð54Þ whereas when b = $hn it becomes a ' rP n rhn ¼ jrhn j$2 ðarhn : rrhn Þrhn $ a ' rrhn n ð59Þ vn þ hP n f n $ hcvn þ pffiffi n n hrP n $ hjrhn j$2 ðvn vn : rrhn Þrhn ð60Þ The term $cPnAn also appears in both (46) and (52) (first on the third line in (46) and last at the right hand-side on the first line in (52)). Next notice that (in (52) these are the third term at the right hand-side on the first line, the second and third terms on the second line, the terms on the third line, and the first term on the fifth line): 1 2 n n hP v ' 2 3=2 rf n þ h2 vn ' rP n f n $ h2 cvn ' rP n vn þ h rvn ' rP n nn $ jrhn j ðrhn ' An Þvn ' rP n rhn þ P n An ' rP n vn $2 a ' rP n b ¼ $jrhn j$2 ðab : rrhn Þrhn hvn ' rP n vn ¼ $hjrhn j$2 ðvn vn : rrhn Þrhn ; and hence all the leading order terms of order O(h) and lower appear in both (46) and (52): these are $ cP n An þ hvn ' rP n vn þ h2 vn ' rP n f n $ h2 cvn ' rP n vn 3=2 We now use these relations to expand the terms in the equation for vn+1 in (46) and show that is identical to (52) to O(h2). First notice that (this is the first term on the second line in (52)) ð55Þ n we also have (using $h Æ v = 0) $2 ¼ 12 h2 vn ' rðP n f n Þ þ 12 h2 vn ' rP n f n $ h2 cvn ' rP n vn þ h3=2 rvn ' rP n nn $ jrhn j ðrhn ' An Þvn ' rP n rhn þ P n An ' rP n vn $2 ¼ 12 h2 vn ' rðP n f n Þ $ 12 h2 cvn ' rP n vn # $ þ h3=2 rvn ' rP n 12 nn $ 2p1 ffi3ffi gn þ vn ' rP n An $ jrhn j ðrhn ' An Þvn ' rP n rhn þ P n An ' rP n vn $2 ¼ 12 h2 vn ' rðP n f n Þ þ 12 h2 cjrhn j ðvn vn : rrhn Þrhn $2 þ h3=2 rvn ' rP n Þ þ vn ' rP n An . vn vn : rrP n vn ¼ $jrhn j$2 ðvn vn vn ..rrrhn Þrhn $ jrhn j ðrhn ' An Þvn ' rP n rhn þ P n An ' rP n vn $2 ¼ 12 h2 vn ' rðP n f n Þ þ 12 h2 cjrhn j ðvn vn : rrhn Þrhn # $ þ h3=2 rvn ' rP n 12 nn $ 2p1 ffi3ffi gn $2 $ 2jrhn j$2 ðvn vn : rrhn Þvn ' rrhn þ 4jrhn j$4 ðvn rhn : rrhn Þðvn vn : rrhn Þrhn ð56Þ and (these identities holds almost surely under iterations within the scheme) # $ # # $ $ P n 12 nn þ 2p1 ffi3ffi gn ' rP n nn ¼ E P n 12 nn þ 2p1 ffi3ffi gn ' rP n nn ¼ $ 12 jrhn j ðP n : rrhn Þrhn $2 ð57Þ ## $ $ # $ $ jrhn j$2 12 nn þ 2p1 ffi3ffi gn ' rhn P n 12 nn þ 2p1 ffi3ffi gn ' rP n rhn # $ # $ ¼ P n 12 nn þ 2p1 ffi3ffi gn ' rP n ðP n $ 1Þ 12 nn þ 2p1 ffi3ffi gn # # $ # $$ ¼ E P n 12 nn þ 2p1 ffi3ffi gn ' rP n ðP n $ 1Þ 12 nn þ 2p1 ffi3ffi gn ¼ 0: ð58Þ $ 2jrhn j ðvn ðP n An Þ : rrhn Þrhn $2 ð61Þ where in the last equality we used (using (54) and since both vn and PnAn are perpendicular to $hn): vn ' rP n An $ jrhn j ðrhn ' An Þvn ' rP n rhn þ P n An ' rP n vn $2 ¼ vn ' rP n An þ vn ' rP n ðP n $ 1ÞAn þ P n An ' rP n vn ¼ vn ' rP n P n An þ P n An ' rP n vn ¼ $2jrhn j$2 ðvn ðP n An Þ : rrhn Þrhn ð62Þ The terms in (61) are the second on the second line, the second on the third line, the one on fourth line and the one on the sixth line in (46). From (57) and (58) we also have (this is the second term on the fifth line and the one on the sixth line in (52)): 316 E. Vanden-Eijnden, G. Ciccotti / Chemical Physics Letters 429 (2006) 310–316 # $ $2 h2 r2 P n 12 nn þ 2p1 ffi3ffi gn ' rP n nn $ h2 r2 jrhn j ## $ $ # $ & 12 nn þ 2p1 ffi3ffi gn ' rhn P n 12 nn þ 2p1 ffi3ffi gn ' rP n rhn 4. Concluding remarks ¼ $ 12 h2 r2 jrhn j$2 ðP n : rrhn Þrhn ð63Þ which is the term on the eight line in (46). Finally, the remaining terms unaccounted for in (52) are (using (54) and (55)): $2 $ 12 h2 jrhn j ðvn vn : rrhn Þvn ' rP n rhn ¼ $ 12 h2 jrhn j ðvn vn : rrhn Þðvn rhn : rrhn Þrhn $4 þ 12 h2 jrhn j ðvn vn : rrhn Þvn ' rrhn $2 $2 $ 12 h2 jrhn j ðvn vn : rrhn Þrhn ' rP n vn ¼ 12 h2 jrhn j$4 ðvn vn : rrhn Þðvn rhn : rrhn Þrhn and (using (56)) 1 2 n n hvv 2 ð64Þ ð65Þ Regarding the numerical integration of Langevin equations with holonomic constraint, we found the literature quite confusing. We hope that the (courageous) reader who bore with us until the end will be gratified to see that, with heavy but straightforward calculations, a very simple, second-order accurate integrator for these equations can be derived. At the end, this integrator requires no more numerical effort than its deterministic counterpart. We also stress that the calculations above show that analyzing the accuracy of integrators is more complicated for Langevin equations than Hamiltonian systems. As a result, one may easily overestimate the order of accuracy of a scheme (as was done, e.g. by one of us in [9]). : rrP n vn . $2 ¼ $ 12 h2 jrhn j ðvn vn vn ..rrrhn Þrhn $ h2 jrhn j$2 ðvn vn : rrhn Þvn ' rrhn þ 2h2 jrhn j$4 ðvn rhn : rrhn Þðvn vn : rrhn Þrhn Acknowledgements ð66Þ so that $2 $ 12 h2 jrhn j ðvn vn : rrhn Þvn ' rP n rhn $ 12 h2 jrhn j$2 ðvn vn : rrhn Þrhn ' rP n vn References þ 12 h2 vn vn : rrP n vn . ¼ $ 12 h2 jrhn j$2 ðvn vn vn ..rrrhn Þrhn $ 12 h2 jrhn j ðvn vn : rrhn Þvn ' rrhn $2 n n þ 2h2 jrhn j# ðvn rhn : rrhn Þðvn vn : rrh $ Þrh n $2 n n n n 1 2 n ¼ $ 2 h v ' r jrh j ðv v : rrh Þrh $4 þ h2 jrhn j ðvn rhn : rrhn Þðvn vn : rrhn Þrhn $4 We thank Christof Schütte, Tony Lelièvre and Luca Maragliano for useful discussions. E. V.-E. is partially supported by NSF Grants DMS02-09959 and DMS02-39625, and by ONR grant N00014-04-1-0565. ð67Þ These are the terms on the fifth line and the one on the seventh line in (46), which were the last ones to account for in this equation (meaning also that we are finally done). [1] W.F. van Gunsteren, H.J.C. Berendsen, Mol. Phys. 45 (1982) 637. [2] A. Brunger, C.L. Brooks, M. Karplus, Chem. Phys. Lett. 105 (1984) 495. [3] R.D. Skeel, J. Izaguirre, Mol. Phys. 100 (2002) 3885. [4] W. Wang, R.D. Skeel, Mol. Phys. 101 (2003) 2149. [5] G.N. Milstein, N.V. Tretyakov, IMA J. Numer. Anal. 23 (2003) 593. [6] J.P. Ryckaert, G. Ciccotti, H.J.C. Berendsen, J. Comput. Phys. 23 (1977) 327. [7] G.N. Milstein, Numerical Integration of Stochastic Differential Equations, Kluwer, Dordrecht, 1995. [8] P.E. Kloeden, E. Platen, Numerical Solutions of Stochastic Differential Equations, Springer, Berlin, 1992. [9] A. Ricci, G. Ciccotti, Mol. Phys. 101 (2003) 1927.