gmxtopology is a Python package for parsing and editing GROMACS topology
files.
The main flow is organized around a few top-level modules:
gmxtopology.topology: topology data modelsgmxtopology.io: topology file reading and writinggmxtopology.parser: section parsing and dispatchgmxtopology.lookup: parameter lookup and virtual-site reduction helpersgmxtopology.schema: schema objects used by the parsergmxtopology.interaction_specs: GROMACS interaction tables
pip install gmxtopologyFor Jupyter/IPython kernel support, install the optional notebook extra:
pip install "gmxtopology[notebook]"From source:
pip install git+https://github.com/vojtechkostal/gmxtopology.gitSee examples/example.ipynb for a fuller walkthrough. The packaged walkthrough uses the single self-contained examples/example.top file.
from gmxtopology import Topology
# load topology from file
fn_top = "./examples/example.top"
top = Topology(fn_top)
# modifying topology parameters
for atom in top.molecules['MOL'][0].atoms:
atom.update(charge=0.0)
for atomtype in top.atomtypes:
atomtype.update(sigma=0.31)
# remove virtual sites from a molecule
top.molecules['SOL'][0].remove_vsites()
# write topology into a file
top.write("./examples/topol-processed.top", overwrite=True)The reader follows local #include directives relative to the including file
and preserves conditional topology sections when writing a modified topology.
Supported directives include:
#define NAMEand#define NAME replacement text#ifdef NAMEand#ifndef NAME#elseand#endif, including nested blocks#include "relative/path.itp"
Missing includes remain errors unless they occur inside a conditional block.
This allows topologies with absent optional restraint files to load when those
files are referenced only behind flags such as #ifdef REST_ON.
For free-energy topologies, [ atoms ] records and supported bonded
interactions may also include the optional topology-B parameters documented by
GROMACS. They are exposed with _b suffixes, such as charge_b, b0_b, and
kb_b.
Sections that gmxtopology does not edit are carried through as opaque records
when writing a flattened topology. This preserves force-field-specific data
such as CHARMM [ cmaptypes ], [ implicit_genborn_params ], and molecular
[ cmap ] sections.
Written topologies contain only the [ atomtypes ] used by molecules in the
[ molecules ] section or referenced by preserved opaque global sections.
Bonded parameter tables such as [ bondtypes ], [ angletypes ], and
[ dihedraltypes ] are resolved onto molecular interactions and omitted from
the output. Relevant [ nonbond_params ] entries remain global because they
cannot be expanded onto bonded records.
Run the parser regression suite with:
python -m pytestThe repository test suite includes pinned
official GROMACS fixtures covering
SPC/E, TIP3P, TIP4P, and urea topologies, plus
prosECCo75 CHARMM36-derived fixtures
covering POPC and CMAP tables. A curated
ParmEd GmxTests snapshot adds
real-world water, peptide, solvated protein, mixed-solvent, and DPPC cases.
PyPI distributions intentionally contain only the package code, documentation, the example notebook, and its small self-contained topology. Clone the repository explicitly when you need the larger examples and regression fixtures:
git clone --depth 1 https://github.com/vojtechkostal/gmxtopology.gitSee CHANGELOG.md for release highlights.
GitHub Trusted Publishing is set up via
publish.yml. The one-time PyPI and TestPyPI
configuration steps are documented in docs/publishing.md.