This repository contains a 2D molecular dynamics (MD) simulation of interacting particles using a Lennard–Jones (12–6) potential with periodic boundary conditions.
The project includes:
- A C++ implementation used for numerical experiments and data generation
- A Python implementation that reproduces the same physics and provides a real-time animation with energy and temperature plots
The simulation models a classical Lennard–Jones fluid and demonstrates thermostatting, energy conservation, velocity distributions, and particle trajectories.
- Identical particles with mass ( m = 1 )
- Motion restricted to two spatial dimensions
- Periodic boundary conditions in a square simulation box
The particles in this simulation interact via a shifted Lennard-Jones potential. To ensure numerical stability and prevent discontinuities, both the potential and its derivative are shifted to zero at the cutoff radius
The core potential is defined as:
To guarantee the continuity of both energy and force, the implementation follows these conditions at the cutoff
-
Zero Potential:
$U(r_c) = 0$ -
Zero Force:
$\frac{dU}{dr} \Big|_{r=r_c} = 0$
- Velocity Verlet–type integration scheme
- Includes a Nosé–Hoover–style thermostat
- A thermostat variable dynamically adjusts the kinetic energy to control temperature
Q: thermostat mass (controls coupling strength)T: target temperature (constant or time-dependent)
- Square-lattice initialization
- Maxwell–Boltzmann velocity distribution
- Removal of center-of-mass velocity
- Periodic boundary conditions (minimum image convention)
- Lennard–Jones forces with cutoff shifting
- Energy tracking (kinetic, potential, total)
- Velocity histograms
- Single-particle trajectories
- Temperature ramps
- Output to text files for analysis