loading...
running...
The science
This is a classical force-field molecular dynamics (MD) engine written from scratch in JavaScript. Every atom is a point mass; the force on each one is the negative gradient of a potential energy made of bonded and non-bonded terms, and Newton's second law is integrated step by step. The same engine runs in the 2D and the 3D page, so both give identical numbers.
The potential energy
U = Σbonds ½kb(r − r0)² + Σangles ½kθ(θ − θ0)² + Σi<j 4εij[(σij/r)12 − (σij/r)6] + Σi<j qiqje²/(4πε0r)
The Lennard-Jones term gives short-range repulsion (Pauli exclusion) and long-range dispersion attraction; unlike pairs use the Lorentz-Berthelot rules σij = (σi+σj)/2 and εij = √(εiεj). The Coulomb term between partial charges is what creates hydrogen bonds in water. Atoms of the same molecule do not feel LJ or Coulomb forces from each other (they are held by bonds and angles). With the Morse bonds switch each bond becomes U = D(1 − e−a(r−r0))² with a = √(k/2D), so a bond can stretch and rupture when it is given about D of energy.
Integration and thermostats
v(t+½Δt) = v(t) + F(t)Δt/2m; r(t+Δt) = r(t) + v(t+½Δt)Δt; v(t+Δt) = v(t+½Δt) + F(t+Δt)Δt/2m
This velocity-Verlet scheme is time-reversible and symplectic, so with the thermostat off (NVE) the total energy stays constant to a few parts per 105. The Langevin thermostat adds friction and random kicks, v → c1v + √(1−c1²)√(kBT/m) ξ with c1 = e−γΔt, and samples the canonical ensemble; Berendsen rescales velocities by λ = √(1 + (Δt/τ)(T0/T − 1)), which relaxes the temperature smoothly but does not give the exact fluctuations. The temperature is T = 2K/(3N−3)kB.
Observables
P = (2Kcm/3 + Wmol/3)/V, Wmol = Σmolecule pairs RAB·FAB g(r) = 〈n(r, r+dr)〉 / (4πr²dr ρ) D = limt→∞ 〈|Δr(t)|²〉 / 6t
The pressure is the molecular pressure: centre-of-mass kinetic energy plus the virial of the forces between molecules, which stays correct with multiple time steps. The radial distribution function g(r) uses heavy atoms (all atoms except hydrogens); a sharp first peak followed by oscillations means a liquid, a split series of peaks means a crystal, g ≈ 1 means a gas. The self-diffusion coefficient comes from the slope of the molecules' mean squared displacement (Einstein relation). Real values to compare: liquid water at 300 K D ≈ 2.3–2.5 × 10−9 m²/s, liquid argon at 90 K ≈ 2 × 10−9 m²/s (this small, cut-off system gives somewhat different values).
Units, parameters and honest limits
- Internal units: Å, amu, kJ/mol; one internal time unit is 0.1 ps (100 fs). Water, CO2, methane and nitrogen use parameters of the published SPC/Fw, EPM2, OPLS-AA and TraPPE families, simplified and rounded; argon uses σ = 3.405 Å, ε = 0.996 kJ/mol.
- Electrostatics use a molecule-based cutoff with a reaction-field correction (dielectric constant 78), the usual cheap replacement for Ewald summation. LJ is force-shifted to zero at the cutoff. Systems of 27–216 molecules with periodic boundaries have finite-size effects: densities and pressures are only qualitatively right and the pressure fluctuates by hundreds of bar.
- Bond topology is fixed: with Morse bonds a bond can break and the atoms fly apart, but atoms never form new partners, so this is thermal dissociation, not a reactive force field and not quantum chemistry. Classical MD also has no zero-point energy: high-frequency vibrations (O–H stretch) carry kBT instead of the much smaller quantum energy.
- Multiple time steps (r-RESPA): bonds and angles are integrated with inner steps of at most 0.5 fs, while the slow non-bonded forces are applied once per outer step (default 2 fs). This makes flexible water about four times cheaper; above about 3 fs the energy drift grows. The Verlet scheme still overestimates stiff-vibration amplitudes by 1/(1 − (ωδt)²/4), so inner steps must stay small.
- Temperatures above about 400 K in liquid water without a barostat boil the box into a gas only if you also lower the density; the density slider is a piston that compresses or expands the periodic box smoothly (0.1% per step).
Built-in numerical checks
The panel at the bottom runs nine checks against analytic or independent results on small, separate simulations: the force-free LJ pair distance (the root of the shifted-force equation, which differs from 21/6σ by 0.24%), the N2 bond-vibration period against 2π√(μ/k), energy and momentum conservation in NVE, a finite-difference test that the atomic virial equals −dU/dV for 64 flexible water molecules (it validates every force term, the switching function and the reaction field), the Langevin mean temperature, the Maxwell kurtosis of 3, and the ideal-gas law P V = N kB T for dilute N2.