๐จ gmxplot โ GROMACS XVG File Visualization Tool
Auto-detect, plot, compare, and summarize your GROMACS simulation data from the command line.
gmxplot is a Python CLI tool that reads GROMACS XVG output files, automatically detects the type of simulation data (RMSD, RMSF, energy, SASA, PCA, gyration, etc.), and generates publication-ready matplotlib figures. It supports single-file plotting, two-file comparison, multi-file overlay, batch directory processing, and CSV statistical summaries โ all with sensible defaults and no manual type specification required.
Features
- Automatic type detection โ No need to specify the plot type.
gmxplotreads the XVG file headers and classifies the data as energy, RMSD, RMSF, gyration, SASA, PCA, or generic XY. - Publication-ready plots โ Clean matplotlib + seaborn-styled figures with consistent color schemes and typography.
- Rolling average overlay โ Raw data shown with transparency; a rolling average line (auto-calculated at 5% of data range) highlights the trend.
- Two-file comparison โ Overlay two simulations (e.g., different mutants, temperatures, force fields) on the same axes with distinct colors.
- Multi-file comparison โ Compare 3+ files simultaneously with a cycling color palette (matplotlib tab10).
- Batch processing โ Automatically find and plot all XVG files in a directory.
- Statistical summaries โ Per-column CSV output with mean, std, min, q10, q50, q90, max, displayed as a Rich console table.
- GROMACS escape code rendering โ Automatic conversion of xmgrace formatting codes (
\S2\Nโ$^{2}$,\sX\Nโ$_{X}$,\f{...}removed). - Metadata-driven axis labels โ Axis titles are read from the XVG file headers, so units (ps vs ns, nm vs ร ) always match the data.
- Multiple output formats โ PNG (default), PDF, SVG, EPS, JPG, TIFF.
Installation
From source
git clone https://github.com/MaybeBio/gmxplot.git
cd gmxplot
pip install -e .
With pip
pip install gmxplot
Dependencies
- Python โฅ 3.10
- numpy, pandas, matplotlib, seaborn, typer, rich
Quick Start
# Detect the type of an XVG file
gmxplot detect simulation.xvg
# Plot a single file (auto-detects type)
gmxplot plot simulation.xvg
# Plot with custom rolling average
gmxplot plot energy.xvg --roll-avg 50
# Save to a specific file
gmxplot plot rmsd.xvg -o rmsd.png
gmxplot plot rmsd.xvg -o rmsd.pdf
# Compare two simulations
gmxplot compare ref.xvg mutant.xvg --label1 WildType --label2 Mutant
# Compare 3+ files
gmxplot multi-compare run1/rmsd.xvg run2/rmsd.xvg run3/rmsd.xvg
# Batch process a directory
gmxplot batch ./simulation/ -o ./plots/ --stats
# Generate statistics CSV
gmxplot stats energy.xvg rmsd.xvg -o summary.csv
CLI Reference
gmxplot plot
Plot a single XVG file with automatic type detection.
Usage: gmxplot plot [OPTIONS] FILE
Arguments:
FILE Path to XVG file [required]
Options:
-r, --roll-avg INTEGER Rolling average window size (auto if not set)
-o, --output TEXT Output file path (PNG, PDF, SVG, JPG)
-d, --dpi INTEGER DPI for saved image [default: 300]
--show Display plot in window
-m, --mean Plot mean line
-s, --std Plot mean +/- std lines
--latex / --no-latex Enable/disable LaTeX rendering (default: off)
--help Show this message and exit
Examples:
gmxplot plot energy.xvg
gmxplot plot rmsd.xvg -o rmsd.png --roll-avg 20
gmxplot plot sasa.xvg -o sasa.pdf --dpi 600
gmxplot plot gyrate.xvg -m -s # with mean and std lines
gmxplot compare
Compare two XVG files side-by-side or overlaid on the same axes.
Usage: gmxplot compare [OPTIONS] FILE1 FILE2
Arguments:
FILE1 Path to first XVG file [required]
FILE2 Path to second XVG file [required]
Options:
-l1, --label1 TEXT Label for first dataset [default: prot_1]
-l2, --label2 TEXT Label for second dataset [default: prot_2]
-r, --roll-avg INTEGER Rolling average window size [default: 50]
-o, --output TEXT Output file path
-d, --dpi INTEGER DPI for saved image [default: 300]
--latex / --no-latex Enable/disable LaTeX rendering (default: off)
--help Show this message and exit
Type-specific behavior:
| Plot Type | Comparison Mode |
|---|---|
| energy | Multi-panel grid: one subplot per component, both datasets overlaid per panel |
| rmsd | Single axes: both RMSD rolling averages overlaid |
| rmsf | Single axes: both RMSF traces overlaid (no rolling average) |
| gyration | Single axes: both Rg traces overlaid |
| sasa | Single axes: both SASA rolling averages overlaid |
| pca | Side-by-side: two hexbin density plots |
| xy | Single axes: generic overlay of both files |
Examples:
gmxplot compare prot1/rmsd.xvg prot2/rmsd.xvg -l1 WT -l2 Mutant
gmxplot compare run1/energy.xvg run2/energy.xvg -o energy_compare.png
gmxplot multi-compare
Compare multiple XVG files (3+) of the same type.
Usage: gmxplot multi-compare [OPTIONS] FILES...
Arguments:
FILES... Paths to XVG files (at least 2) [required]
Options:
-r, --roll-avg INTEGER Rolling average window size [default: 50]
-o, --output TEXT Output file path
-d, --dpi INTEGER DPI for saved image [default: 300]
--latex / --no-latex Enable/disable LaTeX rendering (default: off)
--help Show this message and exit
Uses matplotlib's tab10 color palette (10 cycled colors) for distinguishing traces.
Examples:
gmxplot multi-compare chA/rmsd.xvg chB/rmsd.xvg chC/rmsd.xvg
gmxplot multi-compare prot3/rmsf_ch*.xvg -o rmsf_multi.png
gmxplot detect
Print the detected plot type and metadata for an XVG file without generating a plot.
Usage: gmxplot detect [OPTIONS] FILE
Arguments:
FILE Path to XVG file [required]
Options:
--help Show this message and exit
Example output:
File: tests/fixtures/prot1/energy.xvg
Type: energy
Title: GROMACS Energies
X-axis: Time (ps)
Y-axis: (kJ/mol), (K), (bar), (kg/m^3)
Columns: ['Time', 'Potential', 'Temperature', 'Pressure', 'Density']
Data points: 20001
Columns count: 5
gmxplot batch
Process all XVG files in a directory, generating plots and optionally a statistics CSV.
Usage: gmxplot batch [OPTIONS] [INPUT_DIR]
Arguments:
[INPUT_DIR] Input directory with XVG files [default: .]
Options:
-o, --output-dir TEXT Output directory for plots [default: .]
-r, --roll-avg INTEGER Rolling average window size (auto if not set)
-d, --dpi INTEGER DPI for saved images [default: 300]
-e, --ext TEXT Export format (png, pdf, svg, jpg) [default: png]
--stats / --no-stats Generate statistics CSV [default: True]
--stats-file TEXT Statistics CSV filename [default: xvg-stats.csv]
-m, --mean Plot mean lines
-s, --std Plot mean +/- std lines
--latex / --no-latex Enable/disable LaTeX rendering (default: off)
--help Show this message and exit
Examples:
gmxplot batch ./simulation/ -o ./plots/
gmxplot batch ./data/ -o ./output/ --stats --ext pdf
gmxplot batch ./runs/ --no-stats -m # batch without stats, with mean lines
gmxplot stats
Generate a statistical summary CSV for one or more XVG files, displayed as a Rich table.
Usage: gmxplot stats [OPTIONS] FILES...
Arguments:
FILES... XVG files to analyze [required]
Options:
-o, --output TEXT Output CSV path [default: xvg-stats.csv]
--help Show this message and exit
Per-column statistics computed:
| Field | Description |
|---|---|
| dir | Parent directory of the file |
| file | XVG filename |
| plot | Column name (e.g., Potential, RMSD, Rg) |
| mean | Arithmetic mean |
| std | Standard deviation |
| min | Minimum value |
| q10 | 10th percentile |
| q50 | 50th percentile (median) |
| q90 | 90th percentile |
| max | Maximum value |
Example output:
XVG Statistics Summary
โโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโณโโโโโโโโณโโโโโโโโโณโโโโโโโโโณโโโโโโโโณโโโโโโโโโณโโโโโโโโโ
โ File โ Plot โ Mean โ Std โ Min โ Q10 โ Q50 โ Q90 โ Max โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ rmsdโฆ โ RMSD โ 0.2905โ 0.0323โ 0.0369 โ 0.2544 โ 0.2868โ 0.3324 โ 0.3977 โ
โ energโฆ โ Potentiโฆ โ-5616.โฆโ1095.5โฆโ-5659.39โ-5639.27โ-5616โฆโ-5601.2โฆโ-5570.โฆโ
โโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโดโโโโโโโโดโโโโโโโโโดโโโโโโโโโดโโโโโโโโดโโโโโโโโโดโโโโโโโโโ
Plot Type Detection
Plot type is detected automatically from the @ title "..." header line in each XVG file, with fallback heuristics based on axis labels and column count when the title is unrecognized.
| Plot Type | @ title pattern |
Column Names | Special Features |
|---|---|---|---|
energy |
"GROMACS Energies", "Energy", ... | Time, Potential, Temperature, Pressure, Density | Multi-panel grid (2-column), per-component subplots |
gyration |
"Radius of gyration ..." | Time, Rg, RgX, RgY, RgZ | Rg rolling average only (components not shown) |
rmsd |
"RMSD" | Time, RMSD | Rolling average overlay |
rmsf |
"RMS fluctuation", "RMSF" | Residue, RMSF | Per-residue line (no rolling average) |
sasa |
"Solvent Accessible Surface", "Area per residue ..." | Time/Residue, Area, StdDev | Time-series (with RA) or per-residue (without RA) |
pca |
"2D projection of trajectory" | PC1, PC2 | Hexbin density with viridis colormap + colorbar |
xy |
Any unrecognized title | Auto-detected | Generic fallback, legend-based line labels |
Detection priority
- Title match (fast, authoritative) โ if
@ titlecontains a known keyword, use that type - Axis label / column count fallback โ when the title doesn't match, heuristics examine the y-label for units, column count, and axis names
- Default โ 2+ columns โ
xy, otherwiseunknown
Architecture
gmxplot/
โโโ pyproject.toml # Package config, dependencies, entry point
โโโ README.md
โโโ gmxplot/
โ โโโ __init__.py # Package version
โ โโโ cli.py # Typer CLI: all 6 commands, figure saving, LaTeX setup
โ โโโ parser.py # XVG parsing: XVGMetadata, read_xvg(), classify_plot_type()
โ โโโ plotting.py # Matplotlib figures: plot_energy, plot_rmsd, plot_rmsf, etc.
โ โโโ comparison.py # Comparison: compare_two(), compare_multi(), type-specific funcs
โ โโโ stats.py # Statistics: compute_column_stats(), generate_stats_csv()
โ โโโ escape_codes.py # Escape codes: clean_gromacs_label(), resolve_axis_titles()
โ โโโ config.py # Defaults: figure sizes, DPI, colors, rolling avg params
โโโ tests/
โโโ test_parser.py
โโโ test_plotting.py
โโโ test_comparison.py
โโโ test_stats.py
โโโ test_escape_codes.py
โโโ test_cli.py
โโโ fixtures/ # Sample XVG files for testing
โโโ prot1/ # energy, gyrate, rmsd, rmsf, sasa, 2dproj
โโโ prot2/ # Same types (for comparison testing)
โโโ prot3/ # Chain-specific files (for multi-compare)
โโโ other_xvg/ # Edge cases (hbnum, resarea, cphmd)
Module relationships
cli.py โโโ parser.py (read_xvg, classify_plot_type)
cli.py โโโ plotting.py (create_plot, calculate_roll_avg)
cli.py โโโ comparison.py (compare_two, compare_multi)
cli.py โโโ stats.py (generate_stats_csv, format_stats_table)
plotting.py โโโ escape_codes.py (resolve_axis_titles, clean_gromacs_label)
comparison.py โโโ escape_codes.py
comparison.py โโโ plotting.py (calculate_roll_avg, _parse_y_units)
Data flow
- Parsing: XVG file โ
read_xvg()โXVGMetadata(title, labels, legend entries) +DataFrame(numeric columns with type-specific names) - Classification:
classify_plot_type()matches title against known patterns โ setsmetadata.plot_type - Plotting:
create_plot()dispatches to type-specific function โFigurewith rolling average overlay - Output:
plt.savefig()โ PNG/PDF/SVG on disk, orplt.show()for interactive viewing
Rolling Average
The rolling average window size is calculated as 5% of the data range (max - min along the x-axis), clamped between 3 and 100. This provides a reasonable smoothing level for most GROMACS simulation data without over-smoothing.
- Single plot: Auto-calculated by default; override with
--roll-avg N - Comparison: Default 50 (larger window for trend-focused comparison)
- RMSF: No rolling average (per-residue data is not a time series)
Color Schemes
| Context | Colors | Source |
|---|---|---|
| Single plot raw data | #aec6cf (pastel blue, 50% alpha) |
config.py |
| Single plot rolling avg | #1f77b4 (tab10 blue) |
config.py |
| Two-file comparison | #1f77b4 (blue) vs #d62728 (red) |
COMPARE_COLORS |
| Multi-file comparison | tab10 10-color cycle | MULTI_COLORS |
| PCA density | viridis colormap | matplotlib |
GROMACS Escape Code Handling
GROMACS XVG files use xmgrace-style formatting codes for axis labels and legends. gmxplot converts these to matplotlib-compatible notation:
| Escape Code | Meaning | Conversion | Example |
|---|---|---|---|
\S...\N |
Superscript | $^{...}$ |
nm\S2\N โ nm$^{2}$ |
\s...\N |
Subscript | $_{...}$ |
Rg\sX\N โ Rg$_{X}$ |
\f{...} |
Font switch | Removed | \f{Symbol}alpha โ alpha |
Works with matplotlib's built-in mathtext renderer (no LaTeX installation required). If you enable --latex, the same notation is handled by LaTeX's math mode.
References
gmxplot was inspired by and builds upon ideas from:
- GMXvg โ Batch-oriented matplotlib plotting for GROMACS XVG files with statistical CSV export.
- xvg_plot โ Interactive Plotly-based XVG visualization with rich type detection and multi-file comparison.
Key differences from these tools:
- vs GMXvg: No heavy UtilityLib dependency; cleaner modular architecture; type-specific plot functions with auto-detection; comparison and multi-file support.
- vs xvg_plot: Uses matplotlib instead of Plotly for publication-ready static output; includes statistical summary CSV; uses typer instead of argparse for CLI; supports mean/std overlay lines.
License
MIT
Todos
โ ๏ธ In Chinese
-
- ่พๅบๅๅงxvgๆฐๆฎ
-
- ๅฏ่งๅๅ ถไป้ๆฑ
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmxplot-0.1.0.tar.gz.
File metadata
- Download URL: gmxplot-0.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e997f97b7aca5d52204681aa551544630be41d61f4f1103e4d252717a7abb771
|
|
| MD5 |
9e30077a770ed61e1440be32965124e0
|
|
| BLAKE2b-256 |
8a2c615216273d8a941756a7df817ca522494fef51d7aa6d0000f49b5f34c9c3
|
File details
Details for the file gmxplot-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gmxplot-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5653254458efe55075a7cbc1a9529cffa5838f4af4ae10702073bf002f7fa39b
|
|
| MD5 |
93448f9c24c597b49cbf87607d530a9c
|
|
| BLAKE2b-256 |
d7fb42b1c1550dc396bfbcc239d81c23cd5d87a3eb9156f10e19507af287f2b3
|