mrc
Type-safe MRC-2014 file format reader/writer for Rust
A high-performance, memory-efficient library for reading and writing MRC (Medical Research Council) format files used in cryo-electron microscopy and structural biology.
Note: This crate is under active development. While most features are functional, occasional API changes are possible. Contributions welcome — please report issues and share your ideas!
Installation
[]
= "0.2"
Quick Start
use ;
// Read (auto-detects gzip/bzip2)
let reader = open?;
for slice in reader.slices_f32
// Write
let mut writer = create
.shape
.
.finish?;
writer.write_block?;
writer.finalize?;
Full Documentation
See docs.rs/mrc for the complete API reference, including:
- Reading files —
Reader,MmapReader, compressed I/O, permissive mode - Writing files —
Writer,MmapWriter,GzipWriter,Bzip2Writer - Iterators — slices, slabs, tiles, volumes, auto-conversion to
f32 - Full-volume reads —
read_volume::<T>()andread_volume_f32() - Data modes —
Modeenum and compile-timeVoxeltrait - Headers —
Header,HeaderBuilder, validation, endianness - FEI extended headers — typed
Fei1Metadata/Fei2Metadataparsing - Error handling —
ErrorandHeaderValidationError - Validation —
validate_full/validate_reader/ValidationReport
CLI Tools
| Binary | Description |
|---|---|
mrc-validate |
Comprehensive file validation (header, stats, NaN/Inf scan) |
mrc-header |
Human-readable header inspection with semantic interpretation |
mrc-invert |
Contrast inversion (v → −v) with updated header statistics |
Migrating from v0.1
| v0.1 | v0.2 |
|---|---|
MrcView::new(data) |
Reader::open(path) / open(path) |
MrcFile::create(path, header) |
create(path).shape(dims).mode::<T>().finish() |
MrcView::view::<f32>() |
reader.slices::<f32>() |
MrcViewMut |
Writer + VoxelBlock<T> |
MrcMmap |
MmapReader / MmapWriter |
v0.2 adds SIMD acceleration, parallel encoding, type conversion iterators, compression support, unified reader API, and FEI extended header parsing.
Roadmap
v0.2.x — Core + SIMD + FEI (current)
- Complete MRC-2014 format support
- Iterator-centric API (slices, slabs, tiles)
- Type-safe I/O with compile-time mode checking
- SIMD acceleration (AVX2, NEON)
- Memory-mapped I/O and parallel encoding
- All data types (modes 0–4, 6, 12, 101)
- Compression support (gzip, bzip2)
- FEI1/FEI2 extended header parsing
- Header statistics computation and validation
- Permissive mode and volume stack support
v0.3.x — Extended Features
- Extended header parsing for CCP4, MRCO, SERI, AGAR formats
- Streaming decompression
- Dedicated benchmark suite
License
MIT — see LICENSE.
Acknowledgments
- CCP-EM for the MRC-2014 specification
- EMDB for providing real-world test data
- Cryo-EM community for invaluable feedback