• No results found

2.3 Molecular Dynamics simulations

2.3.1 Algorithms

A standard method for the integration of ordinary differential equations such as eqs. 2.3 and 2.4 is the finite difference approach. This method consists on obtaining the particle positions and velocities at certain time t+∆t, given the system variables at a previous time t. The

equations are solved on a step by step basis and the choice of the time interval will depend

on the method of resolution and the system properties, but it has to be considerably smaller than the shortest characteristic time in a system, e.g., the vibrational timescale for covalent bonds involving hydrogens in atomistic simulations.

In general, a good algorithm should be fast, efficient, accurate and simple. In MD simula- tions the speed of the integration method is not crucial because the fraction of time used to integrate the equations of motion is always very small compared to the time needed to calcu- late the interactions between particles. Efficiency can be understood in different ways, on one hand the minimization of the resource usage, for example by storing the smallest possible number of variables, will require less computer memory and will allow the study of bigger systems. On the other hand, an algorithm is also efficient when it spans longer times with less calculations. This can be achieved setting long time steps ∆t, so a given period of simu- lation will cover longer system times. This feature can reduce noticeably the simulation time, however, longer time steps are also related with worse accuracy, which becomes apparent at large times when the system trajectory diverges from the correct classical trajectory. Any two classical trajectories which are initially very close will diverge exponentially with time with a speed characterized by a Lyapunov exponent [112]. Any tiny error associated with finite precision arithmetic will tend to cause these divergences. Although no integration algorithm will provide and exact solution for long times, a good one will generate trajectories close enough to the the true values.

The inability to exactly generate real trajectories is not a drawback, since the aim of MD is not to specify the exact microstates of the system at every time. In MD simulations the magnitudes of interest are obtained from statistical samples, so a trajectory close enough to the real one will be equally valid provided the constants of motion are conserved. Algo- rithms not showing energy conservation will not generate correct ensemble averages, so the statistical predictions obtained from those simulations will be wrong. Energy conservation is degraded as time step is increased, because any finite difference algorithm is only exact for the limit where time steps tend to zero. Therefore, there will be a trade-off in the time step length between efficiency and accuracy. A good algorithm acceptably preserves energy conservation for relatively large time steps. Other important factors related to energy con- servation are the shape of the potential and the typical particle velocities. Thus, shorter time steps are used at high temperatures, for light molecules, and for rapidly varying potential functions in order to ensure well behaving simulations [110].

One of the most simple and extended method to solve eqs. 2.3 and 2.4 is the Verlet algo-

rithm. It is built from a Taylor expansion of the position around time t using eq. 2.2:

r(t+∆t) =r(t) +v(t)∆t+f(t) 2m ∆t 2+ ∆t3 3! ... r+ O(∆t4) (2.5) similarly,

2 Methods r(t−∆t) =r(t) −v(t)∆t+ f(t) 2m ∆t 2∆t3 3! ... r+ O(∆t4) (2.6)

and summing eqs. 2.5 and 2.6 we obtain

r(t+∆t) +r(t−∆t) =2r(t) + f(t) m ∆t 2+ O( ∆t4) (2.7) or equivalently, r(t+∆t) ≈2r(t) −r(t−∆t) + f(t) m ∆t 2 (2.8)

Here, ∆t is the time step in the Verlet algorithm and the error of the estimation of the coor- dinates at time t+∆t is of order ∆t4. As it is clear from eq. 2.8, the Verlet algorithm does

not use the velocity to compute the positions, however, velocity is usually needed for the calculation of the kinetic energy or of other magnitudes, and it is easily obtained from the positions along the trajectory:

v(t) = r(t+∆t) −r(t−∆t)

2∆t + O(∆t

2) (2.9)

The velocity is only accurate to order ∆t2. The Verlet algorithm is relatively fast, it requires little memory and it exhibits little long-term energy drift [111]. Among its limitations, it is not particularly accurate for long time steps, the velocities are handled in an awkward way and it presents numerical imprecision. The numerical imprecisions are due to the small term (O(∆t2)) that is added to a difference of large terms (O(∆t0)) in eq. 2.8 to find the new

positions.

Some modifications have been developed to reduce the deficiencies of the Verlet algorithm, all of them produce identical trajectories, the differences between them are more for conve- nient score precision in certain averages. A simple one is the Leap-frog algorithm, which is very similar to the Verlet scheme but evaluates the velocities at half-integer time steps and uses them to compute the new positions.

v(t+∆t/2) = v(t−∆t/2) + f(t)

m ∆t (2.10)

r(t+∆t) = r(t) +v(t+∆t/2)∆t (2.11)

Although the velocities appear explicitly in the Leap-frog scheme, they still need to be calculated at the mid-step values, so that the kinetic and potential energies are evaluated at the same time to obtain the total energy. Even so, there are still precision benefits from the fact that the difference between two large quantities are not used to get a small one. There is another algorithm, mostly preferred nowadays, that deals in a more natural way with the velocities and reduces the precision problems. This two step velocity Verlet algorithm is

similar to the original one but differs in the fact that the positions and velocities are updated in two steps: r(t+∆t) = r(t) +v(t)∆t+f(t) 2m ∆t 2 (2.12) v(t+∆t) = v(t) + f(t) +f(t+∆t) 2m ∆t (2.13)

This algorithm involves two stages with a force evaluation in between. Firstly, the new positions at time t+∆t are calculated using eq. 2.12, and the velocities at mid-time step are

evaluated using:

v(t+∆t/2) =v(t) + f(t)

2m ∆t (2.14)

The forces at time t+∆t are then computed with the new positions, and the velocity

update completed:

v(t+∆t) =v(t+∆t/2) + f(t+∆t)

2m ∆t (2.15)

The velocities and positions are obtained at the end of each step, so the kinetic and poten- tial energies can be easily evaluated at the same time.

Other algorithms, such as the Gear predictor-corrector, are also used to integrate the equa- tions of motion in MD [110].