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
//! Isotopes of the element Samarium
#[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 Samarium
pub enum SamariumIsotope {
    /// Isotope Sm128 of Samarium
    Sm128,
    /// Isotope Sm129 of Samarium
    Sm129,
    /// Isotope Sm130 of Samarium
    Sm130,
    /// Isotope Sm131 of Samarium
    Sm131,
    /// Isotope Sm132 of Samarium
    Sm132,
    /// Isotope Sm133 of Samarium
    Sm133,
    /// Isotope Sm134 of Samarium
    Sm134,
    /// Isotope Sm135 of Samarium
    Sm135,
    /// Isotope Sm136 of Samarium
    Sm136,
    /// Isotope Sm137 of Samarium
    Sm137,
    /// Isotope Sm138 of Samarium
    Sm138,
    /// Isotope Sm139 of Samarium
    Sm139,
    /// Isotope Sm140 of Samarium
    Sm140,
    /// Isotope Sm141 of Samarium
    Sm141,
    /// Isotope Sm142 of Samarium
    Sm142,
    /// Isotope Sm143 of Samarium
    Sm143,
    /// Isotope Sm144 of Samarium
    Sm144,
    /// Isotope Sm145 of Samarium
    Sm145,
    /// Isotope Sm146 of Samarium
    Sm146,
    /// Isotope Sm147 of Samarium
    Sm147,
    /// Isotope Sm148 of Samarium
    Sm148,
    /// Isotope Sm149 of Samarium
    Sm149,
    /// Isotope Sm150 of Samarium
    Sm150,
    /// Isotope Sm151 of Samarium
    Sm151,
    /// Isotope Sm152 of Samarium
    Sm152,
    /// Isotope Sm153 of Samarium
    Sm153,
    /// Isotope Sm154 of Samarium
    Sm154,
    /// Isotope Sm155 of Samarium
    Sm155,
    /// Isotope Sm156 of Samarium
    Sm156,
    /// Isotope Sm157 of Samarium
    Sm157,
    /// Isotope Sm158 of Samarium
    Sm158,
    /// Isotope Sm159 of Samarium
    Sm159,
    /// Isotope Sm160 of Samarium
    Sm160,
    /// Isotope Sm161 of Samarium
    Sm161,
    /// Isotope Sm162 of Samarium
    Sm162,
    /// Isotope Sm163 of Samarium
    Sm163,
    /// Isotope Sm164 of Samarium
    Sm164,
    /// Isotope Sm165 of Samarium
    Sm165,
    /// Isotope Sm166 of Samarium
    Sm166,
    /// Isotope Sm167 of Samarium
    Sm167,
    /// Isotope Sm168 of Samarium
    Sm168,
}
impl super::RelativeAtomicMass for SamariumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Sm128 => 127.95842f64,
            Self::Sm129 => 128.95476f64,
            Self::Sm130 => 129.949f64,
            Self::Sm131 => 130.94618f64,
            Self::Sm132 => 131.94087f64,
            Self::Sm133 => 132.93856f64,
            Self::Sm134 => 133.93411f64,
            Self::Sm135 => 134.93252f64,
            Self::Sm136 => 135.928276f64,
            Self::Sm137 => 136.926971f64,
            Self::Sm138 => 137.923244f64,
            Self::Sm139 => 138.922297f64,
            Self::Sm140 => 139.918995f64,
            Self::Sm141 => 140.9184816f64,
            Self::Sm142 => 141.9152044f64,
            Self::Sm143 => 142.9146353f64,
            Self::Sm144 => 143.9120065f64,
            Self::Sm145 => 144.9134173f64,
            Self::Sm146 => 145.913047f64,
            Self::Sm147 => 146.9149044f64,
            Self::Sm148 => 147.9148292f64,
            Self::Sm149 => 148.9171921f64,
            Self::Sm150 => 149.9172829f64,
            Self::Sm151 => 150.9199398f64,
            Self::Sm152 => 151.9197397f64,
            Self::Sm153 => 152.9221047f64,
            Self::Sm154 => 153.9222169f64,
            Self::Sm155 => 154.9246477f64,
            Self::Sm156 => 155.925536f64,
            Self::Sm157 => 156.9284187f64,
            Self::Sm158 => 157.929951f64,
            Self::Sm159 => 158.9332172f64,
            Self::Sm160 => 159.9353353f64,
            Self::Sm161 => 160.9391602f64,
            Self::Sm162 => 161.94146f64,
            Self::Sm163 => 162.94555f64,
            Self::Sm164 => 163.94836f64,
            Self::Sm165 => 164.95297f64,
            Self::Sm166 => 165.956575f64,
            Self::Sm167 => 166.962072f64,
            Self::Sm168 => 167.966033f64,
        }
    }
}
impl super::ElementVariant for SamariumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Sm
    }
}
impl super::MassNumber for SamariumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Sm128 => 128u16,
            Self::Sm129 => 129u16,
            Self::Sm130 => 130u16,
            Self::Sm131 => 131u16,
            Self::Sm132 => 132u16,
            Self::Sm133 => 133u16,
            Self::Sm134 => 134u16,
            Self::Sm135 => 135u16,
            Self::Sm136 => 136u16,
            Self::Sm137 => 137u16,
            Self::Sm138 => 138u16,
            Self::Sm139 => 139u16,
            Self::Sm140 => 140u16,
            Self::Sm141 => 141u16,
            Self::Sm142 => 142u16,
            Self::Sm143 => 143u16,
            Self::Sm144 => 144u16,
            Self::Sm145 => 145u16,
            Self::Sm146 => 146u16,
            Self::Sm147 => 147u16,
            Self::Sm148 => 148u16,
            Self::Sm149 => 149u16,
            Self::Sm150 => 150u16,
            Self::Sm151 => 151u16,
            Self::Sm152 => 152u16,
            Self::Sm153 => 153u16,
            Self::Sm154 => 154u16,
            Self::Sm155 => 155u16,
            Self::Sm156 => 156u16,
            Self::Sm157 => 157u16,
            Self::Sm158 => 158u16,
            Self::Sm159 => 159u16,
            Self::Sm160 => 160u16,
            Self::Sm161 => 161u16,
            Self::Sm162 => 162u16,
            Self::Sm163 => 163u16,
            Self::Sm164 => 164u16,
            Self::Sm165 => 165u16,
            Self::Sm166 => 166u16,
            Self::Sm167 => 167u16,
            Self::Sm168 => 168u16,
        }
    }
}
impl super::IsotopicComposition for SamariumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Sm144 => Some(0.0307f64),
            Self::Sm147 => Some(0.1499f64),
            Self::Sm148 => Some(0.1124f64),
            Self::Sm149 => Some(0.1382f64),
            Self::Sm150 => Some(0.0738f64),
            Self::Sm152 => Some(0.2675f64),
            Self::Sm154 => Some(0.2275f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for SamariumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Sm152
    }
}
impl From<SamariumIsotope> for crate::Isotope {
    fn from(isotope: SamariumIsotope) -> Self {
        crate::Isotope::Sm(isotope)
    }
}
impl From<SamariumIsotope> for crate::Element {
    fn from(_isotope: SamariumIsotope) -> Self {
        crate::Element::Sm
    }
}
impl TryFrom<u64> for SamariumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            128u64 => Ok(Self::Sm128),
            129u64 => Ok(Self::Sm129),
            130u64 => Ok(Self::Sm130),
            131u64 => Ok(Self::Sm131),
            132u64 => Ok(Self::Sm132),
            133u64 => Ok(Self::Sm133),
            134u64 => Ok(Self::Sm134),
            135u64 => Ok(Self::Sm135),
            136u64 => Ok(Self::Sm136),
            137u64 => Ok(Self::Sm137),
            138u64 => Ok(Self::Sm138),
            139u64 => Ok(Self::Sm139),
            140u64 => Ok(Self::Sm140),
            141u64 => Ok(Self::Sm141),
            142u64 => Ok(Self::Sm142),
            143u64 => Ok(Self::Sm143),
            144u64 => Ok(Self::Sm144),
            145u64 => Ok(Self::Sm145),
            146u64 => Ok(Self::Sm146),
            147u64 => Ok(Self::Sm147),
            148u64 => Ok(Self::Sm148),
            149u64 => Ok(Self::Sm149),
            150u64 => Ok(Self::Sm150),
            151u64 => Ok(Self::Sm151),
            152u64 => Ok(Self::Sm152),
            153u64 => Ok(Self::Sm153),
            154u64 => Ok(Self::Sm154),
            155u64 => Ok(Self::Sm155),
            156u64 => Ok(Self::Sm156),
            157u64 => Ok(Self::Sm157),
            158u64 => Ok(Self::Sm158),
            159u64 => Ok(Self::Sm159),
            160u64 => Ok(Self::Sm160),
            161u64 => Ok(Self::Sm161),
            162u64 => Ok(Self::Sm162),
            163u64 => Ok(Self::Sm163),
            164u64 => Ok(Self::Sm164),
            165u64 => Ok(Self::Sm165),
            166u64 => Ok(Self::Sm166),
            167u64 => Ok(Self::Sm167),
            168u64 => Ok(Self::Sm168),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Sm, value)),
        }
    }
}
impl TryFrom<u8> for SamariumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for SamariumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for SamariumIsotope {
    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 SamariumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Sm128 => write!(f, "Sm128"),
            Self::Sm129 => write!(f, "Sm129"),
            Self::Sm130 => write!(f, "Sm130"),
            Self::Sm131 => write!(f, "Sm131"),
            Self::Sm132 => write!(f, "Sm132"),
            Self::Sm133 => write!(f, "Sm133"),
            Self::Sm134 => write!(f, "Sm134"),
            Self::Sm135 => write!(f, "Sm135"),
            Self::Sm136 => write!(f, "Sm136"),
            Self::Sm137 => write!(f, "Sm137"),
            Self::Sm138 => write!(f, "Sm138"),
            Self::Sm139 => write!(f, "Sm139"),
            Self::Sm140 => write!(f, "Sm140"),
            Self::Sm141 => write!(f, "Sm141"),
            Self::Sm142 => write!(f, "Sm142"),
            Self::Sm143 => write!(f, "Sm143"),
            Self::Sm144 => write!(f, "Sm144"),
            Self::Sm145 => write!(f, "Sm145"),
            Self::Sm146 => write!(f, "Sm146"),
            Self::Sm147 => write!(f, "Sm147"),
            Self::Sm148 => write!(f, "Sm148"),
            Self::Sm149 => write!(f, "Sm149"),
            Self::Sm150 => write!(f, "Sm150"),
            Self::Sm151 => write!(f, "Sm151"),
            Self::Sm152 => write!(f, "Sm152"),
            Self::Sm153 => write!(f, "Sm153"),
            Self::Sm154 => write!(f, "Sm154"),
            Self::Sm155 => write!(f, "Sm155"),
            Self::Sm156 => write!(f, "Sm156"),
            Self::Sm157 => write!(f, "Sm157"),
            Self::Sm158 => write!(f, "Sm158"),
            Self::Sm159 => write!(f, "Sm159"),
            Self::Sm160 => write!(f, "Sm160"),
            Self::Sm161 => write!(f, "Sm161"),
            Self::Sm162 => write!(f, "Sm162"),
            Self::Sm163 => write!(f, "Sm163"),
            Self::Sm164 => write!(f, "Sm164"),
            Self::Sm165 => write!(f, "Sm165"),
            Self::Sm166 => write!(f, "Sm166"),
            Self::Sm167 => write!(f, "Sm167"),
            Self::Sm168 => write!(f, "Sm168"),
        }
    }
}
#[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 SamariumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in SamariumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Sm, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in SamariumIsotope::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 SamariumIsotope::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 = SamariumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in SamariumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Sm(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in SamariumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Sm);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in SamariumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = SamariumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = SamariumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = SamariumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(SamariumIsotope::try_from(0_u16).is_err());
        assert!(SamariumIsotope::try_from(1000_u16).is_err());
        assert!(SamariumIsotope::try_from(0_u32).is_err());
        assert!(SamariumIsotope::try_from(1000_u32).is_err());
        assert!(SamariumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in SamariumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}