h5md_reader

A module containing a reader for H5MD trajectory files.

H5MD files are HDF5 files, see https://www.nongnu.org/h5md/. Reading them needs the optional dependency h5py (pip install PQAnalysis[h5md]).

Summary

Classes:

H5MDReader

A class for reading the frames of a single H5MD trajectory file.

Reference

class H5MDReader(filename: str)[source]

Bases: object

A class for reading the frames of a single H5MD trajectory file.

All present time-dependent elements must share the same steps. Values are converted to the PQ units used in PQAnalysis: Angstrom, Angstrom s-1, kcal mol-1 Angstrom-1, e and kcal mol-1. A unit that is missing or not known raises an H5MDReaderError.

Generally, this class should not be used directly. Instead, use the TrajectoryReader with traj_format="h5md" or a .h5md/.h5 file.

Parameters:

filename (str) – The name of the H5MD file.

Raises:

H5MDReaderError – If h5py is not installed.

cell_generator() → Generator[Cell][source]

A generator that yields the cell of each frame.

Yields:

Cell – The cell of the frame, a vacuum cell if the file has no box.

frame_generator(
start: int = 0,
stop: int | None = None,
topology: Topology | None = None,
) → Generator[AtomicSystem][source]

A generator that yields the frames of the file.

Parameters:
  • start (int, optional) – The index of the first frame, by default 0.

  • stop (int | None, optional) – The index after the last frame, by default None, meaning all frames.

  • topology (Topology | None, optional) – The topology of the frames, by default None, meaning it is built from /parameters/atom_names and the species.

Yields:

AtomicSystem – The frames with positions in Angstrom, velocities in Angstrom s-1, forces in kcal mol-1 Angstrom-1, charges in e and the potential energy in kcal mol-1.

Raises:

H5MDReaderError – If the file is not a valid H5MD trajectory or uses a unit that is not supported.

logger = <CustomLogger PQAnalysis.H5MDReader (INFO)>
property number_of_frames: int

The number of frames in the file.

Type:

int

CHARGE_UNITS = {'e': 1.0}

Factors from H5MD charge units to e.

ENERGY_UNITS = {'kcal mol-1': 1.0}

Factors from H5MD energy units to kcal mol-1.

FORCE_UNITS = {'kcal mol-1 Angstrom-1': 1.0}

Factors from H5MD force units to kcal mol-1 Angstrom-1.

LENGTH_UNITS = {'Angstrom': 1.0, 'nm': 10.0}

Factors from H5MD length units to Angstrom.

VELOCITY_UNITS = {'Angstrom fs-1': 1000000000000000.0, 'Angstrom ps-1': 1000000000000.0, 'Angstrom s-1': 1.0, 'nm ps-1': 10000000000000.0}

Factors from H5MD velocity units to Angstrom s-1.