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(µstate)?;§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(µstate)?
.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§
Sourcefn append_microstate(
&mut self,
microstate: &Microstate<B, S, X, C>,
) -> Result<Frame<'_>, AppendError>
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.