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
//! Isotopes of the element Cadmium
#[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 Cadmium
pub enum CadmiumIsotope {
    /// Isotope Cd94 of Cadmium
    Cd94,
    /// Isotope Cd95 of Cadmium
    Cd95,
    /// Isotope Cd96 of Cadmium
    Cd96,
    /// Isotope Cd97 of Cadmium
    Cd97,
    /// Isotope Cd98 of Cadmium
    Cd98,
    /// Isotope Cd99 of Cadmium
    Cd99,
    /// Isotope Cd100 of Cadmium
    Cd100,
    /// Isotope Cd101 of Cadmium
    Cd101,
    /// Isotope Cd102 of Cadmium
    Cd102,
    /// Isotope Cd103 of Cadmium
    Cd103,
    /// Isotope Cd104 of Cadmium
    Cd104,
    /// Isotope Cd105 of Cadmium
    Cd105,
    /// Isotope Cd106 of Cadmium
    Cd106,
    /// Isotope Cd107 of Cadmium
    Cd107,
    /// Isotope Cd108 of Cadmium
    Cd108,
    /// Isotope Cd109 of Cadmium
    Cd109,
    /// Isotope Cd110 of Cadmium
    Cd110,
    /// Isotope Cd111 of Cadmium
    Cd111,
    /// Isotope Cd112 of Cadmium
    Cd112,
    /// Isotope Cd113 of Cadmium
    Cd113,
    /// Isotope Cd114 of Cadmium
    Cd114,
    /// Isotope Cd115 of Cadmium
    Cd115,
    /// Isotope Cd116 of Cadmium
    Cd116,
    /// Isotope Cd117 of Cadmium
    Cd117,
    /// Isotope Cd118 of Cadmium
    Cd118,
    /// Isotope Cd119 of Cadmium
    Cd119,
    /// Isotope Cd120 of Cadmium
    Cd120,
    /// Isotope Cd121 of Cadmium
    Cd121,
    /// Isotope Cd122 of Cadmium
    Cd122,
    /// Isotope Cd123 of Cadmium
    Cd123,
    /// Isotope Cd124 of Cadmium
    Cd124,
    /// Isotope Cd125 of Cadmium
    Cd125,
    /// Isotope Cd126 of Cadmium
    Cd126,
    /// Isotope Cd127 of Cadmium
    Cd127,
    /// Isotope Cd128 of Cadmium
    Cd128,
    /// Isotope Cd129 of Cadmium
    Cd129,
    /// Isotope Cd130 of Cadmium
    Cd130,
    /// Isotope Cd131 of Cadmium
    Cd131,
    /// Isotope Cd132 of Cadmium
    Cd132,
    /// Isotope Cd133 of Cadmium
    Cd133,
    /// Isotope Cd134 of Cadmium
    Cd134,
}
impl super::RelativeAtomicMass for CadmiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Cd94 => 93.956586f64,
            Self::Cd95 => 94.94994f64,
            Self::Cd96 => 95.94034f64,
            Self::Cd97 => 96.9351f64,
            Self::Cd98 => 97.927389f64,
            Self::Cd99 => 98.9249258f64,
            Self::Cd100 => 99.9203488f64,
            Self::Cd101 => 100.9185862f64,
            Self::Cd102 => 101.914482f64,
            Self::Cd103 => 102.9134165f64,
            Self::Cd104 => 103.9098564f64,
            Self::Cd105 => 104.9094639f64,
            Self::Cd106 => 105.9064599f64,
            Self::Cd107 => 106.9066121f64,
            Self::Cd108 => 107.9041834f64,
            Self::Cd109 => 108.9049867f64,
            Self::Cd110 => 109.90300661f64,
            Self::Cd111 => 110.90418287f64,
            Self::Cd112 => 111.90276287f64,
            Self::Cd113 => 112.90440813f64,
            Self::Cd114 => 113.90336509f64,
            Self::Cd115 => 114.90543751f64,
            Self::Cd116 => 115.90476315f64,
            Self::Cd117 => 116.907226f64,
            Self::Cd118 => 117.906922f64,
            Self::Cd119 => 118.909847f64,
            Self::Cd120 => 119.9098681f64,
            Self::Cd121 => 120.9129637f64,
            Self::Cd122 => 121.9134591f64,
            Self::Cd123 => 122.9168925f64,
            Self::Cd124 => 123.9176574f64,
            Self::Cd125 => 124.9212576f64,
            Self::Cd126 => 125.9224291f64,
            Self::Cd127 => 126.926472f64,
            Self::Cd128 => 127.9278129f64,
            Self::Cd129 => 128.93182f64,
            Self::Cd130 => 129.93394f64,
            Self::Cd131 => 130.9406f64,
            Self::Cd132 => 131.94604f64,
            Self::Cd133 => 132.95285f64,
            Self::Cd134 => 133.957638f64,
        }
    }
}
impl super::ElementVariant for CadmiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Cd
    }
}
impl super::MassNumber for CadmiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Cd94 => 94u16,
            Self::Cd95 => 95u16,
            Self::Cd96 => 96u16,
            Self::Cd97 => 97u16,
            Self::Cd98 => 98u16,
            Self::Cd99 => 99u16,
            Self::Cd100 => 100u16,
            Self::Cd101 => 101u16,
            Self::Cd102 => 102u16,
            Self::Cd103 => 103u16,
            Self::Cd104 => 104u16,
            Self::Cd105 => 105u16,
            Self::Cd106 => 106u16,
            Self::Cd107 => 107u16,
            Self::Cd108 => 108u16,
            Self::Cd109 => 109u16,
            Self::Cd110 => 110u16,
            Self::Cd111 => 111u16,
            Self::Cd112 => 112u16,
            Self::Cd113 => 113u16,
            Self::Cd114 => 114u16,
            Self::Cd115 => 115u16,
            Self::Cd116 => 116u16,
            Self::Cd117 => 117u16,
            Self::Cd118 => 118u16,
            Self::Cd119 => 119u16,
            Self::Cd120 => 120u16,
            Self::Cd121 => 121u16,
            Self::Cd122 => 122u16,
            Self::Cd123 => 123u16,
            Self::Cd124 => 124u16,
            Self::Cd125 => 125u16,
            Self::Cd126 => 126u16,
            Self::Cd127 => 127u16,
            Self::Cd128 => 128u16,
            Self::Cd129 => 129u16,
            Self::Cd130 => 130u16,
            Self::Cd131 => 131u16,
            Self::Cd132 => 132u16,
            Self::Cd133 => 133u16,
            Self::Cd134 => 134u16,
        }
    }
}
impl super::IsotopicComposition for CadmiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Cd106 => Some(0.0125f64),
            Self::Cd108 => Some(0.0089f64),
            Self::Cd110 => Some(0.1249f64),
            Self::Cd111 => Some(0.128f64),
            Self::Cd112 => Some(0.2413f64),
            Self::Cd113 => Some(0.1222f64),
            Self::Cd114 => Some(0.2873f64),
            Self::Cd116 => Some(0.0749f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for CadmiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Cd114
    }
}
impl From<CadmiumIsotope> for crate::Isotope {
    fn from(isotope: CadmiumIsotope) -> Self {
        crate::Isotope::Cd(isotope)
    }
}
impl From<CadmiumIsotope> for crate::Element {
    fn from(_isotope: CadmiumIsotope) -> Self {
        crate::Element::Cd
    }
}
impl TryFrom<u64> for CadmiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            94u64 => Ok(Self::Cd94),
            95u64 => Ok(Self::Cd95),
            96u64 => Ok(Self::Cd96),
            97u64 => Ok(Self::Cd97),
            98u64 => Ok(Self::Cd98),
            99u64 => Ok(Self::Cd99),
            100u64 => Ok(Self::Cd100),
            101u64 => Ok(Self::Cd101),
            102u64 => Ok(Self::Cd102),
            103u64 => Ok(Self::Cd103),
            104u64 => Ok(Self::Cd104),
            105u64 => Ok(Self::Cd105),
            106u64 => Ok(Self::Cd106),
            107u64 => Ok(Self::Cd107),
            108u64 => Ok(Self::Cd108),
            109u64 => Ok(Self::Cd109),
            110u64 => Ok(Self::Cd110),
            111u64 => Ok(Self::Cd111),
            112u64 => Ok(Self::Cd112),
            113u64 => Ok(Self::Cd113),
            114u64 => Ok(Self::Cd114),
            115u64 => Ok(Self::Cd115),
            116u64 => Ok(Self::Cd116),
            117u64 => Ok(Self::Cd117),
            118u64 => Ok(Self::Cd118),
            119u64 => Ok(Self::Cd119),
            120u64 => Ok(Self::Cd120),
            121u64 => Ok(Self::Cd121),
            122u64 => Ok(Self::Cd122),
            123u64 => Ok(Self::Cd123),
            124u64 => Ok(Self::Cd124),
            125u64 => Ok(Self::Cd125),
            126u64 => Ok(Self::Cd126),
            127u64 => Ok(Self::Cd127),
            128u64 => Ok(Self::Cd128),
            129u64 => Ok(Self::Cd129),
            130u64 => Ok(Self::Cd130),
            131u64 => Ok(Self::Cd131),
            132u64 => Ok(Self::Cd132),
            133u64 => Ok(Self::Cd133),
            134u64 => Ok(Self::Cd134),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Cd, value)),
        }
    }
}
impl TryFrom<u8> for CadmiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for CadmiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for CadmiumIsotope {
    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 CadmiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Cd94 => write!(f, "Cd94"),
            Self::Cd95 => write!(f, "Cd95"),
            Self::Cd96 => write!(f, "Cd96"),
            Self::Cd97 => write!(f, "Cd97"),
            Self::Cd98 => write!(f, "Cd98"),
            Self::Cd99 => write!(f, "Cd99"),
            Self::Cd100 => write!(f, "Cd100"),
            Self::Cd101 => write!(f, "Cd101"),
            Self::Cd102 => write!(f, "Cd102"),
            Self::Cd103 => write!(f, "Cd103"),
            Self::Cd104 => write!(f, "Cd104"),
            Self::Cd105 => write!(f, "Cd105"),
            Self::Cd106 => write!(f, "Cd106"),
            Self::Cd107 => write!(f, "Cd107"),
            Self::Cd108 => write!(f, "Cd108"),
            Self::Cd109 => write!(f, "Cd109"),
            Self::Cd110 => write!(f, "Cd110"),
            Self::Cd111 => write!(f, "Cd111"),
            Self::Cd112 => write!(f, "Cd112"),
            Self::Cd113 => write!(f, "Cd113"),
            Self::Cd114 => write!(f, "Cd114"),
            Self::Cd115 => write!(f, "Cd115"),
            Self::Cd116 => write!(f, "Cd116"),
            Self::Cd117 => write!(f, "Cd117"),
            Self::Cd118 => write!(f, "Cd118"),
            Self::Cd119 => write!(f, "Cd119"),
            Self::Cd120 => write!(f, "Cd120"),
            Self::Cd121 => write!(f, "Cd121"),
            Self::Cd122 => write!(f, "Cd122"),
            Self::Cd123 => write!(f, "Cd123"),
            Self::Cd124 => write!(f, "Cd124"),
            Self::Cd125 => write!(f, "Cd125"),
            Self::Cd126 => write!(f, "Cd126"),
            Self::Cd127 => write!(f, "Cd127"),
            Self::Cd128 => write!(f, "Cd128"),
            Self::Cd129 => write!(f, "Cd129"),
            Self::Cd130 => write!(f, "Cd130"),
            Self::Cd131 => write!(f, "Cd131"),
            Self::Cd132 => write!(f, "Cd132"),
            Self::Cd133 => write!(f, "Cd133"),
            Self::Cd134 => write!(f, "Cd134"),
        }
    }
}
#[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 CadmiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in CadmiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Cd, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in CadmiumIsotope::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 CadmiumIsotope::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 = CadmiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in CadmiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Cd(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in CadmiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Cd);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in CadmiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = CadmiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = CadmiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = CadmiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(CadmiumIsotope::try_from(0_u16).is_err());
        assert!(CadmiumIsotope::try_from(1000_u16).is_err());
        assert!(CadmiumIsotope::try_from(0_u32).is_err());
        assert!(CadmiumIsotope::try_from(1000_u32).is_err());
        assert!(CadmiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in CadmiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}