Library architecture¶
1 Overview¶
readcon-core is structured as an hourglass API: a Rust core with thin FFI and language-specific wrapper layers.
Python (PyO3) Julia (ccall) C++ (RAII header)
\ | /
\ | /
+------- C FFI (ffi.rs) -----+
|
Rust core library
types | parser | writer | iterators
2 Core types (types.rs)¶
FrameHeader9-line header metadata (cell, angles, atom counts, masses).
AtomDatumSingle atom data (symbol, coordinates, fixed flag, atom ID, optional velocities).
ConFrameComplete frame (header + atom data vector).
Symbol strings use Rc<String> to avoid per-atom string clones
within a type block.
3 Parser (parser.rs)¶
parse_line_of_n<T>Generic whitespace-separated value parser for header lines.
parse_line_of_n_f64fast-float2 specialized parser for the coordinate/velocity hot path.
parse_frame_headerConsumes 9 header lines.
parse_single_frameHeader + coordinate blocks.
parse_velocity_sectionOptional velocity blocks after coordinates (detected by blank separator).
4 Writer (writer.rs)¶
ConFrameWriter<W: Write>Generic buffered writer.
Writes header, coordinate blocks, and velocity blocks (if
frame.has_velocities()).
5 Iterators (iterators.rs)¶
ConFrameIteratorLazy frame-by-frame parser with
next()andforward()(skip without parsing atom data).read_all_frames()Convenience function using memmap2 for large trajectory files.
parse_frames_parallel()Rayon-based parallel parsing behind the
parallelfeature gate.
6 FFI layer (ffi.rs)¶
Opaque handle pattern:
RKRConFrameOpaque Rust frame handle.
CFrame/CAtomTransparent C structs for direct data access.
Iterator lifecycle:
read_con_file_iterator->con_frame_iterator_next->rkr_frame_to_c_frame->free_c_frame->free_rkr_frame->free_con_frame_iterator.
7 C++ wrapper (readcon-core.hpp)¶
Header-only RAII wrappers with lazy caching:
ConFrameIteratorRange-based for loop support.
ConFrameCached accessors for cell, angles, atoms, headers.
ConFrameWriterRAII file writer.