This project performs a molecular dynamics simulation of a simple gas using the Lennard-Jones (LJ) potential to model interactions between particles. The simulation uses the Velocity Verlet integrator and supports trajectory output in the PDB format for visualization.
This project was developed as a learning exercise in molecular dynamics and C/Fortran programming. It simulates a simple gas using the Lennard-Jones potential and implements key MD features such as force calculation, integration, and trajectory output. While it’s not production-ready, it serves as a solid foundation for understanding and extending MD techniques.
- Simulation of 3D particles interacting via Lennard-Jones potential
- Periodic boundary conditions with minimum image convention
- Velocity initialization using Maxwell-Boltzmann distribution (Fortran subroutine)
- Velocity Verlet integration
- Output trajectory in PDB format
- Customizable parameters via
md.mdpconfiguration file - Progress bar display
main.c– Entry point for the simulation.md.c– Implements the core MD algorithm: force computation and integration.utils.c– Handles file I/O (PDB and MDP files), progress bar, and utility functions.init_velocities.f90– Fortran routine to initialize particle velocities.atom.h,params.h,constants.h– Definitions for atoms, parameters, and constants (not provided here but assumed to be included).
You need a C compiler and a Fortran compiler (e.g., gcc and gfortran):
gfortran -c init_velocities.f90 -o init_velocities.o
gcc -c utils.c md.c main.c
gcc main.o md.o utils.o init_velocities.o -o md_sim -lgfortran -lm./md_simMake sure the following files are in the same directory:
h.pdb– Initial atomic coordinates (PDB format).md.mdp– Simulation parameters.
Example contents:
dt = 0.005
nsteps = 1000
ref_temp = 300.0
ref_press = 1.0
rcut = 2.5
skip = 100
dt– Timestep (in reduced units)nsteps– Total simulation stepsref_temp– Reference temperature for velocity initializationref_press– Placeholder (not used currently)rcut– Cutoff radius for the LJ potentialskip– Trajectory output frequency
testtraj.pdb– Appends a PDB frame everyskipsteps. Can be viewed in molecular viewers like VMD, PyMOL, or Chimera.
- No thermostat or barostat is implemented
- Only supports Lennard-Jones interactions
- No parallelization or performance optimization
- Assumes all atoms have the same mass
This project is released under the MIT License. Feel free to modify and use it for educational or research purposes.