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
//! Isotopes of the element Ytterbium
#[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 Ytterbium
pub enum YtterbiumIsotope {
    /// Isotope Yb148 of Ytterbium
    Yb148,
    /// Isotope Yb149 of Ytterbium
    Yb149,
    /// Isotope Yb150 of Ytterbium
    Yb150,
    /// Isotope Yb151 of Ytterbium
    Yb151,
    /// Isotope Yb152 of Ytterbium
    Yb152,
    /// Isotope Yb153 of Ytterbium
    Yb153,
    /// Isotope Yb154 of Ytterbium
    Yb154,
    /// Isotope Yb155 of Ytterbium
    Yb155,
    /// Isotope Yb156 of Ytterbium
    Yb156,
    /// Isotope Yb157 of Ytterbium
    Yb157,
    /// Isotope Yb158 of Ytterbium
    Yb158,
    /// Isotope Yb159 of Ytterbium
    Yb159,
    /// Isotope Yb160 of Ytterbium
    Yb160,
    /// Isotope Yb161 of Ytterbium
    Yb161,
    /// Isotope Yb162 of Ytterbium
    Yb162,
    /// Isotope Yb163 of Ytterbium
    Yb163,
    /// Isotope Yb164 of Ytterbium
    Yb164,
    /// Isotope Yb165 of Ytterbium
    Yb165,
    /// Isotope Yb166 of Ytterbium
    Yb166,
    /// Isotope Yb167 of Ytterbium
    Yb167,
    /// Isotope Yb168 of Ytterbium
    Yb168,
    /// Isotope Yb169 of Ytterbium
    Yb169,
    /// Isotope Yb170 of Ytterbium
    Yb170,
    /// Isotope Yb171 of Ytterbium
    Yb171,
    /// Isotope Yb172 of Ytterbium
    Yb172,
    /// Isotope Yb173 of Ytterbium
    Yb173,
    /// Isotope Yb174 of Ytterbium
    Yb174,
    /// Isotope Yb175 of Ytterbium
    Yb175,
    /// Isotope Yb176 of Ytterbium
    Yb176,
    /// Isotope Yb177 of Ytterbium
    Yb177,
    /// Isotope Yb178 of Ytterbium
    Yb178,
    /// Isotope Yb179 of Ytterbium
    Yb179,
    /// Isotope Yb180 of Ytterbium
    Yb180,
    /// Isotope Yb181 of Ytterbium
    Yb181,
    /// Isotope Yb182 of Ytterbium
    Yb182,
    /// Isotope Yb183 of Ytterbium
    Yb183,
    /// Isotope Yb184 of Ytterbium
    Yb184,
    /// Isotope Yb185 of Ytterbium
    Yb185,
}
impl super::RelativeAtomicMass for YtterbiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Yb148 => 147.96758f64,
            Self::Yb149 => 148.96436f64,
            Self::Yb150 => 149.95852f64,
            Self::Yb151 => 150.9554f64,
            Self::Yb152 => 151.95027f64,
            Self::Yb153 => 152.94932f64,
            Self::Yb154 => 153.946396f64,
            Self::Yb155 => 154.945783f64,
            Self::Yb156 => 155.942825f64,
            Self::Yb157 => 156.942645f64,
            Self::Yb158 => 157.9398705f64,
            Self::Yb159 => 158.940055f64,
            Self::Yb160 => 159.937557f64,
            Self::Yb161 => 160.937907f64,
            Self::Yb162 => 161.935774f64,
            Self::Yb163 => 162.93634f64,
            Self::Yb164 => 163.934495f64,
            Self::Yb165 => 164.93527f64,
            Self::Yb166 => 165.9338747f64,
            Self::Yb167 => 166.934953f64,
            Self::Yb168 => 167.9338896f64,
            Self::Yb169 => 168.9351825f64,
            Self::Yb170 => 169.9347664f64,
            Self::Yb171 => 170.9363302f64,
            Self::Yb172 => 171.9363859f64,
            Self::Yb173 => 172.9382151f64,
            Self::Yb174 => 173.9388664f64,
            Self::Yb175 => 174.9412808f64,
            Self::Yb176 => 175.9425764f64,
            Self::Yb177 => 176.9452656f64,
            Self::Yb178 => 177.946651f64,
            Self::Yb179 => 178.95004f64,
            Self::Yb180 => 179.95212f64,
            Self::Yb181 => 180.95589f64,
            Self::Yb182 => 181.958239f64,
            Self::Yb183 => 182.962426f64,
            Self::Yb184 => 183.965002f64,
            Self::Yb185 => 184.969425f64,
        }
    }
}
impl super::ElementVariant for YtterbiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Yb
    }
}
impl super::MassNumber for YtterbiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Yb148 => 148u16,
            Self::Yb149 => 149u16,
            Self::Yb150 => 150u16,
            Self::Yb151 => 151u16,
            Self::Yb152 => 152u16,
            Self::Yb153 => 153u16,
            Self::Yb154 => 154u16,
            Self::Yb155 => 155u16,
            Self::Yb156 => 156u16,
            Self::Yb157 => 157u16,
            Self::Yb158 => 158u16,
            Self::Yb159 => 159u16,
            Self::Yb160 => 160u16,
            Self::Yb161 => 161u16,
            Self::Yb162 => 162u16,
            Self::Yb163 => 163u16,
            Self::Yb164 => 164u16,
            Self::Yb165 => 165u16,
            Self::Yb166 => 166u16,
            Self::Yb167 => 167u16,
            Self::Yb168 => 168u16,
            Self::Yb169 => 169u16,
            Self::Yb170 => 170u16,
            Self::Yb171 => 171u16,
            Self::Yb172 => 172u16,
            Self::Yb173 => 173u16,
            Self::Yb174 => 174u16,
            Self::Yb175 => 175u16,
            Self::Yb176 => 176u16,
            Self::Yb177 => 177u16,
            Self::Yb178 => 178u16,
            Self::Yb179 => 179u16,
            Self::Yb180 => 180u16,
            Self::Yb181 => 181u16,
            Self::Yb182 => 182u16,
            Self::Yb183 => 183u16,
            Self::Yb184 => 184u16,
            Self::Yb185 => 185u16,
        }
    }
}
impl super::IsotopicComposition for YtterbiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Yb168 => Some(0.00123f64),
            Self::Yb170 => Some(0.02982f64),
            Self::Yb171 => Some(0.1409f64),
            Self::Yb172 => Some(0.2168f64),
            Self::Yb173 => Some(0.16103f64),
            Self::Yb174 => Some(0.32026f64),
            Self::Yb176 => Some(0.12996f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for YtterbiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Yb174
    }
}
impl From<YtterbiumIsotope> for crate::Isotope {
    fn from(isotope: YtterbiumIsotope) -> Self {
        crate::Isotope::Yb(isotope)
    }
}
impl From<YtterbiumIsotope> for crate::Element {
    fn from(_isotope: YtterbiumIsotope) -> Self {
        crate::Element::Yb
    }
}
impl TryFrom<u64> for YtterbiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            148u64 => Ok(Self::Yb148),
            149u64 => Ok(Self::Yb149),
            150u64 => Ok(Self::Yb150),
            151u64 => Ok(Self::Yb151),
            152u64 => Ok(Self::Yb152),
            153u64 => Ok(Self::Yb153),
            154u64 => Ok(Self::Yb154),
            155u64 => Ok(Self::Yb155),
            156u64 => Ok(Self::Yb156),
            157u64 => Ok(Self::Yb157),
            158u64 => Ok(Self::Yb158),
            159u64 => Ok(Self::Yb159),
            160u64 => Ok(Self::Yb160),
            161u64 => Ok(Self::Yb161),
            162u64 => Ok(Self::Yb162),
            163u64 => Ok(Self::Yb163),
            164u64 => Ok(Self::Yb164),
            165u64 => Ok(Self::Yb165),
            166u64 => Ok(Self::Yb166),
            167u64 => Ok(Self::Yb167),
            168u64 => Ok(Self::Yb168),
            169u64 => Ok(Self::Yb169),
            170u64 => Ok(Self::Yb170),
            171u64 => Ok(Self::Yb171),
            172u64 => Ok(Self::Yb172),
            173u64 => Ok(Self::Yb173),
            174u64 => Ok(Self::Yb174),
            175u64 => Ok(Self::Yb175),
            176u64 => Ok(Self::Yb176),
            177u64 => Ok(Self::Yb177),
            178u64 => Ok(Self::Yb178),
            179u64 => Ok(Self::Yb179),
            180u64 => Ok(Self::Yb180),
            181u64 => Ok(Self::Yb181),
            182u64 => Ok(Self::Yb182),
            183u64 => Ok(Self::Yb183),
            184u64 => Ok(Self::Yb184),
            185u64 => Ok(Self::Yb185),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Yb, value)),
        }
    }
}
impl TryFrom<u8> for YtterbiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for YtterbiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for YtterbiumIsotope {
    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 YtterbiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Yb148 => write!(f, "Yb148"),
            Self::Yb149 => write!(f, "Yb149"),
            Self::Yb150 => write!(f, "Yb150"),
            Self::Yb151 => write!(f, "Yb151"),
            Self::Yb152 => write!(f, "Yb152"),
            Self::Yb153 => write!(f, "Yb153"),
            Self::Yb154 => write!(f, "Yb154"),
            Self::Yb155 => write!(f, "Yb155"),
            Self::Yb156 => write!(f, "Yb156"),
            Self::Yb157 => write!(f, "Yb157"),
            Self::Yb158 => write!(f, "Yb158"),
            Self::Yb159 => write!(f, "Yb159"),
            Self::Yb160 => write!(f, "Yb160"),
            Self::Yb161 => write!(f, "Yb161"),
            Self::Yb162 => write!(f, "Yb162"),
            Self::Yb163 => write!(f, "Yb163"),
            Self::Yb164 => write!(f, "Yb164"),
            Self::Yb165 => write!(f, "Yb165"),
            Self::Yb166 => write!(f, "Yb166"),
            Self::Yb167 => write!(f, "Yb167"),
            Self::Yb168 => write!(f, "Yb168"),
            Self::Yb169 => write!(f, "Yb169"),
            Self::Yb170 => write!(f, "Yb170"),
            Self::Yb171 => write!(f, "Yb171"),
            Self::Yb172 => write!(f, "Yb172"),
            Self::Yb173 => write!(f, "Yb173"),
            Self::Yb174 => write!(f, "Yb174"),
            Self::Yb175 => write!(f, "Yb175"),
            Self::Yb176 => write!(f, "Yb176"),
            Self::Yb177 => write!(f, "Yb177"),
            Self::Yb178 => write!(f, "Yb178"),
            Self::Yb179 => write!(f, "Yb179"),
            Self::Yb180 => write!(f, "Yb180"),
            Self::Yb181 => write!(f, "Yb181"),
            Self::Yb182 => write!(f, "Yb182"),
            Self::Yb183 => write!(f, "Yb183"),
            Self::Yb184 => write!(f, "Yb184"),
            Self::Yb185 => write!(f, "Yb185"),
        }
    }
}
#[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 YtterbiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in YtterbiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Yb, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in YtterbiumIsotope::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 YtterbiumIsotope::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 = YtterbiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in YtterbiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Yb(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in YtterbiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Yb);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in YtterbiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = YtterbiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = YtterbiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = YtterbiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(YtterbiumIsotope::try_from(0_u16).is_err());
        assert!(YtterbiumIsotope::try_from(1000_u16).is_err());
        assert!(YtterbiumIsotope::try_from(0_u32).is_err());
        assert!(YtterbiumIsotope::try_from(1000_u32).is_err());
        assert!(YtterbiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in YtterbiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}