eightyseven

Crates.ioeightyseven
lib.rseightyseven
version0.1.4
sourcesrc
created_at2024-05-07 11:51:24.478831
updated_at2024-07-18 15:57:57.656098
descriptionRead and write gro files, pretty quickly.
homepage
repositoryhttps://git.sr.ht/~ma3ke/eightyseven
max_upload_size
id1232093
size444,700
Marieke Westendorp (ma3ke)

documentation

README

eightyseven—read and write gro files, pretty quickly

A gro file (Gromos87) describes molecular structures in a plain-text format. (See the Gromacs manual or the old pretty manual.)

Note that, for now, only reading and writing of the classic fixed format is supported. The additional precision reading mode is on the agenda.

eightyseven can format the atoms section of a gro file in a parallel fashion, with WriteGro::write_par and related methods.

This library comes with its own Structure type, which mirrors the information that is stored in gro files. For Structure, the ReadGro, WriteGro, and WriteGroPar traits are implemented. The reading and writing functionality provided by these traits are provided as good default implementations, which rely on a couple of easy to implement bridging functions. This makes implementing the traits for custom types very easy.

Moreover, rather specialized readers that read only a subset of the atom line fields can be implemented easily and efficiently by setting the flags of the ReadGro::PARSE_LIST constant.

use eightyseven::structure::Structure;

// Read the structure from a file.
use eightyseven::reader::ReadGro;
let mut structure = Structure::open_gro("tests/eq.gro")?;
println!(" title: {}", structure.title);
println!("natoms: {}", structure.natoms());

// Modify the structure.
// For example, center the structure such that the `BB` beads are centered.
let bb_positions = structure
    .atoms
    .iter()
    .filter(|&atom| atom.atomname.as_str() == "BB")
    .map(|atom| atom.position);
let bb_center = bb_positions.clone().sum::<glam::Vec3>() / bb_positions.count() as f32;

for atom in &mut structure.atoms {
    atom.position -= bb_center;
}

// And write the structure.
use eightyseven::writer::WriteGro;
structure.save_gro("eq_offset.gro")?;

// Or, for fast writing of large files, format the atom section in parallel.
use eightyseven::writer::WriteGroPar;
structure.save_gro_par("eq_offset.gro")?;

// For both single-threaded and parallel formatting, generic writers exist as well.
// They can write to any type that implements `io::Write`.
structure.write_par(&mut std::io::empty())?;

Documentation

Documentation is available at docs.rs. Or locally, with cargo doc.

Installation

The usual installation procedure applies.

$ cargo add eightyseven

Tests and benchmarks

Tests and benchmarks are included. Run them in the cloned repository.

$ git clone https://git.sr.ht/~ma3ke/eightyseven
$ cd eightyseven
$ cargo test
$ cargo bench

See also

I have written an xtc reader library as well, called molly. xtc is a compressed trajectory format for Gromacs.

The graphing data format that is output by Gromacs analysis commands is xvg. phrace is a terminal viewer for that data format.


By Marieke Westendorp, 2024.

Commit count: 0

cargo fmt