mythos.input.gromacs_input
GROMACS input file parser.
Handles reading and writing of GROMACS .mdp (molecular dynamics parameter) files. The format is a simple key = value format, similar to oxDNA input files.
Attributes
Classes
Parser and parameter replacer for params in GROMACS topology files. |
Functions
|
Try to parse a value as a numeric type. |
|
Try to parse a value as a boolean. |
|
Parse a value string, handling comments and type inference. |
|
Read a GROMACS .mdp input file. |
|
Write a GROMACS .mdp input configuration to a file handle. |
|
Write a GROMACS .mdp input file. |
|
Update parameters in a GROMACS .mdp file. |
|
Read a preprocessed GROMACS topology file. |
|
Write a modified GROMACS topology file with replaced parameters. |
Module Contents
- mythos.input.gromacs_input.logger
- mythos.input.gromacs_input.INVALID_LINE = 'Invalid line: {}'
- mythos.input.gromacs_input._parse_numeric(value: str) tuple[float | int, bool][source]
Try to parse a value as a numeric type.
- mythos.input.gromacs_input._parse_boolean(value: str) tuple[bool, bool][source]
Try to parse a value as a boolean.
- mythos.input.gromacs_input._parse_value(value: str) str | float | int | bool[source]
Parse a value string, handling comments and type inference.
- mythos.input.gromacs_input.read_mdp(input_file: pathlib.Path) dict[str, str | float | int | bool][source]
Read a GROMACS .mdp input file.
- Parameters:
input_file – Path to the .mdp file.
- Returns:
Dictionary of key-value pairs from the input file.
- mythos.input.gromacs_input.write_mdp_to(input_config: dict, f: io.TextIOWrapper) None[source]
Write a GROMACS .mdp input configuration to a file handle.
- Parameters:
input_config – Dictionary of configuration key-value pairs.
f – File handle to write to.
- mythos.input.gromacs_input.write_mdp(input_config: dict, input_file: pathlib.Path) None[source]
Write a GROMACS .mdp input file.
- Parameters:
input_config – Dictionary of configuration key-value pairs.
input_file – Path to write the .mdp file.
- mythos.input.gromacs_input.update_mdp_params(mdp_file: pathlib.Path, params: dict, out_file: pathlib.Path | None = None) None[source]
Update parameters in a GROMACS .mdp file.
- Parameters:
mdp_file – Path to the .mdp file to update.
params – Dictionary of parameters to update.
out_file – Optional path to write the updated .mdp file. By default overwrites the original file.
- class mythos.input.gromacs_input.GromacsParamsParser(filename: str | pathlib.Path)[source]
Parser and parameter replacer for params in GROMACS topology files.
Reads in a preprocessed topology file, extracts parameters into structured dictionaries. When writing, it replaces parameters in the original file with values from a provided dictionary, preserving other content.
In both cases, it is important the topology file is preprocessed to in order that macros have been expanded.
- file
- parse() dict[str, ParamsDict][source]
Parse topology content and return structured data.
- Returns:
Dictionary with keys ‘nonbond_params’, ‘bond_params’, ‘angle_params’, each mapping parameter names to values.
- Raises:
ValueError – If nonbond_params references unknown atom types.
- replace(params: ParamsDict, output_file: str | pathlib.Path) None[source]
Write topology with replaced parameters to a new file.
Reads the original topology file and writes a new file with parameters replaced from the provided dictionary.
- Parameters:
params – Dictionary mapping parameter names to new values. Keys should match the format from parse(): - “bond_k_MOLNAME_ATOMI_ATOMJ”, “bond_r0_MOLNAME_ATOMI_ATOMJ” - “angle_k_MOLNAME_ATOMI_ATOMJ_ATOMK”, “angle_theta0_MOLNAME_ATOMI_ATOMJ_ATOMK” - “lj_sigma_TYPE1_TYPE2”, “lj_epsilon_TYPE1_TYPE2”
output_file – Path to write the modified topology.
- mythos.input.gromacs_input.read_params_from_topology(topology_file: pathlib.Path) dict[str, ParamsDict][source]
Read a preprocessed GROMACS topology file.
This parses the [atomtypes] section to get bead types, the [nonbond_params] section for nonbonded parameters, and all [moleculetype] sections for bonds and angles.
Parameters are stored with descriptive keys: - Bonds: “bond_k_MOLNAME_ATOMI_ATOMJ” and “bond_r0_MOLNAME_ATOMI_ATOMJ” - Angles: “angle_k_MOLNAME_ATOMI_ATOMJ_ATOMK” and “angle_theta0_MOLNAME_ATOMI_ATOMJ_ATOMK” - Nonbonded: “lj_sigma_TYPE1_TYPE2” and “lj_epsilon_TYPE1_TYPE2”
- Parameters:
topology_file – Path to the preprocessed topology file.
- Returns:
Dictionary with keys ‘nonbond_params’, ‘bond_params’, ‘angle_params’.
- mythos.input.gromacs_input.replace_params_in_topology(topology_file: pathlib.Path, params: ParamsDict, output_file: pathlib.Path) None[source]
Write a modified GROMACS topology file with replaced parameters.
Reads an existing topology file and writes a new file with parameters replaced from the provided dictionary.
- Parameters:
topology_file – Path to the input preprocessed topology file.
params – Dictionary mapping parameter names to new values.
output_file – Path to write the modified topology.