WorksPhysics and Astronomy
How to calculate temperature and energy in Molecular Dynamics
Abstract
Molecular Dynamics (MD) simulation of the dynamics of classical objects has become incredibly popular in natural sciences since the method was developed in the sixties. A conservative estimate is that it involves many hundreds of thousands of scientific articles and all subdisciplines of natural sciences. The earliest MD simulations also introduced a simple time-symmetric expression for the momentum and velocity, which has since been used uncritically in almost all MD simulations. The expression is incorrect and can lead to significant errors. But it is straightforward to replace the expression with the correct one, and the motive of the article is to draw attention to how to calculate velocity, kinetic energy, temperature, and energy in an MD simulation correctly. Newton's algorithm of the discrete dynamics has the same quality as his analytical dynamics, and Newton's discrete dynamics conserves the energy exactly. That is the second motive for the article, namely to show that conservation of energy in a conservative system is only obtained by the correct expressions for the velocity and kinetic energy.
Introduction
Molecular Dynamics (MD) simulation of the dynamics of systems of classical mechanical objects has become incredibly popular in the natural sciences since the method was developed in the sixties [1, 2]. A conservative estimate is that it involves many hundreds of thousands of scientific articles and all subdisciplines of natural sciences [3]. The simulations use algorithms for the time evolution, and almost all of the many MD simulations use the same algorithm where a force impulse spontaneously changes an object’s momentum. The algorithm is formulated by Newton in his famous work Principia [4], but has since been reformulated and appears under different names. The dynamics is, however, independent of which reformulation has been used in a simulation [5, 6].
The earliest MD simulations also introduced a simple time-symmetric expression for the momentum and velocity at the time when the force impulse acts, which has since been used uncritically in almost all of the many MD simulations. Verlet introduced the expression in 1967 [2], obtained from a symmetric Taylor expansion in time of the positions [7], and in standard books for MD simulations it is presented the first leading therm in this expanion [8, 9]. However, as one can realize, the expression is systematic incorrect, and it can lead to significant errors [10, 11]. But it is straightforward to replace the incorrect expression with the correct one [11, 12], and that is one of the motives for this article. Namely to draw attention to how the velocity, kinetic energy, temperature, and energy in an MD simulation with Newtons discrete algorithm are calculated correctly.
Newton’s formulation of discrete dynamics is interesting because it has the same quality as his analytical dynamics. It is time-symmetric and conserves the total momentum, angular momentum, and energy of a system [5, 6]. It can further be shown that there probably exists a ”Shadow Hamiltonian (SH)” for the discrete Newtonian dynamics, corresponding to the Hamiltonian for analytic dynamics, and where the discrete positions lie on the corresponding analytic trajectories for SH [13].
The shadow Hamiltonian can be derived for a harmonic potential, and the energy of the discrete dynamics is conserved exactly per time step [13]. The different dynamics for the discrete versus the analytic dynamics are shown in Figure 1, and for a very large time increment , where the discrete dynamics jumps with only five positions per oscillation. For the dynamics shown in Figure 1 with the analytic solution with
Figure 1. Dynamics for a harmonic oscillator. The discrete positions and the trajectory in blue are the discrete dynamics for a harmonic potential, and the corresponding analytic dynamics in red. The trajectory for the shadow Hamiltonian is in green. The dynamics are for , , and for a very large time step . The discrete positions are located on the analytic trajectory for the shadow Hamiltonian. The inset is for , and it shows the change in kinetic energy , per time step, Eq. (16) in magenta, the work per time step, Eq. (15) in light blue, and the changes in energy per time step, Eq. (19), in gray.
and the energies are for the analytic dynamics and for the analytic shadow Hamiltonian with and [5]. The inset is for , and it shows the change in kinetic energy , per time step, Eq. (16) in magenta, the work per time step, Eq. (15) in light blue, and the changes in energy per time step, Eq. (19), in gray.
For other potentials and systems, one has only derived the first term in a functional expansion of the energy for the discrete Newtonian dynamics, and higher-order terms in the expansion are extremely complicated and have so far not been derived. However, calculations of the energy of the discrete Newtonian dynamics, with the first term included, indicate a rapid convergence of the expansion toward the corresponding analytic energy [14].
The existence of a shadow Hamiltonian means that there is no qualitative difference between the discrete Newtonian dynamics and a corresponding analytical dynamics. So the qualitative dynamical properties of discrete Newtonian dynamics versus traditional analytical dynamics are the same. That is the second motive for the article, namely to show that the energy is conserved exactly, consistent with the corresponding conserved value for the Shadow Hamiltonian, but only with the correct expression for the kinetic energy and temperature.
Discrete Newtonian Dynamics
Newtons discrete algorithm
Newton formulated the MD algorithm for discret dynamics in Proposition I very first in Principia. Below is an algebraic formulation.
Consider a classical conservative system of objects where the momentum and the velocity
for object No. at the position and time is changed by a discrete force-impulse to
according to Newtons second law. The objects are again affected by force impulses at time after a time increment , etc. By a rearrangement of the terms in Eq. (2) one obtains Verlet’s formulation of the dicrete algorithm.
The momenta, and the kinetic energy are constant inbetween the discrete force-impulses, but they change at the discrete times according to Eq. (2), and the kinetic energy changes from
to
Verlet also introduced the time symmetrical expression for the velocities at time
and in the many MD simulations one uses this expression for the velocities at time , to obtain the kinetic energy
and the temperature
for a system with degrees of freedom in the system of objects.
It is here the systematic errors in the temperature and kinetic energy are introduced.
The exact relation between the square of the velocities in the time intervals and and Verlet’s expression at time from Eq. (6) is drived in Appendix § 2.1. It is
The correct expression for the kinetic energy and temperature at time is (see § 2 B)
so Verlet’s expression always underestimates the kinetic energy and the temperatures. The underestimations are usuallly of the order a few per cents or less for the traditional choise of state points and time increment .
The systematic deviation between and is not a consequence of the algorithm; it is due to Verlet’s approximation. The systematic deviation is caused by the geometrical constraint, the “Triangle Inequality Theorem”, first formulated by Euclid [15]. Three consecutive positions, which are not on a straight line (zero force) perform a triangle, and the length of the side opposite the central position is always less than the sum of the two other sides’ lengths. But the exact relation Eq. (9) is only valid for Newton’s algorithm, Eq. (2).
An illustrative example is shown in Figure 2. The figure illustrates the systematic deviation between the velocity and for an elastic collision.
Figure 2. Illustrative example: In blue is three positions and the trajectory at an elastic collision. Verlets approximation for the length is in green. The velocity before and after the collision is , and the connection between and is .
The systematic deviation between the temperature and for the traditional Lennard-Jones (LJ) system are shown in the next figure. Figure 3 shows the deviations for and for various state points and time increments. (Each values of are obtained from two-three simulations for LJ particles and for time steps with by interpolation.) The deviations between and increase for larger temperatures, density, and strength of the short-range repulsive forces. The effect of the strength of the repulsive forces is illustrated in the figure by showing the deviation between and for an LJ potential with the repulsive potential between pairs of objects at short interparticle distances proportional to .
Figure 3. The relative difference between , obtained from Eq. (10), and from Eq. (8), and for differnt time increments , as a function of the density.
The connection between analytic and discrete Newtonian dynamics
Classical mechanical dynamics is traditionally determined by Taylor expansions with polynomials in powers of the discrete time step , where the highest power in , indicates the order of the algorithm. From this, Newton’s discrete algorithm is a third-order predictor of a new position on the classical analytic trajectory. However, Newton’s discrete dynamics is exceptional compared with the dynamics obtained by all other algorithms for classical dynamics because its dynamics has the same qualities as the analytic classical dynamics.
The algorithm, Eq. (2), is symmetric with respect to time, and time-reversible and symplectic. Newton’s third law, where forces between pairs and cancels pairwise, ensures conservation of momentum and angular momentum. The conservation of energy can be determined in analogy with the first law of thermodynamics [5]:
In a system, the change in internal energy equals the heat added minus the work done by the system, , expressed as
and with for a conservativ system [16].
Consider the time-interval and with positions , and force impulses . A force, , performs a work on an object by changing its momentum, and the work can be obtained from Eq. (2). The work performed by the forces on the system of object in the time interval is
By rewriting Eq. (3) to
and inserting in Eq. (13) one gets an expression for the work done by the forces in the time interval
The heat added, , in the time interval is
By rewriting Eq. (3) to
and inserting the squared expression for in Eq. (16), the change in kinetic energy in the time-interval is
and with conservation of the energy
So the expression for the kinetic energy, not by but with and with its change by the discrete force impulses, is consistent with the first law of thermodynamics and with energy conservation in a conservative system [16].
The energy conservation is for each object , and at each discrete change of position for the system of objects, no matter what kind of forces the object is exposed to. So the symmetry of Newton’s discrete algorithm and his second-order differential equation for analytic acceleration ensures time reversibility, symplecticity, and energy conservation for each object in the system, whereas the two other invariances, the conservation of momentum and angular momentum in analytic and discrete classical mechanics are ensured by Newton’s third law.
Moreover, there probably exists an analytic dynamics (SH), where the discrete positions with Newton’s algorithm are located on its analytic trajectories [13]. One can, as mentioned, only derive the first term in a functional expansion of the energy, and higher-order terms in the expansion are extremely complicated and have so far not been derived. However, calculations of the energy for analytic dynamics, and with the first term included, indicate a rapid convergence of the expansion [14]. Another indirect indication of the existence of an SH has been performed by determining a high-order polynomial () fit to the discrete positions [18]. But unfortunately, the authors have used Verlet’s wrong expression for the kinetic energy and temperature.
Summary
The many published articles on MD simulations use Newton’s discrete algorithm, and most of the MD articles use Verlet’s expression for the velocity, Eq. (6), to calculate the kinetic energy and the temperature of the system. The temperature and energy are systematically wrong, and the expression introduces a systematic error that can be significant. The motivation for the article is to draw attention to the fact that it is possible to calculate velocities, kinetic energy, and temperature consistently with the algorithm, and in future simulations this error should be avoided.
Many of the articles with MD are for “ensemble MD ”, with constrained dynamics in order to obtain e.g. canonical dynamics. The dynamics is constrained to sample with a given input temperature. Unfortunately most dynamics are with Verlet’s expression for the temperature, i.e. . These ensemble MD should also be corrected. An example of dynamics and with a Nosé-Hoover thermostat and with is given in [19], but there are many other wayes to constrain the dynamics.
Newton’s discrete dynamics is unique in that it has the same qualities as his analytical mechanics. The energy is conserved, but only if one uses the correct expression, Eq. (10), for the kinetic energy. There is probably a shadow Hamiltonian where the discrete positions generated with the algorithm lie on an analytic trajectory, but here too it is important to use the correct expression for the velocity and the kinetic energy, if one compares the energy of a shadow Hamiltonian with the energy of the discrete Newtonian dynamics.
ACKNOWLEDGMENT
Jeppe C. Dyre is gratfully acknowledged.
Data Availability Statement Data will be available on request.
The exact realtion between the kinetic energies and
The relations, Eqn. (9) and (10), between the squares of the velocities and the corresponding kinetic energies, were first derived by J. Jung, C. Kobayashi, and Y. Sugita [11]. They obtained the relations by using the velocity Verlet algorithm (one of the reformulations of Newton’s discrete algorithm) and the Trotter factorisation to derive the relations. They presented the relations as relations, which are correct to second order with respect to the discrete time increment. It is correct when comparing kinetic temperatures and kinetic energies with the exact analytic solutions. But the relations are exact relations for Newton’s discrete dynamics, which is proved below.
The velocities for each object at time , where a discrete force impulse acts, are given by the discrete positions , and . From the Verlet-formulation Eq. (3), one obtains
and
By squaring the expressions Eqn. (20) and (A2):
and
By inserting by Eq. (23) in Eq. (22) one gets
or, by dividing Eq. (24) by , one obtains the exact relation Eq. (9)
between the squares of the velocities. The corresponding change in kinetic energy in a time interval , centred at time , and the work obeys the first law of thermodynamics according to the proof in § 2 B.
References
- [1]A. Rahman, “Correlations in the Motion of Atoms in Liquid Argon”, Phys. Rev. 136, A405 (1964).DOI
- [2]L. Verlet, “Computer “Experiments” on Classical Fluids. I. Thermodynamical Properties of Lennard-Jones Molecules”, Phys. Rev., 159, 98-103 (1967).DOI
- [3]S. Toxvaerd, “Simulating Physics with Computers”, arXiv:2405.20780v1 (2024).arxiv.org/abs/2405.20780
- [4]I. Newton , PHILOSOPHIA NATURALIS PRINCIPIA MATHEMATICA. LONDINI, Anno MDCLXXXVII. Second Ed.1713; Third Ed. (1726)
- [5]S. Toxvaerd, Comprehensive Computational Chemistry, 3 329 (2023).DOI
- [6]S. Toxvaerd, “Newton’s algorithm for discrete classical dynamics”, J. Chem. Phys. 162 , 024107 (2025).DOI
- [7]see [5], Appendix.
- [8]M. Alland, and D. Tildesley, “Computer simulation of liquids”, Oxford Univ. Press, Second Ed. 2017.
- [9]D. Frenkel, and B. Smit, “Understanding Molecular Simulation: From Algorithms to Application”, Academic Press Third Ed. 2023.
- [10]M. A. Cuendet, and W. van Gunsteren, “On the calculation of velocity-dependent properties in molecular dynamics simulations using the leapfrog integration algorithm”, J. Chem. Phys. 127, 184102 (2007).pubmed.ncbi.nlm.nih.gov/18020625
- [11]J. Jung, C. Kobayashi, and Y. Sugita, “Kinetic energy definition in velocity Verlet integration for accurate pressure evaluation”, J. Chem. Phys. 148, 164109 (2018).DOI
- [12]S. Toxvaerd, “Energy, temperature, and heat capacity in discrete classical dynamics”, Phys. Rev. E 109, 015306 (2024).DOI
- [13]S. Toxvaerd,“Hamiltonians for discrete dynamics,” Phys. Rev E 50, 2271 (1994).pubmed.ncbi.nlm.nih.gov/9962234
- [14]S. Toxvaerd, O. J. Heilmann, and J. C. Dyre,“ Energy conservation in molecular dynamics simulations of classical systems,” J. Chem. Phys. 136, 224106 (2012).DOI
- [15]Euclid, The Thirteen Books of Euclid’s Elements, trans. and ed. Thomas L. Heath, Book I, Proposition 20 (Cambridge: Cambridge University Press, 1908).
- [16]The first law of thermodynamics is formulated for an open system together with the second law of thermodynamics for the condition of work performed by heat flow (one of the formulations of the second law). For a closed system, work results in a change in the systems heat capacity Cᵥ, and Cᵥ can be determined from the internal changes in kinetic energy, consistent with Eq. (18).
- [18]C. De Michele, and G. Ciccotti, “Shadow Hamiltonian in molecular dynamics simulations: Against a possible suggested misuse of its physical meaning ” J. Chem. Phys. 164, 244102 (2026).DOI
- [19]S. Toxvaerd, “ Discrete newtonian dynamics with Nosé-Hoover thermostats ”, Mol. Phys. e2314701 (2024).DOI


