Use GROMACS to perform a molecular dynamics simulation

Updated at:
Copy as MD

This tutorial shows you how to run a GROMACS molecular dynamics (MD) simulation on an Elastic High Performance Computing (E-HPC) cluster — from cluster setup to job submission and result visualization.

StepActionResult
1Connect to the clusterAccess the cluster command line
2Submit a jobReceive a job ID
3View the job resultVisualize molecules in VMD
4View computing performanceAnalyze node and process metrics

Background

GROMACS (GROningen MAchine for Chemical Simulations) is a software package for molecular dynamics simulation. It models Newtonian equations of motion for systems with millions of particles, making it suited for biochemical research involving proteins, lipids, and nucleic acids. GROMACS supports common MD algorithms and can use GPUs to accelerate computing-intensive tasks. For more information, see the GROMACS official website.

Sample datasets

Two datasets are available for this tutorial. This tutorial uses Example 2.

  • Example 1: Lysozyme in water — simulates a protein interacting with ions in a box of water. Download: https://public-ehpc-package.oss-cn-hangzhou.aliyuncs.com/Lysozyme.tar.gz

  • Example 2: Motion of water molecules — tracks the motion of water molecules in a specific space at a specified temperature. Download: https://public-ehpc-package.oss-cn-hangzhou.aliyuncs.com/water_GMX50_bare.tar.gz

Prerequisites

Before you begin, ensure that you have:

  • An E-HPC cluster with the following configuration: For cluster creation instructions, see Create a cluster by using the wizard.

    SettingValue
    Deploy modeStandard
    Nodes2 management nodes, 1 compute node, 1 logon node
    Compute instance typeGPU-accelerated (e.g., ecs.gn5-c8g1.2xlarge)
    ImageCentOS 7.2 (public)
    SchedulerPBS
    VNCEnabled
  • A cluster user with the following settings: This user logs on to the cluster, compiles software, and submits jobs. For instructions, see Create a user.

    SettingValue
    Usernamegmx.test
    User groupsudo permission group
  • The following software installed on the cluster. This tutorial was tested with these versions — other versions may behave differently. For installation instructions, see Install software.

    SoftwareVersion
    Gromacs-gpu2018.1
    openmpi3.0.0
    cuda-toolkit9.0
    VMD (Visual Molecular Dynamics)1.9.3

Step 1: Connect to the cluster

Connect using either the E-HPC client or the E-HPC console. After connecting, you are logged on to /home/gmx.test.

Option A: E-HPC client

Note

The cluster scheduler must be PBS. Make sure the E-HPC client is installed and its environment is configured. For details, see Deploy an environment for an E-HPC client.

  1. Start and log on to the E-HPC client.

  2. In the left-side navigation pane, click Session Management.

  3. In the upper-right corner of the Session Management page, click terminal to open the Terminal window.

Option B: E-HPC console

  1. Log on to the E-HPC console.

  2. In the upper-left corner of the top navigation bar, select a region.

  3. In the left-side navigation pane, click Cluster.

  4. On the Cluster page, find the cluster and click Connect.

  5. In the Connect panel, enter the username and password, and click Connect via SSH.

Step 2: Submit a job

  1. Download and decompress the sample dataset.

    wget https://public-ehpc-package.oss-cn-hangzhou.aliyuncs.com/water_GMX50_bare.tar.gz
    tar xzvf water_GMX50_bare.tar.gz
    chown -R gmx.test water-cut1.0_GMX50_bare
    chgrp -R users water-cut1.0_GMX50_bare
  2. Create a job script named gmx.pbs.

    vim gmx.pbs

    Paste the following content into the file:

    #!/bin/sh
    #PBS -j oe
    #PBS -l select=1:ncpus=8:mpiprocs=4
    #PBS -q workq
    
    # Load module environment
    export MODULEPATH=/opt/ehpcmodulefiles/
    module load gromacs-gpu/2018.1
    module load openmpi/3.0.0
    module load cuda-toolkit/9.0
    export OMP_NUM_THREADS=1
    
    cd /home/gmx.test/water-cut1.0_GMX50_bare/0096
    
    # Preprocess input files to generate a TPR binary input file
    /opt/gromacs-gpu/2018.1/bin/gmx_mpi grompp -f pme.mdp -c conf.gro -p topol.top -o topol_pme.tpr
    
    # Run the simulation: 4 MPI processes, 1 OpenMP thread each, 100,000 steps
    mpirun -np 4 /opt/gromacs-gpu/2018.1/bin/gmx_mpi mdrun -ntomp 1 -nsteps 100000 -pin on -s topol_pme.tpr

    Key parameters:

    ParameterValuePurpose
    ncpus=88 vCPUsMatches the ecs.gn5-c8g1.2xlarge instance (8 vCPUs, 1 P100 GPU)
    mpiprocs=44 MPI processesSplits the simulation across 4 parallel processes
    -ntomp 11 OpenMP thread per MPI processAvoids over-subscribing CPU cores — 4 processes x 1 thread = 4 threads on 8 vCPUs
    -nsteps 100000100,000 iterationsControls simulation length; increase for longer or more accurate runs
    -pin onCPU affinity enabledPins each thread to a fixed CPU core, reducing context-switching overhead

    Adjust ncpus, mpiprocs, and -nsteps based on your computing requirements.

  3. Submit the job.

    qsub gmx.pbs

    The output is the job ID, for example:

    0.scheduler

Step 3: View the job result

  1. Check the job status.

    qstat -x 0.scheduler

    Expected output:

    Job id            Name             User              Time Use S Queue
    ----------------  ---------------- ----------------  -------- - -----
    0.scheduler       gmx.pbs          gmx.test          00:34:42 F workq

    In the S column, R means the job is running and F means it has finished. While the job is running, monitor the live output with:

    tail -f gmx.pbs.o0

    After the job finishes, view the full output with:

    cat gmx.pbs.o0
  2. Visualize the result using VNC and VMD.

    Enable VNC:

    Note

    Make sure the VNC ports are open in the security group for the cluster. The console automatically opens port 12016. If using the client, open the ports manually. Port 12017 supports one user at a time — open additional ports starting from 12017 for each additional user.

    • Using the client: In the left-side navigation pane, click Session Management. In the upper-right corner, click VNC to open VNC Viewer.

    • Using the console:

      1. In the E-HPC console, click Cluster in the left-side navigation pane.

      2. Select the cluster. Choose More > VNC.

      3. Connect to the visualization service. For details, see Use VNC to manage a visualization service.

    Open and load the result in VMD:

    1. In the cloud desktop, choose Application > System Tools > Terminal.

    2. Run /opt/vmd/1.9.3/vmd to open VMD (Visual Molecular Dynamics).

    3. On the VMD Main page, choose File > New Molecule....

    4. Click Browse... and select conf.gro.

      Note

      The file path is /home/gmx.test/water-cut1.0_GMX50_bare/0096/conf.gro.

    5. Click Load. The simulation result appears in the VMD 1.9.3 OpenGL Display window.

    gromacs results.png

Step 4: View computing performance

Note

Computing performance is only viewable in the E-HPC console.

  1. Log on to the E-HPC console.

  2. In the left-side navigation pane, choose Job and Performance Management > E-HPC Tune.

  3. Find the cluster and click Node.

View node performance (NodeView tab):

  1. Select a job and a compute node.

  2. (Optional) Set a time period. When you select a job, the time period automatically matches the job's run window. Adjust it manually as needed.

  3. Click Metrics and select the metrics to view.

  4. Hover over the graph to see detailed data.

gromacs-node performance.png

View process performance (ProcView tab):

  1. Click the ProcView tab.

  2. Select a job and a compute node.

  3. (Optional) Set a time period.

  4. Hover over the graph to see detailed data.

gromacs-process performance.png

Start a performance profiling task:

  1. Click a point in time on the process performance graph, then click the process to profile.

    gromacs-start profiling.png

  2. In the dialog box, set the profiling duration and frequency, and click OK to start real-time profiling.

View profiling results (Profiler tab):

  1. Click the Profiler tab.

  2. Select a profiling task and click View.

  3. Hover over the graph to see detailed data.

gromacs-performance profiling.png

Related topics

Use GROMACS to perform a molecular dynamics simulation

References