Crate extxyz

Source
Expand description

Read large trajectory file in xyz/extxyz format

§Example

use extxyz::{read_xyz_frames, RawAtoms, Info};
 
fn main() -> anyhow::Result<()> {
    // a large xyz/extxyz trajectory file
    let f = "nmd.xyz";
    // skip the first 100 frames, and read frames with a step size `10`
    let selection = (100..).step_by(10);
    let frames = read_xyz_frames(f, selection)?;
    for frame in frames {
        let atoms = RawAtoms::parse_from(&frame)?;
        // it will returen error if the comment is not in normal extxyz format
        let info: Info = atoms.comment.parse()?;
        // get molecule's properties
        let energy = info.get("energy").unwrap();
        // get atom's properties
        for atom in atoms.atoms {
            // parse extra data for each atom
            let atom_properties = info.parse_extra_columns(&atom.extra)?;
            // get `forces` component for each atom
            let forces = &atom_properties["forces"];
        }
    }
 
    Ok(())
}

Structs§

Info
Represents the data parsed from extxyz comment line.
RawAtom
Represents the parsed atom in raw xyz format
RawAtoms
Represents the parsed atoms in raw xyz format

Functions§

read_xyz_frames
Return an iterator that yields strings of the selected frames in the xyz/extxyz format from trajectory in path. Reading frames selectively is suitable for large trajectory files.
read_xyz_frames_direct
Return an iterator that yields strings of the selected frames in the xyz/extxyz format from trajectory in path. Supports large trajectory files.
read_xyz_frames_two_pass
Return an iterator that yields strings of the selected frames in the xyz/extxyz format from trajectory in path. Reading frames selectively is suitable for large trajectory files.