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
419
420
421
422
423
424
425
426
427
428
429
430
431
//! Isotopes of the element Ruthenium
#[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 Ruthenium
pub enum RutheniumIsotope {
    /// Isotope Ru85 of Ruthenium
    Ru85,
    /// Isotope Ru86 of Ruthenium
    Ru86,
    /// Isotope Ru87 of Ruthenium
    Ru87,
    /// Isotope Ru88 of Ruthenium
    Ru88,
    /// Isotope Ru89 of Ruthenium
    Ru89,
    /// Isotope Ru90 of Ruthenium
    Ru90,
    /// Isotope Ru91 of Ruthenium
    Ru91,
    /// Isotope Ru92 of Ruthenium
    Ru92,
    /// Isotope Ru93 of Ruthenium
    Ru93,
    /// Isotope Ru94 of Ruthenium
    Ru94,
    /// Isotope Ru95 of Ruthenium
    Ru95,
    /// Isotope Ru96 of Ruthenium
    Ru96,
    /// Isotope Ru97 of Ruthenium
    Ru97,
    /// Isotope Ru98 of Ruthenium
    Ru98,
    /// Isotope Ru99 of Ruthenium
    Ru99,
    /// Isotope Ru100 of Ruthenium
    Ru100,
    /// Isotope Ru101 of Ruthenium
    Ru101,
    /// Isotope Ru102 of Ruthenium
    Ru102,
    /// Isotope Ru103 of Ruthenium
    Ru103,
    /// Isotope Ru104 of Ruthenium
    Ru104,
    /// Isotope Ru105 of Ruthenium
    Ru105,
    /// Isotope Ru106 of Ruthenium
    Ru106,
    /// Isotope Ru107 of Ruthenium
    Ru107,
    /// Isotope Ru108 of Ruthenium
    Ru108,
    /// Isotope Ru109 of Ruthenium
    Ru109,
    /// Isotope Ru110 of Ruthenium
    Ru110,
    /// Isotope Ru111 of Ruthenium
    Ru111,
    /// Isotope Ru112 of Ruthenium
    Ru112,
    /// Isotope Ru113 of Ruthenium
    Ru113,
    /// Isotope Ru114 of Ruthenium
    Ru114,
    /// Isotope Ru115 of Ruthenium
    Ru115,
    /// Isotope Ru116 of Ruthenium
    Ru116,
    /// Isotope Ru117 of Ruthenium
    Ru117,
    /// Isotope Ru118 of Ruthenium
    Ru118,
    /// Isotope Ru119 of Ruthenium
    Ru119,
    /// Isotope Ru120 of Ruthenium
    Ru120,
    /// Isotope Ru121 of Ruthenium
    Ru121,
    /// Isotope Ru122 of Ruthenium
    Ru122,
    /// Isotope Ru123 of Ruthenium
    Ru123,
    /// Isotope Ru124 of Ruthenium
    Ru124,
    /// Isotope Ru125 of Ruthenium
    Ru125,
}
impl super::RelativeAtomicMass for RutheniumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Ru85 => 84.967117f64,
            Self::Ru86 => 85.957305f64,
            Self::Ru87 => 86.95069f64,
            Self::Ru88 => 87.9416f64,
            Self::Ru89 => 88.93762f64,
            Self::Ru90 => 89.9303444f64,
            Self::Ru91 => 90.9267419f64,
            Self::Ru92 => 91.9202344f64,
            Self::Ru93 => 92.9171044f64,
            Self::Ru94 => 93.9113429f64,
            Self::Ru95 => 94.910406f64,
            Self::Ru96 => 95.90759025f64,
            Self::Ru97 => 96.9075471f64,
            Self::Ru98 => 97.9052868f64,
            Self::Ru99 => 98.9059341f64,
            Self::Ru100 => 99.9042143f64,
            Self::Ru101 => 100.9055769f64,
            Self::Ru102 => 101.9043441f64,
            Self::Ru103 => 102.9063186f64,
            Self::Ru104 => 103.9054275f64,
            Self::Ru105 => 104.9077476f64,
            Self::Ru106 => 105.9073291f64,
            Self::Ru107 => 106.909972f64,
            Self::Ru108 => 107.910188f64,
            Self::Ru109 => 108.913326f64,
            Self::Ru110 => 109.9140407f64,
            Self::Ru111 => 110.91757f64,
            Self::Ru112 => 111.918809f64,
            Self::Ru113 => 112.922844f64,
            Self::Ru114 => 113.9246136f64,
            Self::Ru115 => 114.92882f64,
            Self::Ru116 => 115.9312192f64,
            Self::Ru117 => 116.9361f64,
            Self::Ru118 => 117.93853f64,
            Self::Ru119 => 118.94357f64,
            Self::Ru120 => 119.94631f64,
            Self::Ru121 => 120.95164f64,
            Self::Ru122 => 121.95447f64,
            Self::Ru123 => 122.95989f64,
            Self::Ru124 => 123.96305f64,
            Self::Ru125 => 124.969544f64,
        }
    }
}
impl super::ElementVariant for RutheniumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Ru
    }
}
impl super::MassNumber for RutheniumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Ru85 => 85u16,
            Self::Ru86 => 86u16,
            Self::Ru87 => 87u16,
            Self::Ru88 => 88u16,
            Self::Ru89 => 89u16,
            Self::Ru90 => 90u16,
            Self::Ru91 => 91u16,
            Self::Ru92 => 92u16,
            Self::Ru93 => 93u16,
            Self::Ru94 => 94u16,
            Self::Ru95 => 95u16,
            Self::Ru96 => 96u16,
            Self::Ru97 => 97u16,
            Self::Ru98 => 98u16,
            Self::Ru99 => 99u16,
            Self::Ru100 => 100u16,
            Self::Ru101 => 101u16,
            Self::Ru102 => 102u16,
            Self::Ru103 => 103u16,
            Self::Ru104 => 104u16,
            Self::Ru105 => 105u16,
            Self::Ru106 => 106u16,
            Self::Ru107 => 107u16,
            Self::Ru108 => 108u16,
            Self::Ru109 => 109u16,
            Self::Ru110 => 110u16,
            Self::Ru111 => 111u16,
            Self::Ru112 => 112u16,
            Self::Ru113 => 113u16,
            Self::Ru114 => 114u16,
            Self::Ru115 => 115u16,
            Self::Ru116 => 116u16,
            Self::Ru117 => 117u16,
            Self::Ru118 => 118u16,
            Self::Ru119 => 119u16,
            Self::Ru120 => 120u16,
            Self::Ru121 => 121u16,
            Self::Ru122 => 122u16,
            Self::Ru123 => 123u16,
            Self::Ru124 => 124u16,
            Self::Ru125 => 125u16,
        }
    }
}
impl super::IsotopicComposition for RutheniumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Ru96 => Some(0.0554f64),
            Self::Ru98 => Some(0.0187f64),
            Self::Ru99 => Some(0.1276f64),
            Self::Ru100 => Some(0.126f64),
            Self::Ru101 => Some(0.1706f64),
            Self::Ru102 => Some(0.3155f64),
            Self::Ru104 => Some(0.1862f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for RutheniumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Ru102
    }
}
impl From<RutheniumIsotope> for crate::Isotope {
    fn from(isotope: RutheniumIsotope) -> Self {
        crate::Isotope::Ru(isotope)
    }
}
impl From<RutheniumIsotope> for crate::Element {
    fn from(_isotope: RutheniumIsotope) -> Self {
        crate::Element::Ru
    }
}
impl TryFrom<u64> for RutheniumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            85u64 => Ok(Self::Ru85),
            86u64 => Ok(Self::Ru86),
            87u64 => Ok(Self::Ru87),
            88u64 => Ok(Self::Ru88),
            89u64 => Ok(Self::Ru89),
            90u64 => Ok(Self::Ru90),
            91u64 => Ok(Self::Ru91),
            92u64 => Ok(Self::Ru92),
            93u64 => Ok(Self::Ru93),
            94u64 => Ok(Self::Ru94),
            95u64 => Ok(Self::Ru95),
            96u64 => Ok(Self::Ru96),
            97u64 => Ok(Self::Ru97),
            98u64 => Ok(Self::Ru98),
            99u64 => Ok(Self::Ru99),
            100u64 => Ok(Self::Ru100),
            101u64 => Ok(Self::Ru101),
            102u64 => Ok(Self::Ru102),
            103u64 => Ok(Self::Ru103),
            104u64 => Ok(Self::Ru104),
            105u64 => Ok(Self::Ru105),
            106u64 => Ok(Self::Ru106),
            107u64 => Ok(Self::Ru107),
            108u64 => Ok(Self::Ru108),
            109u64 => Ok(Self::Ru109),
            110u64 => Ok(Self::Ru110),
            111u64 => Ok(Self::Ru111),
            112u64 => Ok(Self::Ru112),
            113u64 => Ok(Self::Ru113),
            114u64 => Ok(Self::Ru114),
            115u64 => Ok(Self::Ru115),
            116u64 => Ok(Self::Ru116),
            117u64 => Ok(Self::Ru117),
            118u64 => Ok(Self::Ru118),
            119u64 => Ok(Self::Ru119),
            120u64 => Ok(Self::Ru120),
            121u64 => Ok(Self::Ru121),
            122u64 => Ok(Self::Ru122),
            123u64 => Ok(Self::Ru123),
            124u64 => Ok(Self::Ru124),
            125u64 => Ok(Self::Ru125),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Ru, value)),
        }
    }
}
impl TryFrom<u8> for RutheniumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for RutheniumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for RutheniumIsotope {
    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 RutheniumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Ru85 => write!(f, "Ru85"),
            Self::Ru86 => write!(f, "Ru86"),
            Self::Ru87 => write!(f, "Ru87"),
            Self::Ru88 => write!(f, "Ru88"),
            Self::Ru89 => write!(f, "Ru89"),
            Self::Ru90 => write!(f, "Ru90"),
            Self::Ru91 => write!(f, "Ru91"),
            Self::Ru92 => write!(f, "Ru92"),
            Self::Ru93 => write!(f, "Ru93"),
            Self::Ru94 => write!(f, "Ru94"),
            Self::Ru95 => write!(f, "Ru95"),
            Self::Ru96 => write!(f, "Ru96"),
            Self::Ru97 => write!(f, "Ru97"),
            Self::Ru98 => write!(f, "Ru98"),
            Self::Ru99 => write!(f, "Ru99"),
            Self::Ru100 => write!(f, "Ru100"),
            Self::Ru101 => write!(f, "Ru101"),
            Self::Ru102 => write!(f, "Ru102"),
            Self::Ru103 => write!(f, "Ru103"),
            Self::Ru104 => write!(f, "Ru104"),
            Self::Ru105 => write!(f, "Ru105"),
            Self::Ru106 => write!(f, "Ru106"),
            Self::Ru107 => write!(f, "Ru107"),
            Self::Ru108 => write!(f, "Ru108"),
            Self::Ru109 => write!(f, "Ru109"),
            Self::Ru110 => write!(f, "Ru110"),
            Self::Ru111 => write!(f, "Ru111"),
            Self::Ru112 => write!(f, "Ru112"),
            Self::Ru113 => write!(f, "Ru113"),
            Self::Ru114 => write!(f, "Ru114"),
            Self::Ru115 => write!(f, "Ru115"),
            Self::Ru116 => write!(f, "Ru116"),
            Self::Ru117 => write!(f, "Ru117"),
            Self::Ru118 => write!(f, "Ru118"),
            Self::Ru119 => write!(f, "Ru119"),
            Self::Ru120 => write!(f, "Ru120"),
            Self::Ru121 => write!(f, "Ru121"),
            Self::Ru122 => write!(f, "Ru122"),
            Self::Ru123 => write!(f, "Ru123"),
            Self::Ru124 => write!(f, "Ru124"),
            Self::Ru125 => write!(f, "Ru125"),
        }
    }
}
#[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 RutheniumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in RutheniumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Ru, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in RutheniumIsotope::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 RutheniumIsotope::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 = RutheniumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in RutheniumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Ru(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in RutheniumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Ru);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in RutheniumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = RutheniumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = RutheniumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = RutheniumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(RutheniumIsotope::try_from(0_u16).is_err());
        assert!(RutheniumIsotope::try_from(1000_u16).is_err());
        assert!(RutheniumIsotope::try_from(0_u32).is_err());
        assert!(RutheniumIsotope::try_from(1000_u32).is_err());
        assert!(RutheniumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in RutheniumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}