During molecular dynamics simulations it is often important to keep the temperature of the system constant. Different algorithms have been developed for thermostating during the last weeks of July.

The instantaneous temperature of a system of N particles can be calculated using value of kinetic energy:

where denotes momentum of the i-th particle and is its mass, is the number of constraints and is the total number of degrees of freedom, is the Boltzmann constant and is the desired temperature.

For instance, a molecule of water has atoms and bonds connecting atoms of hydrogen with one atom of oxygen, so the number of degrees of freedom for this molecules is . If a system for modelling water contains 1000 molecules, then , and .

All the figures of the temperature control in this post are presented for the simulation results of the water SPC/Fw model.

Andersen thermostat

The Andersen thermostat doesn’t keep the energy of a system constant, so it is used for equilibration and initial stabilization of the temperature in microcanonical ensembles (NVE). But it can be used for simulation of a canonical ensemble (NVT). Also the Andersen thermostat can be used only for time-independent properties. At every integration timestep, velocity of random particles is rescaled according to the Maxwell–Boltzmann statistics for the given temperature. Those random particles are chosen according to the Poisson distribution:

where is the stochastic collision frequency. Actually, I have got a post devoted to the Andersen thermostat

picture for the Andersen thermostating

Berendsen thermostat

The idea behind the Berendsen thermostat is to modify the Langevin equation of motion in the sense of removing the local temperature coupling through stochastic collisions (random noise), while retaining the global coupling (principle of least local perturbation). This can be represented in the following equation:

The global additional temperature coupling is accomplished by the equations

Here I present results of thermostating of systems for liquid argon and water:

If the and in practice when , the Berendsen thermostat turns into the Woodcock thermostat, which does not allow for temperature fluctuations.

picture for the Berendsen thermostating

Nosé-Hoover thermostat

For the original Nosé algorithm the idea was to extend the real system by addition of an artificial dynamical variable associated with a mass and having the velocity . So the system Hamiltonian is extended by introducing a thermal reservoir and a friction term in the equations of motion. The friction force is proportional to the product of each particle’s velocity and a friction parameter,

In terms of real system variables the Lagrangian equations of motion can be written as

with the effective relaxation time

where in real-time sampling (Nose-Hoover formalism) and for virtual-time sampling (Nose-formalism).

picture for the Nose-Hoover thermostating

Langevin thermostat

In Langevine dynamics the temperature is maintained by modifying the Newton’s equations of motion with a friction defined by the coefficient and a random force with dispersion

where is the Wiener process.

picture for the Langevin thermostating

Code

Implementation of all the thermostats can be examined in NBodySImulation.jl project and inside the corresponding pull request #5