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.
- What a molecular dynamics simulation actually does
- The four-step loop at the heart of every MD code
- Why time steps are tiny and runs are long
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.
The algorithm
Every MD program, from a 40-line script to LAMMPS, runs the same loop:
- Set up. Place N atoms in a box and give them random velocities.
- Forces. For every atom, add up the forces from its neighbours.
- Move. Use the forces to update velocities and positions over a time step Δt.
- Measure. Record energy, temperature or anything else you need.
- 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.