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
437
438
//! Isotopes of the element Tellurium
#[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 Tellurium
pub enum TelluriumIsotope {
    /// Isotope Te104 of Tellurium
    Te104,
    /// Isotope Te105 of Tellurium
    Te105,
    /// Isotope Te106 of Tellurium
    Te106,
    /// Isotope Te107 of Tellurium
    Te107,
    /// Isotope Te108 of Tellurium
    Te108,
    /// Isotope Te109 of Tellurium
    Te109,
    /// Isotope Te110 of Tellurium
    Te110,
    /// Isotope Te111 of Tellurium
    Te111,
    /// Isotope Te112 of Tellurium
    Te112,
    /// Isotope Te113 of Tellurium
    Te113,
    /// Isotope Te114 of Tellurium
    Te114,
    /// Isotope Te115 of Tellurium
    Te115,
    /// Isotope Te116 of Tellurium
    Te116,
    /// Isotope Te117 of Tellurium
    Te117,
    /// Isotope Te118 of Tellurium
    Te118,
    /// Isotope Te119 of Tellurium
    Te119,
    /// Isotope Te120 of Tellurium
    Te120,
    /// Isotope Te121 of Tellurium
    Te121,
    /// Isotope Te122 of Tellurium
    Te122,
    /// Isotope Te123 of Tellurium
    Te123,
    /// Isotope Te124 of Tellurium
    Te124,
    /// Isotope Te125 of Tellurium
    Te125,
    /// Isotope Te126 of Tellurium
    Te126,
    /// Isotope Te127 of Tellurium
    Te127,
    /// Isotope Te128 of Tellurium
    Te128,
    /// Isotope Te129 of Tellurium
    Te129,
    /// Isotope Te130 of Tellurium
    Te130,
    /// Isotope Te131 of Tellurium
    Te131,
    /// Isotope Te132 of Tellurium
    Te132,
    /// Isotope Te133 of Tellurium
    Te133,
    /// Isotope Te134 of Tellurium
    Te134,
    /// Isotope Te135 of Tellurium
    Te135,
    /// Isotope Te136 of Tellurium
    Te136,
    /// Isotope Te137 of Tellurium
    Te137,
    /// Isotope Te138 of Tellurium
    Te138,
    /// Isotope Te139 of Tellurium
    Te139,
    /// Isotope Te140 of Tellurium
    Te140,
    /// Isotope Te141 of Tellurium
    Te141,
    /// Isotope Te142 of Tellurium
    Te142,
    /// Isotope Te143 of Tellurium
    Te143,
    /// Isotope Te144 of Tellurium
    Te144,
    /// Isotope Te145 of Tellurium
    Te145,
}
impl super::RelativeAtomicMass for TelluriumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Te104 => 103.946723408f64,
            Self::Te105 => 104.9433f64,
            Self::Te106 => 105.9375f64,
            Self::Te107 => 106.935012f64,
            Self::Te108 => 107.9293805f64,
            Self::Te109 => 108.9273045f64,
            Self::Te110 => 109.9224581f64,
            Self::Te111 => 110.9210006f64,
            Self::Te112 => 111.9167279f64,
            Self::Te113 => 112.915891f64,
            Self::Te114 => 113.912089f64,
            Self::Te115 => 114.911902f64,
            Self::Te116 => 115.90846f64,
            Self::Te117 => 116.908646f64,
            Self::Te118 => 117.905854f64,
            Self::Te119 => 118.9064071f64,
            Self::Te120 => 119.9040593f64,
            Self::Te121 => 120.904944f64,
            Self::Te122 => 121.9030435f64,
            Self::Te123 => 122.9042698f64,
            Self::Te124 => 123.9028171f64,
            Self::Te125 => 124.9044299f64,
            Self::Te126 => 125.9033109f64,
            Self::Te127 => 126.9052257f64,
            Self::Te128 => 127.90446128f64,
            Self::Te129 => 128.90659646f64,
            Self::Te130 => 129.906222748f64,
            Self::Te131 => 130.908522213f64,
            Self::Te132 => 131.9085467f64,
            Self::Te133 => 132.9109688f64,
            Self::Te134 => 133.911394f64,
            Self::Te135 => 134.9165557f64,
            Self::Te136 => 135.9201006f64,
            Self::Te137 => 136.9255989f64,
            Self::Te138 => 137.9294722f64,
            Self::Te139 => 138.9353672f64,
            Self::Te140 => 139.939499f64,
            Self::Te141 => 140.9458f64,
            Self::Te142 => 141.95022f64,
            Self::Te143 => 142.95676f64,
            Self::Te144 => 143.961116f64,
            Self::Te145 => 144.967783f64,
        }
    }
}
impl super::ElementVariant for TelluriumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Te
    }
}
impl super::MassNumber for TelluriumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Te104 => 104u16,
            Self::Te105 => 105u16,
            Self::Te106 => 106u16,
            Self::Te107 => 107u16,
            Self::Te108 => 108u16,
            Self::Te109 => 109u16,
            Self::Te110 => 110u16,
            Self::Te111 => 111u16,
            Self::Te112 => 112u16,
            Self::Te113 => 113u16,
            Self::Te114 => 114u16,
            Self::Te115 => 115u16,
            Self::Te116 => 116u16,
            Self::Te117 => 117u16,
            Self::Te118 => 118u16,
            Self::Te119 => 119u16,
            Self::Te120 => 120u16,
            Self::Te121 => 121u16,
            Self::Te122 => 122u16,
            Self::Te123 => 123u16,
            Self::Te124 => 124u16,
            Self::Te125 => 125u16,
            Self::Te126 => 126u16,
            Self::Te127 => 127u16,
            Self::Te128 => 128u16,
            Self::Te129 => 129u16,
            Self::Te130 => 130u16,
            Self::Te131 => 131u16,
            Self::Te132 => 132u16,
            Self::Te133 => 133u16,
            Self::Te134 => 134u16,
            Self::Te135 => 135u16,
            Self::Te136 => 136u16,
            Self::Te137 => 137u16,
            Self::Te138 => 138u16,
            Self::Te139 => 139u16,
            Self::Te140 => 140u16,
            Self::Te141 => 141u16,
            Self::Te142 => 142u16,
            Self::Te143 => 143u16,
            Self::Te144 => 144u16,
            Self::Te145 => 145u16,
        }
    }
}
impl super::IsotopicComposition for TelluriumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Te120 => Some(0.0009f64),
            Self::Te122 => Some(0.0255f64),
            Self::Te123 => Some(0.0089f64),
            Self::Te124 => Some(0.0474f64),
            Self::Te125 => Some(0.0707f64),
            Self::Te126 => Some(0.1884f64),
            Self::Te128 => Some(0.3174f64),
            Self::Te130 => Some(0.3408f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for TelluriumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Te130
    }
}
impl From<TelluriumIsotope> for crate::Isotope {
    fn from(isotope: TelluriumIsotope) -> Self {
        crate::Isotope::Te(isotope)
    }
}
impl From<TelluriumIsotope> for crate::Element {
    fn from(_isotope: TelluriumIsotope) -> Self {
        crate::Element::Te
    }
}
impl TryFrom<u64> for TelluriumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            104u64 => Ok(Self::Te104),
            105u64 => Ok(Self::Te105),
            106u64 => Ok(Self::Te106),
            107u64 => Ok(Self::Te107),
            108u64 => Ok(Self::Te108),
            109u64 => Ok(Self::Te109),
            110u64 => Ok(Self::Te110),
            111u64 => Ok(Self::Te111),
            112u64 => Ok(Self::Te112),
            113u64 => Ok(Self::Te113),
            114u64 => Ok(Self::Te114),
            115u64 => Ok(Self::Te115),
            116u64 => Ok(Self::Te116),
            117u64 => Ok(Self::Te117),
            118u64 => Ok(Self::Te118),
            119u64 => Ok(Self::Te119),
            120u64 => Ok(Self::Te120),
            121u64 => Ok(Self::Te121),
            122u64 => Ok(Self::Te122),
            123u64 => Ok(Self::Te123),
            124u64 => Ok(Self::Te124),
            125u64 => Ok(Self::Te125),
            126u64 => Ok(Self::Te126),
            127u64 => Ok(Self::Te127),
            128u64 => Ok(Self::Te128),
            129u64 => Ok(Self::Te129),
            130u64 => Ok(Self::Te130),
            131u64 => Ok(Self::Te131),
            132u64 => Ok(Self::Te132),
            133u64 => Ok(Self::Te133),
            134u64 => Ok(Self::Te134),
            135u64 => Ok(Self::Te135),
            136u64 => Ok(Self::Te136),
            137u64 => Ok(Self::Te137),
            138u64 => Ok(Self::Te138),
            139u64 => Ok(Self::Te139),
            140u64 => Ok(Self::Te140),
            141u64 => Ok(Self::Te141),
            142u64 => Ok(Self::Te142),
            143u64 => Ok(Self::Te143),
            144u64 => Ok(Self::Te144),
            145u64 => Ok(Self::Te145),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Te, value)),
        }
    }
}
impl TryFrom<u8> for TelluriumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for TelluriumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for TelluriumIsotope {
    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 TelluriumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Te104 => write!(f, "Te104"),
            Self::Te105 => write!(f, "Te105"),
            Self::Te106 => write!(f, "Te106"),
            Self::Te107 => write!(f, "Te107"),
            Self::Te108 => write!(f, "Te108"),
            Self::Te109 => write!(f, "Te109"),
            Self::Te110 => write!(f, "Te110"),
            Self::Te111 => write!(f, "Te111"),
            Self::Te112 => write!(f, "Te112"),
            Self::Te113 => write!(f, "Te113"),
            Self::Te114 => write!(f, "Te114"),
            Self::Te115 => write!(f, "Te115"),
            Self::Te116 => write!(f, "Te116"),
            Self::Te117 => write!(f, "Te117"),
            Self::Te118 => write!(f, "Te118"),
            Self::Te119 => write!(f, "Te119"),
            Self::Te120 => write!(f, "Te120"),
            Self::Te121 => write!(f, "Te121"),
            Self::Te122 => write!(f, "Te122"),
            Self::Te123 => write!(f, "Te123"),
            Self::Te124 => write!(f, "Te124"),
            Self::Te125 => write!(f, "Te125"),
            Self::Te126 => write!(f, "Te126"),
            Self::Te127 => write!(f, "Te127"),
            Self::Te128 => write!(f, "Te128"),
            Self::Te129 => write!(f, "Te129"),
            Self::Te130 => write!(f, "Te130"),
            Self::Te131 => write!(f, "Te131"),
            Self::Te132 => write!(f, "Te132"),
            Self::Te133 => write!(f, "Te133"),
            Self::Te134 => write!(f, "Te134"),
            Self::Te135 => write!(f, "Te135"),
            Self::Te136 => write!(f, "Te136"),
            Self::Te137 => write!(f, "Te137"),
            Self::Te138 => write!(f, "Te138"),
            Self::Te139 => write!(f, "Te139"),
            Self::Te140 => write!(f, "Te140"),
            Self::Te141 => write!(f, "Te141"),
            Self::Te142 => write!(f, "Te142"),
            Self::Te143 => write!(f, "Te143"),
            Self::Te144 => write!(f, "Te144"),
            Self::Te145 => write!(f, "Te145"),
        }
    }
}
#[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 TelluriumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in TelluriumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Te, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in TelluriumIsotope::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 TelluriumIsotope::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 = TelluriumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in TelluriumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Te(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in TelluriumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Te);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in TelluriumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = TelluriumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = TelluriumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = TelluriumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(TelluriumIsotope::try_from(0_u16).is_err());
        assert!(TelluriumIsotope::try_from(1000_u16).is_err());
        assert!(TelluriumIsotope::try_from(0_u32).is_err());
        assert!(TelluriumIsotope::try_from(1000_u32).is_err());
        assert!(TelluriumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in TelluriumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}