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
439
440
//! Isotopes of the element Tin
#[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 Tin
pub enum TinIsotope {
    /// Isotope Sn99 of Tin
    Sn99,
    /// Isotope Sn100 of Tin
    Sn100,
    /// Isotope Sn101 of Tin
    Sn101,
    /// Isotope Sn102 of Tin
    Sn102,
    /// Isotope Sn103 of Tin
    Sn103,
    /// Isotope Sn104 of Tin
    Sn104,
    /// Isotope Sn105 of Tin
    Sn105,
    /// Isotope Sn106 of Tin
    Sn106,
    /// Isotope Sn107 of Tin
    Sn107,
    /// Isotope Sn108 of Tin
    Sn108,
    /// Isotope Sn109 of Tin
    Sn109,
    /// Isotope Sn110 of Tin
    Sn110,
    /// Isotope Sn111 of Tin
    Sn111,
    /// Isotope Sn112 of Tin
    Sn112,
    /// Isotope Sn113 of Tin
    Sn113,
    /// Isotope Sn114 of Tin
    Sn114,
    /// Isotope Sn115 of Tin
    Sn115,
    /// Isotope Sn116 of Tin
    Sn116,
    /// Isotope Sn117 of Tin
    Sn117,
    /// Isotope Sn118 of Tin
    Sn118,
    /// Isotope Sn119 of Tin
    Sn119,
    /// Isotope Sn120 of Tin
    Sn120,
    /// Isotope Sn121 of Tin
    Sn121,
    /// Isotope Sn122 of Tin
    Sn122,
    /// Isotope Sn123 of Tin
    Sn123,
    /// Isotope Sn124 of Tin
    Sn124,
    /// Isotope Sn125 of Tin
    Sn125,
    /// Isotope Sn126 of Tin
    Sn126,
    /// Isotope Sn127 of Tin
    Sn127,
    /// Isotope Sn128 of Tin
    Sn128,
    /// Isotope Sn129 of Tin
    Sn129,
    /// Isotope Sn130 of Tin
    Sn130,
    /// Isotope Sn131 of Tin
    Sn131,
    /// Isotope Sn132 of Tin
    Sn132,
    /// Isotope Sn133 of Tin
    Sn133,
    /// Isotope Sn134 of Tin
    Sn134,
    /// Isotope Sn135 of Tin
    Sn135,
    /// Isotope Sn136 of Tin
    Sn136,
    /// Isotope Sn137 of Tin
    Sn137,
    /// Isotope Sn138 of Tin
    Sn138,
    /// Isotope Sn139 of Tin
    Sn139,
    /// Isotope Sn140 of Tin
    Sn140,
}
impl super::RelativeAtomicMass for TinIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Sn99 => 98.94853f64,
            Self::Sn100 => 99.9385f64,
            Self::Sn101 => 100.93526f64,
            Self::Sn102 => 101.93029f64,
            Self::Sn103 => 102.928105f64,
            Self::Sn104 => 103.9231052f64,
            Self::Sn105 => 104.9212684f64,
            Self::Sn106 => 105.9169574f64,
            Self::Sn107 => 106.9157137f64,
            Self::Sn108 => 107.9118943f64,
            Self::Sn109 => 108.9112921f64,
            Self::Sn110 => 109.907845f64,
            Self::Sn111 => 110.9077401f64,
            Self::Sn112 => 111.90482387f64,
            Self::Sn113 => 112.9051757f64,
            Self::Sn114 => 113.9027827f64,
            Self::Sn115 => 114.903344699f64,
            Self::Sn116 => 115.9017428f64,
            Self::Sn117 => 116.90295398f64,
            Self::Sn118 => 117.90160657f64,
            Self::Sn119 => 118.90331117f64,
            Self::Sn120 => 119.90220163f64,
            Self::Sn121 => 120.9042426f64,
            Self::Sn122 => 121.9034438f64,
            Self::Sn123 => 122.9057252f64,
            Self::Sn124 => 123.9052766f64,
            Self::Sn125 => 124.9077864f64,
            Self::Sn126 => 125.907659f64,
            Self::Sn127 => 126.91039f64,
            Self::Sn128 => 127.910507f64,
            Self::Sn129 => 128.913465f64,
            Self::Sn130 => 129.9139738f64,
            Self::Sn131 => 130.917045f64,
            Self::Sn132 => 131.9178267f64,
            Self::Sn133 => 132.9239134f64,
            Self::Sn134 => 133.9286821f64,
            Self::Sn135 => 134.9349086f64,
            Self::Sn136 => 135.93999f64,
            Self::Sn137 => 136.94655f64,
            Self::Sn138 => 137.95184f64,
            Self::Sn139 => 138.957799f64,
            Self::Sn140 => 139.962973f64,
        }
    }
}
impl super::ElementVariant for TinIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Sn
    }
}
impl super::MassNumber for TinIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Sn99 => 99u16,
            Self::Sn100 => 100u16,
            Self::Sn101 => 101u16,
            Self::Sn102 => 102u16,
            Self::Sn103 => 103u16,
            Self::Sn104 => 104u16,
            Self::Sn105 => 105u16,
            Self::Sn106 => 106u16,
            Self::Sn107 => 107u16,
            Self::Sn108 => 108u16,
            Self::Sn109 => 109u16,
            Self::Sn110 => 110u16,
            Self::Sn111 => 111u16,
            Self::Sn112 => 112u16,
            Self::Sn113 => 113u16,
            Self::Sn114 => 114u16,
            Self::Sn115 => 115u16,
            Self::Sn116 => 116u16,
            Self::Sn117 => 117u16,
            Self::Sn118 => 118u16,
            Self::Sn119 => 119u16,
            Self::Sn120 => 120u16,
            Self::Sn121 => 121u16,
            Self::Sn122 => 122u16,
            Self::Sn123 => 123u16,
            Self::Sn124 => 124u16,
            Self::Sn125 => 125u16,
            Self::Sn126 => 126u16,
            Self::Sn127 => 127u16,
            Self::Sn128 => 128u16,
            Self::Sn129 => 129u16,
            Self::Sn130 => 130u16,
            Self::Sn131 => 131u16,
            Self::Sn132 => 132u16,
            Self::Sn133 => 133u16,
            Self::Sn134 => 134u16,
            Self::Sn135 => 135u16,
            Self::Sn136 => 136u16,
            Self::Sn137 => 137u16,
            Self::Sn138 => 138u16,
            Self::Sn139 => 139u16,
            Self::Sn140 => 140u16,
        }
    }
}
impl super::IsotopicComposition for TinIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Sn112 => Some(0.0097f64),
            Self::Sn114 => Some(0.0066f64),
            Self::Sn115 => Some(0.0034f64),
            Self::Sn116 => Some(0.1454f64),
            Self::Sn117 => Some(0.0768f64),
            Self::Sn118 => Some(0.2422f64),
            Self::Sn119 => Some(0.0859f64),
            Self::Sn120 => Some(0.3258f64),
            Self::Sn122 => Some(0.0463f64),
            Self::Sn124 => Some(0.0579f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for TinIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Sn120
    }
}
impl From<TinIsotope> for crate::Isotope {
    fn from(isotope: TinIsotope) -> Self {
        crate::Isotope::Sn(isotope)
    }
}
impl From<TinIsotope> for crate::Element {
    fn from(_isotope: TinIsotope) -> Self {
        crate::Element::Sn
    }
}
impl TryFrom<u64> for TinIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            99u64 => Ok(Self::Sn99),
            100u64 => Ok(Self::Sn100),
            101u64 => Ok(Self::Sn101),
            102u64 => Ok(Self::Sn102),
            103u64 => Ok(Self::Sn103),
            104u64 => Ok(Self::Sn104),
            105u64 => Ok(Self::Sn105),
            106u64 => Ok(Self::Sn106),
            107u64 => Ok(Self::Sn107),
            108u64 => Ok(Self::Sn108),
            109u64 => Ok(Self::Sn109),
            110u64 => Ok(Self::Sn110),
            111u64 => Ok(Self::Sn111),
            112u64 => Ok(Self::Sn112),
            113u64 => Ok(Self::Sn113),
            114u64 => Ok(Self::Sn114),
            115u64 => Ok(Self::Sn115),
            116u64 => Ok(Self::Sn116),
            117u64 => Ok(Self::Sn117),
            118u64 => Ok(Self::Sn118),
            119u64 => Ok(Self::Sn119),
            120u64 => Ok(Self::Sn120),
            121u64 => Ok(Self::Sn121),
            122u64 => Ok(Self::Sn122),
            123u64 => Ok(Self::Sn123),
            124u64 => Ok(Self::Sn124),
            125u64 => Ok(Self::Sn125),
            126u64 => Ok(Self::Sn126),
            127u64 => Ok(Self::Sn127),
            128u64 => Ok(Self::Sn128),
            129u64 => Ok(Self::Sn129),
            130u64 => Ok(Self::Sn130),
            131u64 => Ok(Self::Sn131),
            132u64 => Ok(Self::Sn132),
            133u64 => Ok(Self::Sn133),
            134u64 => Ok(Self::Sn134),
            135u64 => Ok(Self::Sn135),
            136u64 => Ok(Self::Sn136),
            137u64 => Ok(Self::Sn137),
            138u64 => Ok(Self::Sn138),
            139u64 => Ok(Self::Sn139),
            140u64 => Ok(Self::Sn140),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Sn, value)),
        }
    }
}
impl TryFrom<u8> for TinIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for TinIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for TinIsotope {
    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 TinIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Sn99 => write!(f, "Sn99"),
            Self::Sn100 => write!(f, "Sn100"),
            Self::Sn101 => write!(f, "Sn101"),
            Self::Sn102 => write!(f, "Sn102"),
            Self::Sn103 => write!(f, "Sn103"),
            Self::Sn104 => write!(f, "Sn104"),
            Self::Sn105 => write!(f, "Sn105"),
            Self::Sn106 => write!(f, "Sn106"),
            Self::Sn107 => write!(f, "Sn107"),
            Self::Sn108 => write!(f, "Sn108"),
            Self::Sn109 => write!(f, "Sn109"),
            Self::Sn110 => write!(f, "Sn110"),
            Self::Sn111 => write!(f, "Sn111"),
            Self::Sn112 => write!(f, "Sn112"),
            Self::Sn113 => write!(f, "Sn113"),
            Self::Sn114 => write!(f, "Sn114"),
            Self::Sn115 => write!(f, "Sn115"),
            Self::Sn116 => write!(f, "Sn116"),
            Self::Sn117 => write!(f, "Sn117"),
            Self::Sn118 => write!(f, "Sn118"),
            Self::Sn119 => write!(f, "Sn119"),
            Self::Sn120 => write!(f, "Sn120"),
            Self::Sn121 => write!(f, "Sn121"),
            Self::Sn122 => write!(f, "Sn122"),
            Self::Sn123 => write!(f, "Sn123"),
            Self::Sn124 => write!(f, "Sn124"),
            Self::Sn125 => write!(f, "Sn125"),
            Self::Sn126 => write!(f, "Sn126"),
            Self::Sn127 => write!(f, "Sn127"),
            Self::Sn128 => write!(f, "Sn128"),
            Self::Sn129 => write!(f, "Sn129"),
            Self::Sn130 => write!(f, "Sn130"),
            Self::Sn131 => write!(f, "Sn131"),
            Self::Sn132 => write!(f, "Sn132"),
            Self::Sn133 => write!(f, "Sn133"),
            Self::Sn134 => write!(f, "Sn134"),
            Self::Sn135 => write!(f, "Sn135"),
            Self::Sn136 => write!(f, "Sn136"),
            Self::Sn137 => write!(f, "Sn137"),
            Self::Sn138 => write!(f, "Sn138"),
            Self::Sn139 => write!(f, "Sn139"),
            Self::Sn140 => write!(f, "Sn140"),
        }
    }
}
#[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 TinIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in TinIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Sn, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in TinIsotope::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 TinIsotope::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 = TinIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in TinIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Sn(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in TinIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Sn);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in TinIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = TinIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = TinIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = TinIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(TinIsotope::try_from(0_u16).is_err());
        assert!(TinIsotope::try_from(1000_u16).is_err());
        assert!(TinIsotope::try_from(0_u32).is_err());
        assert!(TinIsotope::try_from(1000_u32).is_err());
        assert!(TinIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in TinIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}