elements_rs 0.2.5

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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
//! Isotopes of the element Xenon
#[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))]
/// Isotopes of the element Xenon
pub enum XenonIsotope {
    /// Isotope Xe108 of Xenon
    Xe108,
    /// Isotope Xe109 of Xenon
    Xe109,
    /// Isotope Xe110 of Xenon
    Xe110,
    /// Isotope Xe111 of Xenon
    Xe111,
    /// Isotope Xe112 of Xenon
    Xe112,
    /// Isotope Xe113 of Xenon
    Xe113,
    /// Isotope Xe114 of Xenon
    Xe114,
    /// Isotope Xe115 of Xenon
    Xe115,
    /// Isotope Xe116 of Xenon
    Xe116,
    /// Isotope Xe117 of Xenon
    Xe117,
    /// Isotope Xe118 of Xenon
    Xe118,
    /// Isotope Xe119 of Xenon
    Xe119,
    /// Isotope Xe120 of Xenon
    Xe120,
    /// Isotope Xe121 of Xenon
    Xe121,
    /// Isotope Xe122 of Xenon
    Xe122,
    /// Isotope Xe123 of Xenon
    Xe123,
    /// Isotope Xe124 of Xenon
    Xe124,
    /// Isotope Xe125 of Xenon
    Xe125,
    /// Isotope Xe126 of Xenon
    Xe126,
    /// Isotope Xe127 of Xenon
    Xe127,
    /// Isotope Xe128 of Xenon
    Xe128,
    /// Isotope Xe129 of Xenon
    Xe129,
    /// Isotope Xe130 of Xenon
    Xe130,
    /// Isotope Xe131 of Xenon
    Xe131,
    /// Isotope Xe132 of Xenon
    Xe132,
    /// Isotope Xe133 of Xenon
    Xe133,
    /// Isotope Xe134 of Xenon
    Xe134,
    /// Isotope Xe135 of Xenon
    Xe135,
    /// Isotope Xe136 of Xenon
    Xe136,
    /// Isotope Xe137 of Xenon
    Xe137,
    /// Isotope Xe138 of Xenon
    Xe138,
    /// Isotope Xe139 of Xenon
    Xe139,
    /// Isotope Xe140 of Xenon
    Xe140,
    /// Isotope Xe141 of Xenon
    Xe141,
    /// Isotope Xe142 of Xenon
    Xe142,
    /// Isotope Xe143 of Xenon
    Xe143,
    /// Isotope Xe144 of Xenon
    Xe144,
    /// Isotope Xe145 of Xenon
    Xe145,
    /// Isotope Xe146 of Xenon
    Xe146,
    /// Isotope Xe147 of Xenon
    Xe147,
    /// Isotope Xe148 of Xenon
    Xe148,
    /// Isotope Xe149 of Xenon
    Xe149,
    /// Isotope Xe150 of Xenon
    Xe150,
}
impl super::RelativeAtomicMass for XenonIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Xe108 => 107.954232285f64,
            Self::Xe109 => 108.95043f64,
            Self::Xe110 => 109.94426f64,
            Self::Xe111 => 110.941607f64,
            Self::Xe112 => 111.935559f64,
            Self::Xe113 => 112.9332217f64,
            Self::Xe114 => 113.92798f64,
            Self::Xe115 => 114.926294f64,
            Self::Xe116 => 115.921581f64,
            Self::Xe117 => 116.920359f64,
            Self::Xe118 => 117.916179f64,
            Self::Xe119 => 118.915411f64,
            Self::Xe120 => 119.911784f64,
            Self::Xe121 => 120.911453f64,
            Self::Xe122 => 121.908368f64,
            Self::Xe123 => 122.908482f64,
            Self::Xe124 => 123.905892f64,
            Self::Xe125 => 124.9063944f64,
            Self::Xe126 => 125.9042983f64,
            Self::Xe127 => 126.9051829f64,
            Self::Xe128 => 127.903531f64,
            Self::Xe129 => 128.9047808611f64,
            Self::Xe130 => 129.903509349f64,
            Self::Xe131 => 130.90508406f64,
            Self::Xe132 => 131.9041550856f64,
            Self::Xe133 => 132.9059108f64,
            Self::Xe134 => 133.90539466f64,
            Self::Xe135 => 134.9072278f64,
            Self::Xe136 => 135.907214484f64,
            Self::Xe137 => 136.91155778f64,
            Self::Xe138 => 137.9141463f64,
            Self::Xe139 => 138.9187922f64,
            Self::Xe140 => 139.9216458f64,
            Self::Xe141 => 140.9267872f64,
            Self::Xe142 => 141.9299731f64,
            Self::Xe143 => 142.9353696f64,
            Self::Xe144 => 143.9389451f64,
            Self::Xe145 => 144.94472f64,
            Self::Xe146 => 145.948518f64,
            Self::Xe147 => 146.95426f64,
            Self::Xe148 => 147.95813f64,
            Self::Xe149 => 148.964573f64,
            Self::Xe150 => 149.968878f64,
        }
    }
}
impl super::ElementVariant for XenonIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Xe
    }
}
impl super::MassNumber for XenonIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Xe108 => 108u16,
            Self::Xe109 => 109u16,
            Self::Xe110 => 110u16,
            Self::Xe111 => 111u16,
            Self::Xe112 => 112u16,
            Self::Xe113 => 113u16,
            Self::Xe114 => 114u16,
            Self::Xe115 => 115u16,
            Self::Xe116 => 116u16,
            Self::Xe117 => 117u16,
            Self::Xe118 => 118u16,
            Self::Xe119 => 119u16,
            Self::Xe120 => 120u16,
            Self::Xe121 => 121u16,
            Self::Xe122 => 122u16,
            Self::Xe123 => 123u16,
            Self::Xe124 => 124u16,
            Self::Xe125 => 125u16,
            Self::Xe126 => 126u16,
            Self::Xe127 => 127u16,
            Self::Xe128 => 128u16,
            Self::Xe129 => 129u16,
            Self::Xe130 => 130u16,
            Self::Xe131 => 131u16,
            Self::Xe132 => 132u16,
            Self::Xe133 => 133u16,
            Self::Xe134 => 134u16,
            Self::Xe135 => 135u16,
            Self::Xe136 => 136u16,
            Self::Xe137 => 137u16,
            Self::Xe138 => 138u16,
            Self::Xe139 => 139u16,
            Self::Xe140 => 140u16,
            Self::Xe141 => 141u16,
            Self::Xe142 => 142u16,
            Self::Xe143 => 143u16,
            Self::Xe144 => 144u16,
            Self::Xe145 => 145u16,
            Self::Xe146 => 146u16,
            Self::Xe147 => 147u16,
            Self::Xe148 => 148u16,
            Self::Xe149 => 149u16,
            Self::Xe150 => 150u16,
        }
    }
}
impl super::IsotopicComposition for XenonIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Xe124 => Some(0.000952f64),
            Self::Xe126 => Some(0.00089f64),
            Self::Xe128 => Some(0.019102f64),
            Self::Xe129 => Some(0.264006f64),
            Self::Xe130 => Some(0.04071f64),
            Self::Xe131 => Some(0.212324f64),
            Self::Xe132 => Some(0.269086f64),
            Self::Xe134 => Some(0.104357f64),
            Self::Xe136 => Some(0.088573f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for XenonIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Xe132
    }
}
impl From<XenonIsotope> for crate::Isotope {
    fn from(isotope: XenonIsotope) -> Self {
        crate::Isotope::Xe(isotope)
    }
}
impl From<XenonIsotope> for crate::Element {
    fn from(_isotope: XenonIsotope) -> Self {
        crate::Element::Xe
    }
}
impl TryFrom<u64> for XenonIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            108u64 => Ok(Self::Xe108),
            109u64 => Ok(Self::Xe109),
            110u64 => Ok(Self::Xe110),
            111u64 => Ok(Self::Xe111),
            112u64 => Ok(Self::Xe112),
            113u64 => Ok(Self::Xe113),
            114u64 => Ok(Self::Xe114),
            115u64 => Ok(Self::Xe115),
            116u64 => Ok(Self::Xe116),
            117u64 => Ok(Self::Xe117),
            118u64 => Ok(Self::Xe118),
            119u64 => Ok(Self::Xe119),
            120u64 => Ok(Self::Xe120),
            121u64 => Ok(Self::Xe121),
            122u64 => Ok(Self::Xe122),
            123u64 => Ok(Self::Xe123),
            124u64 => Ok(Self::Xe124),
            125u64 => Ok(Self::Xe125),
            126u64 => Ok(Self::Xe126),
            127u64 => Ok(Self::Xe127),
            128u64 => Ok(Self::Xe128),
            129u64 => Ok(Self::Xe129),
            130u64 => Ok(Self::Xe130),
            131u64 => Ok(Self::Xe131),
            132u64 => Ok(Self::Xe132),
            133u64 => Ok(Self::Xe133),
            134u64 => Ok(Self::Xe134),
            135u64 => Ok(Self::Xe135),
            136u64 => Ok(Self::Xe136),
            137u64 => Ok(Self::Xe137),
            138u64 => Ok(Self::Xe138),
            139u64 => Ok(Self::Xe139),
            140u64 => Ok(Self::Xe140),
            141u64 => Ok(Self::Xe141),
            142u64 => Ok(Self::Xe142),
            143u64 => Ok(Self::Xe143),
            144u64 => Ok(Self::Xe144),
            145u64 => Ok(Self::Xe145),
            146u64 => Ok(Self::Xe146),
            147u64 => Ok(Self::Xe147),
            148u64 => Ok(Self::Xe148),
            149u64 => Ok(Self::Xe149),
            150u64 => Ok(Self::Xe150),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Xe, value)),
        }
    }
}
impl TryFrom<u8> for XenonIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for XenonIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for XenonIsotope {
    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 XenonIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Xe108 => write!(f, "Xe108"),
            Self::Xe109 => write!(f, "Xe109"),
            Self::Xe110 => write!(f, "Xe110"),
            Self::Xe111 => write!(f, "Xe111"),
            Self::Xe112 => write!(f, "Xe112"),
            Self::Xe113 => write!(f, "Xe113"),
            Self::Xe114 => write!(f, "Xe114"),
            Self::Xe115 => write!(f, "Xe115"),
            Self::Xe116 => write!(f, "Xe116"),
            Self::Xe117 => write!(f, "Xe117"),
            Self::Xe118 => write!(f, "Xe118"),
            Self::Xe119 => write!(f, "Xe119"),
            Self::Xe120 => write!(f, "Xe120"),
            Self::Xe121 => write!(f, "Xe121"),
            Self::Xe122 => write!(f, "Xe122"),
            Self::Xe123 => write!(f, "Xe123"),
            Self::Xe124 => write!(f, "Xe124"),
            Self::Xe125 => write!(f, "Xe125"),
            Self::Xe126 => write!(f, "Xe126"),
            Self::Xe127 => write!(f, "Xe127"),
            Self::Xe128 => write!(f, "Xe128"),
            Self::Xe129 => write!(f, "Xe129"),
            Self::Xe130 => write!(f, "Xe130"),
            Self::Xe131 => write!(f, "Xe131"),
            Self::Xe132 => write!(f, "Xe132"),
            Self::Xe133 => write!(f, "Xe133"),
            Self::Xe134 => write!(f, "Xe134"),
            Self::Xe135 => write!(f, "Xe135"),
            Self::Xe136 => write!(f, "Xe136"),
            Self::Xe137 => write!(f, "Xe137"),
            Self::Xe138 => write!(f, "Xe138"),
            Self::Xe139 => write!(f, "Xe139"),
            Self::Xe140 => write!(f, "Xe140"),
            Self::Xe141 => write!(f, "Xe141"),
            Self::Xe142 => write!(f, "Xe142"),
            Self::Xe143 => write!(f, "Xe143"),
            Self::Xe144 => write!(f, "Xe144"),
            Self::Xe145 => write!(f, "Xe145"),
            Self::Xe146 => write!(f, "Xe146"),
            Self::Xe147 => write!(f, "Xe147"),
            Self::Xe148 => write!(f, "Xe148"),
            Self::Xe149 => write!(f, "Xe149"),
            Self::Xe150 => write!(f, "Xe150"),
        }
    }
}
#[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 XenonIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in XenonIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Xe, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in XenonIsotope::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 XenonIsotope::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 = XenonIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in XenonIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Xe(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in XenonIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Xe);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in XenonIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = XenonIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = XenonIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = XenonIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(XenonIsotope::try_from(0_u16).is_err());
        assert!(XenonIsotope::try_from(1000_u16).is_err());
        assert!(XenonIsotope::try_from(0_u32).is_err());
        assert!(XenonIsotope::try_from(1000_u32).is_err());
        assert!(XenonIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in XenonIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}