Getting Started with GROMACS
for Molecular Dynamics Simulations

📑 In This Article

  1. What is MD Simulation?
  2. Workflow Overview
  3. Installation
  4. Prepare Your Protein
  5. Generate Topology
  6. Solvate the System
  7. Energy Minimization
  8. Equilibration (NVT+NPT)
  9. Production MD Run
  10. Trajectory Analysis
  11. Performance Tips

Overview

GROMACS (GROningen MAchine for Chemical Simulations) is one of the world's most widely used and highly optimized molecular dynamics (MD) simulation packages. Originally developed for biomolecular simulations, it is now used across chemistry, materials science, and drug discovery. Best of all — it's completely free and open-source. This guide takes you from zero to running your first GROMACS simulation of a protein in water, covering every command you need along the way.

✅ What You'll Be Able to Do

🌊 What is Molecular Dynamics Simulation?

Molecular Dynamics simulates the physical movements of atoms and molecules over time, governed by Newton's equations of motion. Each atom is treated as a particle with mass, position, and velocity. Forces between atoms are calculated from a force field, and positions are updated at each timestep (typically 1–2 femtoseconds).

⏱️

Timescale

Typical simulations run nanoseconds to microseconds of biological time

⚛️

Force Fields

AMBER, CHARMM, GROMOS, OPLS-AA describe bonded and non-bonded interactions

💧

Explicit Solvent

Protein is surrounded by explicit water molecules (TIP3P, SPC/E models)

📊

Analysis

RMSD, RMSF, Rg, hydrogen bonds, free energy — extract dynamic properties

🔄 Workflow Overview

📥Get PDBDownload
🧹CleanRemove HOH
⚙️pdb2gmxTopology
📦SolvateBox+water+ions
⬇️EMMinimize
🌡️Equil.NVT+NPT
🚀MD RunProduction
📊AnalyzeRMSD/RMSF

💻 Installation

GROMACS can be installed on Linux, macOS, or Windows (WSL). For best performance, compile from source with GPU (CUDA) support.

Ubuntu / Debian

apt install
sudo apt-get update
sudo apt-get install gromacs

# Verify installation
gmx --version

Compile from Source (GPU Support)

Build with CUDA
wget https://ftp.gromacs.org/gromacs/gromacs-2024.tar.gz
tar xvzf gromacs-2024.tar.gz
cd gromacs-2024
mkdir build && cd build
cmake .. -DGMX_BUILD_OWN_FFTW=ON -DGMX_GPU=CUDA
make -j$(nproc)
sudo make install
source /usr/local/gromacs/bin/GMXRC

📥 Step 1 — Prepare Your Protein

Download your target protein from RCSB PDB. For this tutorial, we use lysozyme (PDB: 1AKI) — a classic GROMACS tutorial protein.

Remove water molecules from PDB file
grep -v "HOH" 1AKI.pdb > 1AKI_clean.pdb
⚠️
Check for Missing Residues

Open your PDB file in PyMOL and check the header for "MISSING" residues. Incomplete structures can cause simulation instability. Use MODELLER or Swiss-Model to rebuild missing loops.

⚙️ Step 2 — Generate Topology with pdb2gmx

The pdb2gmx tool converts your PDB to GROMACS format and assigns force field parameters.

Generate topology — AMBER99SB-ILDN + TIP3P water
gmx pdb2gmx -f 1AKI_clean.pdb -o 1AKI_processed.gro -water tip3p

# When prompted, select force field:
# 6: AMBER99SB-ILDN protein, nucleic AMBER94
ℹ️
Output Files

This generates: topol.top (topology), posre.itp (position restraints), and 1AKI_processed.gro (coordinates).

📦 Step 3 — Define Box and Solvate

1

Define simulation box

Create a dodecahedral box with 1.0 nm distance from protein to box edge.

2

Fill with water

Solvate the protein with explicit TIP3P water molecules.

3

Add ions

Neutralize system charge and add 0.15 M NaCl to mimic physiological salt concentration.

Define box, solvate, and add ions
# Define simulation box
gmx editconf -f 1AKI_processed.gro -o 1AKI_newbox.gro -c -d 1.0 -bt dodecahedron

# Add water
gmx solvate -cp 1AKI_newbox.gro -cs spc216.gro -o 1AKI_solv.gro -p topol.top

# Prepare ion addition
gmx grompp -f ions.mdp -c 1AKI_solv.gro -p topol.top -o ions.tpr

# Add Na+ and Cl- ions
gmx genion -s ions.tpr -o 1AKI_solv_ions.gro -p topol.top -pname NA -nname CL -neutral

⬇️ Step 4 — Energy Minimization

Before any simulation, you must remove steric clashes and bad contacts through energy minimization. This relaxes the structure to a local energy minimum.

minim.mdp — Energy Minimization Parameters
integrator  = steep       ; Steepest descent algorithm
emtol       = 1000.0      ; Stop when max force < 1000 kJ/mol/nm
emstep      = 0.01        ; Initial step size
nsteps      = 50000       ; Max steps
nstlist     = 1
cutoff-scheme = Verlet
ns_type     = grid
coulombtype = PME
rcoulomb    = 1.0
rvdw        = 1.0
pbc         = xyz
Run Energy Minimization
gmx grompp -f minim.mdp -c 1AKI_solv_ions.gro -p topol.top -o em.tpr
gmx mdrun -v -deffnm em

# Check convergence
gmx energy -f em.edr -o potential.xvg
# Select: 10 (Potential Energy), then 0 to quit
📊
Convergence Check

Plot potential.xvg — the potential energy should steadily decrease and converge to a stable negative value (typically −500,000 to −1,000,000 kJ/mol for a small protein in water).

🌡️ Step 5 — Equilibration (NVT + NPT)

Equilibration is performed in two phases to stabilize the system at target temperature and pressure before the production run.

PhaseEnsembleDurationPurpose
NVT Constant N, V, T100 ps Stabilize temperature (300 K)
NPT Constant N, P, T100 ps Stabilize pressure (1 bar) and density
Run NVT then NPT equilibration
# NVT Equilibration (temperature)
gmx grompp -f nvt.mdp -c em.gro -r em.gro -p topol.top -o nvt.tpr
gmx mdrun -v -deffnm nvt

# NPT Equilibration (pressure + density)
gmx grompp -f npt.mdp -c nvt.gro -r nvt.gro -t nvt.cpt -p topol.top -o npt.tpr
gmx mdrun -v -deffnm npt

🚀 Step 6 — Production MD Run

After equilibration, run the production simulation. A typical starting point is 10 nanoseconds (5,000,000 steps at 2 fs timestep).

md.mdp — Production Run Parameters (10 ns)
integrator  = md
nsteps      = 5000000     ; 10 ns total (5M × 2fs)
dt          = 0.002       ; 2 fs timestep
nstxout     = 5000        ; Save coordinates every 10 ps
nstvout     = 5000
nstenergy   = 5000
nstlog      = 5000
continuation = yes
constraint_algorithm = lincs
constraints = h-bonds
tcoupl      = V-rescale
tau_t       = 0.1
ref_t       = 300
pcoupl      = Parrinello-Rahman
pcoupltype  = isotropic
tau_p       = 2.0
ref_p       = 1.0
compressibility = 4.5e-5
Launch Production Run
gmx grompp -f md.mdp -c npt.gro -t npt.cpt -p topol.top -o md.tpr
gmx mdrun -v -deffnm md -ntmpi 1 -ntomp 4  # 4 CPU threads

# For GPU acceleration:
gmx mdrun -v -deffnm md -ntmpi 1 -ntomp 4 -gpu_id 0

📊 Step 7 — Trajectory Analysis

Once your simulation completes, extract key structural and dynamic properties:

📐

RMSD — Structural Stability

backbone
Calculate RMSD over time
gmx rms -s md.tpr -f md.xtc -o rmsd.xvg -tu ns
# Select: 4 (Backbone) for both reference and fit group
🌊

RMSF — Per-Residue Flexibility

C-alpha
Calculate RMSF (residue flexibility)
gmx rmsf -s md.tpr -f md.xtc -o rmsf.xvg -res
# Select: 4 (C-alpha atoms)

Radius of Gyration — Compactness

protein
Radius of gyration over simulation
gmx gyrate -s md.tpr -f md.xtc -o gyrate.xvg
# Select: 1 (Protein)
📈
Fig 1.

Representative MD trajectory analysis — RMSD stabilisation indicates an equilibrated simulation. A plateau in RMSD (typically below 0.3 nm for a globular protein) confirms structural stability.

⚡ Performance Tips

🖥️

Use GPU

GROMACS on a modern GPU (e.g., RTX 3090) runs 50–100× faster than CPU-only.

🧵

Thread Tuning

Run gmx mdrun -ntmpi 1 -ntomp N where N = number of physical CPU cores.

💾

Checkpoint Files

Use -cpi md.cpt to resume interrupted simulations without starting over.

🗜️

Trajectory Compression

Use XTC format (lossy) for coordinate saving to significantly reduce file sizes.

You've now run a complete GROMACS MD simulation workflow. From here, you can explore advanced analyses: free energy perturbation (FEP), umbrella sampling for potentials of mean force (PMF), protein-ligand binding free energy with MM-PBSA, and multi-microsecond enhanced sampling methods like REMD or metadynamics.

← Previous Article Back to Articles