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
432
433
434
435
436
//! Isotopes of the element Palladium
#[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 Palladium
pub enum PalladiumIsotope {
    /// Isotope Pd90 of Palladium
    Pd90,
    /// Isotope Pd91 of Palladium
    Pd91,
    /// Isotope Pd92 of Palladium
    Pd92,
    /// Isotope Pd93 of Palladium
    Pd93,
    /// Isotope Pd94 of Palladium
    Pd94,
    /// Isotope Pd95 of Palladium
    Pd95,
    /// Isotope Pd96 of Palladium
    Pd96,
    /// Isotope Pd97 of Palladium
    Pd97,
    /// Isotope Pd98 of Palladium
    Pd98,
    /// Isotope Pd99 of Palladium
    Pd99,
    /// Isotope Pd100 of Palladium
    Pd100,
    /// Isotope Pd101 of Palladium
    Pd101,
    /// Isotope Pd102 of Palladium
    Pd102,
    /// Isotope Pd103 of Palladium
    Pd103,
    /// Isotope Pd104 of Palladium
    Pd104,
    /// Isotope Pd105 of Palladium
    Pd105,
    /// Isotope Pd106 of Palladium
    Pd106,
    /// Isotope Pd107 of Palladium
    Pd107,
    /// Isotope Pd108 of Palladium
    Pd108,
    /// Isotope Pd109 of Palladium
    Pd109,
    /// Isotope Pd110 of Palladium
    Pd110,
    /// Isotope Pd111 of Palladium
    Pd111,
    /// Isotope Pd112 of Palladium
    Pd112,
    /// Isotope Pd113 of Palladium
    Pd113,
    /// Isotope Pd114 of Palladium
    Pd114,
    /// Isotope Pd115 of Palladium
    Pd115,
    /// Isotope Pd116 of Palladium
    Pd116,
    /// Isotope Pd117 of Palladium
    Pd117,
    /// Isotope Pd118 of Palladium
    Pd118,
    /// Isotope Pd119 of Palladium
    Pd119,
    /// Isotope Pd120 of Palladium
    Pd120,
    /// Isotope Pd121 of Palladium
    Pd121,
    /// Isotope Pd122 of Palladium
    Pd122,
    /// Isotope Pd123 of Palladium
    Pd123,
    /// Isotope Pd124 of Palladium
    Pd124,
    /// Isotope Pd125 of Palladium
    Pd125,
    /// Isotope Pd126 of Palladium
    Pd126,
    /// Isotope Pd127 of Palladium
    Pd127,
    /// Isotope Pd128 of Palladium
    Pd128,
    /// Isotope Pd129 of Palladium
    Pd129,
    /// Isotope Pd130 of Palladium
    Pd130,
    /// Isotope Pd131 of Palladium
    Pd131,
}
impl super::RelativeAtomicMass for PalladiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Pd90 => 89.95737f64,
            Self::Pd91 => 90.95032f64,
            Self::Pd92 => 91.94088f64,
            Self::Pd93 => 92.93651f64,
            Self::Pd94 => 93.9290376f64,
            Self::Pd95 => 94.9248898f64,
            Self::Pd96 => 95.9182151f64,
            Self::Pd97 => 96.916472f64,
            Self::Pd98 => 97.9126983f64,
            Self::Pd99 => 98.9117748f64,
            Self::Pd100 => 99.908505f64,
            Self::Pd101 => 100.9082864f64,
            Self::Pd102 => 101.9056022f64,
            Self::Pd103 => 102.9060809f64,
            Self::Pd104 => 103.9040305f64,
            Self::Pd105 => 104.9050796f64,
            Self::Pd106 => 105.9034804f64,
            Self::Pd107 => 106.9051282f64,
            Self::Pd108 => 107.9038916f64,
            Self::Pd109 => 108.9059504f64,
            Self::Pd110 => 109.9051722f64,
            Self::Pd111 => 110.90768968f64,
            Self::Pd112 => 111.9073297f64,
            Self::Pd113 => 112.910261f64,
            Self::Pd114 => 113.9103686f64,
            Self::Pd115 => 114.913659f64,
            Self::Pd116 => 115.914297f64,
            Self::Pd117 => 116.9179547f64,
            Self::Pd118 => 117.9190667f64,
            Self::Pd119 => 118.9233402f64,
            Self::Pd120 => 119.9245511f64,
            Self::Pd121 => 120.9289503f64,
            Self::Pd122 => 121.930632f64,
            Self::Pd123 => 122.93514f64,
            Self::Pd124 => 123.93714f64,
            Self::Pd125 => 124.94179f64,
            Self::Pd126 => 125.94416f64,
            Self::Pd127 => 126.94907f64,
            Self::Pd128 => 127.95183f64,
            Self::Pd129 => 128.959334f64,
            Self::Pd130 => 129.964863f64,
            Self::Pd131 => 130.972367f64,
        }
    }
}
impl super::ElementVariant for PalladiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Pd
    }
}
impl super::MassNumber for PalladiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Pd90 => 90u16,
            Self::Pd91 => 91u16,
            Self::Pd92 => 92u16,
            Self::Pd93 => 93u16,
            Self::Pd94 => 94u16,
            Self::Pd95 => 95u16,
            Self::Pd96 => 96u16,
            Self::Pd97 => 97u16,
            Self::Pd98 => 98u16,
            Self::Pd99 => 99u16,
            Self::Pd100 => 100u16,
            Self::Pd101 => 101u16,
            Self::Pd102 => 102u16,
            Self::Pd103 => 103u16,
            Self::Pd104 => 104u16,
            Self::Pd105 => 105u16,
            Self::Pd106 => 106u16,
            Self::Pd107 => 107u16,
            Self::Pd108 => 108u16,
            Self::Pd109 => 109u16,
            Self::Pd110 => 110u16,
            Self::Pd111 => 111u16,
            Self::Pd112 => 112u16,
            Self::Pd113 => 113u16,
            Self::Pd114 => 114u16,
            Self::Pd115 => 115u16,
            Self::Pd116 => 116u16,
            Self::Pd117 => 117u16,
            Self::Pd118 => 118u16,
            Self::Pd119 => 119u16,
            Self::Pd120 => 120u16,
            Self::Pd121 => 121u16,
            Self::Pd122 => 122u16,
            Self::Pd123 => 123u16,
            Self::Pd124 => 124u16,
            Self::Pd125 => 125u16,
            Self::Pd126 => 126u16,
            Self::Pd127 => 127u16,
            Self::Pd128 => 128u16,
            Self::Pd129 => 129u16,
            Self::Pd130 => 130u16,
            Self::Pd131 => 131u16,
        }
    }
}
impl super::IsotopicComposition for PalladiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Pd102 => Some(0.0102f64),
            Self::Pd104 => Some(0.1114f64),
            Self::Pd105 => Some(0.2233f64),
            Self::Pd106 => Some(0.2733f64),
            Self::Pd108 => Some(0.2646f64),
            Self::Pd110 => Some(0.1172f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for PalladiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Pd106
    }
}
impl From<PalladiumIsotope> for crate::Isotope {
    fn from(isotope: PalladiumIsotope) -> Self {
        crate::Isotope::Pd(isotope)
    }
}
impl From<PalladiumIsotope> for crate::Element {
    fn from(_isotope: PalladiumIsotope) -> Self {
        crate::Element::Pd
    }
}
impl TryFrom<u64> for PalladiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            90u64 => Ok(Self::Pd90),
            91u64 => Ok(Self::Pd91),
            92u64 => Ok(Self::Pd92),
            93u64 => Ok(Self::Pd93),
            94u64 => Ok(Self::Pd94),
            95u64 => Ok(Self::Pd95),
            96u64 => Ok(Self::Pd96),
            97u64 => Ok(Self::Pd97),
            98u64 => Ok(Self::Pd98),
            99u64 => Ok(Self::Pd99),
            100u64 => Ok(Self::Pd100),
            101u64 => Ok(Self::Pd101),
            102u64 => Ok(Self::Pd102),
            103u64 => Ok(Self::Pd103),
            104u64 => Ok(Self::Pd104),
            105u64 => Ok(Self::Pd105),
            106u64 => Ok(Self::Pd106),
            107u64 => Ok(Self::Pd107),
            108u64 => Ok(Self::Pd108),
            109u64 => Ok(Self::Pd109),
            110u64 => Ok(Self::Pd110),
            111u64 => Ok(Self::Pd111),
            112u64 => Ok(Self::Pd112),
            113u64 => Ok(Self::Pd113),
            114u64 => Ok(Self::Pd114),
            115u64 => Ok(Self::Pd115),
            116u64 => Ok(Self::Pd116),
            117u64 => Ok(Self::Pd117),
            118u64 => Ok(Self::Pd118),
            119u64 => Ok(Self::Pd119),
            120u64 => Ok(Self::Pd120),
            121u64 => Ok(Self::Pd121),
            122u64 => Ok(Self::Pd122),
            123u64 => Ok(Self::Pd123),
            124u64 => Ok(Self::Pd124),
            125u64 => Ok(Self::Pd125),
            126u64 => Ok(Self::Pd126),
            127u64 => Ok(Self::Pd127),
            128u64 => Ok(Self::Pd128),
            129u64 => Ok(Self::Pd129),
            130u64 => Ok(Self::Pd130),
            131u64 => Ok(Self::Pd131),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Pd, value)),
        }
    }
}
impl TryFrom<u8> for PalladiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for PalladiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for PalladiumIsotope {
    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 PalladiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Pd90 => write!(f, "Pd90"),
            Self::Pd91 => write!(f, "Pd91"),
            Self::Pd92 => write!(f, "Pd92"),
            Self::Pd93 => write!(f, "Pd93"),
            Self::Pd94 => write!(f, "Pd94"),
            Self::Pd95 => write!(f, "Pd95"),
            Self::Pd96 => write!(f, "Pd96"),
            Self::Pd97 => write!(f, "Pd97"),
            Self::Pd98 => write!(f, "Pd98"),
            Self::Pd99 => write!(f, "Pd99"),
            Self::Pd100 => write!(f, "Pd100"),
            Self::Pd101 => write!(f, "Pd101"),
            Self::Pd102 => write!(f, "Pd102"),
            Self::Pd103 => write!(f, "Pd103"),
            Self::Pd104 => write!(f, "Pd104"),
            Self::Pd105 => write!(f, "Pd105"),
            Self::Pd106 => write!(f, "Pd106"),
            Self::Pd107 => write!(f, "Pd107"),
            Self::Pd108 => write!(f, "Pd108"),
            Self::Pd109 => write!(f, "Pd109"),
            Self::Pd110 => write!(f, "Pd110"),
            Self::Pd111 => write!(f, "Pd111"),
            Self::Pd112 => write!(f, "Pd112"),
            Self::Pd113 => write!(f, "Pd113"),
            Self::Pd114 => write!(f, "Pd114"),
            Self::Pd115 => write!(f, "Pd115"),
            Self::Pd116 => write!(f, "Pd116"),
            Self::Pd117 => write!(f, "Pd117"),
            Self::Pd118 => write!(f, "Pd118"),
            Self::Pd119 => write!(f, "Pd119"),
            Self::Pd120 => write!(f, "Pd120"),
            Self::Pd121 => write!(f, "Pd121"),
            Self::Pd122 => write!(f, "Pd122"),
            Self::Pd123 => write!(f, "Pd123"),
            Self::Pd124 => write!(f, "Pd124"),
            Self::Pd125 => write!(f, "Pd125"),
            Self::Pd126 => write!(f, "Pd126"),
            Self::Pd127 => write!(f, "Pd127"),
            Self::Pd128 => write!(f, "Pd128"),
            Self::Pd129 => write!(f, "Pd129"),
            Self::Pd130 => write!(f, "Pd130"),
            Self::Pd131 => write!(f, "Pd131"),
        }
    }
}
#[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 PalladiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in PalladiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Pd, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in PalladiumIsotope::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 PalladiumIsotope::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 = PalladiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in PalladiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Pd(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in PalladiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Pd);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in PalladiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = PalladiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = PalladiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = PalladiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(PalladiumIsotope::try_from(0_u16).is_err());
        assert!(PalladiumIsotope::try_from(1000_u16).is_err());
        assert!(PalladiumIsotope::try_from(0_u32).is_err());
        assert!(PalladiumIsotope::try_from(1000_u32).is_err());
        assert!(PalladiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in PalladiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}