gmxtopology
Description
gmxtopology is a Python package for parsing and editing GROMACS topology
files.
Package layout
A topology is read in four small steps, each in its own module:
gmxtopology.preprocess: the GROMACS preprocessor (#include,#define,#ifdef, comments, continuation lines), yielding the active linesgmxtopology.parser: directive parsing;gmxtopology.specslists the parameters of every interaction function typegmxtopology.lookup: default parameters from[ bondtypes ]and friendsgmxtopology.model: the topology data modelgmxtopology.reduceandgmxtopology.writer: select what the system needs and write it
Installation
pip install gmxtopology
For Jupyter/IPython kernel support, install the optional notebook extra:
pip install "gmxtopology[notebook]"
From source:
pip install git+https://github.com/vojtechkostal/gmxtopology.git
Usage
See examples/example.ipynb for a fuller walkthrough. The packaged walkthrough uses the single self-contained examples/example.top file.
from gmxtopology import Topology, drop_vsites
# load topology from file; defines act like `define = -DPOSRES` in an mdp file
top = Topology("./examples/example.top", defines={"POSRES": None})
# modifying topology parameters
for atom in top.moleculetype("MOL").atoms:
atom.update(charge=0.0)
for atomtype in top.atomtypes:
atomtype.update(sigma=0.31)
# remove virtual sites from a molecule
drop_vsites(top.moleculetype("SOL"))
# write topology into a file
top.write("./examples/topol-processed.top", overwrite=True)
Reading
The reader behaves like grompp:
#includefiles are searched next to the including file, ininclude_dirs, and in$GMXLIBand the GROMACSshare/gromacs/topdirectory (found through$GMXDATAor thegmxexecutable), so#include "oplsaa.ff/forcefield.itp"works.#ifdef,#ifndef,#elseand#endifare evaluated against the macros given asdefinesand the#definelines of the files, so only the active branches are read.#definemacros that stand for one number stay symbolic in the parameters and can be edited throughtop.defines; macros that stand for several numbers (such as GROMOSgb_21) are expanded.- Parameters left out of
[ bonds ],[ pairs ],[ angles ],[ dihedrals ]and[ constraints ]are filled in from the parameter tables, matching on bonded atom types, either orientation,Xwildcards in[ dihedraltypes ](including the two-type form), multi-term type-9 dihedrals, andgen-pairs. [ cmaptypes ]and[ cmap ],[ intermolecular_interactions ], B-state parameters and the other interaction directives of the GROMACS manual are parsed into typed records. Unknown directives are errors with file and line.
Molecular interactions are Interaction(section, atoms, func, params) records
in molecule.interactions[section], also reachable as molecule.bonds,
molecule.dihedrals, and so on. Atoms are referred to by their 1-based number
and atom types by name. top.molecules is the ordered [ molecules ] list of
(MoleculeType, count) pairs.
Writing
Written topologies are flat and contain only what the simulated system needs:
- the molecule types listed in
[ molecules ](in that order), - the atom types used by their atoms, and the
[ nonbond_params ]between them, - the CMAP grids that a
[ cmap ]of those molecules refers to, - macros that parameters still refer to.
Bonded parameter tables are not written, because the parameters were resolved onto the molecular interactions. Includes and conditional blocks do not appear.
Testing
Run the parser regression suite with:
python -m pytest
Tests that compare a topology with its written version through gmx grompp
and gmx dump run when gmx is on the PATH.
The 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.git
Changelog
See CHANGELOG.md for release highlights.
Publishing
GitHub Trusted Publishing is set up via
publish.yml. The one-time PyPI and TestPyPI
configuration steps are documented in docs/publishing.md.
Metadata
Release files for gmxtopology 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gmxtopology-0.3.0.tar.gz | 35.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gmxtopology-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 68.3 kB
Release files / gmxtopology-0.3.0.tar.gz
| Download URL | gmxtopology-0.3.0.tar.gz |
|---|---|
| Size | 35.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9082a22197a6abb5ff0d30f9532f1db54c8e6a676dc8638edcc050049b4a0174
|
|
BLAKE2b-256 checksum How to use checksums |
b68dd4891a13e0b7f8ae947ba122f64bf79c52b34bd3da9ad116417baa83a0b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logRelease files / gmxtopology-0.3.0-py3-none-any.whl
| Download URL | gmxtopology-0.3.0-py3-none-any.whl |
|---|---|
| Size | 32.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
117dcd694843e5d84bdae78d8291de43f87bbb7b11eed03a477ff04d18d82e5f
|
|
BLAKE2b-256 checksum How to use checksums |
8f1378984a42d98b7818027e85553f466a3e238ce04f88381f3dcd7782101d53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency log