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
441
442
443
//! Isotopes of the element Osmium
#[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 Osmium
pub enum OsmiumIsotope {
    /// Isotope Os161 of Osmium
    Os161,
    /// Isotope Os162 of Osmium
    Os162,
    /// Isotope Os163 of Osmium
    Os163,
    /// Isotope Os164 of Osmium
    Os164,
    /// Isotope Os165 of Osmium
    Os165,
    /// Isotope Os166 of Osmium
    Os166,
    /// Isotope Os167 of Osmium
    Os167,
    /// Isotope Os168 of Osmium
    Os168,
    /// Isotope Os169 of Osmium
    Os169,
    /// Isotope Os170 of Osmium
    Os170,
    /// Isotope Os171 of Osmium
    Os171,
    /// Isotope Os172 of Osmium
    Os172,
    /// Isotope Os173 of Osmium
    Os173,
    /// Isotope Os174 of Osmium
    Os174,
    /// Isotope Os175 of Osmium
    Os175,
    /// Isotope Os176 of Osmium
    Os176,
    /// Isotope Os177 of Osmium
    Os177,
    /// Isotope Os178 of Osmium
    Os178,
    /// Isotope Os179 of Osmium
    Os179,
    /// Isotope Os180 of Osmium
    Os180,
    /// Isotope Os181 of Osmium
    Os181,
    /// Isotope Os182 of Osmium
    Os182,
    /// Isotope Os183 of Osmium
    Os183,
    /// Isotope Os184 of Osmium
    Os184,
    /// Isotope Os185 of Osmium
    Os185,
    /// Isotope Os186 of Osmium
    Os186,
    /// Isotope Os187 of Osmium
    Os187,
    /// Isotope Os188 of Osmium
    Os188,
    /// Isotope Os189 of Osmium
    Os189,
    /// Isotope Os190 of Osmium
    Os190,
    /// Isotope Os191 of Osmium
    Os191,
    /// Isotope Os192 of Osmium
    Os192,
    /// Isotope Os193 of Osmium
    Os193,
    /// Isotope Os194 of Osmium
    Os194,
    /// Isotope Os195 of Osmium
    Os195,
    /// Isotope Os196 of Osmium
    Os196,
    /// Isotope Os197 of Osmium
    Os197,
    /// Isotope Os198 of Osmium
    Os198,
    /// Isotope Os199 of Osmium
    Os199,
    /// Isotope Os200 of Osmium
    Os200,
    /// Isotope Os201 of Osmium
    Os201,
    /// Isotope Os202 of Osmium
    Os202,
    /// Isotope Os203 of Osmium
    Os203,
}
impl super::RelativeAtomicMass for OsmiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Os161 => 160.98903f64,
            Self::Os162 => 161.98443f64,
            Self::Os163 => 162.98241f64,
            Self::Os164 => 163.97802f64,
            Self::Os165 => 164.9766f64,
            Self::Os166 => 165.972692f64,
            Self::Os167 => 166.971549f64,
            Self::Os168 => 167.967808f64,
            Self::Os169 => 168.967018f64,
            Self::Os170 => 169.963578f64,
            Self::Os171 => 170.963174f64,
            Self::Os172 => 171.960017f64,
            Self::Os173 => 172.959808f64,
            Self::Os174 => 173.957064f64,
            Self::Os175 => 174.956945f64,
            Self::Os176 => 175.954806f64,
            Self::Os177 => 176.954966f64,
            Self::Os178 => 177.953254f64,
            Self::Os179 => 178.953817f64,
            Self::Os180 => 179.952375f64,
            Self::Os181 => 180.953247f64,
            Self::Os182 => 181.95211f64,
            Self::Os183 => 182.953125f64,
            Self::Os184 => 183.9524885f64,
            Self::Os185 => 184.9540417f64,
            Self::Os186 => 185.953835f64,
            Self::Os187 => 186.9557474f64,
            Self::Os188 => 187.9558352f64,
            Self::Os189 => 188.9581442f64,
            Self::Os190 => 189.9584437f64,
            Self::Os191 => 190.9609264f64,
            Self::Os192 => 191.961477f64,
            Self::Os193 => 192.9641479f64,
            Self::Os194 => 193.9651772f64,
            Self::Os195 => 194.968318f64,
            Self::Os196 => 195.969641f64,
            Self::Os197 => 196.97283f64,
            Self::Os198 => 197.97441f64,
            Self::Os199 => 198.97801f64,
            Self::Os200 => 199.97984f64,
            Self::Os201 => 200.98364f64,
            Self::Os202 => 201.98595f64,
            Self::Os203 => 202.992195f64,
        }
    }
}
impl super::ElementVariant for OsmiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Os
    }
}
impl super::MassNumber for OsmiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Os161 => 161u16,
            Self::Os162 => 162u16,
            Self::Os163 => 163u16,
            Self::Os164 => 164u16,
            Self::Os165 => 165u16,
            Self::Os166 => 166u16,
            Self::Os167 => 167u16,
            Self::Os168 => 168u16,
            Self::Os169 => 169u16,
            Self::Os170 => 170u16,
            Self::Os171 => 171u16,
            Self::Os172 => 172u16,
            Self::Os173 => 173u16,
            Self::Os174 => 174u16,
            Self::Os175 => 175u16,
            Self::Os176 => 176u16,
            Self::Os177 => 177u16,
            Self::Os178 => 178u16,
            Self::Os179 => 179u16,
            Self::Os180 => 180u16,
            Self::Os181 => 181u16,
            Self::Os182 => 182u16,
            Self::Os183 => 183u16,
            Self::Os184 => 184u16,
            Self::Os185 => 185u16,
            Self::Os186 => 186u16,
            Self::Os187 => 187u16,
            Self::Os188 => 188u16,
            Self::Os189 => 189u16,
            Self::Os190 => 190u16,
            Self::Os191 => 191u16,
            Self::Os192 => 192u16,
            Self::Os193 => 193u16,
            Self::Os194 => 194u16,
            Self::Os195 => 195u16,
            Self::Os196 => 196u16,
            Self::Os197 => 197u16,
            Self::Os198 => 198u16,
            Self::Os199 => 199u16,
            Self::Os200 => 200u16,
            Self::Os201 => 201u16,
            Self::Os202 => 202u16,
            Self::Os203 => 203u16,
        }
    }
}
impl super::IsotopicComposition for OsmiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Os184 => Some(0.0002f64),
            Self::Os186 => Some(0.0159f64),
            Self::Os187 => Some(0.0196f64),
            Self::Os188 => Some(0.1324f64),
            Self::Os189 => Some(0.1615f64),
            Self::Os190 => Some(0.2626f64),
            Self::Os192 => Some(0.4078f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for OsmiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Os192
    }
}
impl From<OsmiumIsotope> for crate::Isotope {
    fn from(isotope: OsmiumIsotope) -> Self {
        crate::Isotope::Os(isotope)
    }
}
impl From<OsmiumIsotope> for crate::Element {
    fn from(_isotope: OsmiumIsotope) -> Self {
        crate::Element::Os
    }
}
impl TryFrom<u64> for OsmiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            161u64 => Ok(Self::Os161),
            162u64 => Ok(Self::Os162),
            163u64 => Ok(Self::Os163),
            164u64 => Ok(Self::Os164),
            165u64 => Ok(Self::Os165),
            166u64 => Ok(Self::Os166),
            167u64 => Ok(Self::Os167),
            168u64 => Ok(Self::Os168),
            169u64 => Ok(Self::Os169),
            170u64 => Ok(Self::Os170),
            171u64 => Ok(Self::Os171),
            172u64 => Ok(Self::Os172),
            173u64 => Ok(Self::Os173),
            174u64 => Ok(Self::Os174),
            175u64 => Ok(Self::Os175),
            176u64 => Ok(Self::Os176),
            177u64 => Ok(Self::Os177),
            178u64 => Ok(Self::Os178),
            179u64 => Ok(Self::Os179),
            180u64 => Ok(Self::Os180),
            181u64 => Ok(Self::Os181),
            182u64 => Ok(Self::Os182),
            183u64 => Ok(Self::Os183),
            184u64 => Ok(Self::Os184),
            185u64 => Ok(Self::Os185),
            186u64 => Ok(Self::Os186),
            187u64 => Ok(Self::Os187),
            188u64 => Ok(Self::Os188),
            189u64 => Ok(Self::Os189),
            190u64 => Ok(Self::Os190),
            191u64 => Ok(Self::Os191),
            192u64 => Ok(Self::Os192),
            193u64 => Ok(Self::Os193),
            194u64 => Ok(Self::Os194),
            195u64 => Ok(Self::Os195),
            196u64 => Ok(Self::Os196),
            197u64 => Ok(Self::Os197),
            198u64 => Ok(Self::Os198),
            199u64 => Ok(Self::Os199),
            200u64 => Ok(Self::Os200),
            201u64 => Ok(Self::Os201),
            202u64 => Ok(Self::Os202),
            203u64 => Ok(Self::Os203),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Os, value)),
        }
    }
}
impl TryFrom<u8> for OsmiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for OsmiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for OsmiumIsotope {
    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 OsmiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Os161 => write!(f, "Os161"),
            Self::Os162 => write!(f, "Os162"),
            Self::Os163 => write!(f, "Os163"),
            Self::Os164 => write!(f, "Os164"),
            Self::Os165 => write!(f, "Os165"),
            Self::Os166 => write!(f, "Os166"),
            Self::Os167 => write!(f, "Os167"),
            Self::Os168 => write!(f, "Os168"),
            Self::Os169 => write!(f, "Os169"),
            Self::Os170 => write!(f, "Os170"),
            Self::Os171 => write!(f, "Os171"),
            Self::Os172 => write!(f, "Os172"),
            Self::Os173 => write!(f, "Os173"),
            Self::Os174 => write!(f, "Os174"),
            Self::Os175 => write!(f, "Os175"),
            Self::Os176 => write!(f, "Os176"),
            Self::Os177 => write!(f, "Os177"),
            Self::Os178 => write!(f, "Os178"),
            Self::Os179 => write!(f, "Os179"),
            Self::Os180 => write!(f, "Os180"),
            Self::Os181 => write!(f, "Os181"),
            Self::Os182 => write!(f, "Os182"),
            Self::Os183 => write!(f, "Os183"),
            Self::Os184 => write!(f, "Os184"),
            Self::Os185 => write!(f, "Os185"),
            Self::Os186 => write!(f, "Os186"),
            Self::Os187 => write!(f, "Os187"),
            Self::Os188 => write!(f, "Os188"),
            Self::Os189 => write!(f, "Os189"),
            Self::Os190 => write!(f, "Os190"),
            Self::Os191 => write!(f, "Os191"),
            Self::Os192 => write!(f, "Os192"),
            Self::Os193 => write!(f, "Os193"),
            Self::Os194 => write!(f, "Os194"),
            Self::Os195 => write!(f, "Os195"),
            Self::Os196 => write!(f, "Os196"),
            Self::Os197 => write!(f, "Os197"),
            Self::Os198 => write!(f, "Os198"),
            Self::Os199 => write!(f, "Os199"),
            Self::Os200 => write!(f, "Os200"),
            Self::Os201 => write!(f, "Os201"),
            Self::Os202 => write!(f, "Os202"),
            Self::Os203 => write!(f, "Os203"),
        }
    }
}
#[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 OsmiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in OsmiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Os, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in OsmiumIsotope::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 OsmiumIsotope::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 = OsmiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in OsmiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Os(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in OsmiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Os);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in OsmiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = OsmiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = OsmiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = OsmiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(OsmiumIsotope::try_from(0_u16).is_err());
        assert!(OsmiumIsotope::try_from(1000_u16).is_err());
        assert!(OsmiumIsotope::try_from(0_u32).is_err());
        assert!(OsmiumIsotope::try_from(1000_u32).is_err());
        assert!(OsmiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in OsmiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}