elements_rs 0.2.6

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
//! Isotopes of the element Erbium
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "mem_size", derive(mem_dbg::MemSize))]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg))]
#[cfg_attr(feature = "mem_size", mem_size(flat))]
/// Isotopes of the element Erbium
pub enum ErbiumIsotope {
    /// Isotope Er142 of Erbium
    Er142,
    /// Isotope Er143 of Erbium
    Er143,
    /// Isotope Er144 of Erbium
    Er144,
    /// Isotope Er145 of Erbium
    Er145,
    /// Isotope Er146 of Erbium
    Er146,
    /// Isotope Er147 of Erbium
    Er147,
    /// Isotope Er148 of Erbium
    Er148,
    /// Isotope Er149 of Erbium
    Er149,
    /// Isotope Er150 of Erbium
    Er150,
    /// Isotope Er151 of Erbium
    Er151,
    /// Isotope Er152 of Erbium
    Er152,
    /// Isotope Er153 of Erbium
    Er153,
    /// Isotope Er154 of Erbium
    Er154,
    /// Isotope Er155 of Erbium
    Er155,
    /// Isotope Er156 of Erbium
    Er156,
    /// Isotope Er157 of Erbium
    Er157,
    /// Isotope Er158 of Erbium
    Er158,
    /// Isotope Er159 of Erbium
    Er159,
    /// Isotope Er160 of Erbium
    Er160,
    /// Isotope Er161 of Erbium
    Er161,
    /// Isotope Er162 of Erbium
    Er162,
    /// Isotope Er163 of Erbium
    Er163,
    /// Isotope Er164 of Erbium
    Er164,
    /// Isotope Er165 of Erbium
    Er165,
    /// Isotope Er166 of Erbium
    Er166,
    /// Isotope Er167 of Erbium
    Er167,
    /// Isotope Er168 of Erbium
    Er168,
    /// Isotope Er169 of Erbium
    Er169,
    /// Isotope Er170 of Erbium
    Er170,
    /// Isotope Er171 of Erbium
    Er171,
    /// Isotope Er172 of Erbium
    Er172,
    /// Isotope Er173 of Erbium
    Er173,
    /// Isotope Er174 of Erbium
    Er174,
    /// Isotope Er175 of Erbium
    Er175,
    /// Isotope Er176 of Erbium
    Er176,
    /// Isotope Er177 of Erbium
    Er177,
    /// Isotope Er178 of Erbium
    Er178,
    /// Isotope Er179 of Erbium
    Er179,
    /// Isotope Er180 of Erbium
    Er180,
}
impl super::RelativeAtomicMass for ErbiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Er142 => 141.9701f64,
            Self::Er143 => 142.96662f64,
            Self::Er144 => 143.9607f64,
            Self::Er145 => 144.95805f64,
            Self::Er146 => 145.9524184f64,
            Self::Er147 => 146.949964f64,
            Self::Er148 => 147.944735f64,
            Self::Er149 => 148.942306f64,
            Self::Er150 => 149.937916f64,
            Self::Er151 => 150.937449f64,
            Self::Er152 => 151.935057f64,
            Self::Er153 => 152.93508f64,
            Self::Er154 => 153.9327908f64,
            Self::Er155 => 154.9332159f64,
            Self::Er156 => 155.931067f64,
            Self::Er157 => 156.931949f64,
            Self::Er158 => 157.929893f64,
            Self::Er159 => 158.9306918f64,
            Self::Er160 => 159.929077f64,
            Self::Er161 => 160.9300046f64,
            Self::Er162 => 161.9287884f64,
            Self::Er163 => 162.9300408f64,
            Self::Er164 => 163.9292088f64,
            Self::Er165 => 164.9307345f64,
            Self::Er166 => 165.9302995f64,
            Self::Er167 => 166.9320546f64,
            Self::Er168 => 167.9323767f64,
            Self::Er169 => 168.9345968f64,
            Self::Er170 => 169.9354702f64,
            Self::Er171 => 170.9380357f64,
            Self::Er172 => 171.9393619f64,
            Self::Er173 => 172.9424f64,
            Self::Er174 => 173.94423f64,
            Self::Er175 => 174.94777f64,
            Self::Er176 => 175.94994f64,
            Self::Er177 => 176.95399f64,
            Self::Er178 => 177.956779f64,
            Self::Er179 => 178.961267f64,
            Self::Er180 => 179.96438f64,
        }
    }
}
impl super::ElementVariant for ErbiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Er
    }
}
impl super::MassNumber for ErbiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Er142 => 142u16,
            Self::Er143 => 143u16,
            Self::Er144 => 144u16,
            Self::Er145 => 145u16,
            Self::Er146 => 146u16,
            Self::Er147 => 147u16,
            Self::Er148 => 148u16,
            Self::Er149 => 149u16,
            Self::Er150 => 150u16,
            Self::Er151 => 151u16,
            Self::Er152 => 152u16,
            Self::Er153 => 153u16,
            Self::Er154 => 154u16,
            Self::Er155 => 155u16,
            Self::Er156 => 156u16,
            Self::Er157 => 157u16,
            Self::Er158 => 158u16,
            Self::Er159 => 159u16,
            Self::Er160 => 160u16,
            Self::Er161 => 161u16,
            Self::Er162 => 162u16,
            Self::Er163 => 163u16,
            Self::Er164 => 164u16,
            Self::Er165 => 165u16,
            Self::Er166 => 166u16,
            Self::Er167 => 167u16,
            Self::Er168 => 168u16,
            Self::Er169 => 169u16,
            Self::Er170 => 170u16,
            Self::Er171 => 171u16,
            Self::Er172 => 172u16,
            Self::Er173 => 173u16,
            Self::Er174 => 174u16,
            Self::Er175 => 175u16,
            Self::Er176 => 176u16,
            Self::Er177 => 177u16,
            Self::Er178 => 178u16,
            Self::Er179 => 179u16,
            Self::Er180 => 180u16,
        }
    }
}
impl super::IsotopicComposition for ErbiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Er162 => Some(0.00139f64),
            Self::Er164 => Some(0.01601f64),
            Self::Er166 => Some(0.33503f64),
            Self::Er167 => Some(0.22869f64),
            Self::Er168 => Some(0.26978f64),
            Self::Er170 => Some(0.1491f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for ErbiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Er166
    }
}
impl From<ErbiumIsotope> for crate::Isotope {
    fn from(isotope: ErbiumIsotope) -> Self {
        crate::Isotope::Er(isotope)
    }
}
impl From<ErbiumIsotope> for crate::Element {
    fn from(_isotope: ErbiumIsotope) -> Self {
        crate::Element::Er
    }
}
impl TryFrom<u64> for ErbiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            142u64 => Ok(Self::Er142),
            143u64 => Ok(Self::Er143),
            144u64 => Ok(Self::Er144),
            145u64 => Ok(Self::Er145),
            146u64 => Ok(Self::Er146),
            147u64 => Ok(Self::Er147),
            148u64 => Ok(Self::Er148),
            149u64 => Ok(Self::Er149),
            150u64 => Ok(Self::Er150),
            151u64 => Ok(Self::Er151),
            152u64 => Ok(Self::Er152),
            153u64 => Ok(Self::Er153),
            154u64 => Ok(Self::Er154),
            155u64 => Ok(Self::Er155),
            156u64 => Ok(Self::Er156),
            157u64 => Ok(Self::Er157),
            158u64 => Ok(Self::Er158),
            159u64 => Ok(Self::Er159),
            160u64 => Ok(Self::Er160),
            161u64 => Ok(Self::Er161),
            162u64 => Ok(Self::Er162),
            163u64 => Ok(Self::Er163),
            164u64 => Ok(Self::Er164),
            165u64 => Ok(Self::Er165),
            166u64 => Ok(Self::Er166),
            167u64 => Ok(Self::Er167),
            168u64 => Ok(Self::Er168),
            169u64 => Ok(Self::Er169),
            170u64 => Ok(Self::Er170),
            171u64 => Ok(Self::Er171),
            172u64 => Ok(Self::Er172),
            173u64 => Ok(Self::Er173),
            174u64 => Ok(Self::Er174),
            175u64 => Ok(Self::Er175),
            176u64 => Ok(Self::Er176),
            177u64 => Ok(Self::Er177),
            178u64 => Ok(Self::Er178),
            179u64 => Ok(Self::Er179),
            180u64 => Ok(Self::Er180),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Er, value)),
        }
    }
}
impl TryFrom<u8> for ErbiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for ErbiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for ErbiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u32) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl core::fmt::Display for ErbiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Er142 => write!(f, "Er142"),
            Self::Er143 => write!(f, "Er143"),
            Self::Er144 => write!(f, "Er144"),
            Self::Er145 => write!(f, "Er145"),
            Self::Er146 => write!(f, "Er146"),
            Self::Er147 => write!(f, "Er147"),
            Self::Er148 => write!(f, "Er148"),
            Self::Er149 => write!(f, "Er149"),
            Self::Er150 => write!(f, "Er150"),
            Self::Er151 => write!(f, "Er151"),
            Self::Er152 => write!(f, "Er152"),
            Self::Er153 => write!(f, "Er153"),
            Self::Er154 => write!(f, "Er154"),
            Self::Er155 => write!(f, "Er155"),
            Self::Er156 => write!(f, "Er156"),
            Self::Er157 => write!(f, "Er157"),
            Self::Er158 => write!(f, "Er158"),
            Self::Er159 => write!(f, "Er159"),
            Self::Er160 => write!(f, "Er160"),
            Self::Er161 => write!(f, "Er161"),
            Self::Er162 => write!(f, "Er162"),
            Self::Er163 => write!(f, "Er163"),
            Self::Er164 => write!(f, "Er164"),
            Self::Er165 => write!(f, "Er165"),
            Self::Er166 => write!(f, "Er166"),
            Self::Er167 => write!(f, "Er167"),
            Self::Er168 => write!(f, "Er168"),
            Self::Er169 => write!(f, "Er169"),
            Self::Er170 => write!(f, "Er170"),
            Self::Er171 => write!(f, "Er171"),
            Self::Er172 => write!(f, "Er172"),
            Self::Er173 => write!(f, "Er173"),
            Self::Er174 => write!(f, "Er174"),
            Self::Er175 => write!(f, "Er175"),
            Self::Er176 => write!(f, "Er176"),
            Self::Er177 => write!(f, "Er177"),
            Self::Er178 => write!(f, "Er178"),
            Self::Er179 => write!(f, "Er179"),
            Self::Er180 => write!(f, "Er180"),
        }
    }
}
#[cfg(test)]
mod tests {
    use strum::IntoEnumIterator;

    use super::*;
    use crate::isotopes::{
        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
    };
    #[test]
    fn test_relative_atomic_mass() {
        for isotope in ErbiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in ErbiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Er, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in ErbiumIsotope::iter() {
            let mass_number = isotope.mass_number();
            assert!(
                mass_number > 0 && mass_number < 300,
                "Mass number should be reasonable for {isotope:?}"
            );
        }
    }
    #[test]
    fn test_isotopic_composition() {
        for isotope in ErbiumIsotope::iter() {
            let comp = isotope.isotopic_composition();
            if let Some(c) = comp {
                assert!(
                    (0.0..=1.0).contains(&c),
                    "Composition should be between 0 and 1 for {isotope:?}"
                );
            }
        }
    }
    #[test]
    fn test_most_abundant() {
        let most_abundant = ErbiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in ErbiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Er(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in ErbiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Er);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in ErbiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = ErbiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = ErbiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = ErbiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(ErbiumIsotope::try_from(0_u16).is_err());
        assert!(ErbiumIsotope::try_from(1000_u16).is_err());
        assert!(ErbiumIsotope::try_from(0_u32).is_err());
        assert!(ErbiumIsotope::try_from(1000_u32).is_err());
        assert!(ErbiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in ErbiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}