pub struct Writer { /* private fields */ }Expand description
Writer for TACO trajectory files
Implementations§
Source§impl Writer
impl Writer
Sourcepub fn create<P: AsRef<Path>>(
path: P,
num_atoms: u32,
time_step: f64,
simulation_metadata: SimulationMetadata,
atom_metadata: AtomMetadata,
compression_settings: CompressionSettings,
) -> Result<Self>
pub fn create<P: AsRef<Path>>( path: P, num_atoms: u32, time_step: f64, simulation_metadata: SimulationMetadata, atom_metadata: AtomMetadata, compression_settings: CompressionSettings, ) -> Result<Self>
Create a new TACO writer
Sourcepub fn append<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn append<P: AsRef<Path>>(path: P) -> Result<Self>
Open an existing TACO file for appending frames
This method allows you to add more frames to an existing TACO trajectory file without rewriting the entire file. The append operation:
- Reads the existing file header and frame index
- Loads the last frame as the reference for delta encoding
- Positions the file pointer at the end of the frame data
- Allows writing new frames with proper delta encoding chain
- Updates the frame index and header when
finish()is called
§Important Notes
- The delta encoding chain is maintained by using the last existing frame as the reference for the first appended frame
- Full frame intervals are respected based on the total frame count
- All metadata (atom count, compression settings, etc.) is preserved
- The original frame index is overwritten when new frames are appended
§Example
use taco_format::{Writer, Reader, Frame, FrameData, SimulationMetadata, AtomMetadata, CompressionSettings};
use ndarray::Array2;
// Create an initial trajectory file
let mut writer = Writer::create(
"trajectory.taco",
3,
0.001,
SimulationMetadata::default(),
AtomMetadata::default(),
CompressionSettings::default(),
)?;
// Write some initial frames
let positions = Array2::<f32>::zeros((3, 3));
for i in 0..10 {
let frame = Frame::new(i, i as f64 * 0.001, FrameData::new(positions.clone()));
writer.write_frame(frame)?;
}
writer.finish()?;
// Later, append more frames
let mut writer = Writer::append("trajectory.taco")?;
for i in 10..20 {
let frame = Frame::new(i, i as f64 * 0.001, FrameData::new(positions.clone()));
writer.write_frame(frame)?;
}
writer.finish()?;
// Verify we now have 20 frames
let reader = Reader::open("trajectory.taco")?;
assert_eq!(reader.num_frames(), 20);§Errors
Returns an error if:
- The file does not exist or cannot be opened
- The file is not a valid TACO format file
- The file is corrupted or has an invalid frame index
Sourcepub fn create_with_header<P: AsRef<Path>>(
path: P,
header: Header,
) -> Result<Self>
pub fn create_with_header<P: AsRef<Path>>( path: P, header: Header, ) -> Result<Self>
Create a new TACO writer with a custom header
Sourcepub fn write_frame(&mut self, frame: Frame) -> Result<()>
pub fn write_frame(&mut self, frame: Frame) -> Result<()>
Write a single frame
Auto Trait Implementations§
impl Freeze for Writer
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnsafeUnpin for Writer
impl UnwindSafe for Writer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more