Skip to content
SciStack

Particle simulation

N-body systems, molecular dynamics, and the integrators and neighbor searches that move many particles.

Put a planet on an orbit of eccentricity 0.5 and step it forward 100 orbits, 6,283 steps each, with the simplest update: new position from the old velocity, new velocity from the old force. At the end the energy is off by 65 %. Swap in velocity Verlet, which gives the velocity half a kick, moves the particle, and finishes the kick with the force at the new position, and the energy never strays by more than 3 parts in a million. That is why Verlet and its twin, leapfrog, move the particles in nearly every molecular dynamics and N-body code. Astrophysicists bring planets and star clusters, chemists and biophysicists liquids and proteins, engineers and geologists grains in a silo or a landslide. The hard part is the count: a million atoms have 5 × 10¹¹ pairs, so codes compute forces only between neighbors within a cutoff.

In Python, ASE builds atomic structures and runs dynamics with many interatomic potentials, OpenMM runs biomolecular force fields on a GPU, MDAnalysis reads the trajectories that GROMACS, LAMMPS, and other codes write, and REBOUND integrates gravitational N-body systems. For your own code, scipy.spatial.cKDTree finds all pairs within a cutoff with query_pairs, and Numba compiles the force loop. In Julia, Molly.jl runs molecular dynamics in the language itself, and a plain loop over pairs is already fast.

Start with two bodies and check energy and angular momentum over many orbits. Then put a few hundred particles with a Lennard-Jones potential in a periodic box, add neighbor lists, and add a thermostat to hold the temperature. Fields that live on a grid instead of on particles belong to partial differential equations.

What belongs here

Simulating many interacting particles: gravitational N-body problems, molecular dynamics with pair potentials, symplectic integrators such as velocity Verlet, thermostats, periodic boundaries, neighbor lists, and the observables computed from trajectories. Continuum fields belong to pdes; finding the minimum-energy arrangement of a few particles to optimization.

0 tutorials by type and language

PythonJulia
Concept – –
Tool – –
Recipe – –
Visualization – –
Project – –