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
//! Isotopes of the element Antimony
#[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 Antimony
pub enum AntimonyIsotope {
    /// Isotope Sb103 of Antimony
    Sb103,
    /// Isotope Sb104 of Antimony
    Sb104,
    /// Isotope Sb105 of Antimony
    Sb105,
    /// Isotope Sb106 of Antimony
    Sb106,
    /// Isotope Sb107 of Antimony
    Sb107,
    /// Isotope Sb108 of Antimony
    Sb108,
    /// Isotope Sb109 of Antimony
    Sb109,
    /// Isotope Sb110 of Antimony
    Sb110,
    /// Isotope Sb111 of Antimony
    Sb111,
    /// Isotope Sb112 of Antimony
    Sb112,
    /// Isotope Sb113 of Antimony
    Sb113,
    /// Isotope Sb114 of Antimony
    Sb114,
    /// Isotope Sb115 of Antimony
    Sb115,
    /// Isotope Sb116 of Antimony
    Sb116,
    /// Isotope Sb117 of Antimony
    Sb117,
    /// Isotope Sb118 of Antimony
    Sb118,
    /// Isotope Sb119 of Antimony
    Sb119,
    /// Isotope Sb120 of Antimony
    Sb120,
    /// Isotope Sb121 of Antimony
    Sb121,
    /// Isotope Sb122 of Antimony
    Sb122,
    /// Isotope Sb123 of Antimony
    Sb123,
    /// Isotope Sb124 of Antimony
    Sb124,
    /// Isotope Sb125 of Antimony
    Sb125,
    /// Isotope Sb126 of Antimony
    Sb126,
    /// Isotope Sb127 of Antimony
    Sb127,
    /// Isotope Sb128 of Antimony
    Sb128,
    /// Isotope Sb129 of Antimony
    Sb129,
    /// Isotope Sb130 of Antimony
    Sb130,
    /// Isotope Sb131 of Antimony
    Sb131,
    /// Isotope Sb132 of Antimony
    Sb132,
    /// Isotope Sb133 of Antimony
    Sb133,
    /// Isotope Sb134 of Antimony
    Sb134,
    /// Isotope Sb135 of Antimony
    Sb135,
    /// Isotope Sb136 of Antimony
    Sb136,
    /// Isotope Sb137 of Antimony
    Sb137,
    /// Isotope Sb138 of Antimony
    Sb138,
    /// Isotope Sb139 of Antimony
    Sb139,
    /// Isotope Sb140 of Antimony
    Sb140,
    /// Isotope Sb141 of Antimony
    Sb141,
    /// Isotope Sb142 of Antimony
    Sb142,
}
impl super::RelativeAtomicMass for AntimonyIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Sb103 => 102.93969f64,
            Self::Sb104 => 103.93648f64,
            Self::Sb105 => 104.931276f64,
            Self::Sb106 => 105.928638f64,
            Self::Sb107 => 106.9241506f64,
            Self::Sb108 => 107.9222267f64,
            Self::Sb109 => 108.9181411f64,
            Self::Sb110 => 109.9168543f64,
            Self::Sb111 => 110.9132182f64,
            Self::Sb112 => 111.9124f64,
            Self::Sb113 => 112.909375f64,
            Self::Sb114 => 113.90929f64,
            Self::Sb115 => 114.906598f64,
            Self::Sb116 => 115.9067931f64,
            Self::Sb117 => 116.9048415f64,
            Self::Sb118 => 117.9055321f64,
            Self::Sb119 => 118.9039455f64,
            Self::Sb120 => 119.9050794f64,
            Self::Sb121 => 120.903812f64,
            Self::Sb122 => 121.9051699f64,
            Self::Sb123 => 122.9042132f64,
            Self::Sb124 => 123.905935f64,
            Self::Sb125 => 124.905253f64,
            Self::Sb126 => 125.907253f64,
            Self::Sb127 => 126.9069243f64,
            Self::Sb128 => 127.909146f64,
            Self::Sb129 => 128.909147f64,
            Self::Sb130 => 129.911662f64,
            Self::Sb131 => 130.9119888f64,
            Self::Sb132 => 131.9145077f64,
            Self::Sb133 => 132.9152732f64,
            Self::Sb134 => 133.9205357f64,
            Self::Sb135 => 134.9251851f64,
            Self::Sb136 => 135.9307459f64,
            Self::Sb137 => 136.93555f64,
            Self::Sb138 => 137.94145f64,
            Self::Sb139 => 138.94655f64,
            Self::Sb140 => 139.95283f64,
            Self::Sb141 => 140.957552f64,
            Self::Sb142 => 141.963918f64,
        }
    }
}
impl super::ElementVariant for AntimonyIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Sb
    }
}
impl super::MassNumber for AntimonyIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Sb103 => 103u16,
            Self::Sb104 => 104u16,
            Self::Sb105 => 105u16,
            Self::Sb106 => 106u16,
            Self::Sb107 => 107u16,
            Self::Sb108 => 108u16,
            Self::Sb109 => 109u16,
            Self::Sb110 => 110u16,
            Self::Sb111 => 111u16,
            Self::Sb112 => 112u16,
            Self::Sb113 => 113u16,
            Self::Sb114 => 114u16,
            Self::Sb115 => 115u16,
            Self::Sb116 => 116u16,
            Self::Sb117 => 117u16,
            Self::Sb118 => 118u16,
            Self::Sb119 => 119u16,
            Self::Sb120 => 120u16,
            Self::Sb121 => 121u16,
            Self::Sb122 => 122u16,
            Self::Sb123 => 123u16,
            Self::Sb124 => 124u16,
            Self::Sb125 => 125u16,
            Self::Sb126 => 126u16,
            Self::Sb127 => 127u16,
            Self::Sb128 => 128u16,
            Self::Sb129 => 129u16,
            Self::Sb130 => 130u16,
            Self::Sb131 => 131u16,
            Self::Sb132 => 132u16,
            Self::Sb133 => 133u16,
            Self::Sb134 => 134u16,
            Self::Sb135 => 135u16,
            Self::Sb136 => 136u16,
            Self::Sb137 => 137u16,
            Self::Sb138 => 138u16,
            Self::Sb139 => 139u16,
            Self::Sb140 => 140u16,
            Self::Sb141 => 141u16,
            Self::Sb142 => 142u16,
        }
    }
}
impl super::IsotopicComposition for AntimonyIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Sb121 => Some(0.5721f64),
            Self::Sb123 => Some(0.4279f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for AntimonyIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Sb121
    }
}
impl From<AntimonyIsotope> for crate::Isotope {
    fn from(isotope: AntimonyIsotope) -> Self {
        crate::Isotope::Sb(isotope)
    }
}
impl From<AntimonyIsotope> for crate::Element {
    fn from(_isotope: AntimonyIsotope) -> Self {
        crate::Element::Sb
    }
}
impl TryFrom<u64> for AntimonyIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            103u64 => Ok(Self::Sb103),
            104u64 => Ok(Self::Sb104),
            105u64 => Ok(Self::Sb105),
            106u64 => Ok(Self::Sb106),
            107u64 => Ok(Self::Sb107),
            108u64 => Ok(Self::Sb108),
            109u64 => Ok(Self::Sb109),
            110u64 => Ok(Self::Sb110),
            111u64 => Ok(Self::Sb111),
            112u64 => Ok(Self::Sb112),
            113u64 => Ok(Self::Sb113),
            114u64 => Ok(Self::Sb114),
            115u64 => Ok(Self::Sb115),
            116u64 => Ok(Self::Sb116),
            117u64 => Ok(Self::Sb117),
            118u64 => Ok(Self::Sb118),
            119u64 => Ok(Self::Sb119),
            120u64 => Ok(Self::Sb120),
            121u64 => Ok(Self::Sb121),
            122u64 => Ok(Self::Sb122),
            123u64 => Ok(Self::Sb123),
            124u64 => Ok(Self::Sb124),
            125u64 => Ok(Self::Sb125),
            126u64 => Ok(Self::Sb126),
            127u64 => Ok(Self::Sb127),
            128u64 => Ok(Self::Sb128),
            129u64 => Ok(Self::Sb129),
            130u64 => Ok(Self::Sb130),
            131u64 => Ok(Self::Sb131),
            132u64 => Ok(Self::Sb132),
            133u64 => Ok(Self::Sb133),
            134u64 => Ok(Self::Sb134),
            135u64 => Ok(Self::Sb135),
            136u64 => Ok(Self::Sb136),
            137u64 => Ok(Self::Sb137),
            138u64 => Ok(Self::Sb138),
            139u64 => Ok(Self::Sb139),
            140u64 => Ok(Self::Sb140),
            141u64 => Ok(Self::Sb141),
            142u64 => Ok(Self::Sb142),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Sb, value)),
        }
    }
}
impl TryFrom<u8> for AntimonyIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for AntimonyIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for AntimonyIsotope {
    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 AntimonyIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Sb103 => write!(f, "Sb103"),
            Self::Sb104 => write!(f, "Sb104"),
            Self::Sb105 => write!(f, "Sb105"),
            Self::Sb106 => write!(f, "Sb106"),
            Self::Sb107 => write!(f, "Sb107"),
            Self::Sb108 => write!(f, "Sb108"),
            Self::Sb109 => write!(f, "Sb109"),
            Self::Sb110 => write!(f, "Sb110"),
            Self::Sb111 => write!(f, "Sb111"),
            Self::Sb112 => write!(f, "Sb112"),
            Self::Sb113 => write!(f, "Sb113"),
            Self::Sb114 => write!(f, "Sb114"),
            Self::Sb115 => write!(f, "Sb115"),
            Self::Sb116 => write!(f, "Sb116"),
            Self::Sb117 => write!(f, "Sb117"),
            Self::Sb118 => write!(f, "Sb118"),
            Self::Sb119 => write!(f, "Sb119"),
            Self::Sb120 => write!(f, "Sb120"),
            Self::Sb121 => write!(f, "Sb121"),
            Self::Sb122 => write!(f, "Sb122"),
            Self::Sb123 => write!(f, "Sb123"),
            Self::Sb124 => write!(f, "Sb124"),
            Self::Sb125 => write!(f, "Sb125"),
            Self::Sb126 => write!(f, "Sb126"),
            Self::Sb127 => write!(f, "Sb127"),
            Self::Sb128 => write!(f, "Sb128"),
            Self::Sb129 => write!(f, "Sb129"),
            Self::Sb130 => write!(f, "Sb130"),
            Self::Sb131 => write!(f, "Sb131"),
            Self::Sb132 => write!(f, "Sb132"),
            Self::Sb133 => write!(f, "Sb133"),
            Self::Sb134 => write!(f, "Sb134"),
            Self::Sb135 => write!(f, "Sb135"),
            Self::Sb136 => write!(f, "Sb136"),
            Self::Sb137 => write!(f, "Sb137"),
            Self::Sb138 => write!(f, "Sb138"),
            Self::Sb139 => write!(f, "Sb139"),
            Self::Sb140 => write!(f, "Sb140"),
            Self::Sb141 => write!(f, "Sb141"),
            Self::Sb142 => write!(f, "Sb142"),
        }
    }
}
#[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 AntimonyIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in AntimonyIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Sb, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in AntimonyIsotope::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 AntimonyIsotope::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 = AntimonyIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in AntimonyIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Sb(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in AntimonyIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Sb);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in AntimonyIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = AntimonyIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = AntimonyIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = AntimonyIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(AntimonyIsotope::try_from(0_u16).is_err());
        assert!(AntimonyIsotope::try_from(1000_u16).is_err());
        assert!(AntimonyIsotope::try_from(0_u32).is_err());
        assert!(AntimonyIsotope::try_from(1000_u32).is_err());
        assert!(AntimonyIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in AntimonyIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}