GROMACS

Description

According to the manual of GROMACS, GROMACS is an engine for performing molecular dynamics simulations and energy minimization. It is designed for biomolecules such as proteins, lipids, and nucleic acids, but is also used in materials research.

Available Versions

  • gromacs/4.5.4

  • gromacs/4.5.4-sbm1.0

  • gromacs/5.1.4

  • gromacs/2016.3 (default)

  • gromacs/2018.2

  • gromacs/2025.2

Serial Job Submission

submit_gromacs_serial.sh
#!/bin/bash
#SBATCH -J gromacs_serial
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -t 24:00:00
#SBATCH --mem=8G

export INPUT="*.tpr *.edr *.gro *.log"
export OUTPUT="*.trr"

module load gromacs/2025.2

CASE=simulation
job-nanny mdrun -v -nt 1 -s ${CASE}.tpr -o ${CASE}.trr \
                -e ${CASE}.edr -c after_${CASE}.gro -g ${CASE}.log

OpenMP Job Submission

submit_gromacs_omp.sh
#!/bin/bash
#SBATCH -J gromacs_omp
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 7-00:00:00
#SBATCH --mem=32G

export INPUT="conf.gro topol.top"
export OUTPUT="*.trr *.edr *.log"

module load gromacs/2025.2

# Script for multiple steps
job-nanny ./run_omp.sh
run_omp.sh
#!/bin/bash

# Minimization
gmx grompp -f Min.mdp -c conf.gro -p topol.top -o Min.tpr
gmx mdrun -nt $SLURM_CPUS_PER_TASK -v -deffnm Min

# NVT equilibration
gmx grompp -f NVT.mdp -c Min.gro -t Min.trr -p topol.top -o NVT.tpr
gmx mdrun -nt $SLURM_CPUS_PER_TASK -deffnm NVT

# NPT equilibration
gmx grompp -f NPT.mdp -c NVT.gro -t NVT.cpt -p topol.top -o NPT.tpr
gmx mdrun -nt $SLURM_CPUS_PER_TASK -deffnm NPT

# Production
gmx grompp -f MD.mdp -c NPT.gro -t NPT.cpt -p topol.top -o MD.tpr
gmx mdrun -v -nt $SLURM_CPUS_PER_TASK -s MD.tpr -o MD.trr \
          -e MD.edr -c after_MD.gro -g MD.log

MPI Job Submission

submit_gromacs_mpi.sh
#!/bin/bash
#SBATCH -J gromacs_mpi
#SBATCH -N 2
#SBATCH --ntasks-per-node=28
#SBATCH -t 48:00:00
#SBATCH --mem-per-cpu=2G

export INPUT="*.tpr *.edr *.gro"
export OUTPUT="*.trr"

module load gromacs/2025.2

job-nanny srun -n $SLURM_NTASKS mdrun_mpi -v -s simulation.tpr \
                -o simulation.trr -e simulation.edr \
                -c after_simulation.gro -g simulation.log

Hybrid Job Submission (MPI+OpenMP)

submit_gromacs_hybrid.sh
#!/bin/bash
#SBATCH -J gromacs_hybrid
#SBATCH -N 2
#SBATCH --ntasks-per-node=4
#SBATCH -c 7
#SBATCH -t 72:00:00
#SBATCH --mem-per-cpu=2G

export INPUT="*.tpr *.edr *.gro"
export OUTPUT="*.trr"
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

module load gromacs/2025.2

job-nanny srun -n $SLURM_NTASKS mdrun_mpi -v -s simulation.tpr \
                -ntomp $OMP_NUM_THREADS \
                -o simulation.trr -e simulation.edr \
                -c after_simulation.gro -g simulation.log

GPU Job Submission

submit_gromacs_gpu.sh
#!/bin/bash
#SBATCH -J gromacs_gpu
#SBATCH -p gpu
#SBATCH --gres=gpu:1
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -c 8
#SBATCH -t 48:00:00
#SBATCH --mem=32G

export INPUT="*.tpr"
export OUTPUT="*.trr *.edr *.log"

module load gromacs/2025.2
module load cuda/12.9

job-nanny mdrun -v -ntmpi 1 -ntomp $SLURM_CPUS_PER_TASK \
                -s simulation.tpr -o simulation.trr \
                -e simulation.edr -c after.gro -g simulation.log \
                -nb gpu -pme gpu -bonded gpu -update gpu

MDP Parameter Files

Minimization (Min.mdp)

Min.mdp
title                   = Minimization
define                  = -DFLEXIBLE
integrator              = steep
emtol                   = 1000.0
emstep                  = 0.01
nsteps                  = 50000
nstlist                 = 1
ns_type                 = grid
rlist                   = 1.0
coulombtype             = PME
rcoulomb                = 1.0
vdwtype                 = cutoff
rvdw                    = 1.0
pbc                     = xyz

NVT Equilibration (NVT.mdp)

NVT.mdp
title                   = NVT equilibration
define                  = -DPOSRES
integrator              = md
dt                      = 0.002
nsteps                  = 50000
nstxout                 = 500
nstvout                 = 500
nstenergy               = 500
nstlog                  = 500
continuation            = no
constraint_algorithm    = lincs
constraints             = h-bonds
lincs_iter              = 1
lincs_order             = 4
ns_type                 = grid
nstlist                 = 20
rlist                   = 1.0
coulombtype             = PME
rcoulomb                = 1.0
vdwtype                 = cutoff
rvdw                    = 1.0
tcoupl                  = V-rescale
tc-grps                 = Protein Non-Protein
tau_t                   = 0.1 0.1
ref_t                   = 300 300
pcoupl                  = no
pbc                     = xyz
gen-vel                 = yes
gen-temp                = 300
gen-seed                = -1

NPT Equilibration (NPT.mdp)

NPT.mdp
title                   = NPT equilibration
define                  = -DPOSRES
integrator              = md
dt                      = 0.002
nsteps                  = 50000
nstxout                 = 500
nstvout                 = 500
nstenergy               = 500
nstlog                  = 500
continuation            = yes
constraint_algorithm    = lincs
constraints             = h-bonds
lincs_iter              = 1
lincs_order             = 4
ns_type                 = grid
nstlist                 = 20
rlist                   = 1.0
coulombtype             = PME
rcoulomb                = 1.0
vdwtype                 = cutoff
rvdw                    = 1.0
tcoupl                  = V-rescale
tc-grps                 = Protein Non-Protein
tau_t                   = 0.1 0.1
ref_t                   = 300 300
pcoupl                  = Parrinello-Rahman
pcoupltype              = isotropic
tau_p                   = 2.0
compressibility         = 4.5e-5
ref_p                   = 1.0
pbc                     = xyz
gen-vel                 = no

Production (MD.mdp)

MD.mdp
title                   = MD production
integrator              = md
dt                      = 0.002
nsteps                  = 5000000
nstxout                 = 5000
nstvout                 = 5000
nstenergy               = 5000
nstlog                  = 5000
continuation            = yes
constraint_algorithm    = lincs
constraints             = h-bonds
lincs_iter              = 1
lincs_order             = 4
ns_type                 = grid
nstlist                 = 20
rlist                   = 1.0
coulombtype             = PME
rcoulomb                = 1.0
vdwtype                 = cutoff
rvdw                    = 1.0
tcoupl                  = V-rescale
tc-grps                 = Protein Non-Protein
tau_t                   = 0.1 0.1
ref_t                   = 300 300
pcoupl                  = Parrinello-Rahman
pcoupltype              = isotropic
tau_p                   = 2.0
compressibility         = 4.5e-5
ref_p                   = 1.0
pbc                     = xyz

Job Array for Multiple Simulations

submit_gromacs_array.sh
#!/bin/bash
#SBATCH -J gromacs_array
#SBATCH --array=1-10
#SBATCH -N 1
#SBATCH -c 28
#SBATCH -t 7-00:00:00
#SBATCH --mem=64G

TEMPS=(280 285 290 295 300 305 310 315 320 325)
TEMP=${TEMPS[$SLURM_ARRAY_TASK_ID-1]}

export INPUT="template.tpr template.gro"
export OUTPUT="run_${TEMP}K/"

module load gromacs/2025.2

mkdir -p run_${TEMP}K
cd run_${TEMP}K

# Modify temperature in .mdp file
cp ../MD_template.mdp MD.mdp
sed -i "s/ref_t.*/ref_t = $TEMP $TEMP/" MD.mdp

# Prepare and run
gmx grompp -f MD.mdp -c ../conf.gro -p ../topol.top -o MD.tpr
gmx mdrun -v -nt $SLURM_CPUS_PER_TASK -deffnm MD

Trajectory Analysis

analyze_gromacs.sh
#!/bin/bash
#SBATCH -J gromacs_analysis
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -t 04:00:00
#SBATCH --mem=8G

export INPUT="traj.xtc topol.tpr"
export OUTPUT="analysis/"

module load gromacs/2025.2

mkdir -p analysis
cd analysis

# RMSD
echo "4 4" | gmx rms -s ../topol.tpr -f ../traj.xtc -o rmsd.xvg

# Radius of gyration
echo "1" | gmx gyrate -s ../topol.tpr -f ../traj.xtc -o gyrate.xvg

# Root mean square fluctuation (RMSF)
echo "1" | gmx rmsf -s ../topol.tpr -f ../traj.xtc -o rmsf.xvg -res

# Distances
echo "4 5" | gmx distance -s ../topol.tpr -f ../traj.xtc -o dist.xvg

# Hydrogen bonds
echo "4 5" | gmx hbond -s ../topol.tpr -f ../traj.xtc -num hbond.xvg

# Energy
gmx energy -f ../MD.edr -o energy.xvg < energy.in

References

See also