Skip to content
LumenaryAcademy
Methods 80 min

Atomistic simulation

Materials one atom at a time — interatomic potentials, molecular dynamics with velocity Verlet and periodic boundaries, Metropolis Monte Carlo and a phase transition in the Ising model, and how far in time and space such simulations reach.

Code tested · 5AI-draftedAwaiting review by a materials scientist

Your guides: Chloe · The Materials Scientist, Margaret · The Tester, Gideon · The Failure Analyst

MotivationH

A computational microscope

How does a crack tip in silicon decide whether to run or to blunt? What happens in the first ten picoseconds after a neutron knocks an iron atom out of its site in a reactor vessel? How fast will lithium move through a solid electrolyte that nobody has made yet? Microscopes cannot follow atoms that fast, and experiments cannot be done on materials that do not exist. Atomistic simulation can: it follows every atom, at every instant, in a material defined entirely by a formula for the forces between atoms.

There are two great families of methods. Molecular dynamics (MD) moves the atoms by Newton's laws, so it gives real trajectories in time: vibrations, diffusion, melting, a dislocation gliding. Monte Carlo (MC) does not follow time at all; it samples arrangements of atoms with the probabilities that statistical mechanics assigns them, which is the efficient way to find equilibrium properties such as how an alloy orders. This lesson builds a small version of each in NumPy, measures things with them, and then looks at how professionals scale them up to millions of atoms and at what limits remain. The quantum-mechanical calculations that supply the most accurate forces are the subject of the next lesson, density functional theory.

IntuitionH

Atoms as balls, bonds as springs

Electrons are light and quick; nuclei are thousands of times heavier and slow. So for each arrangement of the nuclei, the electrons settle almost instantly into their ground state, and the total energy is a function of the nuclear positions alone, the potential energy surface U(r1,…,rN)U(\mathbf r_1, \ldots, \mathbf r_N). This is the Born–Oppenheimer approximation, which Lumenary Chemistry's computational chemistry lesson introduces. The force on each atom is the downhill slope of that surface, Fi=−∂U/∂ri\mathbf F_i = -\partial U/\partial \mathbf r_i, and at room temperature and above the nuclei move, to a good approximation, as classical particles.

Everything therefore rests on UU. In an interatomic potential, UU is written as a formula with parameters fitted to experiments or to quantum calculations, cheap enough to evaluate millions of times. Choosing a potential is choosing what the simulated material is: the same code with a different potential simulates argon, copper or silicon.

Analogy, not a formal construction

A molecular dynamics simulation is like a film of a vast game of billiards in which the balls are joined by invisible springs of a peculiar shape. A Monte Carlo simulation is more like a photographer who visits the table at random moments and keeps a scrapbook of arrangements, taking more pictures of the arrangements the table spends more time in. The film shows how things happen; the scrapbook is enough to learn what the table is usually like.

DefinitionsH

Potentials, boxes and temperature

Definition— Lennard-Jones potential

The Lennard-Jones potential gives the energy of two atoms a distance rr apart as

V(r)=4ε[(σr)12−(σr)6].V(r) = 4\varepsilon\left[\left(\frac{\sigma}{r}\right)^{12} - \left(\frac{\sigma}{r}\right)^{6}\right].

The r−6r^{-6} term is the van der Waals attraction between fluctuating dipoles; the r−12r^{-12} term is a convenient stand-in for the steep repulsion of overlapping electron clouds. V=0V = 0 at r=σr = \sigma, and the minimum, of depth −ε-\varepsilon, lies at rmin=21/6σ≈1.122 σr_\text{min} = 2^{1/6}\sigma \approx 1.122\,\sigma.

Simulations measure lengths in units of σ\sigma, energies in ε\varepsilon, masses in the atomic mass mm and time in τ=σm/ε\tau = \sigma\sqrt{m/\varepsilon}. In these reduced units one calculation serves every Lennard-Jones substance. For argon, σ=0.3405\sigma = 0.3405 nm and ε/kB=119.8\varepsilon/k_\text{B} = 119.8 K, so τ=2.16\tau = 2.16 ps.

10−111.522.53separation r / σV / εdepth εr = 2^(1/6) σr = σcut-off r_c
The Lennard-Jones potential in reduced units. It crosses zero at r = σ, has its minimum of depth ε at r = 2^(1/6) σ, and is usually cut off at a radius such as r_c = 2.5 σ, where it has fallen to 1.6 per cent of the well depth.

Definition— periodic boundary conditions

A simulation box holds a few hundred to a few billion atoms, while a grain of real material holds 101510^{15} or more. To avoid surfaces everywhere, the box is surrounded by copies of itself in every direction, so an atom leaving through one face re-enters through the opposite face. Under the minimum-image convention, each pair of atoms interacts through the nearest copy, which requires the cut-off radius to be less than half the box width.

ABshaded: the simulated boxaround it: periodic imagesdashed circle: cut-off radius of AA interacts with the nearestimage of B, in the box to the rightan atom leaving one facere-enters through the opposite one
Periodic boundary conditions in two dimensions. Only the shaded central box is simulated; the eight surrounding boxes are images of it. Atom A interacts with every atom inside its cut-off circle, including the image of atom B in the box to the right, which is nearer to A than B itself is.

Definition— kinetic temperature

In a simulation of NN atoms whose total momentum is held at zero, the temperature is defined through equipartition, each of the 3N−33N - 3 free velocity components carrying 12kBT\tfrac12 k_\text{B}T of kinetic energy on average:

T=2(3N−3) kB∑i12mivi2.T = \frac{2}{(3N-3)\,k_\text{B}} \sum_i \tfrac12 m_i v_i^2.

ComputationC

Integrating Newton's equations

Molecular dynamics steps the equations of motion forward by a small time step Δt\Delta t. The obvious scheme, explicit Euler (x←x+vΔtx \leftarrow x + v\Delta t, v←v+aΔtv \leftarrow v + a\Delta t), is a disaster. Almost every MD code uses instead velocity Verlet:

vn+1/2=vn+12anΔt,rn+1=rn+vn+1/2Δt,vn+1=vn+1/2+12an+1Δt,\mathbf v_{n+1/2} = \mathbf v_n + \tfrac12 \mathbf a_n \Delta t, \qquad \mathbf r_{n+1} = \mathbf r_n + \mathbf v_{n+1/2}\Delta t, \qquad \mathbf v_{n+1} = \mathbf v_{n+1/2} + \tfrac12 \mathbf a_{n+1}\Delta t,

a half "kick" of velocity, a "drift" of position, and a second half kick with the new forces. It costs one force evaluation per step, the same as Euler. The block compares the two on the simplest possible system, one atom on a spring.

python
import math

# One atom on a spring, x'' = -x (angular frequency 1, period 2 pi), started at x = 1, v = 0.
# Its energy v^2/2 + x^2/2 should stay exactly 0.5 for ever.
def euler(x, v, dt):
    return x + dt * v, v - dt * x

def velocity_verlet(x, v, dt):
    v_half = v - 0.5 * dt * x            # half kick with the old force
    x = x + dt * v_half                  # drift
    return x, v_half - 0.5 * dt * x      # half kick with the new force

def energy_error(x, v):
    return abs(0.5 * v * v + 0.5 * x * x - 0.5)

dt = 0.05
per_period = round(2 * math.pi / dt)
xe, ve, xv, vv = 1.0, 0.0, 1.0, 0.0
worst_e = worst_v = 0.0
print("periods   worst energy error: Euler       Verlet")
for n in range(1, 1000 * per_period + 1):
    if n <= 50 * per_period:
        xe, ve = euler(xe, ve, dt)
        worst_e = max(worst_e, energy_error(xe, ve))
    xv, vv = velocity_verlet(xv, vv, dt)
    worst_v = max(worst_v, energy_error(xv, vv))
    if n % per_period == 0 and n // per_period in (1, 10, 50, 1000):
        e_text = f"{worst_e:12.3g}" if n <= 50 * per_period else "  (gave up)"
        print(f"{n // per_period:7d}   {e_text:>24s}   {worst_v:10.2e}")

# Velocity Verlet is also time-reversible: flip the velocity and the atom retraces its path.
vv = -vv
for n in range(1000 * per_period):
    xv, vv = velocity_verlet(xv, vv, dt)
print(f"\nforwards 1000 periods, then backwards: x = {xv:.10f} (started at 1), v = {vv:.1e}")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Euler's energy error is 0.185 after one period and 3.4×1063.4 \times 10^6 after fifty: every step multiplies the energy by 1+Δt21 + \Delta t^2, so the atom spirals outwards for ever. Velocity Verlet's error never exceeds 3.1×10−43.1 \times 10^{-4}, which is Δt2/8\Delta t^2/8, however long it runs, and running it backwards brings the atom home to ten decimal places.

Theorem— Properties of velocity Verlet

Velocity Verlet is time-reversible (applying it with −Δt-\Delta t undoes a step exactly) and symplectic (it preserves volumes in the space of positions and momenta, as the exact dynamics does). Its global error in positions is of order Δt2\Delta t^2. For a symplectic method, the energy error stays bounded, oscillating close to zero, over exponentially long times, instead of drifting.

ComputationC

Molecular dynamics of a Lennard-Jones liquid

Now the real thing, in miniature: 108 Lennard-Jones atoms, started on a face-centred cubic lattice at the density of liquid argon near its triple point, with random velocities equivalent to T=1.4 ε/kBT = 1.4\,\varepsilon/k_\text{B}. The block computes forces for all pairs within the cut-off using the minimum image, integrates with velocity Verlet, and measures the kinetic, potential and total energy, the temperature, the pressure from the virial theorem, P=(NkBT+13∑pairsr⋅F)/VP = (Nk_\text{B}T + \tfrac13\sum_\text{pairs}\mathbf r\cdot\mathbf F)/V, and, from how far the atoms wander, the diffusion coefficient.

python
import numpy as np

rng = np.random.default_rng(1964)

# Lennard-Jones atoms in reduced units: lengths in sigma, energies in epsilon, mass 1,
# time in tau = sigma sqrt(m / epsilon).  Argon: sigma = 0.3405 nm, epsilon / k_B = 119.8 K.
sigma, eps_over_kB, mass = 0.3405e-9, 119.8, 39.948 * 1.66054e-27
tau = sigma * np.sqrt(mass / (eps_over_kB * 1.380649e-23))

cells, rho = 3, 0.8442                       # 3 x 3 x 3 FCC cells: 108 atoms, at a liquid's density
a = (4 / rho) ** (1 / 3)                     # FCC cell edge
L = cells * a                                # box edge, periodic in x, y and z
basis = np.array([[0, 0, 0], [0.5, 0.5, 0], [0.5, 0, 0.5], [0, 0.5, 0.5]])
grid = np.array([[i, j, k] for i in range(cells) for j in range(cells) for k in range(cells)])
pos = (grid[:, None, :] + basis[None, :, :]).reshape(-1, 3) * a
N = len(pos)
rc = 2.5                                     # cut-off radius
shift = 4 * (rc**-12 - rc**-6)               # makes the pair energy zero at the cut-off

def forces(pos):
    d = pos[:, None, :] - pos[None, :, :]
    d -= L * np.round(d / L)                 # minimum-image convention
    r2 = np.sum(d * d, axis=-1)
    np.fill_diagonal(r2, np.inf)
    inside = r2 < rc * rc
    inv6 = np.where(inside, 1 / r2**3, 0.0)
    f_over_r = np.where(inside, 24 * inv6 * (2 * inv6 - 1) / r2, 0.0)
    F = np.sum(f_over_r[:, :, None] * d, axis=1)
    U = 0.5 * np.sum(np.where(inside, 4 * inv6 * (inv6 - 1) - shift, 0.0))
    W = 0.5 * np.sum(np.where(inside, 24 * inv6 * (2 * inv6 - 1), 0.0))   # virial: sum of r . F
    return F, U, W

# Random velocities for T = 1.4, with the total momentum removed.
v = rng.normal(0, 1, size=(N, 3))
v -= v.mean(axis=0)
v *= np.sqrt(1.4 * (3 * N - 3) / np.sum(v * v))

dt, steps, settle = 0.004, 3000, 1000
F, U, W = forces(pos)
unwrapped = pos.copy()
temps = []
print(f"{N} atoms in a box {L:.3f} sigma wide; time step {dt} tau = {dt * tau * 1e15:.1f} fs for argon\n")
print(" step    time    kinetic  potential     total   temperature  pressure")
for step in range(steps + 1):
    K = 0.5 * np.sum(v * v)
    T = 2 * K / (3 * N - 3)                  # equipartition, less the 3 momentum constraints
    if step % 300 == 0:
        P = (N * T + W / 3) / L**3           # the virial theorem
        print(f"{step:5d}  {step * dt:6.2f}  {K / N:9.4f}  {U / N:9.4f}  {(K + U) / N:8.4f}  {T:12.3f}  {P:8.3f}")
    if step == settle:
        start = unwrapped.copy()
    if step >= settle:
        temps.append(T)
    if step == steps:
        break
    v += 0.5 * dt * F                        # velocity Verlet: half kick,
    new = pos + dt * v                       # drift,
    unwrapped += new - pos
    pos = new % L                            # wrap back into the box,
    F, U, W = forces(pos)
    v += 0.5 * dt * F                        # second half kick

T_mean = np.mean(temps)
msd = np.mean(np.sum((unwrapped - start) ** 2, axis=1))
t_run = (steps - settle) * dt
D = msd / (6 * t_run)
print(f"\nmean temperature from step {settle}: {T_mean:.3f} epsilon/k_B = {T_mean * eps_over_kB:.0f} K for argon")
print(f"mean square displacement over {t_run:.0f} tau: {msd:.2f} sigma^2, so D = <r^2>/6t = {D:.3f} sigma^2/tau")
print(f"for argon: D = {D * sigma**2 / tau:.1e} m^2/s")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Read the output column by column. The total energy per atom stays at −4.2523 to −4.2525 for all 3000 steps: that is the test that the integrator and the forces are right, and the first thing to check in any MD run. The temperature starts at 1.4 but falls within a few hundred steps to about 0.7, because the atoms began exactly on their lattice sites with zero potential energy to spare; as they start to vibrate, kinetic energy flows into potential energy until the two share it. The stretched lattice (its density is a liquid's, about 12 per cent below the solid's) cannot hold together and melts: its pressure goes from −5.05, a crystal under tension, to small positive values. After melting, each atom wanders 1.20 σ² in mean square over 8 τ, so D=0.025 σ2/τD = 0.025\,\sigma^2/\tau. For argon, that is a temperature of 81 K, close to its real triple point of 83.8 K, and D≈1.3×10−9D \approx 1.3 \times 10^{-9} m² s⁻¹, the order typical of simple liquids and more than a hundred times faster than carbon in steel at 925 °C in diffusion.

Real simulations add a few things this one omits. A thermostat (Nosé–Hoover, Langevin, or velocity rescaling done carefully) holds the temperature at a target value, and a barostat the pressure, so that the simulation samples the conditions of an experiment instead of fixed energy. Neighbour lists, another idea of Verlet's, record which atoms are near which so that force calculations cost O(N)O(N) rather than the O(N2)O(N^2) of the all-pairs loop above. And long-range Coulomb forces in ionic materials need special summation methods, because they cannot simply be cut off.

ComputationC

Monte Carlo and the Ising model

For equilibrium properties, dynamics is not needed. Statistical mechanics says that at temperature TT a configuration of energy EE occurs with probability proportional to e−E/kBTe^{-E/k_\text{B}T} (the Boltzmann distribution, derived in Lumenary Chemistry's statistical thermodynamics). The trouble is that there are astronomically many configurations. In 1953 Nicholas Metropolis, Arianna and Marshall Rosenbluth, and Augusta and Edward Teller found a way to sample them with the right probabilities without ever computing the normalising sum.

Definition— Metropolis algorithm

Starting from any configuration, repeatedly propose a small random change, compute the energy change ΔE\Delta E, and accept the change if ΔE≤0\Delta E \le 0, or with probability e−ΔE/kBTe^{-\Delta E/k_\text{B}T} if ΔE>0\Delta E > 0; otherwise keep the old configuration (and count it again). The sequence of configurations is a Markov chain whose long-run distribution is the Boltzmann distribution, because the acceptance rule satisfies detailed balance: in equilibrium, every move is made as often as its reverse.

The test bed for this lesson is the Ising model: spins si=±1s_i = \pm 1 on a square lattice, with energy E=−J∑⟨ij⟩sisjE = -J\sum_{\langle ij\rangle} s_i s_j summed over neighbouring pairs. It is a model of a magnet, but materials scientists read it just as often as an alloy: put an A atom wherever s=+1s = +1 and a B atom wherever s=−1s = -1, and the same mathematics describes ordering in brass or segregation in a solid solution (phase diagrams). In two dimensions Lars Onsager solved it exactly in 1944: it has a phase transition at kBTc/J=2/ln⁡(1+2)=2.269k_\text{B}T_\text{c}/J = 2/\ln(1 + \sqrt2) = 2.269, below which the spins order spontaneously. The block runs Metropolis on a 32 × 32 lattice, warming it up from complete order, and compares the average magnetisation with the exact infinite-lattice result.

python
import math
import numpy as np

rng = np.random.default_rng(1944)

# The 2-D Ising model on an L x L square lattice with periodic edges, J = 1, k_B = 1.
# Metropolis updates on a checkerboard: no two sites of the same colour are neighbours,
# so all sites of one colour can be updated at once without breaking detailed balance.
L = 32
spins = np.ones((L, L), dtype=np.int64)                 # start fully ordered, all up
black = (np.add.outer(np.arange(L), np.arange(L)) % 2) == 0

def neighbour_sum(s):
    return np.roll(s, 1, 0) + np.roll(s, -1, 0) + np.roll(s, 1, 1) + np.roll(s, -1, 1)

def sweep(s, T):
    for colour in (black, ~black):
        dE = 2 * s * neighbour_sum(s)                   # energy change if each spin flipped
        accept = (dE <= 0) | (rng.random(s.shape) < np.exp(-dE / T))
        s[colour & accept] *= -1

def onsager_m(T):                                       # exact |m| for an infinite lattice
    return (1 - math.sinh(2 / T) ** -4) ** 0.125 if T < Tc else 0.0

Tc = 2 / math.log(1 + math.sqrt(2))
print(f"exact critical temperature (Onsager): Tc = {Tc:.4f} J/k_B\n")
print("   T    <|m|>  exact   heat capacity per spin")
for T in [1.5, 1.8, 2.0, 2.1, 2.2, 2.27, 2.35, 2.5, 2.8, 3.2]:
    for _ in range(300):                                # let it settle at this temperature
        sweep(spins, T)
    m_abs, E = [], []
    for _ in range(1000):                               # then measure
        sweep(spins, T)
        m_abs.append(abs(spins.mean()))
        E.append(-np.sum(spins * (np.roll(spins, 1, 0) + np.roll(spins, 1, 1))))
    C = np.var(np.array(E, dtype=float)) / (T * T * L * L)
    m = np.mean(m_abs)
    print(f"{T:5.2f}   {m:5.3f}  {onsager_m(T):5.3f}   {C:5.2f}   {'#' * round(30 * m)}")
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Below the transition the simulation matches the exact magnetisation (announced by Onsager and proved by Chen-Ning Yang in 1952) to within 0.002 at every temperature, from 0.987 at T=1.5T = 1.5 to 0.783 at T=2.2T = 2.2. Then order collapses: the magnetisation falls from 0.681 at 2.27 to 0.204 at 2.5, and the heat capacity, computed from the size of the energy fluctuations as C=var(E)/kBT2C = \mathrm{var}(E)/k_\text{B}T^2, peaks at 1.64 per spin near TcT_\text{c}. Above TcT_\text{c}, a lattice of 1024 spins still shows a residual magnetisation, 0.075 even at 3.2, where an infinite lattice would show none.

For that question there is kinetic Monte Carlo (KMC). Each possible event, such as an atom jumping into a neighbouring vacancy, is given a physical rate ν e−Ea/kBT\nu\,e^{-E_\text{a}/k_\text{B}T}, with the barrier EaE_\text{a} from a potential or from density functional theory. The algorithm picks events with probabilities proportional to their rates and advances the clock by a random interval set by the total rate. Because it skips the 101210^{12} or so vibrations between jumps, KMC follows diffusion, precipitation and radiation damage over seconds to years, with the vacancy mechanism of diffusion built in jump by jump.

ExplanationH

How far in time and space?

The time step of MD is fixed by the fastest motion in the system: about a tenth of the period of the fastest atomic vibration, which is around 1 fs for most solids (and less with hydrogen present). That single fact sets the limits.

MethodTypical sizeTypical time spanForces from
Density functional theory (and ab initio MD)100–1000 atomsup to about 100 psquantum mechanics, each step
Classical MD, empirical potentialsthousands to billions of atomsns to µsa fitted formula
MD with machine-learned potentialsthousands to many millions of atomsnsa neural network trained on DFT
Kinetic Monte Carloup to about 10810^8 sitesµs to yearsa table of event rates
Phase field, crystal plasticity, finite elementsµm to ms to yearscontinuum equations (multiscale modelling)

A cube of copper one micrometre on a side holds 8.5×10108.5 \times 10^{10} atoms; simulations of that size have been run on the largest supercomputers with simple potentials, but they cover only nanoseconds. A microsecond needs 10910^9 steps of 1 fs. Anything that waits for a rare event, an atom hopping over a barrier of 1 eV at room temperature, a dislocation unpinning, a nucleus forming, is effectively out of reach of brute-force MD. Researchers attack the rare-event problem with transition-state methods such as the nudged elastic band, which finds the lowest barrier between two known states, with accelerated dynamics, and with enhanced sampling such as metadynamics, which pushes a simulation out of states it has already visited.

ExplanationH

Choosing a potential

Lennard-Jones describes noble gases well and other materials badly. Metals need many-body potentials, because the strength of a bond depends on how many neighbours an atom has: Murray Daw and Mike Baskes's embedded-atom method (1984) gives each atom an energy that depends on the electron density its neighbours supply, and it captures vacancies, surfaces and dislocations in FCC metals well. Covalent solids such as silicon need angle-dependent terms (the Stillinger–Weber and Tersoff potentials); ionic ones need charges; reactive force fields such as ReaxFF let bonds form and break.

Since Jörg Behler and Michele Parrinello's 2007 paper, machine-learned interatomic potentials have changed the field. A neural network or other flexible model is trained on thousands to millions of DFT energies and forces, then predicts them for new configurations at a small fraction of the cost. As of 2026, "universal" potentials trained on large public datasets of DFT calculations, such as those from the Materials Project, cover most of the periodic table, and are widely used to screen materials and to start simulations, while carefully trained, system-specific potentials remain the standard for quantitative work (AI-assisted materials discovery). Whatever the potential, it should be tested on the properties that matter for the problem, against DFT or experiment. The NIST Interatomic Potentials Repository and OpenKIM collect published potentials with such comparisons.

ExplanationH

LAMMPS and friends

Production simulations use mature, parallel open-source programs rather than hand-written loops. LAMMPS, developed at Sandia National Laboratories with a large community, is the most widely used for materials, with hundreds of potentials and analysis tools and support for GPUs. GROMACS, developed largely in Sweden, dominates biomolecular simulation; DL_POLY, from the United Kingdom's Daresbury Laboratory, and others fill other niches. The Python Atomic Simulation Environment (ASE), begun at the Technical University of Denmark, builds structures and drives many simulation and DFT codes from one script, and OVITO, from Germany, is a standard tool for visualising and analysing the results: finding dislocations, grain boundaries and defects among millions of atoms.

The simulation from this lesson's block, as a LAMMPS input file (not run here: LAMMPS is not available in the browser):

text
# Not run here: a LAMMPS input for the Lennard-Jones liquid of this lesson.
units           lj
atom_style      atomic
lattice         fcc 0.8442
region          box block 0 3 0 3 0 3
create_box      1 box
create_atoms    1 box
mass            1 1.0
velocity        all create 1.4 1964 mom yes dist gaussian
pair_style      lj/cut 2.5
pair_coeff      1 1 1.0 1.0 2.5
pair_modify     shift yes
timestep        0.004
fix             integrate all nve
compute         msd all msd
thermo_style    custom step temp pe etotal press c_msd[4]
thermo          300
run             3000

And the same idea for copper with a simple many-body potential, driven from Python with ASE (not run here: ASE is not available in the browser):

python
# Not run here: needs ASE installed.
from ase.build import bulk
from ase.calculators.emt import EMT
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
from ase.md.verlet import VelocityVerlet
from ase import units

atoms = bulk("Cu", "fcc", a=3.61, cubic=True).repeat((5, 5, 5))   # 500 atoms
atoms.calc = EMT()                                                # effective-medium theory
MaxwellBoltzmannDistribution(atoms, temperature_K=600)
dyn = VelocityVerlet(atoms, timestep=2 * units.fs)
dyn.run(1000)
print(atoms.get_temperature())

Good practice is the same whichever code is used: check that energy is conserved without a thermostat, that results do not change when the time step is halved or the box doubled, that the system has equilibrated before averaging, and that the potential has been tested for the property being computed.

History & global context

A short history

The Metropolis paper of 1953 ran on MANIAC, one of the first stored-program computers, at Los Alamos; Arianna Rosenbluth wrote the code. Berni Alder and Thomas Wainwright, at Livermore, ran the first molecular dynamics in 1957 with hard spheres and found that they freeze, a result many doubted. Aneesur Rahman, at Argonne, simulated 864 argon atoms with a Lennard-Jones potential in 1964 and compared their diffusion with experiment, and Loup Verlet, in Orsay, introduced his integrator and neighbour lists in 1967. The Ising model was proposed by Wilhelm Lenz and solved in one dimension by his student Ernst Ising in the 1920s; Onsager's two-dimensional solution of 1944 was the first exact solution of a model with a sharp phase transition, proof that the statistical mechanics of simple interactions can produce one. The machine-learned potentials of the 2010s and 2020s are the latest chapter of the same story: better forces, more atoms, longer times.

Common misconceptionsH

Common misconceptions

Misconception

"A bigger time step simply gets you further, faster." Beyond about a tenth of the fastest vibrational period the integration becomes inaccurate and then unstable, and the energy blows up. Reaching longer times needs cheaper forces, more processors, or methods for rare events.

Misconception

"The simulation is the material." It is the potential's material. A simulation of "iron" with a potential that gets the vacancy energy wrong will get diffusion wrong, however many atoms and steps it uses.

Misconception

"Monte Carlo steps are a kind of time." Metropolis sweeps sample equilibrium; their order has no physical meaning. Only kinetic Monte Carlo, with physical rates, has a clock.

Misconception

"Temperature is a property of each atom." Temperature is a property of the ensemble, defined by an average over many degrees of freedom. A single atom has a kinetic energy, not a temperature, and a small simulation's instantaneous temperature fluctuates by several per cent.

Exercises

Exercises

Use reduced Lennard-Jones units unless a question gives others.

1. Atomistic simulation

Warm-upHuman

A simulation box is built from 6×6×66 \times 6 \times 6 face-centred cubic unit cells. How many atoms does it contain? (This is the number Aneesur Rahman used for liquid argon in 1964.)

2. Atomistic simulation

Warm-upHuman

For argon, the Lennard-Jones parameter σ\sigma is 340.5 pm. At what separation, in picometres, is the Lennard-Jones pair energy lowest? Give the nearest whole number.

3. Atomistic simulation

CoreHuman

A molecular dynamics simulation of a metal uses a time step of 2 fs. How many steps does it need to simulate 10 ns?

4. Atomistic simulation

CoreHuman

Why do molecular dynamics codes use velocity Verlet rather than explicit Euler? Select all that apply.

Choose all that apply

5. Atomistic simulation

CoreHuman

An aluminium–copper alloy is aged at 150 °C for 10 hours, during which copper atoms cluster by vacancy jumps into the first small precipitates. You want to simulate the clustering atom by atom, over the whole 10 hours. Which method fits best?

Choose one

6. Atomistic simulation

CoreComputational

Write minimum_image(d, L) that takes displacement vectors between atoms in a cubic periodic box of edge L (a NumPy array whose last axis has length 3, or a single vector) and returns the displacements to the nearest periodic image, each component lying between −L/2-L/2 and L/2L/2.

For example, with L=10L = 10, a displacement of (9,0,−6)(9, 0, -6) becomes (−1,0,4)(-1, 0, 4).

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

7. Atomistic simulation

StretchComputational

For the 2-D Ising model with energy E=−J∑⟨ij⟩sisjE = -J\sum_{\langle ij\rangle} s_i s_j on a lattice with periodic edges, write:

  • delta_energy(s, i, j, J=1.0): the change in energy if the spin at row i, column j of the NumPy array s (entries ±1\pm 1, any rectangular shape) were flipped. Use the four nearest neighbours, wrapping round the edges.
  • acceptance(dE, T): the Metropolis acceptance probability, with kB=1k_\text{B} = 1.

Do not modify s.

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Further reading and resources