Skip to main content

AppendMicrostate

Trait AppendMicrostate 

Source
pub trait AppendMicrostate<B, S, X, C> {
    // Required method
    fn append_microstate(
        &mut self,
        microstate: &Microstate<B, S, X, C>,
    ) -> Result<Frame<'_>, AppendError>;
}
Expand description

Write a frame to a GSD file with the contents of a microstate.

§Basic usage

hoomd-microstate implements AppendMicrostate for typical combinations of Point/OrientedPoint site types with commonly used boundary conditions. The provided implementations write all sites to the GSD file.

use hoomd_geometry::shape::Rectangle;
use hoomd_gsd::hoomd::HoomdGsdFile;
use hoomd_microstate::{
    AppendMicrostate, Body, Microstate, boundary::Closed, property::Point,
};
use hoomd_vector::Cartesian;

let square = Closed(Rectangle::with_equal_edges(10.0.try_into()?));

let microstate = Microstate::builder()
    .boundary(square)
    .bodies([
        Body::point(Cartesian::from([1.0, 0.0])),
        Body::point(Cartesian::from([-1.0, 2.0])),
    ])
    .try_build()?;

// let path = "file.gsd";
let mut hoomd_gsd_file = HoomdGsdFile::create(path)?;
hoomd_gsd_file.append_microstate(&microstate)?;

§Writing additional data chunks

append_microstate returns the GSD Frame so you can add data chunks to the frame, such as log values.

use hoomd_geometry::shape::Rectangle;
use hoomd_gsd::hoomd::HoomdGsdFile;
use hoomd_microstate::{
    AppendMicrostate, Body, Microstate, boundary::Closed, property::Point,
};
use hoomd_vector::Cartesian;

let square = Closed(Rectangle::with_equal_edges(10.0.try_into()?));

let microstate = Microstate::builder()
    .boundary(square)
    .bodies([
        Body::point(Cartesian::from([1.0, 0.0])),
        Body::point(Cartesian::from([-1.0, 2.0])),
    ])
    .try_build()?;

// let path = "file.gsd";
let mut hoomd_gsd_file = HoomdGsdFile::create(path)?;
hoomd_gsd_file
    .append_microstate(&microstate)?
    .log_scalar("height", 10.0_f64)?
    .log_scalars("energy", [1.0_f64, 2.0, 3.0])?;

§Custom implementations

You can implement AppendMicrostate for your custom site type and/or boundary condition. Your implementation could choose to write bodies instead of sites. See the “Type-dependent Interactions” tutorial for a complete example.

Required Methods§

Source

fn append_microstate( &mut self, microstate: &Microstate<B, S, X, C>, ) -> Result<Frame<'_>, AppendError>

Append the contents of the microstate as a frame in a GSD file.

§Errors

Returns an AppendError when any of the following occur:

  • The file is not opened in a write mode.
  • An I/O error writing to the file.

Implementations on Foreign Types§

Source§

impl<B, X> AppendMicrostate<B, OrientedPoint<Cartesian<2>, Angle>, X, Closed<Hypercuboid<2>>> for HoomdGsdFile

Source§

impl<B, X> AppendMicrostate<B, OrientedPoint<Cartesian<2>, Angle>, X, Periodic<Hypercuboid<2>>> for HoomdGsdFile

Source§

impl<B, X> AppendMicrostate<B, OrientedPoint<Cartesian<3>, Versor>, X, Closed<Hypercuboid<3>>> for HoomdGsdFile

Source§

impl<B, X> AppendMicrostate<B, OrientedPoint<Cartesian<3>, Versor>, X, Periodic<Hypercuboid<3>>> for HoomdGsdFile

Source§

impl<B, X> AppendMicrostate<B, Point<Cartesian<2>>, X, Closed<Hypercuboid<2>>> for HoomdGsdFile

Source§

fn append_microstate( &mut self, microstate: &Microstate<B, Point<Cartesian<2>>, X, Closed<Hypercuboid<2>>>, ) -> Result<Frame<'_>, AppendError>

Source§

impl<B, X> AppendMicrostate<B, Point<Cartesian<2>>, X, Periodic<Hypercuboid<2>>> for HoomdGsdFile

Source§

fn append_microstate( &mut self, microstate: &Microstate<B, Point<Cartesian<2>>, X, Periodic<Hypercuboid<2>>>, ) -> Result<Frame<'_>, AppendError>

Source§

impl<B, X> AppendMicrostate<B, Point<Cartesian<3>>, X, Closed<Hypercuboid<3>>> for HoomdGsdFile

Source§

fn append_microstate( &mut self, microstate: &Microstate<B, Point<Cartesian<3>>, X, Closed<Hypercuboid<3>>>, ) -> Result<Frame<'_>, AppendError>

Source§

impl<B, X> AppendMicrostate<B, Point<Cartesian<3>>, X, Periodic<Hypercuboid<3>>> for HoomdGsdFile

Source§

fn append_microstate( &mut self, microstate: &Microstate<B, Point<Cartesian<3>>, X, Periodic<Hypercuboid<3>>>, ) -> Result<Frame<'_>, AppendError>

Implementors§