Physics
Physics Feb 2026 · Part 1 of 2

How molecular dynamics works

Molecular dynamics is a way of making a movie of atoms. We start by putting atoms somewhere. Then we work out the force on each one, nudge them a tiny step, and repeat. Do that a few million times and we have a movie.

This page builds the idea from the beginning. Knowing that force makes things accelerate is enough to start. Everything below is something to play with.

1. What is a film of atoms actually for?

Making the film is not the point. What we want are answers we cannot get any other way. They come in two kinds.

Numbers we can check against experiment. Nearly every property of a material is really an average over atoms jiggling about. Run the film long enough, average over it, and out come real measurable quantities: melting and boiling points, density, stiffness, viscosity, how tightly a drug molecule holds on to its target, how fast a reaction goes. Those averages are the actual product. The film is just how we get them.

Mechanisms nothing can show us. No instrument watches a protein fold, or lithium ions squeezing through a battery electrode, or a crack starting deep inside a lump of metal. Experiments usually tell us what happened. The film tells us how it happened.

Some things this is genuinely used for:

Keep this in mind for the rest of the page. Everything below is machinery for producing those averages. In section 7 we will measure one yourself, and watch it tell a solid apart from a liquid.

2. The whole method is one loop

Here is the entire algorithm. There is nothing hidden behind it.

  1. Look at where all the atoms are.
  2. Work out the force on each atom.
  3. Use a = F / m to get each atom's acceleration.
  4. Move every atom forward by a very small slice of time.
  5. Go back to step 1.

That "small slice of time" is usually about one femtosecond, a millionth of a billionth of a second. Atoms vibrate incredibly fast, so if we take bigger steps we miss the motion and the simulation blows up.

try it One atom, one step at a time
medium
position
,
velocity
,
force
,
steps taken
0
The ball sits in a valley. Push the step size up and watch the simulation lose track of the motion, then fly apart. This is the single most common way a real simulation fails.

3. Force is the steepness of an energy hill

Step 2 of the loop says "work out the force". Where does it come from? In almost every simulation, forces are not stored directly. Instead we store energy, and the force falls out of it.

Think of a ball on a hill. Where the hill is steep, the ball is pushed hard. Where it is flat, nothing pushes it. And the push is always downhill. That is the whole rule:

force = − (how fast energy changes with position)

The minus sign just means "downhill". If we know the energy of every arrangement of atoms, we know every force, everywhere. So the real job of a molecular simulation is to answer one question: given where the atoms are, what is the energy?

drag it Drag the ball. Watch the arrow.
the ball force on it the slope right there
Steep hill, big arrow. Flat bottom, no arrow. The arrow always points downhill. That is the only thing "force is minus the slope of the energy" means.

4. The energy between two atoms

Now we need actual energy values. Start with the simplest case in all of chemistry: two atoms of argon, a gas that does not react with anything.

They feel two competing effects.

Add those together and we get a curve with a dip in it. The bottom of the dip is the comfortable distance, where the atoms would happily sit. This is the Lennard-Jones potential, and it is the single most used model in all of molecular simulation.

drag it Drag the right-hand atom
distance
,
energy
,
force
,
they are
,
Press Let go and watch from a stretched position. The atoms fall toward each other, overshoot, get shoved back, and oscillate, exactly like a ball rolling in the valley from section 3. That is a vibrating molecule.

5. Many atoms: just add up every pair

With more than two atoms, the simplest assumption is that the total energy is the sum over every pair of atoms, one pair at a time:

total energy = sum of the energy of every pair

That is called a pair potential. It is a guess, and a surprisingly good one for simple things like argon. Below are a few hundred argon atoms doing nothing but obeying that rule.

Careful: whose energy is it? This trips people up, so it is worth pinning down now. The thing that physically exists is one number for the whole system: the total energy of all the atoms together. That total is what forces come from, and it is the only part that is real.

Splitting the total up and saying "this particular atom owns 3 units of it" is bookkeeping we invent for convenience. It is useful, and every model on this page does it, but no experiment can hand us one atom's share, because an atom's energy only means anything in relation to its neighbours. Hold on to that distinction. It comes back in Part 2, where it decides what the machine learning model is actually taught.

Nobody programmed "become a liquid" or "form a crystal" into this. Those behaviours simply appear once we add up pairs and let the atoms move.

play A few hundred argon atoms ,
40 K
atoms
,
pairs checked / step
,
measured temp
,
simulated time
,
It starts frozen. Below about 50 K it is a solid, every atom pinned, six neighbours around each one. Above about 100 K it boils and the atoms fill the box. In between it is a liquid: still stuck together, but flowing. Blue means many neighbours, orange means few, so a droplet shows a blue core and an orange skin: its inside and its surface.

Those two temperatures are not settings. Nothing in the code mentions melting or boiling. They are consequences of one curve from section 4, added up over every pair.

6. Temperature is just how fast the atoms are moving

"Temperature" sounds like its own thing, but in a simulation it is only a measure of motion. Add up the kinetic energy of every atom, divide by the number of atoms, and that is the temperature.

Not every atom moves at the same speed. They constantly collide and trade energy, so at any moment there is a spread, a few crawling, a few racing, most somewhere in the middle. That spread always settles into the same characteristic shape.

watch The spread of atom speeds
measured right now, in the box above the shape theory predicts
The orange curve is not fitted to the bars. It is the Maxwell–Boltzmann distribution, worked out on paper in the 1860s. The bars are our simulation. Nobody told the simulation about this curve; it falls out of atoms bumping into each other. Change the temperature above and watch both move together.

7. Getting a real number out of the film

Section 1 promised that the point of all this is averages we can compare with the real world. Here is one of them, done properly.

Pick a moment. Remember where every atom is. Then keep watching, and measure how far each atom has wandered from its remembered spot. Average the square of that distance over all the atoms. That is the mean squared displacement, and it settles the question "solid or liquid?" without anybody having to squint at the picture.

The slope of that climb is the diffusion coefficient, a number we can look up in a table and check. This is a measurement, not a picture.

measure it How far do the atoms actually get? settling
25 K
watched for
0.0 ps
mean squared distance
0.00
typical wander
0.00
verdict
measuring
Leave it cold, around 25 K, and the curve jumps up briefly and then lies flat. The atoms are stuck, jiggling inside a cage of neighbours about half an angstrom across, and the jiggling never adds up to going anywhere. Push the slider to 100 K and the same curve turns into a straight climb that never stops.

Nothing changed except one number, but the measurement now says liquid instead of solid, and it says so in units an experimentalist could argue with.

8. Where "add up the pairs" falls apart

Pair potentials work well for argon. For metals they fail, and the reason is worth understanding, because it is the same reason machine learning became useful later.

In a metal the outer electrons are not tied to single atoms. They are shared across the whole piece of metal, like a pooled resource. So how strongly an atom is held depends on how many neighbours it has in total, not on each neighbour separately.

Add a neighbour to a lonely atom and we get a strong new bond. Add a neighbour to an atom that already has eleven and we barely gain anything, the shared electrons are already spread thin. Bonds get weaker as atoms get more crowded.

A pair potential cannot express that. It counts every bond separately, so twelve neighbours must be worth exactly twelve times one neighbour. The fix is the embedded atom method (EAM): on top of the pair sum, each atom gets an extra energy that depends on the total electron density it sits in, and that extra term grows like a square root rather than a straight line.

compare How tightly is an atom held?
4
pair model says
,
EAM says
,
they disagree by
,
Both models are tuned to give the same answer for an atom buried in bulk copper, with 12 neighbours. That is the only place they are made to agree. Everywhere else, surfaces, edges, cracks, defects, melting, they disagree, and the pair model is the one that is wrong.

We can check which one is right with a real measurement. A vacancy is a missing atom inside a crystal. The energy needed to make one is compared below with the energy needed to boil a single atom away entirely (the cohesive energy).

For coppervacancy energy ÷ cohesive energy
Pair potential predicts1.0
EAM predicts~0.3
Experiment0.36

A pair potential is not slightly off here. It is wrong by roughly a factor of three, and no amount of re-tuning its numbers fixes it, the shape of the model is what is wrong. Adding one many-body term repairs it.

Copper values: cohesive energy 3.54 eV, vacancy formation energy about 1.28 eV.

9. So the whole field is one question

Every model on this page is an attempt to answer the same question: given the positions of the atoms, what is the energy? Once we can answer it, the loop in section 2 does the rest.

The answers get better and more expensive as we go down this list:

ModelIdeaTrouble
Pair potentialAdd up every pairWrong for metals, cannot break bonds
EAMPairs plus a crowding termBuilt for metals; must be hand-tuned per material
Classical force fieldSprings for bonds, plus pair termsBonds can never break (not covered here)
Quantum mechanicsActually solve for the electronsCorrect, but agonisingly slow

Notice the pattern. Every model above is a shape that a human chose, with a few numbers fitted to data. Choose the shape well and it works in the situations it was designed for. Step outside those situations and it breaks, and we cannot fix it by adjusting the numbers.

That is the opening for machine learning. Instead of a human guessing the shape of the energy function, run the slow, accurate quantum calculation a few thousand times, then let a flexible function learn the shape from those answers.

Part 1 of a two-part explainer. Continue to Where machine learning comes in, or reach me on GitHub or by email.

Aayush Neupane
Aayush Neupane
CS Researcher & Engineer · MS CS, University of Kansas
More physics →