Lab 1.7 · 25 min

Lab: two atoms by hand

Two argon atoms, a calculator and three time steps. We compute the Lennard-Jones energy and force by hand, move the atoms with two different recipes (Euler and velocity Verlet), and let the numbers show why every MD code uses Verlet and why the time step must be small.

The setup

Two argon atoms sit on a line. We use reduced units (Lesson 2.1): lengths in σ (3.4 Å for argon), energies in ε (the depth of the well), masses in units of the argon mass, so m = 1. One time unit is about 2.2 ps.

atom 1: x1 = 0.00 v1 = 0 (at rest) atom 2: x2 = 1.05 v2 = 0 (at rest) distance r = x2 − x1 = 1.05 (a little closer than the atoms like) time step dt = 0.01

The atoms are slightly squeezed, so they will push apart and then vibrate like two balls on a spring. Nothing is added or taken away, so the total energy must stay constant. That is our test of whether a recipe can be trusted.

Step 1

The energy between two atoms

Why: MD needs a rule for how atoms push and pull. Real atoms repel strongly when squeezed and attract weakly when a little apart. The Lennard-Jones formula captures both with just two numbers (σ and ε).

In reduced units the formula is U(r)=4(r−12−r−6)U(r) = 4\left(r^{-12} - r^{-6}\right). Work out r−6 first, then square it to get r−12:

r = 1.05: r^6 = 1.05×1.05×1.05×1.05×1.05×1.05 = 1.3401 r^-6 = 1/1.3401 = 0.7462 r^-12 = 0.7462 × 0.7462 = 0.5568 U = 4 × (0.5568 − 0.7462) = 4 × (−0.1894) = −0.7575
rr⁻⁶r⁻¹²U(r)meaning
0.951.36041.8506+1.9610squeezed: energy up
1.001.00001.00000.0000r = σ
1.050.74620.5568−0.7575our start
1.12250.50000.2500−1.0000the minimum, r = 21/6
1.500.08780.0077−0.3203weak attraction
2.500.00410.0000−0.0163almost nothing

What the numbers say: The energy is lowest at r = 1.1225 (exactly −1 ε), rises steeply below r = 1 and fades to almost zero by r = 2.5. That last fact is why we can ignore far-away pairs (cutoffs, Lesson 2.5). Limitation: one formula for simple atoms only; molecules and ions need more terms (Chapters 4 and 5).

Step 2

From energy to force

Why: Newton's law needs forces, not energies. A force always pushes "downhill": it is minus the slope of the energy. Getting the force wrong is the most common bug in MD codes, so we also check it.

The slope of rn is n·rn−1. Applying this to both terms:

dU/dr = 4 × (−12 r^-13 + 6 r^-7) F(r) = −dU/dr = 24 × (2 r^-13 − r^-7) r = 1.05: r^-13 = r^-12 / r = 0.5568 / 1.05 = 0.5303 r^-7 = r^-6 / r = 0.7462 / 1.05 = 0.7107 F = 24 × (2×0.5303 − 0.7107) = 24 × 0.3499 = 8.399 positive: pushes the atoms apart

Check with the slope measured directly between two nearby points (a "finite difference"):

U(1.051) − U(1.049) = −0.016799 over a distance 0.002 F ≈ −(−0.016799)/0.002 = 8.3996 ✓ agrees with 8.399
rF (formula)F (finite difference)direction
1.0024.00024.001strong push apart
1.058.3998.400push apart
1.12250.0000.000no force at the minimum
1.50−1.158−1.158gentle pull together

What the numbers say: The force is large and repulsive when the atoms are squeezed, zero at the minimum, and weakly attractive beyond it. The finite-difference check costs one line and catches sign errors and missing factors.

Step 3

Newton's law for the pair

Why: To move atoms we need their accelerations, a = F/m. The two atoms feel equal and opposite forces (Newton's third law), so their total momentum stays zero.

force on atom 2 = +8.399 a2 = +8.399 / 1 = +8.399 force on atom 1 = −8.399 a1 = −8.399 total momentum = m v1 + m v2 = 0 at the start, and it must stay 0

What the numbers say: In every table below, v1 = −v2 exactly. If your own code ever gives a drifting total momentum, the forces are not equal and opposite (a bug).

Step 4

Recipe 1: Euler, three steps by hand

Why: The simplest idea: move each atom with its current velocity, and change the velocity with its current acceleration, both for the whole step. Let us see what happens to the energy.

Euler: x_new = x + v·dt v_new = v + a·dt step 1: x2 = 1.05 + 0×0.01 = 1.05000 (uses the OLD velocity 0: the atom does not move!) v2 = 0 + 8.3991×0.01 = 0.08399 energy: KE = ½v1² + ½v2² = 0.08399² = 0.007054 U(1.05) = −0.757512 E = −0.750457 up by 0.0071 in one step step 2: x2 = 1.05 + 0.08399×0.01 = 1.05084 x1 = −0.00084, r = 1.05168 v2 = 0.08399 + 8.3991×0.01 = 0.16798 (still the force at r = 1.05) E = −0.743121 up again
nx1x2v2rFE
00.000001.050000.000001.050008.3991−0.757512
10.000001.050000.083991.050008.3991−0.750457
2−0.000841.050840.167981.051688.0653−0.743121
3−0.002521.052520.248631.055047.4251−0.735531

What the numbers say: The energy rises by about 0.007 every step. Euler uses the force from the start of the step for the whole step, but the force is getting smaller as the atoms separate, so every kick is a little too big. The error always has the same sign, so it piles up.

Step 5

Recipe 2: velocity Verlet, three steps by hand

Why: Verlet uses the average of the old and new forces for the velocity, like the trapezoid rule for areas. It needs the same single force calculation per step as Euler, so it costs the same.

velocity Verlet: 1. v_half = v + ½a·dt (half kick, old force) 2. x_new = x + v_half·dt (move) 3. compute the NEW force at x_new 4. v_new = v_half + ½a_new·dt (half kick, new force) step 1: v2_half = 0 + ½×8.3991×0.01 = 0.041996 x2 = 1.05 + 0.041996×0.01 = 1.05042 x1 = −0.00042, r = 1.05084 new force F(1.05084) = 8.2310 v2 = 0.041996 + ½×8.2310×0.01 = 0.083151 energy: KE = 0.083151² = 0.006914 U(1.05084) = −0.764496 E = −0.757582 changed by only −0.00007
nx1x2v2rFE
00.000001.050000.000001.050008.3991−0.757512
1−0.000421.050420.083151.050848.2310−0.757582
2−0.001661.051660.163041.053337.7472−0.757771
3−0.003681.053680.236791.057367.0031−0.758028

What the numbers say: After three steps the Verlet energy error is 0.0005, against 0.022 for Euler: about 40 times smaller for the same work. The small errors also go up and down instead of piling up (next step).

Step 6

Many steps: drift or wobble?

Why: Three steps do not prove anything about a whole simulation. We let the computer repeat our hand recipe for about three vibrations (2 time units) and compare different time steps.

dtEuler: E(end) − E₀Verlet: largest |E − E₀|
0.020+1.7650.00497
0.010+0.8490.00123
0.005+0.3310.00031
Euler: halving dt roughly halves the error -> error grows like dt ("first order") Verlet: 0.00497 / 0.00123 = 4.0 0.00123 / 0.00031 = 4.0 -> error grows like dt² ("second order") Euler, dt = 0.01: E rises from −0.76 to above 0, the molecule BREAKS at t = 3.35 Euler, dt = 0.005: breaks at t = 6.17 Verlet: never breaks (checked to t = 50)

What the numbers say: Euler adds energy steadily until the atoms fly apart: an unphysical result from a numerical error. Verlet keeps the energy within 0.2 % for dt = 0.01, forever. Its limitation: the energy is not exact (it wobbles), and the wobble grows as dt². This is why every MD code uses Verlet or its twin, leap-frog.

Step 7

How large may the time step be?

Why: A larger dt means fewer steps, so a cheaper simulation. But the time step must resolve the fastest motion in the system. We estimate that motion by hand and then test it.

Near the minimum the LJ well looks like a spring. Its stiffness is the curvature of U there, and two atoms of mass 1 vibrate like one particle with half the mass (the reduced mass μ = 1/2):

stiffness k = U''(r_min) = 36 × 2^(2/3) = 57.15 frequency ω = √(k/μ) = √(57.15/0.5) = 10.69 period = 2π/ω = 6.2832/10.69 = 0.588 time units
dtsteps per vibrationVerlet: largest |E − E₀| (20 time units)
0.0158.80.0012
0.0319.60.011
0.069.80.047
0.124.91.81 (molecule nearly breaks)
0.202.929 (explodes)
rule of thumb: at least ~20 steps per period of the fastest vibration Verlet is unstable when ω·dt > 2, i.e. dt > 2/10.69 = 0.19

What the numbers say: For argon, dt = 0.01 τ ≈ 22 fs is fine. A water O–H bond vibrates with a period of about 9 fs, so water needs dt ≈ 0.5–1 fs, or constraints that freeze the bond (Lesson 4.4). The time step is set by the fastest motion, not by what you want to study.

Summary

EulerVelocity Verlet
force calculations per step11
energy error after 3 steps (dt = 0.01)+0.022−0.0005
halving dt reduces the error by≈ 2×4×
long runenergy drifts up, molecule breaksenergy wobbles, stays bounded
use it for MD?noyes (with dt ≲ period/20)

The same steps with forces from many atoms, in three dimensions, are a complete MD program. Everything later in the course adds to this loop; nothing replaces it.