Skip to main content

Writer

Struct Writer 

Source
pub struct Writer { /* private fields */ }
Expand description

Writer for TACO trajectory files

Implementations§

Source§

impl Writer

Source

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

Source

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
Source

pub fn create_with_header<P: AsRef<Path>>( path: P, header: Header, ) -> Result<Self>

Create a new TACO writer with a custom header

Source

pub fn write_frame(&mut self, frame: Frame) -> Result<()>

Write a single frame

Source

pub fn write_frames(&mut self, frames: Vec<Frame>) -> Result<()>

Write multiple frames sequentially

Source

pub fn finish(self) -> Result<()>

Finish writing the file, write the index and update the header

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,