Skip to content

Commit 88e25ff

Browse files
committed
Merge branch 'main' of https://github.com/elemeng/mrc
modified: Cargo.lock modified: Cargo.toml modified: src/header.rs modified: src/lib.rs
2 parents c6d2b94 + cf2370e commit 88e25ff

4 files changed

Lines changed: 86 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ readme = "README.md"
1515
[dependencies]
1616
bytemuck = { version = "1.15", default-features = false, features = ["derive"] }
1717
memmap2 = { version = "0.9", optional = true }
18+
thiserror = { version = "2.0.16", default-features = false }
1819
half = { version = "2.6", optional = true, default-features = false, features = [
1920
"bytemuck",
2021
] }
@@ -53,4 +54,4 @@ default = ["std", "mmap", "file", "f16"]
5354
mmap = ["std", "dep:memmap2"]
5455
file = ["std"]
5556
std = []
56-
f16 = ["dep:half", "std"]
57+
f16 = []

src/header.rs

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,72 @@
1-
use core::f32;
2-
31
#[repr(C, align(4))]
42
#[derive(Debug, Clone, Copy, PartialEq)]
5-
#[non_exhaustive]
63
pub struct Header {
4+
/// number of columns in 3D data array (fast axis)
75
pub nx: i32,
6+
/// Number of rows in 3D data array (medium axis)
87
pub ny: i32,
8+
/// Number of sections in 3D data array (slow axis)
99
pub nz: i32,
10+
/// Mode value (see `Mode` enum)
1011
pub mode: i32,
12+
/// Location of first column in unit cell
1113
pub nxstart: i32,
14+
/// Location of first row in unit cell
1215
pub nystart: i32,
16+
/// Location of first section in unit cell
1317
pub nzstart: i32,
18+
/// Sampling along X axis of unit cell
1419
pub mx: i32,
20+
/// Sampling along Y axis of unit cell
1521
pub my: i32,
22+
/// Sampling along Z axis of unit cell
1623
pub mz: i32,
17-
pub xlen: f32, // Unit cell edge length along X (Å).
18-
pub ylen: f32, // Unit cell edge length along Y (Å).
19-
pub zlen: f32, // Unit cell edge length along Z (Å).
20-
pub alpha: f32, // Angle between Y and Z axes (degrees).
21-
pub beta: f32, // Angle between X and Z axes (degrees).
22-
pub gamma: f32, // Angle between X and Y axes (degrees).
23-
pub mapc: i32, // 1-based index of column axis (1 = X, 2 = Y, 3 = Z).
24-
pub mapr: i32, // 1-based index of row axis.
25-
pub maps: i32, // 1-based index of section axis.
26-
pub dmin: f32, // Minimum density value.
27-
pub dmax: f32, // Maximum density value.
28-
pub dmean: f32, // Mean density value.
29-
pub ispg: i32, // Space-group number (1 = P1).
30-
pub nsymbt: i32, // Bytes of symmetry data following the header.
31-
pub extra: [u8; 100], // Reserved; bytes 8–11 hold EXTTYP, 12–15 NVERSION.
32-
pub origin: [f32; 3], // Volume origin in voxels.
33-
pub map: [u8; 4], // Magic bytes “MAP ”.
34-
pub machst: [u8; 4], // Machine stamp (little-endian: 0x44 0x44 0x00 0x00).
35-
pub rms: f32, // RMS deviation of density values.
36-
pub nlabl: i32, // Number of valid labels (0–10).
37-
pub label: [u8; 800], // Ten 80-byte text labels.
24+
/// CELLA: Cell dimensions (unit cell edge length) in Angstroms (Å) along X axis
25+
pub xlen: f32,
26+
/// CELLA: Cell dimensions (unit cell edge length) in Angstroms (Å) along Y axis
27+
pub ylen: f32,
28+
/// CELLA: Cell dimensions (unit cell edge length) in Angstroms (Å) along Z axis
29+
pub zlen: f32,
30+
/// CELLB: Cell angles in degrees between the crystallographic axes Y and Z axes
31+
pub alpha: f32,
32+
/// CELLB: Cell angles in degrees between the crystallographic axes X and Z axes
33+
pub beta: f32,
34+
/// CELLB: Cell angles in degrees between the crystallographic axes X and Y axes
35+
pub gamma: f32,
36+
/// 1-based index of column axis (1,2,3 for X,Y,Z)
37+
pub mapc: i32,
38+
/// 1-based index of row axis (1,2,3 for X,Y,Z)
39+
pub mapr: i32,
40+
/// 1-based index of section axis (1,2,3 for X,Y,Z)
41+
pub maps: i32,
42+
/// Minimum density value
43+
pub dmin: f32,
44+
/// Maximum density value
45+
pub dmax: f32,
46+
/// Mean density value
47+
pub dmean: f32,
48+
/// Space group number; 0 implies 2D image or image stack.
49+
/// For crystallography, represents the actual spacegroup.
50+
/// For volume stacks, conventionally ISPG = spacegroup number + 400.
51+
pub ispg: i32,
52+
/// Size of extended header record ("symmetry data") in bytes.
53+
pub nsymbt: i32,
54+
/// Extra space used for anything.
55+
/// Bytes 8–11 hold EXTTYP, 12–15 NVERSION.
56+
pub extra: [u8; 100],
57+
/// Volume/phase origin (pixels/voxels) or origin of subvolume
58+
pub origin: [f32; 3],
59+
/// Must contain "MAP " to identify file type
60+
pub map: [u8; 4],
61+
/// Machine stamp that encodes byte order of data
62+
/// (little-endian: 0x44 0x44 0x00 0x00)
63+
pub machst: [u8; 4],
64+
/// RMS deviation of map from mean density
65+
pub rms: f32,
66+
/// Number of valid labels in `label` field (0–10)
67+
pub nlabl: i32,
68+
/// 10 text labels of 80 bytes each
69+
pub label: [u8; 800],
3870
}
3971

4072
impl Default for Header {

src/lib.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,19 @@ pub use mrcfile::{MrcFile, open_file};
3232

3333
// Error type
3434

35-
#[derive(Debug)]
35+
#[derive(thiserror::Error, Debug)]
3636
pub enum Error {
37+
#[error("IO error")]
3738
Io,
39+
#[error("Invalid MRC header")]
3840
InvalidHeader,
41+
#[error("Invalid MRC mode")]
3942
InvalidMode,
43+
#[error("Invalid dimensions")]
4044
InvalidDimensions,
45+
#[error("Type mismatch")]
4146
TypeMismatch,
4247
#[cfg(feature = "mmap")]
48+
#[error("Memory mapping error")]
4349
Mmap,
4450
}
45-
46-
impl core::fmt::Display for Error {
47-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48-
match self {
49-
Error::Io => write!(f, "IO error"),
50-
Error::InvalidHeader => write!(f, "Invalid MRC header"),
51-
Error::InvalidMode => write!(f, "Invalid MRC mode"),
52-
Error::InvalidDimensions => write!(f, "Invalid dimensions"),
53-
Error::TypeMismatch => write!(f, "Type mismatch"),
54-
#[cfg(feature = "mmap")]
55-
Error::Mmap => write!(f, "Memory mapping error"),
56-
}
57-
}
58-
}
59-
60-
#[cfg(feature = "std")]
61-
impl core::error::Error for Error {}

0 commit comments

Comments
 (0)