Crate xdrfile

Source
Expand description

§xdrfile

Read and write xdr trajectory files in .xtc and .trr file format

This crate is mainly intended to be a wrapper around the GROMACS libxdrfile XTC library and provides basic functionality to read and write xtc and trr files with a safe api.

§Basic usage example

use xdrfile::*;

fn main() -> Result<()> {
    // get a handle to the file
    let mut trj = XTCTrajectory::open_read("tests/1l2y.xtc")?;

    // find number of atoms in the file
    let num_atoms = trj.get_num_atoms()?;

    // a frame object is used to get to read or write from a trajectory
    // without instantiating data arrays for every step
    let mut frame = Frame::with_len(num_atoms);

    // read the first frame of the trajectory
    trj.read(&mut frame)?;

    assert_eq!(frame.step, 1);
    assert_eq!(frame.len(), num_atoms);

    let first_atom_coords = frame.coords[0];
    assert_eq!(first_atom_coords, [-0.8901, 0.4127, -0.055499997]);

    Ok(())
}

§Frame iteration

For convenience, the trajectory implementations provide “into_iter” to be turned into an iterator that yields Rc. If a frame is not kept during iteration, the Iterator reuses it for better performance (and hence, Rc is required)

use xdrfile::*;

fn main() -> Result<()> {
    // get a handle to the file
    let trj = XTCTrajectory::open_read("tests/1l2y.xtc")?;

    // iterate over all frames
    for (idx, result) in trj.into_iter().enumerate() {
        let frame = result?;
        println!("{}", frame.time);
        assert_eq!(idx+1, frame.step);
    }
    Ok(())
}

Modules§

c_abi
Low level bindings to the c library from GROMACS

Structs§

Frame
A frame represents a single step in a trajectory.
TRRTrajectory
Handle to Read/Write TRR Trajectories
TrajectoryIterator
Iterator for trajectories. This iterator yields a Result<Frame, Error> for each frame in the trajectory file and stops with yielding None once the trajectory is EOF. Also yields None after the first occurrence of an error
XTCTrajectory
Handle to Read/Write XTC Trajectories

Enums§

Error
Error type for the xdrfile library
ErrorCode
Error codes returned from the C API
ErrorTask
The task being attempted when the C API returns an error
FileMode
File Mode for accessing trajectories.

Traits§

Trajectory
The trajectory trait defines shared methods for xtc and trr trajectories

Type Aliases§

Result
Result type for errors in the xdrfile crate