Skip to main content

openmassspec_core/
enums.rs

1//! Shared enums and types used across the open mass-spec parsers.
2//!
3//! These mirror the enums historically defined in `opentfraw::types` (which is
4//! where the vocabulary first lived) but are intentionally **vendor neutral**:
5//! anything Thermo-specific (e.g. firmware byte codes, scan-filter symbols)
6//! stays in the vendor crate.
7
8/// Detector / mass analyzer family.
9///
10/// The variants follow Thermo's preamble encoding (the most detailed source
11/// available across vendors); other vendors map their detector class onto the
12/// closest equivalent.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum Analyzer {
15    /// Ion trap.
16    ITMS,
17    /// Triple quadrupole.
18    TQMS,
19    /// Single quadrupole.
20    SQMS,
21    /// Time-of-flight.
22    TOFMS,
23    /// Fourier-transform (Orbitrap, FT-ICR).
24    FTMS,
25    /// Magnetic sector.
26    Sector,
27}
28
29/// Scan polarity.
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
31pub enum Polarity {
32    Negative,
33    Positive,
34}
35
36/// Whether a spectrum holds centroided peak picks or the raw profile signal.
37#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum ScanMode {
39    Centroid,
40    Profile,
41}
42
43/// MSn order (MS1, MS2, ...).
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45pub enum MsPower {
46    Undefined,
47    Ms1,
48    Ms2,
49    Ms3,
50    Ms4,
51    Ms5,
52    Ms6,
53    Ms7,
54    Ms8,
55}
56
57/// Activation method used for MSn fragmentation.
58#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub enum Activation {
60    /// Higher-energy collisional dissociation (Q Exactive style).
61    HCD,
62    /// Multi-photon induced dissociation.
63    MPID,
64    /// Electron transfer dissociation.
65    ETD,
66    /// Collision-induced dissociation. On FTMS analyzers this is
67    /// conventionally rendered as beam-type CID (HCD-equivalent) in mzML.
68    CID,
69    /// Electron-capture dissociation.
70    ECD,
71    /// Infrared multiphoton dissociation.
72    IRMPD,
73    /// Proton-transfer / activated-ion variant.
74    PD,
75    /// Pulsed q dissociation.
76    PQD,
77    /// Ultraviolet photodissociation.
78    UVPD,
79    /// Surface-induced dissociation.
80    SID,
81    /// ETD with supplemental HCD.
82    EThcD,
83}
84
85/// Compression codec applied to a `<binaryDataArray>`'s `<binary>` payload
86/// by the mzML writer.
87///
88/// Selects both the bytes actually written (compressed or not) and the
89/// matching PSI-MS cvParam. `Zlib` is the default for
90/// [`crate::write_mzml`]/[`crate::write_indexed_mzml`], matching
91/// msconvert/OpenMS output; pass `NoCompression` to
92/// [`crate::write_mzml_with_compression`]/
93/// [`crate::write_indexed_mzml_with_compression`] to keep the previous
94/// (pre-1.4) uncompressed byte layout.
95#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
96pub enum Compression {
97    /// No compression: `MS:1000576` ("no compression").
98    NoCompression,
99    /// DEFLATE/zlib compression: `MS:1000574` ("zlib compression").
100    #[default]
101    Zlib,
102}
103
104/// Unit + meaning of a per-peak ion mobility array.
105///
106/// Selects the CV term and unit emitted by the mzML writer when a
107/// [`crate::SpectrumRecord::inv_mobility_per_peak`] array is present.
108#[derive(Debug, Clone, Copy, PartialEq, Eq)]
109pub enum MobilityArrayKind {
110    /// Bruker TIMS convention: per-peak 1/K0 in volt-second per square
111    /// centimeter. Emitted as MS:1003008 "raw inverse reduced ion mobility
112    /// array" with unit MS:1002814.
113    InverseReducedVsPerCm2,
114    /// Waters traveling-wave IMS convention: per-peak drift time in
115    /// milliseconds. Emitted as MS:1003007 "raw ion mobility array" with
116    /// unit UO:0000028 "millisecond".
117    DriftTimeMilliseconds,
118}
119
120impl MsPower {
121    /// Numeric MS level (1 for MS1, 2 for MS2, ...). Returns 1 for `Undefined`,
122    /// matching the convention used in mzML output.
123    pub fn ms_level(self) -> u32 {
124        match self {
125            Self::Undefined | Self::Ms1 => 1,
126            Self::Ms2 => 2,
127            Self::Ms3 => 3,
128            Self::Ms4 => 4,
129            Self::Ms5 => 5,
130            Self::Ms6 => 6,
131            Self::Ms7 => 7,
132            Self::Ms8 => 8,
133        }
134    }
135}