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
//! Isotopes of the element Dysprosium
#[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 Dysprosium
pub enum DysprosiumIsotope {
    /// Isotope Dy138 of Dysprosium
    Dy138,
    /// Isotope Dy139 of Dysprosium
    Dy139,
    /// Isotope Dy140 of Dysprosium
    Dy140,
    /// Isotope Dy141 of Dysprosium
    Dy141,
    /// Isotope Dy142 of Dysprosium
    Dy142,
    /// Isotope Dy143 of Dysprosium
    Dy143,
    /// Isotope Dy144 of Dysprosium
    Dy144,
    /// Isotope Dy145 of Dysprosium
    Dy145,
    /// Isotope Dy146 of Dysprosium
    Dy146,
    /// Isotope Dy147 of Dysprosium
    Dy147,
    /// Isotope Dy148 of Dysprosium
    Dy148,
    /// Isotope Dy149 of Dysprosium
    Dy149,
    /// Isotope Dy150 of Dysprosium
    Dy150,
    /// Isotope Dy151 of Dysprosium
    Dy151,
    /// Isotope Dy152 of Dysprosium
    Dy152,
    /// Isotope Dy153 of Dysprosium
    Dy153,
    /// Isotope Dy154 of Dysprosium
    Dy154,
    /// Isotope Dy155 of Dysprosium
    Dy155,
    /// Isotope Dy156 of Dysprosium
    Dy156,
    /// Isotope Dy157 of Dysprosium
    Dy157,
    /// Isotope Dy158 of Dysprosium
    Dy158,
    /// Isotope Dy159 of Dysprosium
    Dy159,
    /// Isotope Dy160 of Dysprosium
    Dy160,
    /// Isotope Dy161 of Dysprosium
    Dy161,
    /// Isotope Dy162 of Dysprosium
    Dy162,
    /// Isotope Dy163 of Dysprosium
    Dy163,
    /// Isotope Dy164 of Dysprosium
    Dy164,
    /// Isotope Dy165 of Dysprosium
    Dy165,
    /// Isotope Dy166 of Dysprosium
    Dy166,
    /// Isotope Dy167 of Dysprosium
    Dy167,
    /// Isotope Dy168 of Dysprosium
    Dy168,
    /// Isotope Dy169 of Dysprosium
    Dy169,
    /// Isotope Dy170 of Dysprosium
    Dy170,
    /// Isotope Dy171 of Dysprosium
    Dy171,
    /// Isotope Dy172 of Dysprosium
    Dy172,
    /// Isotope Dy173 of Dysprosium
    Dy173,
    /// Isotope Dy174 of Dysprosium
    Dy174,
    /// Isotope Dy175 of Dysprosium
    Dy175,
    /// Isotope Dy176 of Dysprosium
    Dy176,
}
impl super::RelativeAtomicMass for DysprosiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Dy138 => 137.9625f64,
            Self::Dy139 => 138.95959f64,
            Self::Dy140 => 139.95402f64,
            Self::Dy141 => 140.95128f64,
            Self::Dy142 => 141.94619f64,
            Self::Dy143 => 142.943994f64,
            Self::Dy144 => 143.9392695f64,
            Self::Dy145 => 144.937474f64,
            Self::Dy146 => 145.9328445f64,
            Self::Dy147 => 146.9310827f64,
            Self::Dy148 => 147.927157f64,
            Self::Dy149 => 148.927322f64,
            Self::Dy150 => 149.9255933f64,
            Self::Dy151 => 150.9261916f64,
            Self::Dy152 => 151.9247253f64,
            Self::Dy153 => 152.9257724f64,
            Self::Dy154 => 153.9244293f64,
            Self::Dy155 => 154.925759f64,
            Self::Dy156 => 155.9242847f64,
            Self::Dy157 => 156.9254707f64,
            Self::Dy158 => 157.9244159f64,
            Self::Dy159 => 158.925747f64,
            Self::Dy160 => 159.9252046f64,
            Self::Dy161 => 160.9269405f64,
            Self::Dy162 => 161.9268056f64,
            Self::Dy163 => 162.9287383f64,
            Self::Dy164 => 163.9291819f64,
            Self::Dy165 => 164.9317105f64,
            Self::Dy166 => 165.9328139f64,
            Self::Dy167 => 166.935661f64,
            Self::Dy168 => 167.93713f64,
            Self::Dy169 => 168.94031f64,
            Self::Dy170 => 169.94239f64,
            Self::Dy171 => 170.94612f64,
            Self::Dy172 => 171.94846f64,
            Self::Dy173 => 172.95283f64,
            Self::Dy174 => 173.955845f64,
            Self::Dy175 => 174.960569f64,
            Self::Dy176 => 175.963918f64,
        }
    }
}
impl super::ElementVariant for DysprosiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Dy
    }
}
impl super::MassNumber for DysprosiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Dy138 => 138u16,
            Self::Dy139 => 139u16,
            Self::Dy140 => 140u16,
            Self::Dy141 => 141u16,
            Self::Dy142 => 142u16,
            Self::Dy143 => 143u16,
            Self::Dy144 => 144u16,
            Self::Dy145 => 145u16,
            Self::Dy146 => 146u16,
            Self::Dy147 => 147u16,
            Self::Dy148 => 148u16,
            Self::Dy149 => 149u16,
            Self::Dy150 => 150u16,
            Self::Dy151 => 151u16,
            Self::Dy152 => 152u16,
            Self::Dy153 => 153u16,
            Self::Dy154 => 154u16,
            Self::Dy155 => 155u16,
            Self::Dy156 => 156u16,
            Self::Dy157 => 157u16,
            Self::Dy158 => 158u16,
            Self::Dy159 => 159u16,
            Self::Dy160 => 160u16,
            Self::Dy161 => 161u16,
            Self::Dy162 => 162u16,
            Self::Dy163 => 163u16,
            Self::Dy164 => 164u16,
            Self::Dy165 => 165u16,
            Self::Dy166 => 166u16,
            Self::Dy167 => 167u16,
            Self::Dy168 => 168u16,
            Self::Dy169 => 169u16,
            Self::Dy170 => 170u16,
            Self::Dy171 => 171u16,
            Self::Dy172 => 172u16,
            Self::Dy173 => 173u16,
            Self::Dy174 => 174u16,
            Self::Dy175 => 175u16,
            Self::Dy176 => 176u16,
        }
    }
}
impl super::IsotopicComposition for DysprosiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Dy156 => Some(0.00056f64),
            Self::Dy158 => Some(0.00095f64),
            Self::Dy160 => Some(0.02329f64),
            Self::Dy161 => Some(0.18889f64),
            Self::Dy162 => Some(0.25475f64),
            Self::Dy163 => Some(0.24896f64),
            Self::Dy164 => Some(0.2826f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for DysprosiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Dy164
    }
}
impl From<DysprosiumIsotope> for crate::Isotope {
    fn from(isotope: DysprosiumIsotope) -> Self {
        crate::Isotope::Dy(isotope)
    }
}
impl From<DysprosiumIsotope> for crate::Element {
    fn from(_isotope: DysprosiumIsotope) -> Self {
        crate::Element::Dy
    }
}
impl TryFrom<u64> for DysprosiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            138u64 => Ok(Self::Dy138),
            139u64 => Ok(Self::Dy139),
            140u64 => Ok(Self::Dy140),
            141u64 => Ok(Self::Dy141),
            142u64 => Ok(Self::Dy142),
            143u64 => Ok(Self::Dy143),
            144u64 => Ok(Self::Dy144),
            145u64 => Ok(Self::Dy145),
            146u64 => Ok(Self::Dy146),
            147u64 => Ok(Self::Dy147),
            148u64 => Ok(Self::Dy148),
            149u64 => Ok(Self::Dy149),
            150u64 => Ok(Self::Dy150),
            151u64 => Ok(Self::Dy151),
            152u64 => Ok(Self::Dy152),
            153u64 => Ok(Self::Dy153),
            154u64 => Ok(Self::Dy154),
            155u64 => Ok(Self::Dy155),
            156u64 => Ok(Self::Dy156),
            157u64 => Ok(Self::Dy157),
            158u64 => Ok(Self::Dy158),
            159u64 => Ok(Self::Dy159),
            160u64 => Ok(Self::Dy160),
            161u64 => Ok(Self::Dy161),
            162u64 => Ok(Self::Dy162),
            163u64 => Ok(Self::Dy163),
            164u64 => Ok(Self::Dy164),
            165u64 => Ok(Self::Dy165),
            166u64 => Ok(Self::Dy166),
            167u64 => Ok(Self::Dy167),
            168u64 => Ok(Self::Dy168),
            169u64 => Ok(Self::Dy169),
            170u64 => Ok(Self::Dy170),
            171u64 => Ok(Self::Dy171),
            172u64 => Ok(Self::Dy172),
            173u64 => Ok(Self::Dy173),
            174u64 => Ok(Self::Dy174),
            175u64 => Ok(Self::Dy175),
            176u64 => Ok(Self::Dy176),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Dy, value)),
        }
    }
}
impl TryFrom<u8> for DysprosiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for DysprosiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for DysprosiumIsotope {
    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 DysprosiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Dy138 => write!(f, "Dy138"),
            Self::Dy139 => write!(f, "Dy139"),
            Self::Dy140 => write!(f, "Dy140"),
            Self::Dy141 => write!(f, "Dy141"),
            Self::Dy142 => write!(f, "Dy142"),
            Self::Dy143 => write!(f, "Dy143"),
            Self::Dy144 => write!(f, "Dy144"),
            Self::Dy145 => write!(f, "Dy145"),
            Self::Dy146 => write!(f, "Dy146"),
            Self::Dy147 => write!(f, "Dy147"),
            Self::Dy148 => write!(f, "Dy148"),
            Self::Dy149 => write!(f, "Dy149"),
            Self::Dy150 => write!(f, "Dy150"),
            Self::Dy151 => write!(f, "Dy151"),
            Self::Dy152 => write!(f, "Dy152"),
            Self::Dy153 => write!(f, "Dy153"),
            Self::Dy154 => write!(f, "Dy154"),
            Self::Dy155 => write!(f, "Dy155"),
            Self::Dy156 => write!(f, "Dy156"),
            Self::Dy157 => write!(f, "Dy157"),
            Self::Dy158 => write!(f, "Dy158"),
            Self::Dy159 => write!(f, "Dy159"),
            Self::Dy160 => write!(f, "Dy160"),
            Self::Dy161 => write!(f, "Dy161"),
            Self::Dy162 => write!(f, "Dy162"),
            Self::Dy163 => write!(f, "Dy163"),
            Self::Dy164 => write!(f, "Dy164"),
            Self::Dy165 => write!(f, "Dy165"),
            Self::Dy166 => write!(f, "Dy166"),
            Self::Dy167 => write!(f, "Dy167"),
            Self::Dy168 => write!(f, "Dy168"),
            Self::Dy169 => write!(f, "Dy169"),
            Self::Dy170 => write!(f, "Dy170"),
            Self::Dy171 => write!(f, "Dy171"),
            Self::Dy172 => write!(f, "Dy172"),
            Self::Dy173 => write!(f, "Dy173"),
            Self::Dy174 => write!(f, "Dy174"),
            Self::Dy175 => write!(f, "Dy175"),
            Self::Dy176 => write!(f, "Dy176"),
        }
    }
}
#[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 DysprosiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in DysprosiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Dy, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in DysprosiumIsotope::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 DysprosiumIsotope::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 = DysprosiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in DysprosiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Dy(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in DysprosiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Dy);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in DysprosiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = DysprosiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = DysprosiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = DysprosiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(DysprosiumIsotope::try_from(0_u16).is_err());
        assert!(DysprosiumIsotope::try_from(1000_u16).is_err());
        assert!(DysprosiumIsotope::try_from(0_u32).is_err());
        assert!(DysprosiumIsotope::try_from(1000_u32).is_err());
        assert!(DysprosiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in DysprosiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}