Skip to content

A simple Molecular Dynamics simulation of a Lennard jones gas in C

Notifications You must be signed in to change notification settings

StochasticCactus/Simple-MD

Repository files navigation

Lennard-Jones Gas Molecular Dynamics Simulation

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.


About This Project

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.


Features

  • 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.mdp configuration file
  • Progress bar display

File Structure

  • 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).

How to Build

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

How to Run

./md_sim

Make sure the following files are in the same directory:

  • h.pdb – Initial atomic coordinates (PDB format).
  • md.mdp – Simulation parameters.

md.mdp 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 steps
  • ref_temp – Reference temperature for velocity initialization
  • ref_press – Placeholder (not used currently)
  • rcut – Cutoff radius for the LJ potential
  • skip – Trajectory output frequency

Output

  • testtraj.pdb – Appends a PDB frame every skip steps. Can be viewed in molecular viewers like VMD, PyMOL, or Chimera.

Known Limitations

  • No thermostat or barostat is implemented
  • Only supports Lennard-Jones interactions
  • No parallelization or performance optimization
  • Assumes all atoms have the same mass

License

This project is released under the MIT License. Feel free to modify and use it for educational or research purposes.

About

A simple Molecular Dynamics simulation of a Lennard jones gas in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published