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
//! Isotopes of the element Iodine
#[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 Iodine
pub enum IodineIsotope {
    /// Isotope I108 of Iodine
    I108,
    /// Isotope I109 of Iodine
    I109,
    /// Isotope I110 of Iodine
    I110,
    /// Isotope I111 of Iodine
    I111,
    /// Isotope I112 of Iodine
    I112,
    /// Isotope I113 of Iodine
    I113,
    /// Isotope I114 of Iodine
    I114,
    /// Isotope I115 of Iodine
    I115,
    /// Isotope I116 of Iodine
    I116,
    /// Isotope I117 of Iodine
    I117,
    /// Isotope I118 of Iodine
    I118,
    /// Isotope I119 of Iodine
    I119,
    /// Isotope I120 of Iodine
    I120,
    /// Isotope I121 of Iodine
    I121,
    /// Isotope I122 of Iodine
    I122,
    /// Isotope I123 of Iodine
    I123,
    /// Isotope I124 of Iodine
    I124,
    /// Isotope I125 of Iodine
    I125,
    /// Isotope I126 of Iodine
    I126,
    /// Isotope I127 of Iodine
    I127,
    /// Isotope I128 of Iodine
    I128,
    /// Isotope I129 of Iodine
    I129,
    /// Isotope I130 of Iodine
    I130,
    /// Isotope I131 of Iodine
    I131,
    /// Isotope I132 of Iodine
    I132,
    /// Isotope I133 of Iodine
    I133,
    /// Isotope I134 of Iodine
    I134,
    /// Isotope I135 of Iodine
    I135,
    /// Isotope I136 of Iodine
    I136,
    /// Isotope I137 of Iodine
    I137,
    /// Isotope I138 of Iodine
    I138,
    /// Isotope I139 of Iodine
    I139,
    /// Isotope I140 of Iodine
    I140,
    /// Isotope I141 of Iodine
    I141,
    /// Isotope I142 of Iodine
    I142,
    /// Isotope I143 of Iodine
    I143,
    /// Isotope I144 of Iodine
    I144,
    /// Isotope I145 of Iodine
    I145,
    /// Isotope I146 of Iodine
    I146,
    /// Isotope I147 of Iodine
    I147,
}
impl super::RelativeAtomicMass for IodineIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::I108 => 107.94348f64,
            Self::I109 => 108.9380853f64,
            Self::I110 => 109.935089f64,
            Self::I111 => 110.9302692f64,
            Self::I112 => 111.928005f64,
            Self::I113 => 112.9236501f64,
            Self::I114 => 113.92185f64,
            Self::I115 => 114.918048f64,
            Self::I116 => 115.91681f64,
            Self::I117 => 116.913648f64,
            Self::I118 => 117.913074f64,
            Self::I119 => 118.910074f64,
            Self::I120 => 119.910087f64,
            Self::I121 => 120.9074051f64,
            Self::I122 => 121.9075888f64,
            Self::I123 => 122.9055885f64,
            Self::I124 => 123.906209f64,
            Self::I125 => 124.9046294f64,
            Self::I126 => 125.9056233f64,
            Self::I127 => 126.9044719f64,
            Self::I128 => 127.9058086f64,
            Self::I129 => 128.9049837f64,
            Self::I130 => 129.9066702f64,
            Self::I131 => 130.9061263f64,
            Self::I132 => 131.9079935f64,
            Self::I133 => 132.907797f64,
            Self::I134 => 133.9097588f64,
            Self::I135 => 134.9100488f64,
            Self::I136 => 135.914604f64,
            Self::I137 => 136.9180282f64,
            Self::I138 => 137.9227264f64,
            Self::I139 => 138.926506f64,
            Self::I140 => 139.93173f64,
            Self::I141 => 140.93569f64,
            Self::I142 => 141.9412f64,
            Self::I143 => 142.94565f64,
            Self::I144 => 143.95139f64,
            Self::I145 => 144.95605f64,
            Self::I146 => 145.961846f64,
            Self::I147 => 146.966505f64,
        }
    }
}
impl super::ElementVariant for IodineIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::I
    }
}
impl super::MassNumber for IodineIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::I108 => 108u16,
            Self::I109 => 109u16,
            Self::I110 => 110u16,
            Self::I111 => 111u16,
            Self::I112 => 112u16,
            Self::I113 => 113u16,
            Self::I114 => 114u16,
            Self::I115 => 115u16,
            Self::I116 => 116u16,
            Self::I117 => 117u16,
            Self::I118 => 118u16,
            Self::I119 => 119u16,
            Self::I120 => 120u16,
            Self::I121 => 121u16,
            Self::I122 => 122u16,
            Self::I123 => 123u16,
            Self::I124 => 124u16,
            Self::I125 => 125u16,
            Self::I126 => 126u16,
            Self::I127 => 127u16,
            Self::I128 => 128u16,
            Self::I129 => 129u16,
            Self::I130 => 130u16,
            Self::I131 => 131u16,
            Self::I132 => 132u16,
            Self::I133 => 133u16,
            Self::I134 => 134u16,
            Self::I135 => 135u16,
            Self::I136 => 136u16,
            Self::I137 => 137u16,
            Self::I138 => 138u16,
            Self::I139 => 139u16,
            Self::I140 => 140u16,
            Self::I141 => 141u16,
            Self::I142 => 142u16,
            Self::I143 => 143u16,
            Self::I144 => 144u16,
            Self::I145 => 145u16,
            Self::I146 => 146u16,
            Self::I147 => 147u16,
        }
    }
}
impl super::IsotopicComposition for IodineIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::I127 => Some(1f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for IodineIsotope {
    fn most_abundant_isotope() -> Self {
        Self::I127
    }
}
impl From<IodineIsotope> for crate::Isotope {
    fn from(isotope: IodineIsotope) -> Self {
        crate::Isotope::I(isotope)
    }
}
impl From<IodineIsotope> for crate::Element {
    fn from(_isotope: IodineIsotope) -> Self {
        crate::Element::I
    }
}
impl TryFrom<u64> for IodineIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            108u64 => Ok(Self::I108),
            109u64 => Ok(Self::I109),
            110u64 => Ok(Self::I110),
            111u64 => Ok(Self::I111),
            112u64 => Ok(Self::I112),
            113u64 => Ok(Self::I113),
            114u64 => Ok(Self::I114),
            115u64 => Ok(Self::I115),
            116u64 => Ok(Self::I116),
            117u64 => Ok(Self::I117),
            118u64 => Ok(Self::I118),
            119u64 => Ok(Self::I119),
            120u64 => Ok(Self::I120),
            121u64 => Ok(Self::I121),
            122u64 => Ok(Self::I122),
            123u64 => Ok(Self::I123),
            124u64 => Ok(Self::I124),
            125u64 => Ok(Self::I125),
            126u64 => Ok(Self::I126),
            127u64 => Ok(Self::I127),
            128u64 => Ok(Self::I128),
            129u64 => Ok(Self::I129),
            130u64 => Ok(Self::I130),
            131u64 => Ok(Self::I131),
            132u64 => Ok(Self::I132),
            133u64 => Ok(Self::I133),
            134u64 => Ok(Self::I134),
            135u64 => Ok(Self::I135),
            136u64 => Ok(Self::I136),
            137u64 => Ok(Self::I137),
            138u64 => Ok(Self::I138),
            139u64 => Ok(Self::I139),
            140u64 => Ok(Self::I140),
            141u64 => Ok(Self::I141),
            142u64 => Ok(Self::I142),
            143u64 => Ok(Self::I143),
            144u64 => Ok(Self::I144),
            145u64 => Ok(Self::I145),
            146u64 => Ok(Self::I146),
            147u64 => Ok(Self::I147),
            _ => Err(crate::errors::Error::Isotope(crate::Element::I, value)),
        }
    }
}
impl TryFrom<u8> for IodineIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for IodineIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for IodineIsotope {
    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 IodineIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::I108 => write!(f, "I108"),
            Self::I109 => write!(f, "I109"),
            Self::I110 => write!(f, "I110"),
            Self::I111 => write!(f, "I111"),
            Self::I112 => write!(f, "I112"),
            Self::I113 => write!(f, "I113"),
            Self::I114 => write!(f, "I114"),
            Self::I115 => write!(f, "I115"),
            Self::I116 => write!(f, "I116"),
            Self::I117 => write!(f, "I117"),
            Self::I118 => write!(f, "I118"),
            Self::I119 => write!(f, "I119"),
            Self::I120 => write!(f, "I120"),
            Self::I121 => write!(f, "I121"),
            Self::I122 => write!(f, "I122"),
            Self::I123 => write!(f, "I123"),
            Self::I124 => write!(f, "I124"),
            Self::I125 => write!(f, "I125"),
            Self::I126 => write!(f, "I126"),
            Self::I127 => write!(f, "I127"),
            Self::I128 => write!(f, "I128"),
            Self::I129 => write!(f, "I129"),
            Self::I130 => write!(f, "I130"),
            Self::I131 => write!(f, "I131"),
            Self::I132 => write!(f, "I132"),
            Self::I133 => write!(f, "I133"),
            Self::I134 => write!(f, "I134"),
            Self::I135 => write!(f, "I135"),
            Self::I136 => write!(f, "I136"),
            Self::I137 => write!(f, "I137"),
            Self::I138 => write!(f, "I138"),
            Self::I139 => write!(f, "I139"),
            Self::I140 => write!(f, "I140"),
            Self::I141 => write!(f, "I141"),
            Self::I142 => write!(f, "I142"),
            Self::I143 => write!(f, "I143"),
            Self::I144 => write!(f, "I144"),
            Self::I145 => write!(f, "I145"),
            Self::I146 => write!(f, "I146"),
            Self::I147 => write!(f, "I147"),
        }
    }
}
#[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 IodineIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in IodineIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::I, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in IodineIsotope::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 IodineIsotope::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 = IodineIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in IodineIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::I(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in IodineIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::I);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in IodineIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = IodineIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = IodineIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = IodineIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(IodineIsotope::try_from(0_u16).is_err());
        assert!(IodineIsotope::try_from(1000_u16).is_err());
        assert!(IodineIsotope::try_from(0_u32).is_err());
        assert!(IodineIsotope::try_from(1000_u32).is_err());
        assert!(IodineIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in IodineIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}