mythos.input.gromacs_input ========================== .. py:module:: mythos.input.gromacs_input .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: mythos.input.gromacs_input.logger mythos.input.gromacs_input.ParamsDict mythos.input.gromacs_input.INVALID_LINE Classes ------- .. autoapisummary:: mythos.input.gromacs_input.GromacsParamsParser Functions --------- .. autoapisummary:: mythos.input.gromacs_input._parse_numeric mythos.input.gromacs_input._parse_boolean mythos.input.gromacs_input._parse_value mythos.input.gromacs_input.read_mdp mythos.input.gromacs_input.write_mdp_to mythos.input.gromacs_input.write_mdp mythos.input.gromacs_input.update_mdp_params mythos.input.gromacs_input.read_params_from_topology mythos.input.gromacs_input.replace_params_in_topology Module Contents --------------- .. py:data:: logger .. py:type:: ParamsDict :canonical: dict[str, float] .. py:data:: INVALID_LINE :value: 'Invalid line: {}' .. py:function:: _parse_numeric(value: str) -> tuple[float | int, bool] Try to parse a value as a numeric type. .. py:function:: _parse_boolean(value: str) -> tuple[bool, bool] Try to parse a value as a boolean. .. py:function:: _parse_value(value: str) -> str | float | int | bool Parse a value string, handling comments and type inference. .. py:function:: read_mdp(input_file: pathlib.Path) -> dict[str, str | float | int | bool] Read a GROMACS .mdp input file. :param input_file: Path to the .mdp file. :returns: Dictionary of key-value pairs from the input file. .. py:function:: write_mdp_to(input_config: dict, f: io.TextIOWrapper) -> None Write a GROMACS .mdp input configuration to a file handle. :param input_config: Dictionary of configuration key-value pairs. :param f: File handle to write to. .. py:function:: write_mdp(input_config: dict, input_file: pathlib.Path) -> None Write a GROMACS .mdp input file. :param input_config: Dictionary of configuration key-value pairs. :param input_file: Path to write the .mdp file. .. py:function:: update_mdp_params(mdp_file: pathlib.Path, params: dict, out_file: pathlib.Path | None = None) -> None Update parameters in a GROMACS .mdp file. :param mdp_file: Path to the .mdp file to update. :param params: Dictionary of parameters to update. :param out_file: Optional path to write the updated .mdp file. By default overwrites the original file. .. py:class:: GromacsParamsParser(filename: str | pathlib.Path) 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. .. py:attribute:: file .. py:method:: _parser_init() -> None .. py:method:: parse() -> dict[str, ParamsDict] 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. .. py:method:: replace(params: ParamsDict, output_file: str | pathlib.Path) -> None 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. :param 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" :param output_file: Path to write the modified topology. .. py:method:: _process_line(line: str) -> None .. py:method:: _handle_section_header(stripped: str) -> None .. py:method:: _handle_section_data(stripped: str, original_line: str) -> None .. py:method:: _handle_molecule_section_data(section: str | None, parts: list[str], original_line: str) -> str .. py:method:: _handle_nonbond_params(parts: list[str], original_line: str) -> str .. py:function:: read_params_from_topology(topology_file: pathlib.Path) -> dict[str, ParamsDict] 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" :param topology_file: Path to the preprocessed topology file. :returns: Dictionary with keys 'nonbond_params', 'bond_params', 'angle_params'. .. py:function:: replace_params_in_topology(topology_file: pathlib.Path, params: ParamsDict, output_file: pathlib.Path) -> None 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. :param topology_file: Path to the input preprocessed topology file. :param params: Dictionary mapping parameter names to new values. :param output_file: Path to write the modified topology.