Gromacs  2026.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::H5md Class Reference

#include <gromacs/fileio/h5md/h5md.h>

Description

Manager of an H5MD filehandle. The class is designed to read/write data according to de Buyl et al., 2014 (https://doi.org/10.1016/j.cpc.2014.01.018) and https://www.nongnu.org/h5md/h5md.html.

Public Member Functions

 H5md (const std::filesystem::path &fileName, H5mdFileMode mode)
 Open an H5MD file and manage its filehandle. More...
 
 H5md (const H5md &)=delete
 
H5mdoperator= (const H5md &)=delete
 
 H5md (H5md &&)=delete
 
H5mdoperator= (H5md &&)=delete
 
hid_t fileid () const
 Return the HDF5 handle of the file. More...
 
void flush (bool throwExceptionUponError=true)
 Write all unwritten data to the file. More...
 
void setupFileFromInput (const gmx_mtop_t &topology, const t_inputrec &inputRecord)
 Set up the file from input data. More...
 
void setupFromExistingFile ()
 Set up from an existing file. More...
 
void setupFromExistingFileForAppending (int64_t restartingFromStep, int64_t numParticles)
 Set up from an existing file when restarting a simulation from a checkpoint. More...
 
bool readNextFrame (t_trxframe *frame, const std::string &selectionName="system")
 Read the next frame of the trajectory. More...
 
void writeNextFrame (ArrayRef< const RVec > positions, ArrayRef< const RVec > velocities, ArrayRef< const RVec > forces, const matrix box, int64_t step, double time)
 Write input data as the next frame of the trajectory. More...
 

Constructor & Destructor Documentation

gmx::H5md::H5md ( const std::filesystem::path &  fileName,
H5mdFileMode  mode 
)

Open an H5MD file and manage its filehandle.

Parameters
[in]fileNameName of the file to open. The same as the file path.
[in]modeThe mode to open the file.
Exceptions
FileIOErrorif fileName is specified and the file cannot be opened.

Member Function Documentation

hid_t gmx::H5md::fileid ( ) const

Return the HDF5 handle of the file.

This handle is used as the root container of the file's data hierarchy, to which the tree of groups and data sets can be added.

Returns
The file handle.
void gmx::H5md::flush ( bool  throwExceptionUponError = true)

Write all unwritten data to the file.

Parameters
[in]throwExceptionUponErrorWhether to throw an exception if an error occurs. Assumes a valid file_ identifier.
Exceptions
FileIOErrorIf there were errors during flushing (and throwExceptionUponError is true).
bool gmx::H5md::readNextFrame ( t_trxframe *  frame,
const std::string &  selectionName = "system" 
)

Read the next frame of the trajectory.

Parameters
[out]frameContainer to read data into.
[in]selectionNameName of group to read frame for.
Returns
True if a frame was read, otherwise false.
void gmx::H5md::setupFileFromInput ( const gmx_mtop_t &  topology,
const t_inputrec &  inputRecord 
)

Set up the file from input data.

Parameters
[in]topologyTopology data of system.
[in]inputRecordSimulation parameters.
void gmx::H5md::setupFromExistingFile ( )

Set up from an existing file.

Scans for trajectory data available in the /particles/system group of the HDF5 file. For trajectories written by GROMACS this group contains data for all atoms in the simulated system.

Note
Ignores trajectory data in other subgroups of /particles.
void gmx::H5md::setupFromExistingFileForAppending ( int64_t  restartingFromStep,
int64_t  numParticles 
)

Set up from an existing file when restarting a simulation from a checkpoint.

Scans for trajectory data available in the /particles/system group of the HDF5 file. For trajectories written by GROMACS this group contains data for all atoms in the simulated system.

Note
Ignores trajectory data in other subgroups of /particles.
Parameters
[in]restartingFromStepStep which we are restarting the simulation from
[in]numParticlesNumber of particles in system
Exceptions
gmx::FileIOErrorif the existing file contents are not for a system of numParticles.
void gmx::H5md::writeNextFrame ( ArrayRef< const RVec positions,
ArrayRef< const RVec velocities,
ArrayRef< const RVec forces,
const matrix  box,
int64_t  step,
double  time 
)

Write input data as the next frame of the trajectory.

Parameters
[in]positionsPosition data to write (or empty if not to write).
[in]velocitiesVelocity data to write (or empty if not to write).
[in]forcesForce data to write (or empty if not to write).
[in]boxSimulation box for frame.
[in]stepSimulation step for frame.
[in]timeSimulation time for frame.
Exceptions
gmx::FileIOErrorif position, velocity or force data is given but the corresponding data set has not been created, or if the size of the data buffers do not match the number of atoms of the system.

The documentation for this class was generated from the following files: