Principal Component Analysis and Free Energy Landscape Mapping Using GROMACS

Nov 22, 2023·
Yassir Boulaamane
Yassir Boulaamane
· 3 min read

A free-energy landscape in this workflow is a histogram of the trajectory in the plane of the first two principal components. PCA finds those axes. SHAM turns the occupancy into a free energy. The frame you extract is only as meaningful as the components you kept.

The trajectory names come from the 100 ns run md_0_100. One projection file is labeled lovastatin (pc15_lovastatina.xvg). That is the example name, not a requirement.

From a covariance matrix to one low-energy frameFive steps: gmx covar, keep components past 50 percent of the variance, project PC1 and PC2, run gmx sham, then trjconv at the time of the minimum. The example time is 520 ps.Histogram the motion you keptcovarEigenvaluesKeepPast 50%ProjectPC1, PC2shamFES.xpmtrjconvdump 520
Figure 1. The 50% rule decides how many components are worth projecting. The landscape in this note uses only PC1 and PC2. 520 is the dump time, in picoseconds, from the example minimum. Replace it after you read fel.dat.

Covariance

gmx covar wants a .tpr. If a run was pointed at md_0_100.gro and failed, use the .tpr. When prompted, select protein and ligand.

gmx covar -s md_0_100.tpr -f md_0_100.xtc -o eigenvalues.xvg -v eigenvectors.trr -xpma covar.xpm

How many components

From eigenvalues.xvg:

  • Total variance is the sum of the eigenvalues.
  • Explained variance of one component is that eigenvalue divided by the total, times 100.
  • Cumulative variance adds those fractions until you pass the cutoff.

Keep the smallest set of components whose cumulative variance is more than 50%.

Project PC1 through PC5

-proj writes a 1D time series for each selected eigenvector. -2d writes a combined projection of the first five. -tu ns puts the time axis in nanoseconds. The lovastatin filenames are the example.

gmx anaeig -f md_0_100.xtc -s md_0_100.tpr -v eigenvectors.trr -first 1 -last 5 \
-proj pc15_lovastatina.xvg -2d project2d_s100_lovastatina.xvg -tu ns

The PC1–PC2 plane

Project the first component, then the second, and paste them into one three-column file. The awk fields assume the usual .xvg layout of this paste: time and value from PC1, then the value from PC2.

gmx anaeig -f md_0_100.xtc -s md_0_100.tpr -v eigenvectors.trr -last 1 -proj pc1.xvg
gmx anaeig -f md_0_100.xtc -s md_0_100.tpr -v eigenvectors.trr -first 2 -last 2 -proj pc2.xvg
paste pc1.xvg pc2.xvg | awk '{print $1, $2, $4}' > PC1PC2.xvg

Free energy with SHAM

gmx sham -f PC1PC2.xvg -ls FES.xpm

xpm2txt.py turns the XPM matrix into three columns: X, Y, and energy. The invocation recorded here is Python 2.7.

python2.7 xpm2txt.py -f FES.xpm -o fel.dat

The minimum

Plot fel.dat, read the time of the lowest point, and dump that frame. The example time is 520 ps. It is not a universal minimum.

gmx trjconv -s md_0_100.tpr -f md_0_100.xtc -o min_energy.pdb -dump 520

That PDB is the conformation that occupied the bottom of this PC1–PC2 histogram. It is not, by itself, proof that the simulation visited every basin that matters. The 50% cutoff and the choice to stop at two components are the assumptions sitting under the picture.