Modelintro
Lennard-Jones potential
Also called 12-6 potential, LJ potential.
The pair potential 4 epsilon ((sigma/r)^12 - (sigma/r)^6), with steep repulsion and van der Waals attraction. It is the standard model of simple liquids such as argon.
The Lennard-Jones potential is the pair potential between two atoms at distance , where is the depth of the well and is the distance at which . The term is the London dispersion attraction, and the term is a steep repulsion chosen for convenience, not derived. It is one model inside the general idea of an interatomic potential: the energy is a sum over pairs, which makes it the simplest model in use, the standard test fluid of molecular dynamics, and the nonbonded term of a molecular mechanics force field. It is a good model for noble gases such as argon and a poor one for metals, where the embedded atom method adds the many-body terms that pairs miss.
The machine
Unknowns. The positions of atoms, with and .
Functional form. The potential energy is a sum over pairs:
The force on atom is , with the scalar pair force
positive when the pair repels. By Newton's third law, the pair adds to and the opposite to .
Parameters. Two per pair of species, both fitted, not derived:
- , the well depth, an energy.
- , the distance where , a length.
For argon, Allen and Tildesley list K and nm in their Table 1.1, from fits to gas-phase data; the values nm and K are also in use. The exponent 6 is derived: it is the leading term of the dispersion energy between two atoms in quantum mechanics. The exponent 12 is a choice. It is the square of the term, which made it cheap to compute and gives closed forms; the true Pauli repulsion decays more like an exponential.
Reduced units. Measure lengths in , energies in and masses in the atomic mass . Then time is in , temperature is , density is , and pressure is . For argon with nm, K and u, s. A typical time step is then about 11 fs.
Cutoff. In a simulation the sum is cut at , often , and the page or code must say how:
- Truncated: for and 0 beyond. The energy jumps by at .
- Truncated and shifted: for . The energy is continuous; the force is unchanged inside and jumps to 0 at .
- Shifted-force: for . Energy and force are both continuous, but the force is changed everywhere inside .
- Tail correction: with the truncated form, add the part of the energy and the pressure beyond , under the assumption that the radial distribution function is 1 there:
The four choices define four different models, with different phase diagrams.
Standing assumptions. The atoms are spherical and have no charge, the energy is pairwise additive, and the two parameters do not depend on the density or the temperature. In a periodic box, the cutoff satisfies (see periodic boundary conditions).
LJ-ENERGY-FORCES(r_1..r_N, ε, σ, r_c, variant)- 1
U ← 0; F_i ← 0 for each atom i - 2
for each pair i < j: - 3
r ← |r_ij| (the minimum image in a periodic box); if r ≥ r_c then skip the pair - 4
x ← (σ / r)^6 - 5
u ← 4ε (x^2 - x); f ← 24ε (2x^2 - x) / r - 6
shifted: u ← u - φ(r_c). shifted-force: u ← u - φ(r_c) + (r - r_c) f(r_c); f ← f - f(r_c) - 7
U ← U + u; F_i ← F_i + f r_ij / r; F_j ← F_j - f r_ij / r - 8
return U, F
Line L4 computes one power and line L5 reuses it, so a pair costs no square root beyond itself; codes that test avoid even that one. The cost is one evaluation per pair within the cutoff, pair tests with the direct loop in the real RAM, and at fixed density with a linked-cell list or a Verlet neighbor list.
What it counts
The model gives a potential energy and the forces for every configuration, and through them, by simulation, every equilibrium and transport property of the model fluid or solid.
- Energy and forces for molecular dynamics and Monte Carlo.
- Pressure by the virial: , plus for the truncated form.
- Structure, such as the radial distribution function, and from it the energy and pressure as integrals over .
- Phase behavior: the gas, liquid and solid phases, the critical point and the triple point of the model.
By the law of corresponding states, all these results depend on , and only through the reduced units. One simulation at serves every substance that the model fits, once the units are converted. This is a property of the model, exact for any two-parameter pair potential of the form ; whether real argon and krypton follow it is a question of measurement.
Relation to other models
- Interatomic potentials in general. The interatomic potential page gives the idea and the classes of models. Lennard-Jones is the simplest member of the class of pair potentials.
- Other pair potentials. The Mie potential replaces 12 and 6 by general exponents and ; the Buckingham potential uses an exponential repulsion; the Morse potential models a chemical bond. The Weeks-Chandler-Andersen potential keeps only the repulsive part, truncated and shifted at the minimum . Hard spheres are the limit of a very steep repulsion.
- Force fields. A molecular mechanics force field uses a Lennard-Jones term for each nonbonded pair of atoms, with mixed parameters such as the Lorentz-Berthelot rules and , and adds bonds, angles, dihedrals and charges.
- Many-body models. No pair potential can describe metals well: it gives the Cauchy relation between the elastic constants of a cubic crystal under zero stress, which metals break. The embedded atom method adds an energy that depends on the local density. The Behler-Parrinello potential fits a general many-body function to quantum data.
- Charges. Ions need a Coulomb term added to the Lennard-Jones term, which has no cutoff and needs Ewald summation.
Known results in the model
The results below are of three kinds: exact properties of the function, computed values that the test file checks, and simulation results, which are measurements.
Exact properties of the function.
- , and the pair force there is .
- The minimum is at , with . Set : , so , and then .
- At the usual cutoff, , about 1.6 percent of the well depth.
Computed values (checked by the tests).
| configuration | value |
|---|---|
| truncated at , at | |
| truncated and shifted, at | |
| shifted-force, at | |
| 8 atoms on the corners of a cube of side (full potential) | |
| tail correction at , | , |
| static fcc lattice, sums and over the lattice | , |
| fcc lattice at its minimum (full potential) | , |
The cube can be checked by hand. It has 12 edges at , each ; 12 face diagonals at , each ; and 4 body diagonals at , each . The sum is . For the lattice, the energy per atom at nearest-neighbor distance is ; its minimum is at with value .
Simulation results (measurements).
- The critical point depends on the cutoff. For the full potential, simulations give to : Smit gives 1.316, and the NIST reference value is 1.3120. For the potential truncated and shifted at , Smit gives . The same name thus covers models whose critical temperatures differ by about 20 percent, which is why every result must state the cutoff and its treatment.
- Properties differ between truncation schemes. Wang, Ramirez-Hinestrosa, Dobnikar and Frenkel compare published results for different truncations and show that they are not interchangeable; they propose a truncated form that goes to zero smoothly at a short cutoff.
- Argon. Rahman's 1964 simulation of 864 atoms of liquid argon, and Verlet's 1967 equation of state, agreed with experiment for the structure and the thermodynamics to within a few percent, which made the Lennard-Jones fluid the model system of the field. This agreement is a measurement for argon, not a property of the model.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lennard-jones-potential/. The authors are listed in prov/3RCYBF.jsonl.
import math
from typing import Optional
Point = list[float]
def phi(r: float, eps: float = 1.0, sigma: float = 1.0) -> float:
"""The full Lennard-Jones pair energy 4 eps ((sigma/r)^12 - (sigma/r)^6)."""
x = (sigma / r) ** 6
return 4 * eps * (x * x - x)
def pair_force(r: float, eps: float = 1.0, sigma: float = 1.0) -> float:
"""f(r) = -dphi/dr = 24 eps (2 (sigma/r)^12 - (sigma/r)^6) / r; positive means repulsive."""
x = (sigma / r) ** 6
return 24 * eps * (2 * x * x - x) / r
def pair(r: float, rc: Optional[float], variant: str = "truncated", eps: float = 1.0, sigma: float = 1.0) -> tuple[float, float]:
"""Energy and force magnitude of one pair at distance r.
variant is "full" (no cutoff), "truncated" (zero beyond rc),
"shifted" (phi(r) - phi(rc) inside rc) or "shifted-force"
(phi(r) - phi(rc) - (r - rc) phi'(rc) inside rc).
"""
if variant == "full":
return phi(r, eps, sigma), pair_force(r, eps, sigma)
if rc is None or r >= rc: # @line L3
if rc is None:
raise ValueError("this variant needs a cutoff")
return 0.0, 0.0 # @line L3
x = (sigma / r) ** 6 # @line L4
u = 4 * eps * (x * x - x) # @line L5
f = 24 * eps * (2 * x * x - x) / r # @line L5
if variant == "shifted":
u -= phi(rc, eps, sigma) # @line L6
elif variant == "shifted-force":
fc = pair_force(rc, eps, sigma)
u += -phi(rc, eps, sigma) + (r - rc) * fc # @line L6
f -= fc # @line L6
elif variant != "truncated":
raise ValueError("unknown variant")
return u, f
def energy_forces(
positions: list[Point],
rc: Optional[float] = None,
variant: str = "full",
box: Optional[float] = None,
eps: float = 1.0,
sigma: float = 1.0,
) -> tuple[float, list[Point]]:
"""Total energy and the force on each atom, by the direct loop over pairs.
With box set, distances use the minimum image in a cubic periodic box,
and the cutoff must be at most box / 2.
"""
if box is not None and (rc is None or rc > box / 2):
raise ValueError("a periodic box needs a cutoff of at most half the box")
n = len(positions)
dim = len(positions[0]) if n else 3
u_total = 0.0 # @line L1
forces = [[0.0] * dim for _ in range(n)] # @line L1
for i in range(n): # @line L2
for j in range(i + 1, n): # @line L2
d = [positions[i][a] - positions[j][a] for a in range(dim)]
if box is not None:
d = [x - box * round(x / box) for x in d]
r = math.sqrt(sum(x * x for x in d)) # @line L3
u, f = pair(r, rc, variant, eps, sigma)
u_total += u # @line L7
for a in range(dim):
forces[i][a] += f * d[a] / r # @line L7
forces[j][a] -= f * d[a] / r # @line L7
return u_total, forces # @line L8
def tail_energy_per_atom(rho: float, rc: float, eps: float = 1.0, sigma: float = 1.0) -> float:
"""U_tail / N = (8/3) pi rho eps sigma^3 ((1/3)(sigma/rc)^9 - (sigma/rc)^3), for g(r) = 1 beyond rc."""
x = sigma / rc
return (8 / 3) * math.pi * rho * eps * sigma ** 3 * (x ** 9 / 3 - x ** 3)
def tail_pressure(rho: float, rc: float, eps: float = 1.0, sigma: float = 1.0) -> float:
"""P_tail = (16/3) pi rho^2 eps sigma^3 ((2/3)(sigma/rc)^9 - (sigma/rc)^3), for g(r) = 1 beyond rc."""
x = sigma / rc
return (16 / 3) * math.pi * rho * rho * eps * sigma ** 3 * (2 * x ** 9 / 3 - x ** 3)
def reduced_time_unit(sigma_m: float, eps_over_kb: float, mass_kg: float) -> float:
"""tau = sigma sqrt(m / eps) in seconds."""
kb = 1.380649e-23
return sigma_m * math.sqrt(mass_kg / (eps_over_kb * kb))
test_lennard_jones_potential.py 121 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lennard-jones-potential/. The authors are listed in prov/3RCYBF.jsonl.
import itertools
import math
import random
import pytest
from lennard_jones_potential import (
energy_forces,
pair,
pair_force,
phi,
reduced_time_unit,
tail_energy_per_atom,
tail_pressure,
)
RMIN = 2 ** (1 / 6)
def test_check_values():
assert RMIN == pytest.approx(1.122462, abs=1e-6)
assert phi(RMIN) == pytest.approx(-1.0, abs=1e-14)
assert pair_force(RMIN) == pytest.approx(0.0, abs=1e-12)
assert phi(1.0) == 0.0
assert pair_force(1.0) == pytest.approx(24.0)
assert phi(2.5) == pytest.approx(-0.016317, abs=5e-7)
def test_scaling_with_eps_and_sigma():
assert phi(2.0 * 3.4, eps=1.7, sigma=3.4) == pytest.approx(1.7 * phi(2.0))
assert pair_force(2.0 * 3.4, eps=1.7, sigma=3.4) == pytest.approx(1.7 / 3.4 * pair_force(2.0))
def test_cube_of_eight_atoms():
pos = [[RMIN * i, RMIN * j, RMIN * k] for i in range(2) for j in range(2) for k in range(2)]
u, f = energy_forces(pos)
assert u == pytest.approx(-15.1033, abs=5e-5)
for fi in f:
# each corner feels the same force, pointing to the center
assert math.sqrt(sum(x * x for x in fi)) == pytest.approx(math.sqrt(sum(x * x for x in f[0])))
assert [sum(fi[a] for fi in f) for a in range(3)] == pytest.approx([0.0, 0.0, 0.0], abs=1e-12)
def test_cutoff_variants():
rc = 2.5
assert pair(2.6, rc, "truncated") == (0.0, 0.0)
assert pair(2.5 - 1e-9, rc, "shifted")[0] == pytest.approx(0.0, abs=1e-9)
u, f = pair(2.5 - 1e-9, rc, "shifted-force")
assert u == pytest.approx(0.0, abs=1e-12) and f == pytest.approx(0.0, abs=1e-8)
assert pair(RMIN, rc, "shifted")[0] == pytest.approx(-1.0 + 0.016316891136)
assert pair(2.0, rc, "truncated")[0] == pytest.approx(-0.0615234375)
assert pair(2.0, rc, "shifted")[0] == pytest.approx(-0.045206546364)
assert pair(2.0, rc, "shifted-force")[0] == pytest.approx(-0.0257068076376)
# truncation and shifting do not change the force inside the cutoff
assert pair(1.3, rc, "shifted")[1] == pair(1.3, rc, "truncated")[1] == pytest.approx(pair_force(1.3))
@pytest.mark.parametrize("variant,box", [("full", None), ("truncated", None), ("shifted-force", None), ("shifted", 6.0)])
def test_forces_are_minus_the_gradient(variant, box):
rng = random.Random(5)
pos = []
while len(pos) < 12:
p = [rng.uniform(0, 6.0) for _ in range(3)]
if all(math.dist(p, q) > 0.95 for q in pos):
pos.append(p)
rc = None if variant == "full" else 2.5
_, f = energy_forces(pos, rc, variant, box)
h = 1e-6
for i in range(0, 12, 3):
for a in range(3):
plus = [list(p) for p in pos]
minus = [list(p) for p in pos]
plus[i][a] += h
minus[i][a] -= h
num = -(energy_forces(plus, rc, variant, box)[0] - energy_forces(minus, rc, variant, box)[0]) / (2 * h)
assert f[i][a] == pytest.approx(num, rel=1e-6, abs=1e-6)
def simpson(g, a, b, n):
h = (b - a) / n
s = g(a) + g(b)
for k in range(1, n):
s += (4 if k % 2 else 2) * g(a + k * h)
return s * h / 3
def test_tail_corrections_against_quadrature():
rho, rc = 0.8, 2.5
# U_tail / N = 2 pi rho int_rc^inf r^2 phi(r) dr, with r = rc / t on (0, 1].
u = 2 * math.pi * rho * simpson(lambda t: 0.0 if t == 0 else (rc / t) ** 2 * phi(rc / t) * rc / t ** 2, 0.0, 1.0, 2000)
assert tail_energy_per_atom(rho, rc) == pytest.approx(u, rel=1e-8)
# P_tail = -(2/3) pi rho^2 int_rc^inf r^3 phi'(r) dr.
p = (2 / 3) * math.pi * rho ** 2 * simpson(lambda t: 0.0 if t == 0 else (rc / t) ** 3 * pair_force(rc / t) * rc / t ** 2, 0.0, 1.0, 2000)
assert tail_pressure(rho, rc) == pytest.approx(p, rel=1e-8)
assert tail_energy_per_atom(rho, rc) == pytest.approx(-0.428346, abs=1e-6)
assert tail_pressure(rho, rc) == pytest.approx(-0.684417, abs=1e-6)
def test_fcc_lattice_sums_and_minimum():
s6 = s12 = 0.0
R = 8.0
for i, j, k in itertools.product(range(-12, 13), repeat=3):
if (i + j + k) % 2 == 0 and (i, j, k) != (0, 0, 0):
d2 = (i * i + j * j + k * k) / 2.0
if d2 <= R * R:
s6 += d2 ** -3
s12 += d2 ** -6
s6 += math.sqrt(2) * 4 * math.pi / (3 * R ** 3) # the r^-6 sum beyond R, as an integral
assert s12 == pytest.approx(12.13188, abs=1e-5)
assert s6 == pytest.approx(14.45392, abs=2e-4)
rnn = (2 * s12 / s6) ** (1 / 6)
assert rnn == pytest.approx(1.09017, abs=2e-5)
assert -s6 * s6 / (2 * s12) == pytest.approx(-8.6102, abs=2e-4)
def test_argon_time_unit():
m = 39.948 * 1.66053906660e-27
assert reduced_time_unit(0.3405e-9, 119.8, m) == pytest.approx(2.156e-12, rel=1e-3)
References
- J. E. Jones, On the determination of molecular fields. II. From the equation of state of a gas, Proceedings of the Royal Society of London A 106(738), 1924, 463-477, the fit of an inverse-power repulsion and attraction to the second virial coefficient of argon
- J. E. Lennard-Jones, Cohesion, Proceedings of the Physical Society 43(5), 1931, 461-482, the pair potential with an r^-12 repulsion and the r^-6 attraction of London
- Michael P. Allen and Dominic J. Tildesley, Computer Simulation of Liquids, second edition, Oxford University Press, 2017, Section 1.3 (model systems and interaction potentials, with the argon parameters of Table 1.1), Section 1.6.3 (potential truncation) and Section 2.8 (long-range corrections)
- Berend Smit, Phase diagrams of Lennard-Jones fluids, Journal of Chemical Physics 96(11), 1992, 8639-8640, the critical temperature of the full and of the truncated and shifted potential
- Xipeng Wang, Simon Ramirez-Hinestrosa, Jure Dobnikar and Daan Frenkel, The Lennard-Jones potential, when (not) to use it, Physical Chemistry Chemical Physics 22, 2020, the effect of the cutoff and the shift on the computed properties, and the truncated form they propose
- Aneesur Rahman, Correlations in the motion of atoms in liquid argon, Physical Review 136(2A), 1964, A405-A411, the first molecular dynamics of a Lennard-Jones liquid, for argon
- Loup Verlet, Computer "experiments" on classical fluids. I. Thermodynamical properties of Lennard-Jones molecules, Physical Review 159(1), 1967, 98-103, the equation of state of the Lennard-Jones fluid from molecular dynamics
- National Institute of Standards and Technology, Lennard-Jones Fluid Properties, NIST Standard Reference Simulation Website, the critical point of the full Lennard-Jones fluid from simulation
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 3RCYBF Edit this page History Report an error Markdown