Guides / Molecular dynamics

timestepconstraintsshakehydrogen-mass-repartitioningintegrator

Timestep and constraints in MD, why hydrogens set the clock

The integration step must be shorter than the fastest vibration, which is a bond to hydrogen. Constraining those bonds is what allows the standard 2 fs step.

Updated 5 min read

The timestep is the interval between successive force evaluations, and it is set by the fastest motion in the system. That motion is the stretching of bonds to hydrogen, with a period near ten femtoseconds. An integrator needs several steps per oscillation to remain stable, so an unconstrained system is limited to about one femtosecond. Fixing every bond to hydrogen at its equilibrium length removes that motion entirely. The next fastest motions permit a 2 fs step, which is the standard for production dynamics with constrained hydrogens. Larger steps are possible with further tricks, each with a cost in what the simulation still describes faithfully.

Why a stiff spring sets the clock

Classical integrators such as leapfrog Verlet advance positions using the current velocity and forces. They are accurate only when the force changes little over one step. A harmonic bond is a stiff spring, and the stiffest ones involve the lightest atom, hydrogen. The carbon-hydrogen stretch appears in infrared spectra near three thousand wavenumbers, which corresponds to a period of roughly eleven femtoseconds. Oxygen-hydrogen and nitrogen-hydrogen stretches are faster still.

A rule of thumb from numerical analysis is that the step should be about a tenth of the shortest period or less. That gives one femtosecond for a system with vibrating hydrogens, and for safety many practitioners used half a femtosecond. At those steps, one nanosecond of simulation costs one to two million force evaluations.

The physics gives permission to do better. At room temperature, a bond to hydrogen is almost entirely in its quantum ground state. The classical spring was already modelling something that does not behave classically. Freezing its length loses nothing real.

Constraints, from SHAKE to the rigid water molecule

A constraint algorithm takes the positions produced by an unconstrained step and adjusts them iteratively until every constrained bond has its target length, then corrects velocities to match. SHAKE was the original scheme, RATTLE its velocity-consistent refinement, and SETTLE an analytic solution for the three constraints of a rigid water molecule. OpenMM uses a constraint solver of its own for general bonds, and treats water as rigid by default. The constraints=HBonds setting fixes bonds to hydrogen, and AllBonds fixes every bond, which some force fields were parametrised to allow.

Water is the special case. In TIP3P the oxygen-hydrogen bonds and the hydrogen-oxygen-hydrogen angle are all fixed, so each water is a rigid triangle. Since water molecules outnumber everything else, as shown in the solvation box and counter-ions, the saving from rigid water alone is large.

With bonds to hydrogen constrained, the fastest remaining motions are angle bends involving hydrogen and stretches between heavy atoms. These permit 2 fs, the setting used in the examples throughout this cluster.

Arithmetic for one nanosecond

The worked example is pure counting. One nanosecond is a million femtoseconds. At 2 fs that is five hundred thousand force evaluations. For a solvated kinase of thirty thousand atoms, each evaluation computes bonded terms, short-range non-bonded pairs within the cutoff and a PME grid, then updates positions and solves constraints. At 1 fs the same nanosecond costs a million evaluations, twice the time. At 4 fs it costs a quarter of a million.

from openmm import unit
from openmm.app import PME, HBonds

# 2 fs, standard: bonds to hydrogen constrained, water rigid
system = ff.createSystem(model.topology, nonbondedMethod=PME,
                         nonbondedCutoff=1.0 * unit.nanometer,
                         constraints=HBonds, rigidWater=True)

# 4 fs with hydrogen mass repartitioning: heavier hydrogens, same group mass
system_hmr = ff.createSystem(model.topology, nonbondedMethod=PME,
                             nonbondedCutoff=1.0 * unit.nanometer,
                             constraints=HBonds, rigidWater=True,
                             hydrogenMass=1.5 * unit.amu)

steps_per_ns_2fs = int(1.0 * unit.nanosecond / (0.002 * unit.picosecond))  # 500000
steps_per_ns_4fs = int(1.0 * unit.nanosecond / (0.004 * unit.picosecond))  # 250000

The hydrogenMass argument moves mass from each heavy atom onto its bonded hydrogens. Total mass and therefore equilibrium thermodynamics are unchanged, while the angle motions that involve hydrogen slow down enough to tolerate 4 fs. Dynamic properties such as diffusion coefficients and rotational correlation times are altered, so hydrogen mass repartitioning suits questions about stable states and conformations, not about rates.

Integrators and thermostats interact with the step

The choice of integrator changes how much step error is tolerated. OpenMM's LangevinMiddleIntegrator applies the thermostat in the middle of the position update, a scheme that samples configurations more accurately at a given step than the older Langevin integrator and is the recommended default. Multiple-timestep schemes evaluate slow forces less often than fast ones, and are another route to efficiency, with more parameters to get wrong.

Thermostats can hide a timestep that is too large. Integration error injects energy, and a Langevin thermostat removes it, so the temperature reads correctly while the dynamics are biased. The honest test is a short run with the thermostat removed, in the constant-energy ensemble, checking that total energy drifts little over a hundred picoseconds. A drift that grows with the step is the signature of integrator error rather than a physical effect.

When the run blows up

A step that is far too large, or a system with a clash that minimisation did not fix, leads to a characteristic failure. Forces become huge, an atom moves a bond length in one step, the constraint solver cannot find a solution, and coordinates become not-a-number. OpenMM raises an error about particle coordinates. The fix is almost never to lower the timestep below 2 fs. It is to look at the structure. Overlapping atoms from a bad docking pose, a missing hydrogen on a charged group, a ligand whose parameters assign a tiny Lennard-Jones radius, or a water placed inside a ring are the usual culprits. The order of minimisation and restrained equilibration in the three phases of a run exists largely to prevent this failure.

If the structure is clean and the system still fails, check the ligand's parametrisation as described in force fields explained, and check that the input file's hydrogens match what the force field expects. The conventions of SDF and MOL files around explicit hydrogens cause a share of these problems when a ligand is converted between formats.

Key points

Questions people ask

Why is the molecular dynamics timestep usually 2 femtoseconds?
The integrator stays stable only when the step is a small fraction of the fastest oscillation period in the system. Bonds between a heavy atom and hydrogen vibrate with periods near ten femtoseconds, which forces a step of about one femtosecond. Constraining those bonds to fixed lengths removes the fastest motion, and the next fastest, heavy-atom stretches and angle bends, allows about 2 fs.
What does constraining bonds to hydrogen do to the physics?
It replaces a stiff harmonic vibration with a fixed length. Those vibrations are quantum mechanical in reality, mostly in their ground state at room temperature, so the classical spring was already a poor description. Removing it changes little of chemical interest and allows a step twice as long, halving the cost of every nanosecond.
What is hydrogen mass repartitioning?
A trick that moves some mass from each heavy atom onto the hydrogens bonded to it, keeping the total mass of each group unchanged. Heavier hydrogens oscillate more slowly in angle motions, which allows a 4 fs step with constrained bonds. Equilibrium properties are unchanged because they do not depend on the mass distribution, but dynamic quantities such as diffusion rates are altered.
What happens if the timestep is too large?
Energy is no longer conserved by the integrator and atoms gain spurious kinetic energy. The thermostat hides a mild case by removing the excess heat, which quietly biases the sampling. A severe case produces forces that grow without bound, coordinates become infinite or not-a-number, and the program stops with an error about particle positions.

Further reading

In practice: Advanced Modeling runs molecular dynamics with OpenMM. Nanosecond runs answer narrow questions, such as whether a pose holds; the guides say which questions they cannot answer.

← All guides