GROMACS Energy (.edr) Parser

Parser for GROMACS energy (.edr) files.

class kbkit.io.edr.EdrParser(path: str | Path)[source]

Bases: object

Interface for extracting energy properties from GROMACS .edr files.

Wraps gmx energy to provide access to available properties in .edr file. Supports additional properties, configurational_enthalpy and fluctuation properties (heat capacity and isothermal compressibility). Note that the fluctuation properties return a float object rather than a timeseries.

Parameters:

edr_path (str or list[str]) – Path to an .edr file.

GROMACS_UNITS: ClassVar = {'density': 'kg/m^3', 'enthalpy': 'kJ/mol', 'kinetic-en': 'kJ/mol', 'potential': 'kJ/mol', 'pressure': 'bar', 'temperature': 'K', 'time': 'ps', 'total-energy': 'kJ/mol', 'volume': 'nm^3'}
DEFAULT_UNITS: ClassVar = {'cp': 'kJ/mol/K', 'cv': 'kJ/mol/K', 'density': 'kg/m^3', 'enthalpy': 'kJ/mol', 'isothermal-compressibility': '1/kPa', 'kinetic-en': 'kJ/mol', 'molar-volume': 'cm^3/mol', 'number-density': 'molecule/nm^3', 'potential': 'kJ/mol', 'pressure': 'kPa', 'temperature': 'K', 'time': 'ps', 'total-energy': 'kJ/mol', 'volume': 'nm^3'}
FLUCT_PROPS: ClassVar = ('cp', 'cv', 'isothermal-compressibility')
property units: dict[str, str]

Returns a dictionary mapping properties to their units.

get_gmx_property(name: str, avg: bool = False, **kwargs) tuple | float[source]

Extract gromacs property from energy file.

Parameters:
  • name (str) – Name of property to extract using gmx energy.

  • kwargs (dict[str, str]) – Dictionary of optional inputs to gmx energy command (e.g., {“-b”: 10000})

Returns:

Tuple of property time series (time, values).

Return type:

tuple

property data: dict[str, ndarray]

Extract energy data from EDR file.

available_properties() list[str][source]

Return a list of available energy properties in the .edr file(s).

Returns:

Sorted list of property names in .edr files.

Return type:

list[str]

get(name: str, start_time: float = 0, units: str | None = None) ndarray[source]

Extract time series data for a given property.

Parameters:
  • name (str) – Property name to extract (e.g., “potential”, “temperature”).

  • start_time (float, optional) – time (in ps) after which data should be included.

  • units (str, optional) – Returns property in desired units. If empty, used default values (See units()).

Returns:

  • np.ndarray – Array of values.

  • .. note:: – Filters data based on start_time for reproducibility.

molar_volume(nmol: int, volume: float = 0, start_time: float = 0, units: str | None = None) ndarray | float[source]

Calculate molar volume of a simulation.

If ensemble is NVT, i.e., volume is not accessible in .edr file, an input volume is required (i.e., read from bottom of .gro file in SystemProperties).

Parameters:
  • nmol (int) – Number of total molecules in system.

  • volume (float, optional) – Simulation box volume.

  • start_time (float, optional) – Start time for enthalpy calculation.

  • units (str, optional) – Desired output units. Defaults to pyedr units (kJ/mol).

Returns:

Molar volume of molecular simulation.

Return type:

np.ndarray

configurational_enthalpy(volume: float = 0, start_time: float = 0, units: str | None = None) ndarray[source]

Calculate enthalpy from potential energy.

If ensemble is NVT, i.e., volume is not accessible in .edr file, an input volume is required (i.e., read from bottom of .gro file in SystemProperties).

Parameters:
  • volume (float, optional) – Simulation box volume.

  • start_time (float, optional) – Start time for enthalpy calculation.

  • units (str, optional) – Desired output units. Defaults to pyedr units (kJ/mol).

Returns:

Enthalpy of molecular simulation.

Return type:

np.ndarray

Notes

Enthalpy, \(H\), is calculated from potential energy (\(U\)) according to:

\[H = U + pV\]
where:
  • \(p\) is pressure

  • \(V\) is volume

molar_enthalpy(nmol: int, volume: float = 0, start_time: float = 0, units: str | None = None) ndarray[source]

Calculate molar enthalpy.

Parameters:
  • nmol (int) – Number of total molecules in system.

  • volume (float, optional) – Simulation box volume.

  • start_time (float, optional) – Start time for enthalpy calculation.

  • units (str, optional) – Desired output units. Defaults to pyedr units (kJ/mol).

Returns:

Configurational enthalpy normalized by the total number of molecules.

Return type:

np.ndarray

cp(nmol: int, volume: float = 0, start_time: float = 0, units: str | None = None) float[source]

Calculate constant pressure heat capacity from configurational_enthalpy().

Parameters:
  • nmol (int) – Number of total molecules in system.

  • volume (float, optional) – Simulation box volume.

  • start_time (float, optional) – Start time for enthalpy calculation.

  • units (str, optional) – Desired output units. Defaults to pyedr units (kJ/mol).

Returns:

Constant pressure heat capacity.

Return type:

float

Notes

Constant pressure heat capacity, \(c_p\) is calculated according to:

\[\begin{split}\begin{aligned} c_p &= \frac{\langle H^2 \rangle - \langle H \rangle ^2}{k_B T^2} \\ &= \frac{\sigma_H^2}{k_B T^2} \end{aligned}\end{split}\]
where:
  • \(\langle H^2 \rangle - \langle H \rangle ^2\) is the variance of the enthalpy (also writted as \(\sigma_H^2\))

  • \(k_B\) is Boltzmann constant

  • \(T\) is absolute temperature

cv(nmol: int, start_time: float = 0, units: str | None = None) float[source]

Calculate constant volume heat capacity.

Parameters:
  • nmol (int) – Number of total molecules in system.

  • start_time (float, optional) – Start time for enthalpy calculation.

  • units (str, optional) – Desired output units. Defaults to pyedr units (kJ/mol).

Returns:

Constant volume heat capacity.

Return type:

float

Notes

Constant volume heat capacity, \(c_v\) is calculated according to:

\[\begin{split}\begin{aligned} c_v &= \frac{\langle U^2 \rangle - \langle U \rangle ^2}{k_B T^2} \\ &= \frac{\sigma_U^2}{k_B T^2} \end{aligned}\end{split}\]
where:
  • \(\langle U^2 \rangle - \langle U \rangle ^2\) is the variance of the potential (also writted as \(\sigma_U^2\))

  • \(k_B\) is Boltzmann constant

  • \(T\) is absolute temperature

isothermal_compressibility(start_time: float = 0, units: str | None = None) float[source]

Isothermal compressibility.

Parameters:
  • start_time (float, optional) – Start time for enthalpy calculation.

  • units (str, optional) – Desired output units. Defaults to pyedr units (kJ/mol).

Returns:

Isothermal compressibility.

Return type:

float