Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 47 · Molecular Dynamics

Velocity Verlet and energy conservation

Why molecular dynamics uses velocity Verlet: compare it with Euler, watch energy drift, test time reversibility and choose a safe time step.

The forces tell the atoms where to accelerate. The integrator decides how to turn those accelerations into new positions. A simple choice such as the Euler method looks fine for a few steps but quietly pumps energy into the system; after a million steps, your cold crystal is boiling. Molecular dynamics programs use an integrator with a special mathematical property, and this lesson shows what it is and why it matters.

Left: energy of an oscillator over time, with Euler climbing and velocity Verlet staying flat. Right: the four steps of velocity Verlet
Over 200 steps of size 0.1, Euler multiplies the oscillator energy by (1 + Δt²) each step. Velocity Verlet keeps it near the start value.

What you will learn

  • How the velocity Verlet scheme works, step by step.
  • Why it is time-reversible and conserves energy over very long runs.
  • How to measure energy drift in a real Lennard-Jones simulation.
  • How to choose a time step.

Key terms

Integrator: a rule for advancing positions and velocities by one time step.

Order of accuracy: if the global error scales like Δt^p, the method is of order p.

Symplectic: an integrator that preserves the geometric structure of Hamiltonian motion, so energy errors stay bounded.

Time-reversible: running the algorithm forward and then with reversed velocities brings you back to the start.

Energy drift: a steady rise or fall of the total energy during a run that should conserve it.

The scheme

Start with positions x, velocities v and accelerations a = F/m at time t. One step of size Δt:

Text
1.  v ← v + ½ Δt · a(t)          half kick
2.  x ← x + Δt · v               drift
3.  a ← F(x) / m                 new forces at the new positions
4.  v ← v + ½ Δt · a(t + Δt)     second half kick

Only one force evaluation is needed per step, and that is the expensive part. Memory use is minimal.

It is equivalent to the older Verlet algorithm, x(t+Δt) = 2x(t) − x(t−Δt) + a(t)Δt², which Loup Verlet used in his 1967 simulations of argon, but it handles velocities cleanly.

Why it is better than Euler

The Euler method updates x ← x + Δt·v and v ← v + Δt·a using the values at the start of the step. For a harmonic oscillator, a straightforward calculation shows the energy grows by the factor (1 + Δt²) every step. After 200 steps of 0.1 that is 1.01²⁰⁰ ≈ 7.3. The error is small each step but it always has the same sign, so it accumulates.

Velocity Verlet has the same order of accuracy (second order globally) but two more important properties:

  • It is time-reversible: replacing Δt by −Δt undoes a step exactly.
  • It is symplectic: it exactly conserves a slightly modified "shadow" energy, so the true energy oscillates in a narrow band around its initial value instead of drifting.

This is why we accept a modest-order method for simulations of billions of steps.

Choosing a time step

The step must resolve the fastest motion in the system. Rule of thumb: at least 10 to 20 steps per oscillation of the fastest vibration. For Lennard-Jones fluids in reduced units, Δt ≈ 0.005 is standard; much above 0.01 the energy fluctuations grow quickly, and above about 0.03 collisions become badly resolved. For molecules with hydrogen atoms, the fastest vibration (the O-H bond stretch has a period around 9 fs) forces steps near 1 to 2 fs, or constraints on bond lengths.

Common misconceptions

  • "Higher order is always better." In MD, the structure-preserving property (symplectic) is worth more than a higher order of accuracy.
  • "If the energy fluctuates, the simulation is wrong." Small fluctuations around a constant mean are normal; a steady drift is the red flag.
  • "A conserved energy proves the trajectory is accurate." Individual trajectories separate from the exact one exponentially (chaos); what is preserved is the statistical behavior.

Try it

Compare Euler with velocity Verlet on the oscillator a = −x, where the exact energy is constant. The ratio of final to initial energy is printed.

Python Euler against velocity Verlet

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Now the real thing: 36 Lennard-Jones atoms in a two-dimensional periodic box, run for 5 time units with four different time steps. The program reports the size of the energy fluctuation per atom.

Python Energy fluctuation against time step

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The fluctuation should grow roughly like Δt²: doubling the step multiplies it by about four. Finally, the reversibility test. We run forward, flip every velocity, run the same number of steps and see how close the atoms come to their starting positions.

Python Time-reversibility test

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. How many force evaluations does velocity Verlet need per time step?

    The new forces computed in step 3 are reused in the first half kick of the next step.
  2. 2. Why does the explicit Euler method heat up an oscillator?

    The error always adds energy, so it accumulates linearly in the number of steps.
  3. 3. What does 'symplectic' guarantee in practice?

    A symplectic integrator conserves a shadow Hamiltonian, so the true energy only oscillates.
  4. 4. The energy fluctuation of velocity Verlet is observed to scale like Δt². If you double Δt, the fluctuation grows by about...

    Doubling Δt multiplies Δt² by 4.
  5. 5. What limits the time step in a simulation of water with flexible O-H bonds?

    Every oscillation period needs many steps; the O-H stretch is the fastest motion.

Summary

  • Velocity Verlet is kick (½Δt), drift (Δt), recompute forces, kick (½Δt); it needs one force evaluation per step.
  • It is second-order, time-reversible and symplectic, so energy oscillates instead of drifting.
  • Euler's energy error always has the same sign and grows without bound.
  • Reduced-unit Lennard-Jones runs use Δt ≈ 0.005; check the energy fluctuation scales like Δt².

Next: Temperature, pressure and structure