How to Use gmx cluster: Extract a Representative Structure from a GROMACS Trajectory - StemSkills Lab
Skip to content

How to Use gmx cluster: Extract a Representative Structure from a GROMACS Trajectory

How to Use gmx cluster: Extract a Representative Structure from a GROMACS Trajectory

You finished a molecular dynamics run, you have thousands of frames, and now you need one structure: a figure for the thesis, a coordinate file to deposit, or a starting pose to re-dock a ligand into. Picking a single frame by eye is not defensible. This tutorial shows the right way with gmx cluster, which groups the whole trajectory by pairwise RMSD and returns the true central conformation.

Answer: To find one representative structure from a GROMACS trajectory, run gmx cluster with the gromos method. It groups every frame by pairwise RMSD, then returns the central structure of the most populated cluster. Clean periodic boundary conditions first with gmx trjconv, fit on backbone atoms, and choose the RMSD cutoff from the distribution.

By the StemSkills Lab team, 10+ years in structural bioinformatics, drug design, and multiscale molecular modeling.

On this page

What does gmx cluster actually do?

gmx cluster computes the RMSD between every pair of frames in your trajectory, then groups frames that are structurally similar into clusters. The most populated cluster is the conformation your system spent the most time in, and its central member is the single structure that best represents that ensemble. That central member, not a random frame, is what belongs in your figure or your next docking run.

The default algorithm in GROMACS is linkage, but for extracting a representative structure the gromos method is the standard choice. It comes from the classic paper by Daura and colleagues (Daura, Gademann, Jaun, Seebach, van Gunsteren, Mark, Angew. Chem. Int. Ed. 1999, 38, 236-240). The GROMACS manual summarises the gromos algorithm plainly: count the number of neighbors of each structure within the cutoff, take the structure with the largest number of neighbors together with all of them as one cluster, remove that group from the pool, and repeat until every frame is assigned.

Because gromos removes the biggest group first, cluster 1 in the output is the most populated cluster, and its center is defined by GROMACS as the structure with “the smallest average RMSD from all other structures of the cluster.” That gives you a principled, reproducible answer instead of a guess.

Want the guided, hands-on version?

Our live Molecular Modeling & MD Simulations cohort bootcamp takes you from zero to running real docking and MD workflows, with a portfolio project for your grad-school applications.

Join the waitlist (free) →

How do I prepare the trajectory before clustering?

Clustering compares shapes, so periodic-boundary artifacts must go first, otherwise a molecule that hops across the box looks like a huge conformational change. Fix this with gmx trjconv before you cluster.

A reliable recipe for a solvated protein is to remove jumps, then make molecules whole and center the protein:

gmx trjconv -s md.tpr -f md.xtc -o md_nojump.xtc -pbc nojump

gmx trjconv -s md.tpr -f md_nojump.xtc -o md_center.xtc -pbc mol -center

For the first command choose your protein group; for the second, select the protein as the group to center and System as the output group. You do not need to fit the trajectory yourself, because gmx cluster does a least-squares fit internally (the -fit option is on by default). What matters is that the frames are PBC-clean before they reach the clustering step.

How do I run gmx cluster with the gromos method?

Now run the clustering on the cleaned trajectory. This command asks for the gromos method explicitly, sets a cutoff, and requests the full set of useful outputs:

gmx cluster -s md.tpr -f md_center.xtc \
  -method gromos -cutoff 0.12 \
  -cl clusters.pdb -g cluster.log \
  -sz clust-size.xvg -o rmsd-clust.xpm \
  -dist rmsd-dist.xvg -clid clust-id.xvg

gmx cluster will prompt you twice: once for the group to use for the least-squares fit, and once for the group used for the RMSD calculation and output. For most proteins choose Backbone (or C-alpha) for both. Do not choose System or Protein that includes flexible side chains and water, because irrelevant atoms will dominate the RMSD and blur your clusters. If you want a custom selection, build an index file with gmx make_ndx and add -n index.ndx.

Here is what each flag writes, straight from the tool’s own documentation:

FlagOutput fileWhat it contains
-clclusters.pdbThe central structure of each cluster (one model per cluster)
-gcluster.logOptions used plus a detailed list of every cluster and its members
-szclust-size.xvgThe size (population) of each cluster
-ormsd-clust.xpmThe RMSD matrix with a graphical depiction of the clusters
-distrmsd-dist.xvgThe RMSD distribution across all frame pairs
-clidclust-id.xvgThe cluster number as a function of time

How do I read the gmx cluster outputs?

Open cluster.log first. It reports how many clusters were found, the population of each, and the frame (time) of the central member of each cluster. With the gromos method the clusters are listed largest first, so cluster 1 is your most populated conformation and the one you almost always want.

Plot clust-size.xvg to see how the population is distributed. A healthy result has one or a few dominant clusters plus a tail of small ones. Plot clust-id.xvg to see when each cluster was visited during the run, which tells you whether your dominant conformation is stable throughout or only appears late.

The rmsd-clust.xpm file is an XPM matrix, not a normal image, so a standard viewer will not open it. Convert it to an EPS figure with the GROMACS helper:

gmx xpm2ps -f rmsd-clust.xpm -o rmsd-clust.eps

Alternatively, read the XPM directly in Python with a small parser and display it with Matplotlib. The block structure along the diagonal shows your clusters at a glance.

How do I extract the representative structure?

You have two clean options, and both are defensible.

Option A, straight from clusters.pdb. The file written by -cl holds the central structure of each cluster as separate models, ordered by population. Cluster 1 is the first model. Extract it with gmx trjconv, treating the multi-model PDB as a short trajectory:

gmx trjconv -f clusters.pdb -s clusters.pdb -o representative.pdb -dump 0

Option B, straight from the trajectory. Read the central frame time of cluster 1 from cluster.log, then dump that exact frame out of your cleaned trajectory (replace 1200 with the reported time in picoseconds):

gmx trjconv -s md.tpr -f md_center.xtc -o representative.pdb -dump 1200

Option B is handy when you want the full system (for example protein plus a bound ligand or crystallographic waters) rather than only the atoms you clustered on. Either way you now have a single representative.pdb that you can show in a figure, deposit alongside your thesis data, or feed back into a docking workflow.

How do I choose the RMSD cutoff?

The cutoff is the one parameter that decides everything, and it is in nanometers. The GROMACS default is 0.1 nm. Too large and every frame collapses into one giant cluster; too small and you get hundreds of singletons and no clear representative.

Let the data guide you. Plot rmsd-dist.xvg, the distribution of pairwise RMSD values. A sensible cutoff sits near the first peak or the shoulder before the bulk of the distribution, so that structurally similar frames fall inside it and genuinely different conformations do not. For a folded protein backbone, values in the 0.1 to 0.25 nm range are typical starting points. Run two or three cutoffs and compare the cluster count and the size of cluster 1; the goal is a dominant, well-populated top cluster rather than a single blob or a cloud of singletons.

Which clustering method should I pick?

gmx cluster ships five algorithms. For pulling out a representative structure, gromos is the workhorse. The others have their uses, but they answer slightly different questions.

MethodHow it groups framesBest for
gromosNeighbor counting within the cutoff (Daura 1999); biggest group taken firstExtracting the representative structure of the dominant conformation
linkage (default)Adds a structure to a cluster if it is within the cutoff of any memberQuick exploration, but can chain dissimilar frames together
jarvis-patrickGroups frames that share enough nearest neighborsDensity-based grouping with a neighbor-list criterion
monte-carloReorders the RMSD matrix to reveal block structureVisualising similarity, not assigning discrete clusters
diagonalizationDiagonalises the RMSD matrixInspecting the matrix; not a practical clustering choice

If your goal is one defensible structure for a figure or a re-docking step, set -method gromos and move on. Explore the others only when you have a specific reason to.

Troubleshooting: the classic failures

Everything collapses into one cluster. Your cutoff is too large for the flexibility of your system. Lower -cutoff (try 0.1 nm, then step down) and check rmsd-dist.xvg to see where the real structural spread begins.

Hundreds of singletons. The cutoff is too small, so almost no two frames count as neighbors. Raise -cutoff and re-run. If you clustered on all atoms, switch the fit and RMSD group to Backbone so that side-chain noise stops fragmenting the clusters.

Clusters look meaningless. You probably fit on the wrong atom group. Water and mobile side chains swamp the RMSD signal. Re-run and select Backbone or C-alpha for both prompts.

The job runs out of memory or takes forever. gmx cluster builds a full frame-by-frame RMSD matrix, so cost grows with the square of the number of frames. A 10,000-frame trajectory means roughly 50 million unique pairwise comparisons (N times N minus 1, over two), and the matrix must be held in memory. Thin the trajectory before clustering with -skip (for example -skip 10 to use every tenth frame) or -dt (for example -dt 100 to sample every 100 ps), and fit on backbone atoms only. Reducing frames rarely changes which conformation dominates, and it turns an impossible run into a fast one.

rmsd-clust.xpm will not open. It is an XPM matrix, not a bitmap. Convert it with gmx xpm2ps -f rmsd-clust.xpm -o rmsd-clust.eps, or parse it in Python and plot with Matplotlib.

FAQ

Is the most populated cluster always cluster 1? With the gromos method, yes. The algorithm removes the largest group first, so clusters are numbered from most to least populated. Other methods do not guarantee this ordering.

What units is the cutoff in? Nanometers. The GROMACS default is 0.1 nm. A cutoff of 0.12 means 1.2 angstrom of RMSD between frames.

Should I fit the trajectory before running gmx cluster? You must remove PBC artifacts first, but you do not need a separate rotational fit, because gmx cluster performs a least-squares fit internally (the -fit option is on by default).

Can I get the average structure instead of the central one? Yes, add -av and -cl writes the average structure of each cluster. For a physically real coordinate file, prefer the central structure (the default), because an average can have distorted geometry.

How many frames should my trajectory have for clustering? Enough to sample the conformations you care about, but few enough that the RMSD matrix fits in memory. Thinning to a few thousand frames with -skip or -dt is common and usually preserves the dominant cluster.

Where this fits in your MD workflow

Clustering is one step in a longer pipeline. If you are still building the foundations, start with our pillar guide to learning molecular dynamics with GROMACS, and see how analysis steps like this connect to the bigger picture in the computational biology skills roadmap. Master the representative-structure step and you will have a clean, citable coordinate file for figures, deposition, and downstream docking.

Want the guided, hands-on version?

Our live Molecular Modeling & MD Simulations cohort bootcamp takes you from zero to running real docking and MD workflows, with a portfolio project for your grad-school applications.

Join the waitlist (free) →

Think you know Molecular Dynamics (GROMACS)?
Take the free StemSkills assessment and earn a verifiable certificate you can download and add to your LinkedIn profile.
Start the free assessment

Keep going

How to Run an MD Simulation of a Vaccine Construct-TLR Complex in GROMACS: Setup, Length and What to Report Take a docked vaccine construct into GROMACS: which pose to carry forward, force field and box setup, how… How to Install PyMOL for Free (Open-Source PyMOL on Windows, Linux and Mac): A Step-by-Step Guide for Students Open-source PyMOL is free under a BSD-like licence. Install it with one conda command on Windows, Linux or… How to Install AutoDock Vina on Windows 10 and 11: A Step-by-Step Guide for Beginners (Vina 1.2.7 + AutoDockTools) Install AutoDock Vina 1.2.7 on Windows the way it ships today: one bare .exe, no MSI, plus MGLTools…
See live workshops