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.
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.
Here is the entire algorithm. There is nothing hidden behind it.
a = F / m to get each atom's acceleration.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.
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:
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?
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.
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:
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.
"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.
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.
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.
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 copper | vacancy energy ÷ cohesive energy |
|---|---|
| Pair potential predicts | 1.0 |
| EAM predicts | ~0.3 |
| Experiment | 0.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.
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:
| Model | Idea | Trouble |
|---|---|---|
| Pair potential | Add up every pair | Wrong for metals, cannot break bonds |
| EAM | Pairs plus a crowding term | Built for metals; must be hand-tuned per material |
| Classical force field | Springs for bonds, plus pair terms | Bonds can never break (not covered here) |
| Quantum mechanics | Actually solve for the electrons | Correct, 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.