avatar

Shamrat Kumar Paul

shamratpaul@gmail.com


← Back to Blog

Plot the *.xvg file


Plot the *.xvg file.

GROMACS typically outputs data in the XVG file format. While tools like xmgrace (on Linux) or Gnuplot are commonly used to visualize these files, Python offers a flexible and powerful alternative for creating publication-quality plots.

Visualization using Python

You can easily plot .xvg data using numpy and matplotlib. Here is a simple script to get you started:

Python Script (plot_rmsd.py)

import numpy as np
import matplotlib.pyplot as plt

# Initialize lists for data
x, y = [], []

# Open the .xvg file
# Note: Ensure you provide the correct local path to your file
with open("rmsd-1aki.xvg") as f:
    for line in f:
        # Skip comment lines (starting with # or @)
        if line.startswith(('#', '@')):
            continue
        
        cols = line.split()
        if len(cols) >= 2:
            x.append(float(cols[0]))
            y.append(float(cols[1]))

# Create the plot
plt.figure(figsize=(8, 6))
plt.plot(x, y, color='red', label='1AKI', linewidth=1.5)

# Formatting the axes and title
plt.title("Root Mean Square Deviation (RMSD)", fontsize=14)
plt.xlabel('Time (ns)', fontsize=12)
plt.ylabel('RMSD (nm)', fontsize=12)
plt.legend()
plt.grid(True, linestyle='--', alpha=0.6)

# Display the plot
plt.tight_layout()
plt.show()

Resulting Plot

Below is an example of the visualization generated by this method:

RMSD Plot


Tip: GROMACS .xvg files contain metadata lines starting with @ or #. The script above is designed to skip these lines automatically, so you don’t need to manually delete headers.


Powered by Jekyll and Minimal Light theme.