Lesson 1.1 · 10 min

What is molecular dynamics?

Atoms never sit still. MD follows every one of them, step by tiny step, and turns that motion into properties you can measure.

The idea

Everything around you is made of atoms, and those atoms are always moving: vibrating, colliding and drifting. How they move decides whether something is a solid, a liquid or a gas, how fast ions travel in a battery, and how a protein folds.

Molecular dynamics (MD) is a way to watch that motion on a computer. We put atoms in a box, work out the force on each one, and use Newton's law to move every atom forward by a very small time step. Then we do it again, millions of times.

The result is a trajectory: a movie of every atom's position over time. From it we can measure temperature, pressure, structure and diffusion, and compare them with experiments.

Key idea. MD does not guess how atoms behave. It only needs a rule for the forces between atoms. Everything else follows from Newton's law.

The algorithm

Every MD program, from a 40-line script to LAMMPS, runs the same loop:

  1. Set up. Place N atoms in a box and give them random velocities.
  2. Forces. For every atom, add up the forces from its neighbours.
  3. Move. Use the forces to update velocities and positions over a time step Δt.
  4. Measure. Record energy, temperature or anything else you need.
  5. Repeat from step 2 until you have enough data.
positions, velocities = set_up_box()
forces = compute_forces(positions)
for step in range(n_steps):
    velocities += 0.5 * dt * forces / mass
    positions  += dt * velocities
    forces      = compute_forces(positions)
    velocities += 0.5 * dt * forces / mass
    record(positions, velocities)

That update rule is called velocity Verlet. You will see why it is better than the obvious approach in Lesson 1.5.