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
//! Isotopes of the element Promethium
#[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 Promethium
pub enum PromethiumIsotope {
    /// Isotope Pm126 of Promethium
    Pm126,
    /// Isotope Pm127 of Promethium
    Pm127,
    /// Isotope Pm128 of Promethium
    Pm128,
    /// Isotope Pm129 of Promethium
    Pm129,
    /// Isotope Pm130 of Promethium
    Pm130,
    /// Isotope Pm131 of Promethium
    Pm131,
    /// Isotope Pm132 of Promethium
    Pm132,
    /// Isotope Pm133 of Promethium
    Pm133,
    /// Isotope Pm134 of Promethium
    Pm134,
    /// Isotope Pm135 of Promethium
    Pm135,
    /// Isotope Pm136 of Promethium
    Pm136,
    /// Isotope Pm137 of Promethium
    Pm137,
    /// Isotope Pm138 of Promethium
    Pm138,
    /// Isotope Pm139 of Promethium
    Pm139,
    /// Isotope Pm140 of Promethium
    Pm140,
    /// Isotope Pm141 of Promethium
    Pm141,
    /// Isotope Pm142 of Promethium
    Pm142,
    /// Isotope Pm143 of Promethium
    Pm143,
    /// Isotope Pm144 of Promethium
    Pm144,
    /// Isotope Pm145 of Promethium
    Pm145,
    /// Isotope Pm146 of Promethium
    Pm146,
    /// Isotope Pm147 of Promethium
    Pm147,
    /// Isotope Pm148 of Promethium
    Pm148,
    /// Isotope Pm149 of Promethium
    Pm149,
    /// Isotope Pm150 of Promethium
    Pm150,
    /// Isotope Pm151 of Promethium
    Pm151,
    /// Isotope Pm152 of Promethium
    Pm152,
    /// Isotope Pm153 of Promethium
    Pm153,
    /// Isotope Pm154 of Promethium
    Pm154,
    /// Isotope Pm155 of Promethium
    Pm155,
    /// Isotope Pm156 of Promethium
    Pm156,
    /// Isotope Pm157 of Promethium
    Pm157,
    /// Isotope Pm158 of Promethium
    Pm158,
    /// Isotope Pm159 of Promethium
    Pm159,
    /// Isotope Pm160 of Promethium
    Pm160,
    /// Isotope Pm161 of Promethium
    Pm161,
    /// Isotope Pm162 of Promethium
    Pm162,
    /// Isotope Pm163 of Promethium
    Pm163,
    /// Isotope Pm164 of Promethium
    Pm164,
    /// Isotope Pm165 of Promethium
    Pm165,
}
impl super::RelativeAtomicMass for PromethiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Pm126 => 125.95792f64,
            Self::Pm127 => 126.95192f64,
            Self::Pm128 => 127.9487f64,
            Self::Pm129 => 128.94323f64,
            Self::Pm130 => 129.94053f64,
            Self::Pm131 => 130.93567f64,
            Self::Pm132 => 131.93384f64,
            Self::Pm133 => 132.929782f64,
            Self::Pm134 => 133.928353f64,
            Self::Pm135 => 134.924823f64,
            Self::Pm136 => 135.923585f64,
            Self::Pm137 => 136.92048f64,
            Self::Pm138 => 137.919548f64,
            Self::Pm139 => 138.9168f64,
            Self::Pm140 => 139.91604f64,
            Self::Pm141 => 140.913555f64,
            Self::Pm142 => 141.91289f64,
            Self::Pm143 => 142.9109383f64,
            Self::Pm144 => 143.9125964f64,
            Self::Pm145 => 144.9127559f64,
            Self::Pm146 => 145.9147024f64,
            Self::Pm147 => 146.915145f64,
            Self::Pm148 => 147.9174819f64,
            Self::Pm149 => 148.9183423f64,
            Self::Pm150 => 149.920991f64,
            Self::Pm151 => 150.9212175f64,
            Self::Pm152 => 151.923506f64,
            Self::Pm153 => 152.9241567f64,
            Self::Pm154 => 153.926472f64,
            Self::Pm155 => 154.928137f64,
            Self::Pm156 => 155.9311175f64,
            Self::Pm157 => 156.9331214f64,
            Self::Pm158 => 157.936565f64,
            Self::Pm159 => 158.939287f64,
            Self::Pm160 => 159.9431f64,
            Self::Pm161 => 160.94607f64,
            Self::Pm162 => 161.95022f64,
            Self::Pm163 => 162.95357f64,
            Self::Pm164 => 163.958819f64,
            Self::Pm165 => 164.96278f64,
        }
    }
}
impl super::ElementVariant for PromethiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Pm
    }
}
impl super::MassNumber for PromethiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Pm126 => 126u16,
            Self::Pm127 => 127u16,
            Self::Pm128 => 128u16,
            Self::Pm129 => 129u16,
            Self::Pm130 => 130u16,
            Self::Pm131 => 131u16,
            Self::Pm132 => 132u16,
            Self::Pm133 => 133u16,
            Self::Pm134 => 134u16,
            Self::Pm135 => 135u16,
            Self::Pm136 => 136u16,
            Self::Pm137 => 137u16,
            Self::Pm138 => 138u16,
            Self::Pm139 => 139u16,
            Self::Pm140 => 140u16,
            Self::Pm141 => 141u16,
            Self::Pm142 => 142u16,
            Self::Pm143 => 143u16,
            Self::Pm144 => 144u16,
            Self::Pm145 => 145u16,
            Self::Pm146 => 146u16,
            Self::Pm147 => 147u16,
            Self::Pm148 => 148u16,
            Self::Pm149 => 149u16,
            Self::Pm150 => 150u16,
            Self::Pm151 => 151u16,
            Self::Pm152 => 152u16,
            Self::Pm153 => 153u16,
            Self::Pm154 => 154u16,
            Self::Pm155 => 155u16,
            Self::Pm156 => 156u16,
            Self::Pm157 => 157u16,
            Self::Pm158 => 158u16,
            Self::Pm159 => 159u16,
            Self::Pm160 => 160u16,
            Self::Pm161 => 161u16,
            Self::Pm162 => 162u16,
            Self::Pm163 => 163u16,
            Self::Pm164 => 164u16,
            Self::Pm165 => 165u16,
        }
    }
}
impl super::IsotopicComposition for PromethiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        None
    }
}
impl super::MostAbundantIsotope for PromethiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Pm165
    }
}
impl From<PromethiumIsotope> for crate::Isotope {
    fn from(isotope: PromethiumIsotope) -> Self {
        crate::Isotope::Pm(isotope)
    }
}
impl From<PromethiumIsotope> for crate::Element {
    fn from(_isotope: PromethiumIsotope) -> Self {
        crate::Element::Pm
    }
}
impl TryFrom<u64> for PromethiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            126u64 => Ok(Self::Pm126),
            127u64 => Ok(Self::Pm127),
            128u64 => Ok(Self::Pm128),
            129u64 => Ok(Self::Pm129),
            130u64 => Ok(Self::Pm130),
            131u64 => Ok(Self::Pm131),
            132u64 => Ok(Self::Pm132),
            133u64 => Ok(Self::Pm133),
            134u64 => Ok(Self::Pm134),
            135u64 => Ok(Self::Pm135),
            136u64 => Ok(Self::Pm136),
            137u64 => Ok(Self::Pm137),
            138u64 => Ok(Self::Pm138),
            139u64 => Ok(Self::Pm139),
            140u64 => Ok(Self::Pm140),
            141u64 => Ok(Self::Pm141),
            142u64 => Ok(Self::Pm142),
            143u64 => Ok(Self::Pm143),
            144u64 => Ok(Self::Pm144),
            145u64 => Ok(Self::Pm145),
            146u64 => Ok(Self::Pm146),
            147u64 => Ok(Self::Pm147),
            148u64 => Ok(Self::Pm148),
            149u64 => Ok(Self::Pm149),
            150u64 => Ok(Self::Pm150),
            151u64 => Ok(Self::Pm151),
            152u64 => Ok(Self::Pm152),
            153u64 => Ok(Self::Pm153),
            154u64 => Ok(Self::Pm154),
            155u64 => Ok(Self::Pm155),
            156u64 => Ok(Self::Pm156),
            157u64 => Ok(Self::Pm157),
            158u64 => Ok(Self::Pm158),
            159u64 => Ok(Self::Pm159),
            160u64 => Ok(Self::Pm160),
            161u64 => Ok(Self::Pm161),
            162u64 => Ok(Self::Pm162),
            163u64 => Ok(Self::Pm163),
            164u64 => Ok(Self::Pm164),
            165u64 => Ok(Self::Pm165),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Pm, value)),
        }
    }
}
impl TryFrom<u8> for PromethiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for PromethiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for PromethiumIsotope {
    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 PromethiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Pm126 => write!(f, "Pm126"),
            Self::Pm127 => write!(f, "Pm127"),
            Self::Pm128 => write!(f, "Pm128"),
            Self::Pm129 => write!(f, "Pm129"),
            Self::Pm130 => write!(f, "Pm130"),
            Self::Pm131 => write!(f, "Pm131"),
            Self::Pm132 => write!(f, "Pm132"),
            Self::Pm133 => write!(f, "Pm133"),
            Self::Pm134 => write!(f, "Pm134"),
            Self::Pm135 => write!(f, "Pm135"),
            Self::Pm136 => write!(f, "Pm136"),
            Self::Pm137 => write!(f, "Pm137"),
            Self::Pm138 => write!(f, "Pm138"),
            Self::Pm139 => write!(f, "Pm139"),
            Self::Pm140 => write!(f, "Pm140"),
            Self::Pm141 => write!(f, "Pm141"),
            Self::Pm142 => write!(f, "Pm142"),
            Self::Pm143 => write!(f, "Pm143"),
            Self::Pm144 => write!(f, "Pm144"),
            Self::Pm145 => write!(f, "Pm145"),
            Self::Pm146 => write!(f, "Pm146"),
            Self::Pm147 => write!(f, "Pm147"),
            Self::Pm148 => write!(f, "Pm148"),
            Self::Pm149 => write!(f, "Pm149"),
            Self::Pm150 => write!(f, "Pm150"),
            Self::Pm151 => write!(f, "Pm151"),
            Self::Pm152 => write!(f, "Pm152"),
            Self::Pm153 => write!(f, "Pm153"),
            Self::Pm154 => write!(f, "Pm154"),
            Self::Pm155 => write!(f, "Pm155"),
            Self::Pm156 => write!(f, "Pm156"),
            Self::Pm157 => write!(f, "Pm157"),
            Self::Pm158 => write!(f, "Pm158"),
            Self::Pm159 => write!(f, "Pm159"),
            Self::Pm160 => write!(f, "Pm160"),
            Self::Pm161 => write!(f, "Pm161"),
            Self::Pm162 => write!(f, "Pm162"),
            Self::Pm163 => write!(f, "Pm163"),
            Self::Pm164 => write!(f, "Pm164"),
            Self::Pm165 => write!(f, "Pm165"),
        }
    }
}
#[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 PromethiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in PromethiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Pm, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in PromethiumIsotope::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 PromethiumIsotope::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 = PromethiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in PromethiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Pm(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in PromethiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Pm);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in PromethiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = PromethiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = PromethiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = PromethiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(PromethiumIsotope::try_from(0_u16).is_err());
        assert!(PromethiumIsotope::try_from(1000_u16).is_err());
        assert!(PromethiumIsotope::try_from(0_u32).is_err());
        assert!(PromethiumIsotope::try_from(1000_u32).is_err());
        assert!(PromethiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in PromethiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}