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
//! Isotopes of the element Lanthanum
#[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 Lanthanum
pub enum LanthanumIsotope {
    /// Isotope La116 of Lanthanum
    La116,
    /// Isotope La117 of Lanthanum
    La117,
    /// Isotope La118 of Lanthanum
    La118,
    /// Isotope La119 of Lanthanum
    La119,
    /// Isotope La120 of Lanthanum
    La120,
    /// Isotope La121 of Lanthanum
    La121,
    /// Isotope La122 of Lanthanum
    La122,
    /// Isotope La123 of Lanthanum
    La123,
    /// Isotope La124 of Lanthanum
    La124,
    /// Isotope La125 of Lanthanum
    La125,
    /// Isotope La126 of Lanthanum
    La126,
    /// Isotope La127 of Lanthanum
    La127,
    /// Isotope La128 of Lanthanum
    La128,
    /// Isotope La129 of Lanthanum
    La129,
    /// Isotope La130 of Lanthanum
    La130,
    /// Isotope La131 of Lanthanum
    La131,
    /// Isotope La132 of Lanthanum
    La132,
    /// Isotope La133 of Lanthanum
    La133,
    /// Isotope La134 of Lanthanum
    La134,
    /// Isotope La135 of Lanthanum
    La135,
    /// Isotope La136 of Lanthanum
    La136,
    /// Isotope La137 of Lanthanum
    La137,
    /// Isotope La138 of Lanthanum
    La138,
    /// Isotope La139 of Lanthanum
    La139,
    /// Isotope La140 of Lanthanum
    La140,
    /// Isotope La141 of Lanthanum
    La141,
    /// Isotope La142 of Lanthanum
    La142,
    /// Isotope La143 of Lanthanum
    La143,
    /// Isotope La144 of Lanthanum
    La144,
    /// Isotope La145 of Lanthanum
    La145,
    /// Isotope La146 of Lanthanum
    La146,
    /// Isotope La147 of Lanthanum
    La147,
    /// Isotope La148 of Lanthanum
    La148,
    /// Isotope La149 of Lanthanum
    La149,
    /// Isotope La150 of Lanthanum
    La150,
    /// Isotope La151 of Lanthanum
    La151,
    /// Isotope La152 of Lanthanum
    La152,
    /// Isotope La153 of Lanthanum
    La153,
    /// Isotope La154 of Lanthanum
    La154,
    /// Isotope La155 of Lanthanum
    La155,
    /// Isotope La156 of Lanthanum
    La156,
    /// Isotope La157 of Lanthanum
    La157,
}
impl super::RelativeAtomicMass for LanthanumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::La116 => 115.9563f64,
            Self::La117 => 116.94999f64,
            Self::La118 => 117.94673f64,
            Self::La119 => 118.94099f64,
            Self::La120 => 119.93807f64,
            Self::La121 => 120.93315f64,
            Self::La122 => 121.93071f64,
            Self::La123 => 122.9263f64,
            Self::La124 => 123.924574f64,
            Self::La125 => 124.920816f64,
            Self::La126 => 125.919513f64,
            Self::La127 => 126.916375f64,
            Self::La128 => 127.915592f64,
            Self::La129 => 128.912694f64,
            Self::La130 => 129.912369f64,
            Self::La131 => 130.91007f64,
            Self::La132 => 131.910119f64,
            Self::La133 => 132.908218f64,
            Self::La134 => 133.908514f64,
            Self::La135 => 134.906984f64,
            Self::La136 => 135.907635f64,
            Self::La137 => 136.9064504f64,
            Self::La138 => 137.9071149f64,
            Self::La139 => 138.9063563f64,
            Self::La140 => 139.9094806f64,
            Self::La141 => 140.910966f64,
            Self::La142 => 141.9140909f64,
            Self::La143 => 142.9160795f64,
            Self::La144 => 143.919646f64,
            Self::La145 => 144.921808f64,
            Self::La146 => 145.925875f64,
            Self::La147 => 146.928418f64,
            Self::La148 => 147.932679f64,
            Self::La149 => 148.93535f64,
            Self::La150 => 149.93947f64,
            Self::La151 => 150.94232f64,
            Self::La152 => 151.94682f64,
            Self::La153 => 152.95036f64,
            Self::La154 => 153.95517f64,
            Self::La155 => 154.95901f64,
            Self::La156 => 155.964519f64,
            Self::La157 => 156.968792f64,
        }
    }
}
impl super::ElementVariant for LanthanumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::La
    }
}
impl super::MassNumber for LanthanumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::La116 => 116u16,
            Self::La117 => 117u16,
            Self::La118 => 118u16,
            Self::La119 => 119u16,
            Self::La120 => 120u16,
            Self::La121 => 121u16,
            Self::La122 => 122u16,
            Self::La123 => 123u16,
            Self::La124 => 124u16,
            Self::La125 => 125u16,
            Self::La126 => 126u16,
            Self::La127 => 127u16,
            Self::La128 => 128u16,
            Self::La129 => 129u16,
            Self::La130 => 130u16,
            Self::La131 => 131u16,
            Self::La132 => 132u16,
            Self::La133 => 133u16,
            Self::La134 => 134u16,
            Self::La135 => 135u16,
            Self::La136 => 136u16,
            Self::La137 => 137u16,
            Self::La138 => 138u16,
            Self::La139 => 139u16,
            Self::La140 => 140u16,
            Self::La141 => 141u16,
            Self::La142 => 142u16,
            Self::La143 => 143u16,
            Self::La144 => 144u16,
            Self::La145 => 145u16,
            Self::La146 => 146u16,
            Self::La147 => 147u16,
            Self::La148 => 148u16,
            Self::La149 => 149u16,
            Self::La150 => 150u16,
            Self::La151 => 151u16,
            Self::La152 => 152u16,
            Self::La153 => 153u16,
            Self::La154 => 154u16,
            Self::La155 => 155u16,
            Self::La156 => 156u16,
            Self::La157 => 157u16,
        }
    }
}
impl super::IsotopicComposition for LanthanumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::La138 => Some(0.0008881f64),
            Self::La139 => Some(0.9991119f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for LanthanumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::La139
    }
}
impl From<LanthanumIsotope> for crate::Isotope {
    fn from(isotope: LanthanumIsotope) -> Self {
        crate::Isotope::La(isotope)
    }
}
impl From<LanthanumIsotope> for crate::Element {
    fn from(_isotope: LanthanumIsotope) -> Self {
        crate::Element::La
    }
}
impl TryFrom<u64> for LanthanumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            116u64 => Ok(Self::La116),
            117u64 => Ok(Self::La117),
            118u64 => Ok(Self::La118),
            119u64 => Ok(Self::La119),
            120u64 => Ok(Self::La120),
            121u64 => Ok(Self::La121),
            122u64 => Ok(Self::La122),
            123u64 => Ok(Self::La123),
            124u64 => Ok(Self::La124),
            125u64 => Ok(Self::La125),
            126u64 => Ok(Self::La126),
            127u64 => Ok(Self::La127),
            128u64 => Ok(Self::La128),
            129u64 => Ok(Self::La129),
            130u64 => Ok(Self::La130),
            131u64 => Ok(Self::La131),
            132u64 => Ok(Self::La132),
            133u64 => Ok(Self::La133),
            134u64 => Ok(Self::La134),
            135u64 => Ok(Self::La135),
            136u64 => Ok(Self::La136),
            137u64 => Ok(Self::La137),
            138u64 => Ok(Self::La138),
            139u64 => Ok(Self::La139),
            140u64 => Ok(Self::La140),
            141u64 => Ok(Self::La141),
            142u64 => Ok(Self::La142),
            143u64 => Ok(Self::La143),
            144u64 => Ok(Self::La144),
            145u64 => Ok(Self::La145),
            146u64 => Ok(Self::La146),
            147u64 => Ok(Self::La147),
            148u64 => Ok(Self::La148),
            149u64 => Ok(Self::La149),
            150u64 => Ok(Self::La150),
            151u64 => Ok(Self::La151),
            152u64 => Ok(Self::La152),
            153u64 => Ok(Self::La153),
            154u64 => Ok(Self::La154),
            155u64 => Ok(Self::La155),
            156u64 => Ok(Self::La156),
            157u64 => Ok(Self::La157),
            _ => Err(crate::errors::Error::Isotope(crate::Element::La, value)),
        }
    }
}
impl TryFrom<u8> for LanthanumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for LanthanumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for LanthanumIsotope {
    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 LanthanumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::La116 => write!(f, "La116"),
            Self::La117 => write!(f, "La117"),
            Self::La118 => write!(f, "La118"),
            Self::La119 => write!(f, "La119"),
            Self::La120 => write!(f, "La120"),
            Self::La121 => write!(f, "La121"),
            Self::La122 => write!(f, "La122"),
            Self::La123 => write!(f, "La123"),
            Self::La124 => write!(f, "La124"),
            Self::La125 => write!(f, "La125"),
            Self::La126 => write!(f, "La126"),
            Self::La127 => write!(f, "La127"),
            Self::La128 => write!(f, "La128"),
            Self::La129 => write!(f, "La129"),
            Self::La130 => write!(f, "La130"),
            Self::La131 => write!(f, "La131"),
            Self::La132 => write!(f, "La132"),
            Self::La133 => write!(f, "La133"),
            Self::La134 => write!(f, "La134"),
            Self::La135 => write!(f, "La135"),
            Self::La136 => write!(f, "La136"),
            Self::La137 => write!(f, "La137"),
            Self::La138 => write!(f, "La138"),
            Self::La139 => write!(f, "La139"),
            Self::La140 => write!(f, "La140"),
            Self::La141 => write!(f, "La141"),
            Self::La142 => write!(f, "La142"),
            Self::La143 => write!(f, "La143"),
            Self::La144 => write!(f, "La144"),
            Self::La145 => write!(f, "La145"),
            Self::La146 => write!(f, "La146"),
            Self::La147 => write!(f, "La147"),
            Self::La148 => write!(f, "La148"),
            Self::La149 => write!(f, "La149"),
            Self::La150 => write!(f, "La150"),
            Self::La151 => write!(f, "La151"),
            Self::La152 => write!(f, "La152"),
            Self::La153 => write!(f, "La153"),
            Self::La154 => write!(f, "La154"),
            Self::La155 => write!(f, "La155"),
            Self::La156 => write!(f, "La156"),
            Self::La157 => write!(f, "La157"),
        }
    }
}
#[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 LanthanumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in LanthanumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::La, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in LanthanumIsotope::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 LanthanumIsotope::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 = LanthanumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in LanthanumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::La(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in LanthanumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::La);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in LanthanumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = LanthanumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = LanthanumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = LanthanumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(LanthanumIsotope::try_from(0_u16).is_err());
        assert!(LanthanumIsotope::try_from(1000_u16).is_err());
        assert!(LanthanumIsotope::try_from(0_u32).is_err());
        assert!(LanthanumIsotope::try_from(1000_u32).is_err());
        assert!(LanthanumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in LanthanumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}