demoAIDynamics and chaos
A Lennard-Jones liquid by molecular dynamics in two dimensions
100 atoms in a periodic box, velocity Verlet, no thermostat. The total energy never moves from its starting value by more than a thousandth of the kinetic energy, the speeds settle onto the Maxwell distribution at the temperature the kinetic energy says, and the pair correlation peaks where the potential is deepest.
Open in the workbenchDownload .vivOutputs below are from the site build’s run; Run all runs it again in your browser.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Atoms interact by the Lennard-Jones potential , in units where . The box is periodic with the minimum-image rule, there is no cutoff (every pair, small), and the integrator is velocity Verlet, which is symplectic: the energy wobbles but does not drift.
What is checked
Momentum stays at zero to rounding, because every force has an equal and opposite partner. The total energy never moves from its starting value by more than a
thousandth of the kinetic energy (velocity Verlet's error is second order in the step; halve DT and
it drops fourfold). And the speeds, collected over the second half of the run, follow the
two-dimensional Maxwell distribution at the temperature
that equipartition gives, averaged over the same half — the
histogram against that curve is the second figure, and the test checks that their mean speeds
agree to two percent.
The pair correlation is the third figure: near zero inside the core, a first peak close to where the potential is deepest, then ripples that fade toward 1. The fourth test checks the position and height of that peak.
The force loop is written with arrays: for each atom, the displacements to all the others are
one array, the minimum image is one line, and the pair forces are a pow and two products.
The post also shows a recorded run of the same program at 400 atoms and three times the steps
(the large setting), compiled to C and run natively; 100 atoms takes a
few seconds in a browser tab.
Printed
Tests 4 of 4 pass
- momentum stays at zero to rounding (passes)
- the total energy never moves from its starting value by more than a thousandth of the kinetic energy (passes)
- the mean speed matches the 2-D Maxwell distribution at the measured temperature to two percent (passes)
- g(r) peaks near 2^(1/6) sigma, the bottom of the potential, and is above 1 there (passes)
The large run, recorded by the author
N = 400 · STEPS = 6000 · FRAME_EVERY = 200 · compiled Viv -> C -> cc -O2, one core of an Apple M2 Pro, 21 s, 2026-09-22 · viv run --set N=400 --set STEPS=6000 --set FRAME_EVERY=200 posts/2026-09-22-molecular-dynamics-2d.viv
- ✓ momentum stays at zero to rounding
- ✓ the energy drifts by less than a part in a thousand of the kinetic energy
- ✓ the mean speed matches the 2-D Maxwell distribution at the measured temperature to two percent
- ✓ g(r) peaks near 2^(1/6) sigma, the bottom of the potential, and is above 1 there