Skip to main content

A Python library for parsing and editing GROMACS topology files.

Project description

gmxtopology

Description

gmxtopology is a Python package for parsing and editing GROMACS topology files.

Package layout

The main flow is organized around a few top-level modules:

  • gmxtopology.topology: topology data models
  • gmxtopology.io: topology file reading and writing
  • gmxtopology.parser: section parsing and dispatch
  • gmxtopology.lookup: parameter lookup and virtual-site reduction helpers
  • gmxtopology.schema: schema objects used by the parser
  • gmxtopology.interaction_specs: GROMACS interaction tables

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

# 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)

Topology preprocessing

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 NAME and #define NAME replacement text
  • #ifdef NAME and #ifndef NAME
  • #else and #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.

Testing

Run the parser regression suite with:

python -m pytest

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gmxtopology-0.2.0.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmxtopology-0.2.0-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file gmxtopology-0.2.0.tar.gz.

File metadata

  • Download URL: gmxtopology-0.2.0.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gmxtopology-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8d0f44520a36a84958e2b4c5db884cc20532b6c917b8ecc3ae6c791455543586
MD5 70fdc6c7b26f924bd535167b8a4c2aff
BLAKE2b-256 9bc6a3f3bcd51fdf8c5954296769c89807ff41b50b82615fa39c2d1609c3b32e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmxtopology-0.2.0.tar.gz:

Publisher: publish.yml on vojtechkostal/gmxtopology

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gmxtopology-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gmxtopology-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gmxtopology-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53c0bb42d8886570954d8c54048978535c9a34d9f240de14e7617e41926a6be0
MD5 f3894d17a39d29af04c02713d9903ad8
BLAKE2b-256 49bdff743eabbe582d9f59a8e52e235959887cc6a3b8a376de233cb1d0b8109e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmxtopology-0.2.0-py3-none-any.whl:

Publisher: publish.yml on vojtechkostal/gmxtopology

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page