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
417
418
419
420
421
422
423
424
425
426
427
428
429
//! Isotopes of the element Thallium
#[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 Thallium
pub enum ThalliumIsotope {
    /// Isotope Tl176 of Thallium
    Tl176,
    /// Isotope Tl177 of Thallium
    Tl177,
    /// Isotope Tl178 of Thallium
    Tl178,
    /// Isotope Tl179 of Thallium
    Tl179,
    /// Isotope Tl180 of Thallium
    Tl180,
    /// Isotope Tl181 of Thallium
    Tl181,
    /// Isotope Tl182 of Thallium
    Tl182,
    /// Isotope Tl183 of Thallium
    Tl183,
    /// Isotope Tl184 of Thallium
    Tl184,
    /// Isotope Tl185 of Thallium
    Tl185,
    /// Isotope Tl186 of Thallium
    Tl186,
    /// Isotope Tl187 of Thallium
    Tl187,
    /// Isotope Tl188 of Thallium
    Tl188,
    /// Isotope Tl189 of Thallium
    Tl189,
    /// Isotope Tl190 of Thallium
    Tl190,
    /// Isotope Tl191 of Thallium
    Tl191,
    /// Isotope Tl192 of Thallium
    Tl192,
    /// Isotope Tl193 of Thallium
    Tl193,
    /// Isotope Tl194 of Thallium
    Tl194,
    /// Isotope Tl195 of Thallium
    Tl195,
    /// Isotope Tl196 of Thallium
    Tl196,
    /// Isotope Tl197 of Thallium
    Tl197,
    /// Isotope Tl198 of Thallium
    Tl198,
    /// Isotope Tl199 of Thallium
    Tl199,
    /// Isotope Tl200 of Thallium
    Tl200,
    /// Isotope Tl201 of Thallium
    Tl201,
    /// Isotope Tl202 of Thallium
    Tl202,
    /// Isotope Tl203 of Thallium
    Tl203,
    /// Isotope Tl204 of Thallium
    Tl204,
    /// Isotope Tl205 of Thallium
    Tl205,
    /// Isotope Tl206 of Thallium
    Tl206,
    /// Isotope Tl207 of Thallium
    Tl207,
    /// Isotope Tl208 of Thallium
    Tl208,
    /// Isotope Tl209 of Thallium
    Tl209,
    /// Isotope Tl210 of Thallium
    Tl210,
    /// Isotope Tl211 of Thallium
    Tl211,
    /// Isotope Tl212 of Thallium
    Tl212,
    /// Isotope Tl213 of Thallium
    Tl213,
    /// Isotope Tl214 of Thallium
    Tl214,
    /// Isotope Tl215 of Thallium
    Tl215,
    /// Isotope Tl216 of Thallium
    Tl216,
    /// Isotope Tl217 of Thallium
    Tl217,
}
impl super::RelativeAtomicMass for ThalliumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Tl176 => 176.000624f64,
            Self::Tl177 => 176.996431f64,
            Self::Tl178 => 177.99485f64,
            Self::Tl179 => 178.991111f64,
            Self::Tl180 => 179.990057f64,
            Self::Tl181 => 180.98626f64,
            Self::Tl182 => 181.985713f64,
            Self::Tl183 => 182.982193f64,
            Self::Tl184 => 183.981886f64,
            Self::Tl185 => 184.978789f64,
            Self::Tl186 => 185.978651f64,
            Self::Tl187 => 186.9759063f64,
            Self::Tl188 => 187.976021f64,
            Self::Tl189 => 188.973588f64,
            Self::Tl190 => 189.973828f64,
            Self::Tl191 => 190.9717842f64,
            Self::Tl192 => 191.972225f64,
            Self::Tl193 => 192.970502f64,
            Self::Tl194 => 193.971081f64,
            Self::Tl195 => 194.969774f64,
            Self::Tl196 => 195.970481f64,
            Self::Tl197 => 196.969576f64,
            Self::Tl198 => 197.970483f64,
            Self::Tl199 => 198.969877f64,
            Self::Tl200 => 199.9709633f64,
            Self::Tl201 => 200.970822f64,
            Self::Tl202 => 201.972102f64,
            Self::Tl203 => 202.9723446f64,
            Self::Tl204 => 203.9738639f64,
            Self::Tl205 => 204.9744278f64,
            Self::Tl206 => 205.9761106f64,
            Self::Tl207 => 206.9774197f64,
            Self::Tl208 => 207.982019f64,
            Self::Tl209 => 208.9853594f64,
            Self::Tl210 => 209.990074f64,
            Self::Tl211 => 210.993475f64,
            Self::Tl212 => 211.99834f64,
            Self::Tl213 => 213.001915f64,
            Self::Tl214 => 214.00694f64,
            Self::Tl215 => 215.01064f64,
            Self::Tl216 => 216.0158f64,
            Self::Tl217 => 217.01966f64,
        }
    }
}
impl super::ElementVariant for ThalliumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Tl
    }
}
impl super::MassNumber for ThalliumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Tl176 => 176u16,
            Self::Tl177 => 177u16,
            Self::Tl178 => 178u16,
            Self::Tl179 => 179u16,
            Self::Tl180 => 180u16,
            Self::Tl181 => 181u16,
            Self::Tl182 => 182u16,
            Self::Tl183 => 183u16,
            Self::Tl184 => 184u16,
            Self::Tl185 => 185u16,
            Self::Tl186 => 186u16,
            Self::Tl187 => 187u16,
            Self::Tl188 => 188u16,
            Self::Tl189 => 189u16,
            Self::Tl190 => 190u16,
            Self::Tl191 => 191u16,
            Self::Tl192 => 192u16,
            Self::Tl193 => 193u16,
            Self::Tl194 => 194u16,
            Self::Tl195 => 195u16,
            Self::Tl196 => 196u16,
            Self::Tl197 => 197u16,
            Self::Tl198 => 198u16,
            Self::Tl199 => 199u16,
            Self::Tl200 => 200u16,
            Self::Tl201 => 201u16,
            Self::Tl202 => 202u16,
            Self::Tl203 => 203u16,
            Self::Tl204 => 204u16,
            Self::Tl205 => 205u16,
            Self::Tl206 => 206u16,
            Self::Tl207 => 207u16,
            Self::Tl208 => 208u16,
            Self::Tl209 => 209u16,
            Self::Tl210 => 210u16,
            Self::Tl211 => 211u16,
            Self::Tl212 => 212u16,
            Self::Tl213 => 213u16,
            Self::Tl214 => 214u16,
            Self::Tl215 => 215u16,
            Self::Tl216 => 216u16,
            Self::Tl217 => 217u16,
        }
    }
}
impl super::IsotopicComposition for ThalliumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Tl203 => Some(0.2952f64),
            Self::Tl205 => Some(0.7048f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for ThalliumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Tl205
    }
}
impl From<ThalliumIsotope> for crate::Isotope {
    fn from(isotope: ThalliumIsotope) -> Self {
        crate::Isotope::Tl(isotope)
    }
}
impl From<ThalliumIsotope> for crate::Element {
    fn from(_isotope: ThalliumIsotope) -> Self {
        crate::Element::Tl
    }
}
impl TryFrom<u64> for ThalliumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            176u64 => Ok(Self::Tl176),
            177u64 => Ok(Self::Tl177),
            178u64 => Ok(Self::Tl178),
            179u64 => Ok(Self::Tl179),
            180u64 => Ok(Self::Tl180),
            181u64 => Ok(Self::Tl181),
            182u64 => Ok(Self::Tl182),
            183u64 => Ok(Self::Tl183),
            184u64 => Ok(Self::Tl184),
            185u64 => Ok(Self::Tl185),
            186u64 => Ok(Self::Tl186),
            187u64 => Ok(Self::Tl187),
            188u64 => Ok(Self::Tl188),
            189u64 => Ok(Self::Tl189),
            190u64 => Ok(Self::Tl190),
            191u64 => Ok(Self::Tl191),
            192u64 => Ok(Self::Tl192),
            193u64 => Ok(Self::Tl193),
            194u64 => Ok(Self::Tl194),
            195u64 => Ok(Self::Tl195),
            196u64 => Ok(Self::Tl196),
            197u64 => Ok(Self::Tl197),
            198u64 => Ok(Self::Tl198),
            199u64 => Ok(Self::Tl199),
            200u64 => Ok(Self::Tl200),
            201u64 => Ok(Self::Tl201),
            202u64 => Ok(Self::Tl202),
            203u64 => Ok(Self::Tl203),
            204u64 => Ok(Self::Tl204),
            205u64 => Ok(Self::Tl205),
            206u64 => Ok(Self::Tl206),
            207u64 => Ok(Self::Tl207),
            208u64 => Ok(Self::Tl208),
            209u64 => Ok(Self::Tl209),
            210u64 => Ok(Self::Tl210),
            211u64 => Ok(Self::Tl211),
            212u64 => Ok(Self::Tl212),
            213u64 => Ok(Self::Tl213),
            214u64 => Ok(Self::Tl214),
            215u64 => Ok(Self::Tl215),
            216u64 => Ok(Self::Tl216),
            217u64 => Ok(Self::Tl217),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Tl, value)),
        }
    }
}
impl TryFrom<u8> for ThalliumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for ThalliumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for ThalliumIsotope {
    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 ThalliumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Tl176 => write!(f, "Tl176"),
            Self::Tl177 => write!(f, "Tl177"),
            Self::Tl178 => write!(f, "Tl178"),
            Self::Tl179 => write!(f, "Tl179"),
            Self::Tl180 => write!(f, "Tl180"),
            Self::Tl181 => write!(f, "Tl181"),
            Self::Tl182 => write!(f, "Tl182"),
            Self::Tl183 => write!(f, "Tl183"),
            Self::Tl184 => write!(f, "Tl184"),
            Self::Tl185 => write!(f, "Tl185"),
            Self::Tl186 => write!(f, "Tl186"),
            Self::Tl187 => write!(f, "Tl187"),
            Self::Tl188 => write!(f, "Tl188"),
            Self::Tl189 => write!(f, "Tl189"),
            Self::Tl190 => write!(f, "Tl190"),
            Self::Tl191 => write!(f, "Tl191"),
            Self::Tl192 => write!(f, "Tl192"),
            Self::Tl193 => write!(f, "Tl193"),
            Self::Tl194 => write!(f, "Tl194"),
            Self::Tl195 => write!(f, "Tl195"),
            Self::Tl196 => write!(f, "Tl196"),
            Self::Tl197 => write!(f, "Tl197"),
            Self::Tl198 => write!(f, "Tl198"),
            Self::Tl199 => write!(f, "Tl199"),
            Self::Tl200 => write!(f, "Tl200"),
            Self::Tl201 => write!(f, "Tl201"),
            Self::Tl202 => write!(f, "Tl202"),
            Self::Tl203 => write!(f, "Tl203"),
            Self::Tl204 => write!(f, "Tl204"),
            Self::Tl205 => write!(f, "Tl205"),
            Self::Tl206 => write!(f, "Tl206"),
            Self::Tl207 => write!(f, "Tl207"),
            Self::Tl208 => write!(f, "Tl208"),
            Self::Tl209 => write!(f, "Tl209"),
            Self::Tl210 => write!(f, "Tl210"),
            Self::Tl211 => write!(f, "Tl211"),
            Self::Tl212 => write!(f, "Tl212"),
            Self::Tl213 => write!(f, "Tl213"),
            Self::Tl214 => write!(f, "Tl214"),
            Self::Tl215 => write!(f, "Tl215"),
            Self::Tl216 => write!(f, "Tl216"),
            Self::Tl217 => write!(f, "Tl217"),
        }
    }
}
#[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 ThalliumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in ThalliumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Tl, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in ThalliumIsotope::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 ThalliumIsotope::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 = ThalliumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in ThalliumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Tl(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in ThalliumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Tl);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in ThalliumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = ThalliumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = ThalliumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = ThalliumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(ThalliumIsotope::try_from(0_u16).is_err());
        assert!(ThalliumIsotope::try_from(1000_u16).is_err());
        assert!(ThalliumIsotope::try_from(0_u32).is_err());
        assert!(ThalliumIsotope::try_from(1000_u32).is_err());
        assert!(ThalliumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in ThalliumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}