What is molecular dynamics?
Molecular dynamics (MD) is a way of making a movie of atoms on a computer. You place atoms in a box, work out the force each one feels from its neighbors, and use Newton's second law, F = m·a, to move every atom a tiny step forward in time. Then you recalculate the forces at the new positions and do it again. Repeat millions of times, string the frames together, and you can watch a liquid flow, a crystal melt, a protein fold or a drug molecule settle into its target.
↻ Then back to step 2, millions or billions of times.
The steps have to be tiny because atoms move fast. A chemical bond vibrates back and forth about once every 10 femtoseconds (a femtosecond is 10⁻¹⁵ s, a millionth of a billionth of a second). With 1-femtosecond steps, one nanosecond of simulated time takes a million steps, and a microsecond takes a billion.
Why people bother
MD works like a computational microscope. Experiments usually see averages over trillions of molecules, or frozen snapshots. MD shows every atom at every instant. It's used to design drugs, understand how proteins work, find better battery materials, and predict melting points and how fast things diffuse. The field goes back to the 1950s: Alder and Wainwright simulated colliding hard spheres in 1957, and in 1964 Aneesur Rahman simulated 864 argon atoms, the same kind of system you'll play with below.
How is this different from the Monte Carlo darts? Monte Carlo jumps between random snapshots and has no clock. MD follows the actual path the atoms take. Once the starting positions and velocities are set, Newton's laws decide everything that follows (apart from optional thermostats, there's no randomness). That means MD can also tell you how fast things happen, such as how quickly a molecule diffuses or how long a bond takes to break, not only which arrangements are likely.
Forces come from an energy landscape
The one ingredient every MD simulation needs is a rule for the energy of the atoms, given where they are. The forces follow from it: each atom is pushed downhill on the energy landscape, and the steeper the slope, the harder the push (force = minus the slope).
The simplest case is a pair of neutral atoms such as argon. Their energy is described well by the Lennard-Jones formula, proposed by John Lennard-Jones in 1924:
for argon: σ = 3.4 Å, ε = 10.3 meV
- Too close, and the atoms' electron clouds overlap, causing steep repulsion (the r⁻¹² term). This is why atoms have a size.
- A little apart, and a weak attraction pulls them together (the r⁻⁶ "van der Waals" term, caused by fleeting ripples in each atom's electron cloud).
- Far apart, and almost nothing happens.
Drag the right-hand atom (or anywhere on the chart), or use the slider.
- Distance between the atoms
- —
- Energy
- —
- Force on the right-hand atom
- —
A box of atoms
Here are a few hundred argon-like atoms, all interacting through exactly that curve and moved forward with the four-step loop. It's 2D so you can see every atom; real simulations are 3D, but the rules are the same. Each step is about 11 femtoseconds of argon time. Atoms are colored by speed, because temperature is just how fast atoms jiggle.
Start from
- Temperature right now
- —
- Simulated time
- —
- Atoms
- —
- Total energy per atom
- —
Click any atom to follow it.
Energy per atom: kinetic (motion), potential (from the curve above), and their total
Radial distribution function g(r): how crowded it is at each distance from an atom
Things to try
- Melt a crystal: press Crystal, then raise the temperature a little at a time. Between roughly 80 and 110 K the neat rows break up and atoms start wandering: it melts. (Melting in 2D happens gradually rather than all at once.) Cool it down again and it refreezes, usually with defects.
- Follow an atom: click any atom. In the liquid it rattles around inside a cage of neighbors, then occasionally squeezes out and moves on. That slow wandering is diffusion. The colored lines show the forces on it right now: orange pushes it away, teal pulls it in.
- Condensing vapor: the atoms start hot and spread out, then the thermostat cools them. Once they're slow enough, the attraction wins and they clump into droplets and tiny crystals.
- Switch off the thermostat: watch the energy chart. Kinetic and potential energy trade back and forth, but the total stays flat, because Newton's laws conserve energy. With the thermostat on, the box behaves as if it's touching surroundings held at a fixed temperature.
- Show the neighboring copies: the box is surrounded on every side by copies of itself, so an atom leaving one edge comes back in through the opposite one. This "periodic boundary" trick lets a few hundred atoms stand in for a big chunk of material, with no walls.
Turning the movie into numbers
A raw MD run is an enormous pile of coordinates. Its value comes from averaging over it. Temperature is the average kinetic energy. Pressure comes from the forces. How far atoms wander over time (like the trail of the atom you followed) gives the diffusion coefficient. Run long enough and you can extract melting points, heat capacities, viscosities and how tightly a drug binds.
One of the most useful averages is the radial distribution function, g(r), plotted beside the simulation. It answers this question: standing on one atom, how much more (or less) likely am I to find another atom at distance r than if the atoms were sprinkled at random?
- Gas: nothing closer than about 3.4 Å (atoms can't overlap), then flat at 1. No structure.
- Liquid: a tall first peak (the shell of nearest neighbors), then a few smaller, washed-out bumps. Order only at short range.
- Crystal: sharp peaks at the exact lattice distances, continuing far out.
This is the curve X-ray and neutron diffraction experiments measure, and the kind of curve Reverse Monte Carlo fits, from the last explainer. MD runs the other way: it starts from the forces and predicts g(r). Comparing the two is one of the main ways scientists check that their forces are right.
Why the steps have to be so small
The loop assumes the force stays roughly constant during each step. If a step is long compared with the fastest motion in the system, atoms overshoot, and the simulation gains energy from nowhere. The fastest motion is usually a bond to a hydrogen atom: the O–H bond in water vibrates about once every 9 femtoseconds.
Below, the same O–H bond is simulated with two stepping rules. The dashed outline shows the exact motion, and you can watch the hydrogen hop from step to step.
- Euler: move each atom using its current velocity and current force. It's the most obvious rule, but it adds a little energy at every step, so the vibration grows until the molecule flies apart. Nobody uses it for MD.
- Velocity Verlet: update the velocity by half a step, move, recompute the force, then finish updating the velocity. It costs the same (one force calculation per step), but its energy error stays bounded instead of growing, even over billions of steps. Variants of it drive almost every MD simulation. Loup Verlet popularized the approach for MD in 1967.
- Steps per O–H vibration
- —
- Velocity Verlet, after 10 vibrations
- —
- Euler, after 10 vibrations
- —
How far the bond is stretched over 10 vibrations (1 = the starting stretch)
Rule of thumb: about ten steps per fastest vibration. That's why simulations with hydrogen atoms use 0.5–1 fs steps, or 2 fs if the bonds to hydrogen are frozen with constraints, while the argon box above gets away with about 11 fs. Push the slider past about 2.9 fs and even Verlet blows up.
Where the forces come from: classical force fields
Lennard-Jones is fine for argon, but molecules have bonds, angles and electric charges. "Classical" MD handles these with a force field: one big formula that adds up a few simple kinds of term. A typical one looks like this:
Bond stretching
½ k (r − r₀)²Every chemical bond is a spring with a natural length r₀.
Angle bending
½ kθ (θ − θ₀)²The angle between two bonds prefers a natural opening θ₀.
Twisting (torsion)
kφ [1 + cos(nφ − δ)]Rotating around a bond has comfortable and awkward positions.
Van der Waals
4ε [(σ/r)¹² − (σ/r)⁶]The Lennard-Jones curve from section 2, between atoms that aren't bonded.
Electrostatics
q₁q₂ ÷ (4πε₀ r)Each atom carries a fixed partial charge. Opposites attract, likes repel.
Every bond, angle, twist and pair of atoms contributes a term. The numbers in them (spring stiffnesses, natural lengths, charges, ε and σ) are fitted to experiments and to quantum-mechanical calculations on small molecules, then published as force fields with names like AMBER, CHARMM, OPLS and GROMOS.
Strength: speed
Forces come from one formula, so a step takes a small fraction of a second even with hundreds of thousands of atoms. Simulating a protein in water for microseconds is routine on a single GPU.
Weakness: it only knows what it was built for
- Bonds are springs, so they can't break and new ones can't form. No chemical reactions.
- Charges are usually fixed, so the electrons can't respond to their surroundings.
- It's only as accurate as its fitting, and numbers fitted for one situation may not carry over to another.
Special "reactive" force fields that let bonds break do exist, but they need careful fitting for each chemistry.
Ab initio molecular dynamics
"Ab initio" is Latin for "from the beginning". Ab initio MD (AIMD) throws away the pre-made formula. At every single step, it calculates the energy and forces directly from the quantum mechanics of the electrons. The atoms still move with exactly the same Newton loop; only step 2, "work out the forces", changes.
The key idea: electrons are fast, nuclei are slow
An atom is a heavy nucleus surrounded by light electrons, and it's the electrons that form chemical bonds. A proton is about 1,836 times heavier than an electron, so whenever the nuclei shift slightly, the electrons rearrange almost instantly. This is the Born–Oppenheimer approximation, and it lets each step split in two. First freeze the nuclei and solve for the electrons' lowest-energy arrangement. Then read off the force on every nucleus and move the nuclei with Newton's laws.
The electron calculation is usually done with density functional theory (DFT), developed by Walter Kohn and colleagues in the 1960s (Kohn shared the 1998 Nobel Prize in Chemistry for it). DFT works with the electron density, a single cloud, instead of the full quantum state of every electron, and that makes it affordable for hundreds of atoms. It's iterative: guess the cloud, work out the electric field it creates, find the cloud that field would produce, and repeat until nothing changes. Running that inner loop at every step is why AIMD is so expensive.
Try it: pull a molecule apart
Here a hydrogen molecule (H₂) gets a sudden kick of energy that sets its bond vibrating. On the left, the bond is a force-field spring. On the right, the force comes from H₂'s true quantum-mechanical energy curve, which is what an ab initio calculation produces. (To keep the page instant, that curve is pre-computed and approximated by a Morse function; a real AIMD code would recalculate it from the electrons at every step.) Give the bond more than about 4.7 eV and see what happens.
Energy versus bond length: the spring model and the true H₂ curve
Below 4.7 eV, both bonds survive, although the quantum bond stretches further outward than inward, because real bonds are lopsided. Above it, the quantum bond breaks and two free hydrogen atoms fly apart. The spring never breaks, however hard you kick it. Bonds that can break and form are the main reason people pay for AIMD.
What AIMD is used for
- Chemical reactions and catalysis: watching bonds break and form, in solution or on a catalyst's surface.
- Water and acids: protons hopping from molecule to molecule through water (the Grotthuss mechanism), which fixed-bond force fields can't describe.
- Batteries: how ions move through electrolytes, and how electrolytes break down at electrode surfaces.
- Extreme conditions: materials at the pressures and temperatures inside planets, where no force field fitted to ordinary conditions can be trusted.
- Enzymes: often in combination with classical MD, using quantum mechanics only for the atoms that react and a force field for everything else. That approach, QM/MM, was recognized by the 2013 Nobel Prize in Chemistry.
Two flavors, and the catches
Born–Oppenheimer MD fully re-solves the electrons at every step. In 1985 Roberto Car and Michele Parrinello found a shortcut: treat the electrons' state as extra variables that move along with the nuclei, so it stays close to the right answer without being re-solved from scratch each step. Car–Parrinello MD made AIMD practical and is still widely used.
AIMD isn't exact. DFT involves an approximation of its own (the choice of "functional"), and the nuclei are still treated as classical balls, so quantum effects of the nuclei, such as zero-point vibration and tunneling, are missing unless more expensive methods (path-integral MD) are added. It's also slow: typically a few hundred atoms for tens to hundreds of picoseconds.
The trade-off, and where AI comes in
Every method trades accuracy against how big and how long a simulation can be. The cost of DFT grows roughly with the cube of the number of atoms: double the atoms and the work goes up about eightfold. A classical force field that ignores atoms beyond a cutoff distance grows roughly in proportion to the number of atoms.
Rough, typical ranges on log scales. The edges keep moving as computers get faster.
Machine-learned potentials
The newest approach sits in between. Run a few thousand DFT calculations on small snapshots of your system, then train a neural network to predict the energy and forces from the atom positions. Then run MD with the network in place of DFT. Done well, this gets close to DFT accuracy at a cost much nearer to a classical force field, and bonds can still break. Jörg Behler and Michele Parrinello (the same Parrinello) pioneered the idea in 2007, and it's now one of the most active areas of the field.
This connects back to Bishop. The network is learning a function over a space with thousands of dimensions (three coordinates per atom) from a limited set of samples. It has the same weakness as any machine-learning model: it's only trustworthy for arrangements that resemble its training data, and it can fail badly when a simulation wanders somewhere new. Careful practitioners keep checking it against fresh DFT calculations.
Side by side
| Classical MD | Ab initio MD | Machine-learned potentials | |
|---|---|---|---|
| Forces come from | A fitted formula (springs, charges, Lennard-Jones) | The quantum mechanics of the electrons, solved at every step (usually with DFT) | A neural network trained on DFT results |
| Can bonds break? | No (except special reactive force fields) | Yes | Yes, if the training data covered it |
| Electrons | Left out; atoms carry fixed charges | Included explicitly | Included indirectly, through what the network learned |
| Typical size | Thousands to millions of atoms, or more | Tens to about a thousand atoms | Hundreds to millions of atoms |
| Typical length | Nanoseconds to microseconds | Picoseconds to about a nanosecond | Up to nanoseconds or longer |
| Main limitation | Only as good as its formula and fitted numbers | Very expensive, and DFT is itself approximate | Only trustworthy close to its training data |
| Typical uses | Proteins, drugs, membranes, polymers, liquids | Reactions, catalysis, water and acids, extreme conditions | Big or long simulations that need near-quantum accuracy |