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
//! Isotopes of the element Zirconium
#[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 Zirconium
pub enum ZirconiumIsotope {
    /// Isotope Zr77 of Zirconium
    Zr77,
    /// Isotope Zr78 of Zirconium
    Zr78,
    /// Isotope Zr79 of Zirconium
    Zr79,
    /// Isotope Zr80 of Zirconium
    Zr80,
    /// Isotope Zr81 of Zirconium
    Zr81,
    /// Isotope Zr82 of Zirconium
    Zr82,
    /// Isotope Zr83 of Zirconium
    Zr83,
    /// Isotope Zr84 of Zirconium
    Zr84,
    /// Isotope Zr85 of Zirconium
    Zr85,
    /// Isotope Zr86 of Zirconium
    Zr86,
    /// Isotope Zr87 of Zirconium
    Zr87,
    /// Isotope Zr88 of Zirconium
    Zr88,
    /// Isotope Zr89 of Zirconium
    Zr89,
    /// Isotope Zr90 of Zirconium
    Zr90,
    /// Isotope Zr91 of Zirconium
    Zr91,
    /// Isotope Zr92 of Zirconium
    Zr92,
    /// Isotope Zr93 of Zirconium
    Zr93,
    /// Isotope Zr94 of Zirconium
    Zr94,
    /// Isotope Zr95 of Zirconium
    Zr95,
    /// Isotope Zr96 of Zirconium
    Zr96,
    /// Isotope Zr97 of Zirconium
    Zr97,
    /// Isotope Zr98 of Zirconium
    Zr98,
    /// Isotope Zr99 of Zirconium
    Zr99,
    /// Isotope Zr100 of Zirconium
    Zr100,
    /// Isotope Zr101 of Zirconium
    Zr101,
    /// Isotope Zr102 of Zirconium
    Zr102,
    /// Isotope Zr103 of Zirconium
    Zr103,
    /// Isotope Zr104 of Zirconium
    Zr104,
    /// Isotope Zr105 of Zirconium
    Zr105,
    /// Isotope Zr106 of Zirconium
    Zr106,
    /// Isotope Zr107 of Zirconium
    Zr107,
    /// Isotope Zr108 of Zirconium
    Zr108,
    /// Isotope Zr109 of Zirconium
    Zr109,
    /// Isotope Zr110 of Zirconium
    Zr110,
    /// Isotope Zr111 of Zirconium
    Zr111,
    /// Isotope Zr112 of Zirconium
    Zr112,
    /// Isotope Zr113 of Zirconium
    Zr113,
}
impl super::RelativeAtomicMass for ZirconiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Zr77 => 76.966076f64,
            Self::Zr78 => 77.95566f64,
            Self::Zr79 => 78.94948f64,
            Self::Zr80 => 79.9404f64,
            Self::Zr81 => 80.93731f64,
            Self::Zr82 => 81.93135f64,
            Self::Zr83 => 82.9292421f64,
            Self::Zr84 => 83.9233269f64,
            Self::Zr85 => 84.9214444f64,
            Self::Zr86 => 85.9162972f64,
            Self::Zr87 => 86.914818f64,
            Self::Zr88 => 87.9102213f64,
            Self::Zr89 => 88.9088814f64,
            Self::Zr90 => 89.9046977f64,
            Self::Zr91 => 90.9056396f64,
            Self::Zr92 => 91.9050347f64,
            Self::Zr93 => 92.9064699f64,
            Self::Zr94 => 93.9063108f64,
            Self::Zr95 => 94.9080385f64,
            Self::Zr96 => 95.9082714f64,
            Self::Zr97 => 96.9109512f64,
            Self::Zr98 => 97.9127289f64,
            Self::Zr99 => 98.916667f64,
            Self::Zr100 => 99.9180006f64,
            Self::Zr101 => 100.921448f64,
            Self::Zr102 => 101.9231409f64,
            Self::Zr103 => 102.927191f64,
            Self::Zr104 => 103.929436f64,
            Self::Zr105 => 104.934008f64,
            Self::Zr106 => 105.93676f64,
            Self::Zr107 => 106.94174f64,
            Self::Zr108 => 107.94487f64,
            Self::Zr109 => 108.95041f64,
            Self::Zr110 => 109.95396f64,
            Self::Zr111 => 110.95968f64,
            Self::Zr112 => 111.9637f64,
            Self::Zr113 => 112.971723f64,
        }
    }
}
impl super::ElementVariant for ZirconiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Zr
    }
}
impl super::MassNumber for ZirconiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Zr77 => 77u16,
            Self::Zr78 => 78u16,
            Self::Zr79 => 79u16,
            Self::Zr80 => 80u16,
            Self::Zr81 => 81u16,
            Self::Zr82 => 82u16,
            Self::Zr83 => 83u16,
            Self::Zr84 => 84u16,
            Self::Zr85 => 85u16,
            Self::Zr86 => 86u16,
            Self::Zr87 => 87u16,
            Self::Zr88 => 88u16,
            Self::Zr89 => 89u16,
            Self::Zr90 => 90u16,
            Self::Zr91 => 91u16,
            Self::Zr92 => 92u16,
            Self::Zr93 => 93u16,
            Self::Zr94 => 94u16,
            Self::Zr95 => 95u16,
            Self::Zr96 => 96u16,
            Self::Zr97 => 97u16,
            Self::Zr98 => 98u16,
            Self::Zr99 => 99u16,
            Self::Zr100 => 100u16,
            Self::Zr101 => 101u16,
            Self::Zr102 => 102u16,
            Self::Zr103 => 103u16,
            Self::Zr104 => 104u16,
            Self::Zr105 => 105u16,
            Self::Zr106 => 106u16,
            Self::Zr107 => 107u16,
            Self::Zr108 => 108u16,
            Self::Zr109 => 109u16,
            Self::Zr110 => 110u16,
            Self::Zr111 => 111u16,
            Self::Zr112 => 112u16,
            Self::Zr113 => 113u16,
        }
    }
}
impl super::IsotopicComposition for ZirconiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Zr90 => Some(0.5145f64),
            Self::Zr91 => Some(0.1122f64),
            Self::Zr92 => Some(0.1715f64),
            Self::Zr94 => Some(0.1738f64),
            Self::Zr96 => Some(0.028f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for ZirconiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Zr90
    }
}
impl From<ZirconiumIsotope> for crate::Isotope {
    fn from(isotope: ZirconiumIsotope) -> Self {
        crate::Isotope::Zr(isotope)
    }
}
impl From<ZirconiumIsotope> for crate::Element {
    fn from(_isotope: ZirconiumIsotope) -> Self {
        crate::Element::Zr
    }
}
impl TryFrom<u64> for ZirconiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            77u64 => Ok(Self::Zr77),
            78u64 => Ok(Self::Zr78),
            79u64 => Ok(Self::Zr79),
            80u64 => Ok(Self::Zr80),
            81u64 => Ok(Self::Zr81),
            82u64 => Ok(Self::Zr82),
            83u64 => Ok(Self::Zr83),
            84u64 => Ok(Self::Zr84),
            85u64 => Ok(Self::Zr85),
            86u64 => Ok(Self::Zr86),
            87u64 => Ok(Self::Zr87),
            88u64 => Ok(Self::Zr88),
            89u64 => Ok(Self::Zr89),
            90u64 => Ok(Self::Zr90),
            91u64 => Ok(Self::Zr91),
            92u64 => Ok(Self::Zr92),
            93u64 => Ok(Self::Zr93),
            94u64 => Ok(Self::Zr94),
            95u64 => Ok(Self::Zr95),
            96u64 => Ok(Self::Zr96),
            97u64 => Ok(Self::Zr97),
            98u64 => Ok(Self::Zr98),
            99u64 => Ok(Self::Zr99),
            100u64 => Ok(Self::Zr100),
            101u64 => Ok(Self::Zr101),
            102u64 => Ok(Self::Zr102),
            103u64 => Ok(Self::Zr103),
            104u64 => Ok(Self::Zr104),
            105u64 => Ok(Self::Zr105),
            106u64 => Ok(Self::Zr106),
            107u64 => Ok(Self::Zr107),
            108u64 => Ok(Self::Zr108),
            109u64 => Ok(Self::Zr109),
            110u64 => Ok(Self::Zr110),
            111u64 => Ok(Self::Zr111),
            112u64 => Ok(Self::Zr112),
            113u64 => Ok(Self::Zr113),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Zr, value)),
        }
    }
}
impl TryFrom<u8> for ZirconiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for ZirconiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for ZirconiumIsotope {
    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 ZirconiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Zr77 => write!(f, "Zr77"),
            Self::Zr78 => write!(f, "Zr78"),
            Self::Zr79 => write!(f, "Zr79"),
            Self::Zr80 => write!(f, "Zr80"),
            Self::Zr81 => write!(f, "Zr81"),
            Self::Zr82 => write!(f, "Zr82"),
            Self::Zr83 => write!(f, "Zr83"),
            Self::Zr84 => write!(f, "Zr84"),
            Self::Zr85 => write!(f, "Zr85"),
            Self::Zr86 => write!(f, "Zr86"),
            Self::Zr87 => write!(f, "Zr87"),
            Self::Zr88 => write!(f, "Zr88"),
            Self::Zr89 => write!(f, "Zr89"),
            Self::Zr90 => write!(f, "Zr90"),
            Self::Zr91 => write!(f, "Zr91"),
            Self::Zr92 => write!(f, "Zr92"),
            Self::Zr93 => write!(f, "Zr93"),
            Self::Zr94 => write!(f, "Zr94"),
            Self::Zr95 => write!(f, "Zr95"),
            Self::Zr96 => write!(f, "Zr96"),
            Self::Zr97 => write!(f, "Zr97"),
            Self::Zr98 => write!(f, "Zr98"),
            Self::Zr99 => write!(f, "Zr99"),
            Self::Zr100 => write!(f, "Zr100"),
            Self::Zr101 => write!(f, "Zr101"),
            Self::Zr102 => write!(f, "Zr102"),
            Self::Zr103 => write!(f, "Zr103"),
            Self::Zr104 => write!(f, "Zr104"),
            Self::Zr105 => write!(f, "Zr105"),
            Self::Zr106 => write!(f, "Zr106"),
            Self::Zr107 => write!(f, "Zr107"),
            Self::Zr108 => write!(f, "Zr108"),
            Self::Zr109 => write!(f, "Zr109"),
            Self::Zr110 => write!(f, "Zr110"),
            Self::Zr111 => write!(f, "Zr111"),
            Self::Zr112 => write!(f, "Zr112"),
            Self::Zr113 => write!(f, "Zr113"),
        }
    }
}
#[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 ZirconiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in ZirconiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Zr, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in ZirconiumIsotope::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 ZirconiumIsotope::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 = ZirconiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in ZirconiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Zr(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in ZirconiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Zr);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in ZirconiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = ZirconiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = ZirconiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = ZirconiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(ZirconiumIsotope::try_from(0_u16).is_err());
        assert!(ZirconiumIsotope::try_from(1000_u16).is_err());
        assert!(ZirconiumIsotope::try_from(0_u32).is_err());
        assert!(ZirconiumIsotope::try_from(1000_u32).is_err());
        assert!(ZirconiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in ZirconiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}