This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · posts/molecular-dynamics-2d

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.

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.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 41–220