CE 530 Molecular Simulation Lecture Molecular Dynamics Simulation David A. Kofke Department of Chemical Engineering SUNY Buffalo kofke@eng.buffalo.edu
MD of hard disks intuitive Review and Preview collision detection and impulsive dynamics Monte Carlo convenient sampling of ensembles no dynamics biasing possible to improve performance Molecular dynamics equations of motion integration schemes evaluation of dynamical properties extensions to other ensembles focus on atomic systems for now
3 Classical Equations of Motion Several formulations are in use Newtonian Lagrangian Hamiltonian Advantages of non-newtonian formulations more general, no need for fictitious forces better suited for multiparticle systems better handling of constraints can be formulated from more basic postulates Assume conservative forces! F =! U Gradient of a scalar potential energy
4 Newtonian Formulation Cartesian spatial coordinates r i = (x i,y i,z i ) are primary variables for N atoms, system of N nd-order differential equations m d r i dt m!!r i = F i Sample application: D motion in central force field m!!x = F ê x = f (r)ˆr ê x = xf x + y m!!y = F ê y = f (r)ˆr ê y = yf x + y Polar coordinates are more natural and convenient r F = f (r)ˆr mr! θ = l constant angular momentum m!! r = f (r) + l mr 3 fictitious (centrifugal) force
5 Generalized Coordinates Any convenient coordinates for description of particular system use q i as symbol for general coordinate examples diatomic {q,,q 6 } = {x com, y com, z com, r, θ, φ} -D motion in central field {q, q } = {r, θ} Kinetic energy general quadratic form K = M 0 (q) + examples rotating diatomic -D central motion M j (q)!q j + usually vanish M jk (q)!q j!q k ( ) + 8 m!r + r! K = m!q +!q +!q 3 K = m (!r + r θ! ) θ r φ θ + (r sinθ)!φ
6 Lagrangian Formulation Independent of coordinate system Define the Lagrangian L(q,!q) K(q,!q) U (q) Equations of motion d dt L!q L = 0 j q j j = N N second-order differential equations Central-force example ( ) U (r) L = m!r + r θ! d dt L!r = L r m!! r = mr θ! f (r)! F r =! r U = f (r) d dt L θ! = L θ d dt ( mr θ! ) = 0
7 Hamiltonian Formulation. Motivation Appropriate for application to statistical mechanics and quantum mechanics Newtonian and Lagrangian viewpoints take the q i as the fundamental variables N-variable configuration space!q i appears only as a convenient shorthand for dq/dt working formulas are nd-order differential equations Hamiltonian formulation seeks to work with st-order differential equations N variables treat the coordinate and its time derivative as independent variables appropriate quantum-mechanically
Hamiltonian Formulation. Preparation 8 Mathematically, Lagrangian treats q and!q as distinct L(q j,!q j,t) identify the generalized momentum as p j = L!q j e.g. if L = K U = m!q U (q); p = L /!q = m!q Lagrangian equations of motion We would like a formulation in which p is an independent variable p i is the derivative of the Lagrangian with respect to!q i, and we re looking to replace!q i with p i we need? dp dt j L = q j
9 Hamiltonian Formulation 3. Defintion a Legendre transform! Define the Hamiltonian, H H(q,p) = L(q,!q) p j!q j = K(q,!q) +U (q) + = a j!q j +U (q) + = + a j!q j +U (q) = K +U K!q!q j j (a j!q j )!q j H equals the total energy (kinetic plus potential)
0 Hamiltonian Formulation 4. Dynamics Hamilton s equations of motion From Lagrangian equations, written in terms of momentum Differential change in L dl = L L dq + q!q d!q =!pdq + pd!q Legendre transform H = (L p!q) dh = (!pdq!qdp) dh =!pdq +!qdp!q = + H p!p = H q dp dt =!p = L q p = L!q Lagrange s equation of motion Definition of momentum Hamilton s equations of motion Conservation of energy dh dt =!p dq dt +!q dp dt =!p!q +!q!p = 0
Hamiltonian Formulation 5. Example Particle motion in central force field H = K + U r pθ p = + + Ur () m mr r dr p () r dθ p () θ!q = + H = = dt m dt p mr dp (3) r pθ dp = f() r (4) θ!p = H Lagrange s equations = 0 dt 3 q mr dt m!! r = mr θ! f (r)! F r =! r U = f (r) Equations no simpler, but theoretical basis is better d dt ( mr θ! ) = 0
Phase Space (again) Return to the complete picture of phase space full specification of microstate of the system is given by the values of all positions and all momenta of all atoms Γ = (p N,r N ) view positions and momenta as completely independent coordinates connection between them comes only through equation of motion Motion through phase space helpful to think of dynamics as simple movement through the highdimensional phase space facilitate connection to quantum mechanics basis for theoretical treatments of dynamics understanding of integrators Γ
3 Integration Algorithms Equations of motion in cartesian coordinates dr j dt dp dt j = p j m = F j r = ( r, r ) p = ( p, p ) i= i j F Desirable features of an integrator minimal need to compute forces (a very expensive calculation) good stability for large time steps good accuracy conserves energy and momentum time-reversible area-preserving (symplectic) x x N y y -dimensional space (for example) Fj = Fij pairwise additive forces More on these later
Verlet Algorithm. Equations 4 Very simple, very good, very popular algorithm Consider expansion of coordinate forward and backward in time r(t + δt) = r(t) + m p(t)δt + m F(t)δt + 3!!!! r(t)δt3 + O(δt 4 ) r(t δt) = r(t) m p(t)δt + m F(t)δt 3!!!! r(t)δt3 + O(δt 4 ) Add these together Rearrange 4 r( t+ δt) + r( t δt) = r( t) + F( t) δt + O( δt ) update without ever consulting velocities! m m 4 r( t+ δt) = r( t) r( t δt) + F( t) δt + O( δt )
Verlet Algorithm. Flow diagram 5 One force evaluation per time step One MD Cycle Configuration r(t) Previous configuration r(t-dt) Compute forces F(t) on all atoms using r(t) Advance all positions according to r(t+δt) = r(t)-r(t-δt)+f(t)/m dt Add to block sum Entire Simulation Initialization Reset block sums New configuration move per cycle Add to block sum cycles per block Compute block average blocks per simulation Compute final results No End of block? Yes Block averages
6 Verlet Algorithm. Flow Diagram r v F t-δt t t+δt Given current position and position at end of previous time step Schematic from Allen & Tildesley, Computer Simulation of Liquids
7 Verlet Algorithm. Flow Diagram r v F t-δt t t+δt Compute the force at the current position Schematic from Allen & Tildesley, Computer Simulation of Liquids
8 Verlet Algorithm. Flow Diagram r v F t-δt t t+δt Compute new position from present and previous positions, and present force Schematic from Allen & Tildesley, Computer Simulation of Liquids
9 Verlet Algorithm. Flow Diagram r v F t-δt t-δt t t+δt Advance to next time step, repeat Schematic from Allen & Tildesley, Computer Simulation of Liquids
Forces. Formalism 3 Force is the gradient of the potential F Force on, due to = ur ( ) ur ( ) ur ( ) = e x e x y du( r) r r = x dr e + e x y f( r) = x x + y y r e e y y 4 y x r r x x y y = ( ) + ( ) Energy Force / F = F 0 -.0.5.0 Separation, r/σ.5
Forces. LJ Model 4 Force is the gradient of the potential f( r ) F e ey = x x y r + e.g., Lennard-Jones model σ σ ur () = 4ε r r du f() r = dr 6 48ε σ σ =+ σ r r 3 7 4 8 48ε σ σ F = x x y σ r + r e e 4 0 y - y x r r x x y y = ( ) + ( ) Energy Force /.0.5.0 Separation, r/σ.5
7 Verlet Algorithm. 4. Loose Ends Initialization how to get position at previous time step when starting out? simple approximation r( t δt) = r( t ) v( t ) δt 0 0 0 Obtaining the velocities not evaluated during normal course of algorithm needed to compute some properties, e.g. temperature diffusion constant finite difference v() t = [ r( t+ δt) r( t δt) ] + O( δt ) δ t
Verlet Algorithm 5. Performance Issues 8 Time reversible forward time step replace δt with -δt r( t δt) = r( t) r( t + δt) + F() t δt m same algorithm, with same positions and forces, moves system backward in time Numerical imprecision of adding large/small numbers m r( t+ δt) = r( t) r( t δt) + F( t) δt r( t+ ( δt) ) = r( t) r( t ( δt) ) + F( t) ( δ t) O(δt ) O(δt ) m r( t+ δt) r( t) = r( t) r( t δt) + F( t) δt m O(δt 0 ) O(δt 0 ) O(δt )
Initial Velocities (from Lecture 3) Random direction randomize each component independently randomize direction by choosing point on spherical surface Magnitude consistent with desired temperature. Choices: Maxwell-Boltzmann: Uniform over (-/,+/), then scale so that Constant at vx =± kt/ m Same for y, z components ( x ) prob( v ) exp mv / kt Be sure to shift so center-of-mass momentum is zero P x N p i, x p p P ix, ix, x x N v ix, = / kt m 9
30 Leapfrog Algorithm Eliminates addition of small numbers O(δt ) to differences in large ones O(δt 0 ) Algorithm δ m r( t+ t) = r( t) + v( t+ δt) δt v( t+ δt) = v( t δt) + F( t) δt
3 Leapfrog Algorithm Eliminates addition of small numbers O(δt ) to differences in large ones O(δt 0 ) Algorithm δ m r( t+ t) = r( t) + v( t+ δt) δt v( t+ δt) = v( t δt) + F( t) δt Mathematically equivalent to Verlet algorithm r( t+ δt) = r( t) + ( t t) v δ + F( t) δt δt m
3 Leapfrog Algorithm Eliminates addition of small numbers O(δt ) to differences in large ones O(δt 0 ) Algorithm δ m r( t+ t) = r( t) + v( t+ δt) δt v( t+ δt) = v( t δt) + F( t) δt Mathematically equivalent to Verlet algorithm r( t+ δt) = r( t) + ( t t) v δ + F( t) δt δt m r(t) as evaluated from previous time step r() t = r( t δt) + v( t δt) δt
33 Leapfrog Algorithm Eliminates addition of small numbers O(δt ) to differences in large ones O(δt 0 ) Algorithm δ m r( t+ t) = r( t) + v( t+ δt) δt v( t+ δt) = v( t δt) + F( t) δt Mathematically equivalent to Verlet algorithm r( t+ δt) = r( t) + ( t t) v δ + F( t) δt δt m r(t) as evaluated from previous time step r() t = r( t δt) + v( t δt) δt ( ) r( t+ δt) = r( t) + r( t) r( t δt) + F( t) δt m
34 Leapfrog Algorithm Eliminates addition of small numbers O(δt ) to differences in large ones O(δt 0 ) Algorithm δ m r( t+ t) = r( t) + v( t+ δt) δt v( t+ δt) = v( t δt) + F( t) δt Mathematically equivalent to Verlet algorithm r( t+ δt) = r( t) + ( t t) v δ + F( t) δt δt m r(t) as evaluated from previous time step r() t = r( t δt) + v( t δt) δt ( ) r( t+ δt) = r( t) + r( t) r( t δt) + F( t) δt m r( t+ δt) = r( t) r( t δt) + F( t) δt original algorithm m
35 Leapfrog Algorithm. Flow Diagram r v F t-δt t t+δt Given current position, and velocity at last half-step Schematic from Allen & Tildesley, Computer Simulation of Liquids
36 Leapfrog Algorithm. Flow Diagram r v F t-δt t t+δt Compute current force Schematic from Allen & Tildesley, Computer Simulation of Liquids
37 Leapfrog Algorithm. Flow Diagram r v F t-δt t t+δt Compute velocity at next half-step Schematic from Allen & Tildesley, Computer Simulation of Liquids
38 Leapfrog Algorithm. Flow Diagram r v F t-δt t t+δt Compute next position Schematic from Allen & Tildesley, Computer Simulation of Liquids
39 Leapfrog Algorithm. Flow Diagram r v F t-δt t-δt t t+δt Advance to next time step, repeat Schematic from Allen & Tildesley, Computer Simulation of Liquids
40 Leapfrog Algorithm. 3. Loose Ends Initialization how to get velocity at previous time step when starting out? simple approximation 0 δ = 0 m 0 v( t t) v( t ) F( t ) δt Obtaining the velocities interpolate v() t = ( t δt) ( t δt) v + + v
4 Velocity Verlet Algorithm Roundoff advantage of leapfrog, but better treatment of velocities Algorithm v( + ) = v( ) + [ F( ) + F( + ) m ] Implemented in stages given current force compute r at new time add current-force term to velocity (gives v at half-time step) compute new force add new-force term to velocity Also mathematically equivalent to Verlet algorithm (in giving values of r) m r( t + δt) = r( t) + v( t) δt + F( t) δt t δt t t t δt δt
4 Velocity Verlet Algorithm. Flow Diagram t-δt t t+δt r v Given current position, velocity, and force F Schematic from Allen & Tildesley, Computer Simulation of Liquids
43 Velocity Verlet Algorithm. Flow Diagram t-δt t t+δt r v Compute new position F Schematic from Allen & Tildesley, Computer Simulation of Liquids
44 Velocity Verlet Algorithm. Flow Diagram t-δt t t+δt r v Compute velocity at half step F Schematic from Allen & Tildesley, Computer Simulation of Liquids
45 Velocity Verlet Algorithm. Flow Diagram t-δt t t+δt r v Compute force at new position F Schematic from Allen & Tildesley, Computer Simulation of Liquids
46 Velocity Verlet Algorithm. Flow Diagram t-δt t t+δt r v Compute velocity at full step F Schematic from Allen & Tildesley, Computer Simulation of Liquids
47 Velocity Verlet Algorithm. Flow Diagram t-δt t-δt t t+δt r v Advance to next time step, repeat F Schematic from Allen & Tildesley, Computer Simulation of Liquids
48 Other Algorithms Predictor-Corrector not time reversible easier to apply in some instances constraints rigid rotations Beeman better treatment of velocities Velocity-corrected Verlet
49 Summary Several formulations of mechanics Hamiltonian preferred independence of choice of coordinates emphasis on phase space Integration algorithms Calculation of forces Simple Verlet algorithms Verlet Leapfrog Velocity Verlet Next up: Calculation of dynamical properties