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
//! Isotopes of the element Gold
#[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 Gold
pub enum GoldIsotope {
    /// Isotope Au170 of Gold
    Au170,
    /// Isotope Au171 of Gold
    Au171,
    /// Isotope Au172 of Gold
    Au172,
    /// Isotope Au173 of Gold
    Au173,
    /// Isotope Au174 of Gold
    Au174,
    /// Isotope Au175 of Gold
    Au175,
    /// Isotope Au176 of Gold
    Au176,
    /// Isotope Au177 of Gold
    Au177,
    /// Isotope Au178 of Gold
    Au178,
    /// Isotope Au179 of Gold
    Au179,
    /// Isotope Au180 of Gold
    Au180,
    /// Isotope Au181 of Gold
    Au181,
    /// Isotope Au182 of Gold
    Au182,
    /// Isotope Au183 of Gold
    Au183,
    /// Isotope Au184 of Gold
    Au184,
    /// Isotope Au185 of Gold
    Au185,
    /// Isotope Au186 of Gold
    Au186,
    /// Isotope Au187 of Gold
    Au187,
    /// Isotope Au188 of Gold
    Au188,
    /// Isotope Au189 of Gold
    Au189,
    /// Isotope Au190 of Gold
    Au190,
    /// Isotope Au191 of Gold
    Au191,
    /// Isotope Au192 of Gold
    Au192,
    /// Isotope Au193 of Gold
    Au193,
    /// Isotope Au194 of Gold
    Au194,
    /// Isotope Au195 of Gold
    Au195,
    /// Isotope Au196 of Gold
    Au196,
    /// Isotope Au197 of Gold
    Au197,
    /// Isotope Au198 of Gold
    Au198,
    /// Isotope Au199 of Gold
    Au199,
    /// Isotope Au200 of Gold
    Au200,
    /// Isotope Au201 of Gold
    Au201,
    /// Isotope Au202 of Gold
    Au202,
    /// Isotope Au203 of Gold
    Au203,
    /// Isotope Au204 of Gold
    Au204,
    /// Isotope Au205 of Gold
    Au205,
    /// Isotope Au206 of Gold
    Au206,
    /// Isotope Au207 of Gold
    Au207,
    /// Isotope Au208 of Gold
    Au208,
    /// Isotope Au209 of Gold
    Au209,
    /// Isotope Au210 of Gold
    Au210,
}
impl super::RelativeAtomicMass for GoldIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Au170 => 169.99597f64,
            Self::Au171 => 170.991876f64,
            Self::Au172 => 171.989942f64,
            Self::Au173 => 172.986241f64,
            Self::Au174 => 173.984717f64,
            Self::Au175 => 174.981304f64,
            Self::Au176 => 175.98025f64,
            Self::Au177 => 176.97687f64,
            Self::Au178 => 177.976032f64,
            Self::Au179 => 178.973174f64,
            Self::Au180 => 179.972523f64,
            Self::Au181 => 180.970079f64,
            Self::Au182 => 181.969618f64,
            Self::Au183 => 182.967591f64,
            Self::Au184 => 183.967452f64,
            Self::Au185 => 184.96579f64,
            Self::Au186 => 185.965953f64,
            Self::Au187 => 186.964543f64,
            Self::Au188 => 187.965349f64,
            Self::Au189 => 188.963948f64,
            Self::Au190 => 189.964698f64,
            Self::Au191 => 190.963702f64,
            Self::Au192 => 191.964814f64,
            Self::Au193 => 192.9641373f64,
            Self::Au194 => 193.9654178f64,
            Self::Au195 => 194.9650352f64,
            Self::Au196 => 195.9665699f64,
            Self::Au197 => 196.96656879f64,
            Self::Au198 => 197.96824242f64,
            Self::Au199 => 198.96876528f64,
            Self::Au200 => 199.970756f64,
            Self::Au201 => 200.9716575f64,
            Self::Au202 => 201.973856f64,
            Self::Au203 => 202.9751544f64,
            Self::Au204 => 203.97783f64,
            Self::Au205 => 204.97985f64,
            Self::Au206 => 205.98474f64,
            Self::Au207 => 206.9884f64,
            Self::Au208 => 207.99345f64,
            Self::Au209 => 208.99735f64,
            Self::Au210 => 210.0025f64,
        }
    }
}
impl super::ElementVariant for GoldIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Au
    }
}
impl super::MassNumber for GoldIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Au170 => 170u16,
            Self::Au171 => 171u16,
            Self::Au172 => 172u16,
            Self::Au173 => 173u16,
            Self::Au174 => 174u16,
            Self::Au175 => 175u16,
            Self::Au176 => 176u16,
            Self::Au177 => 177u16,
            Self::Au178 => 178u16,
            Self::Au179 => 179u16,
            Self::Au180 => 180u16,
            Self::Au181 => 181u16,
            Self::Au182 => 182u16,
            Self::Au183 => 183u16,
            Self::Au184 => 184u16,
            Self::Au185 => 185u16,
            Self::Au186 => 186u16,
            Self::Au187 => 187u16,
            Self::Au188 => 188u16,
            Self::Au189 => 189u16,
            Self::Au190 => 190u16,
            Self::Au191 => 191u16,
            Self::Au192 => 192u16,
            Self::Au193 => 193u16,
            Self::Au194 => 194u16,
            Self::Au195 => 195u16,
            Self::Au196 => 196u16,
            Self::Au197 => 197u16,
            Self::Au198 => 198u16,
            Self::Au199 => 199u16,
            Self::Au200 => 200u16,
            Self::Au201 => 201u16,
            Self::Au202 => 202u16,
            Self::Au203 => 203u16,
            Self::Au204 => 204u16,
            Self::Au205 => 205u16,
            Self::Au206 => 206u16,
            Self::Au207 => 207u16,
            Self::Au208 => 208u16,
            Self::Au209 => 209u16,
            Self::Au210 => 210u16,
        }
    }
}
impl super::IsotopicComposition for GoldIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Au197 => Some(1f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for GoldIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Au197
    }
}
impl From<GoldIsotope> for crate::Isotope {
    fn from(isotope: GoldIsotope) -> Self {
        crate::Isotope::Au(isotope)
    }
}
impl From<GoldIsotope> for crate::Element {
    fn from(_isotope: GoldIsotope) -> Self {
        crate::Element::Au
    }
}
impl TryFrom<u64> for GoldIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            170u64 => Ok(Self::Au170),
            171u64 => Ok(Self::Au171),
            172u64 => Ok(Self::Au172),
            173u64 => Ok(Self::Au173),
            174u64 => Ok(Self::Au174),
            175u64 => Ok(Self::Au175),
            176u64 => Ok(Self::Au176),
            177u64 => Ok(Self::Au177),
            178u64 => Ok(Self::Au178),
            179u64 => Ok(Self::Au179),
            180u64 => Ok(Self::Au180),
            181u64 => Ok(Self::Au181),
            182u64 => Ok(Self::Au182),
            183u64 => Ok(Self::Au183),
            184u64 => Ok(Self::Au184),
            185u64 => Ok(Self::Au185),
            186u64 => Ok(Self::Au186),
            187u64 => Ok(Self::Au187),
            188u64 => Ok(Self::Au188),
            189u64 => Ok(Self::Au189),
            190u64 => Ok(Self::Au190),
            191u64 => Ok(Self::Au191),
            192u64 => Ok(Self::Au192),
            193u64 => Ok(Self::Au193),
            194u64 => Ok(Self::Au194),
            195u64 => Ok(Self::Au195),
            196u64 => Ok(Self::Au196),
            197u64 => Ok(Self::Au197),
            198u64 => Ok(Self::Au198),
            199u64 => Ok(Self::Au199),
            200u64 => Ok(Self::Au200),
            201u64 => Ok(Self::Au201),
            202u64 => Ok(Self::Au202),
            203u64 => Ok(Self::Au203),
            204u64 => Ok(Self::Au204),
            205u64 => Ok(Self::Au205),
            206u64 => Ok(Self::Au206),
            207u64 => Ok(Self::Au207),
            208u64 => Ok(Self::Au208),
            209u64 => Ok(Self::Au209),
            210u64 => Ok(Self::Au210),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Au, value)),
        }
    }
}
impl TryFrom<u8> for GoldIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for GoldIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for GoldIsotope {
    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 GoldIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Au170 => write!(f, "Au170"),
            Self::Au171 => write!(f, "Au171"),
            Self::Au172 => write!(f, "Au172"),
            Self::Au173 => write!(f, "Au173"),
            Self::Au174 => write!(f, "Au174"),
            Self::Au175 => write!(f, "Au175"),
            Self::Au176 => write!(f, "Au176"),
            Self::Au177 => write!(f, "Au177"),
            Self::Au178 => write!(f, "Au178"),
            Self::Au179 => write!(f, "Au179"),
            Self::Au180 => write!(f, "Au180"),
            Self::Au181 => write!(f, "Au181"),
            Self::Au182 => write!(f, "Au182"),
            Self::Au183 => write!(f, "Au183"),
            Self::Au184 => write!(f, "Au184"),
            Self::Au185 => write!(f, "Au185"),
            Self::Au186 => write!(f, "Au186"),
            Self::Au187 => write!(f, "Au187"),
            Self::Au188 => write!(f, "Au188"),
            Self::Au189 => write!(f, "Au189"),
            Self::Au190 => write!(f, "Au190"),
            Self::Au191 => write!(f, "Au191"),
            Self::Au192 => write!(f, "Au192"),
            Self::Au193 => write!(f, "Au193"),
            Self::Au194 => write!(f, "Au194"),
            Self::Au195 => write!(f, "Au195"),
            Self::Au196 => write!(f, "Au196"),
            Self::Au197 => write!(f, "Au197"),
            Self::Au198 => write!(f, "Au198"),
            Self::Au199 => write!(f, "Au199"),
            Self::Au200 => write!(f, "Au200"),
            Self::Au201 => write!(f, "Au201"),
            Self::Au202 => write!(f, "Au202"),
            Self::Au203 => write!(f, "Au203"),
            Self::Au204 => write!(f, "Au204"),
            Self::Au205 => write!(f, "Au205"),
            Self::Au206 => write!(f, "Au206"),
            Self::Au207 => write!(f, "Au207"),
            Self::Au208 => write!(f, "Au208"),
            Self::Au209 => write!(f, "Au209"),
            Self::Au210 => write!(f, "Au210"),
        }
    }
}
#[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 GoldIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in GoldIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Au, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in GoldIsotope::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 GoldIsotope::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 = GoldIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in GoldIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Au(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in GoldIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Au);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in GoldIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = GoldIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = GoldIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = GoldIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(GoldIsotope::try_from(0_u16).is_err());
        assert!(GoldIsotope::try_from(1000_u16).is_err());
        assert!(GoldIsotope::try_from(0_u32).is_err());
        assert!(GoldIsotope::try_from(1000_u32).is_err());
        assert!(GoldIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in GoldIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}