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 Gadolinium
#[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 Gadolinium
pub enum GadoliniumIsotope {
    /// Isotope Gd133 of Gadolinium
    Gd133,
    /// Isotope Gd134 of Gadolinium
    Gd134,
    /// Isotope Gd135 of Gadolinium
    Gd135,
    /// Isotope Gd136 of Gadolinium
    Gd136,
    /// Isotope Gd137 of Gadolinium
    Gd137,
    /// Isotope Gd138 of Gadolinium
    Gd138,
    /// Isotope Gd139 of Gadolinium
    Gd139,
    /// Isotope Gd140 of Gadolinium
    Gd140,
    /// Isotope Gd141 of Gadolinium
    Gd141,
    /// Isotope Gd142 of Gadolinium
    Gd142,
    /// Isotope Gd143 of Gadolinium
    Gd143,
    /// Isotope Gd144 of Gadolinium
    Gd144,
    /// Isotope Gd145 of Gadolinium
    Gd145,
    /// Isotope Gd146 of Gadolinium
    Gd146,
    /// Isotope Gd147 of Gadolinium
    Gd147,
    /// Isotope Gd148 of Gadolinium
    Gd148,
    /// Isotope Gd149 of Gadolinium
    Gd149,
    /// Isotope Gd150 of Gadolinium
    Gd150,
    /// Isotope Gd151 of Gadolinium
    Gd151,
    /// Isotope Gd152 of Gadolinium
    Gd152,
    /// Isotope Gd153 of Gadolinium
    Gd153,
    /// Isotope Gd154 of Gadolinium
    Gd154,
    /// Isotope Gd155 of Gadolinium
    Gd155,
    /// Isotope Gd156 of Gadolinium
    Gd156,
    /// Isotope Gd157 of Gadolinium
    Gd157,
    /// Isotope Gd158 of Gadolinium
    Gd158,
    /// Isotope Gd159 of Gadolinium
    Gd159,
    /// Isotope Gd160 of Gadolinium
    Gd160,
    /// Isotope Gd161 of Gadolinium
    Gd161,
    /// Isotope Gd162 of Gadolinium
    Gd162,
    /// Isotope Gd163 of Gadolinium
    Gd163,
    /// Isotope Gd164 of Gadolinium
    Gd164,
    /// Isotope Gd165 of Gadolinium
    Gd165,
    /// Isotope Gd166 of Gadolinium
    Gd166,
    /// Isotope Gd167 of Gadolinium
    Gd167,
    /// Isotope Gd168 of Gadolinium
    Gd168,
    /// Isotope Gd169 of Gadolinium
    Gd169,
    /// Isotope Gd170 of Gadolinium
    Gd170,
    /// Isotope Gd171 of Gadolinium
    Gd171,
    /// Isotope Gd172 of Gadolinium
    Gd172,
}
impl super::RelativeAtomicMass for GadoliniumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Gd133 => 132.96133f64,
            Self::Gd134 => 133.95566f64,
            Self::Gd135 => 134.95245f64,
            Self::Gd136 => 135.9473f64,
            Self::Gd137 => 136.94502f64,
            Self::Gd138 => 137.94025f64,
            Self::Gd139 => 138.93813f64,
            Self::Gd140 => 139.933674f64,
            Self::Gd141 => 140.932126f64,
            Self::Gd142 => 141.928116f64,
            Self::Gd143 => 142.92675f64,
            Self::Gd144 => 143.922963f64,
            Self::Gd145 => 144.921713f64,
            Self::Gd146 => 145.9183188f64,
            Self::Gd147 => 146.9191014f64,
            Self::Gd148 => 147.9181215f64,
            Self::Gd149 => 148.9193481f64,
            Self::Gd150 => 149.9186644f64,
            Self::Gd151 => 150.920356f64,
            Self::Gd152 => 151.9197995f64,
            Self::Gd153 => 152.921758f64,
            Self::Gd154 => 153.9208741f64,
            Self::Gd155 => 154.9226305f64,
            Self::Gd156 => 155.9221312f64,
            Self::Gd157 => 156.9239686f64,
            Self::Gd158 => 157.9241123f64,
            Self::Gd159 => 158.926397f64,
            Self::Gd160 => 159.9270624f64,
            Self::Gd161 => 160.9296775f64,
            Self::Gd162 => 161.930993f64,
            Self::Gd163 => 162.9341769f64,
            Self::Gd164 => 163.93583f64,
            Self::Gd165 => 164.93936f64,
            Self::Gd166 => 165.94146f64,
            Self::Gd167 => 166.94545f64,
            Self::Gd168 => 167.94808f64,
            Self::Gd169 => 168.9526f64,
            Self::Gd170 => 169.956146f64,
            Self::Gd171 => 170.961127f64,
            Self::Gd172 => 171.964605f64,
        }
    }
}
impl super::ElementVariant for GadoliniumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Gd
    }
}
impl super::MassNumber for GadoliniumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Gd133 => 133u16,
            Self::Gd134 => 134u16,
            Self::Gd135 => 135u16,
            Self::Gd136 => 136u16,
            Self::Gd137 => 137u16,
            Self::Gd138 => 138u16,
            Self::Gd139 => 139u16,
            Self::Gd140 => 140u16,
            Self::Gd141 => 141u16,
            Self::Gd142 => 142u16,
            Self::Gd143 => 143u16,
            Self::Gd144 => 144u16,
            Self::Gd145 => 145u16,
            Self::Gd146 => 146u16,
            Self::Gd147 => 147u16,
            Self::Gd148 => 148u16,
            Self::Gd149 => 149u16,
            Self::Gd150 => 150u16,
            Self::Gd151 => 151u16,
            Self::Gd152 => 152u16,
            Self::Gd153 => 153u16,
            Self::Gd154 => 154u16,
            Self::Gd155 => 155u16,
            Self::Gd156 => 156u16,
            Self::Gd157 => 157u16,
            Self::Gd158 => 158u16,
            Self::Gd159 => 159u16,
            Self::Gd160 => 160u16,
            Self::Gd161 => 161u16,
            Self::Gd162 => 162u16,
            Self::Gd163 => 163u16,
            Self::Gd164 => 164u16,
            Self::Gd165 => 165u16,
            Self::Gd166 => 166u16,
            Self::Gd167 => 167u16,
            Self::Gd168 => 168u16,
            Self::Gd169 => 169u16,
            Self::Gd170 => 170u16,
            Self::Gd171 => 171u16,
            Self::Gd172 => 172u16,
        }
    }
}
impl super::IsotopicComposition for GadoliniumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Gd152 => Some(0.002f64),
            Self::Gd154 => Some(0.0218f64),
            Self::Gd155 => Some(0.148f64),
            Self::Gd156 => Some(0.2047f64),
            Self::Gd157 => Some(0.1565f64),
            Self::Gd158 => Some(0.2484f64),
            Self::Gd160 => Some(0.2186f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for GadoliniumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Gd158
    }
}
impl From<GadoliniumIsotope> for crate::Isotope {
    fn from(isotope: GadoliniumIsotope) -> Self {
        crate::Isotope::Gd(isotope)
    }
}
impl From<GadoliniumIsotope> for crate::Element {
    fn from(_isotope: GadoliniumIsotope) -> Self {
        crate::Element::Gd
    }
}
impl TryFrom<u64> for GadoliniumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            133u64 => Ok(Self::Gd133),
            134u64 => Ok(Self::Gd134),
            135u64 => Ok(Self::Gd135),
            136u64 => Ok(Self::Gd136),
            137u64 => Ok(Self::Gd137),
            138u64 => Ok(Self::Gd138),
            139u64 => Ok(Self::Gd139),
            140u64 => Ok(Self::Gd140),
            141u64 => Ok(Self::Gd141),
            142u64 => Ok(Self::Gd142),
            143u64 => Ok(Self::Gd143),
            144u64 => Ok(Self::Gd144),
            145u64 => Ok(Self::Gd145),
            146u64 => Ok(Self::Gd146),
            147u64 => Ok(Self::Gd147),
            148u64 => Ok(Self::Gd148),
            149u64 => Ok(Self::Gd149),
            150u64 => Ok(Self::Gd150),
            151u64 => Ok(Self::Gd151),
            152u64 => Ok(Self::Gd152),
            153u64 => Ok(Self::Gd153),
            154u64 => Ok(Self::Gd154),
            155u64 => Ok(Self::Gd155),
            156u64 => Ok(Self::Gd156),
            157u64 => Ok(Self::Gd157),
            158u64 => Ok(Self::Gd158),
            159u64 => Ok(Self::Gd159),
            160u64 => Ok(Self::Gd160),
            161u64 => Ok(Self::Gd161),
            162u64 => Ok(Self::Gd162),
            163u64 => Ok(Self::Gd163),
            164u64 => Ok(Self::Gd164),
            165u64 => Ok(Self::Gd165),
            166u64 => Ok(Self::Gd166),
            167u64 => Ok(Self::Gd167),
            168u64 => Ok(Self::Gd168),
            169u64 => Ok(Self::Gd169),
            170u64 => Ok(Self::Gd170),
            171u64 => Ok(Self::Gd171),
            172u64 => Ok(Self::Gd172),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Gd, value)),
        }
    }
}
impl TryFrom<u8> for GadoliniumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for GadoliniumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for GadoliniumIsotope {
    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 GadoliniumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Gd133 => write!(f, "Gd133"),
            Self::Gd134 => write!(f, "Gd134"),
            Self::Gd135 => write!(f, "Gd135"),
            Self::Gd136 => write!(f, "Gd136"),
            Self::Gd137 => write!(f, "Gd137"),
            Self::Gd138 => write!(f, "Gd138"),
            Self::Gd139 => write!(f, "Gd139"),
            Self::Gd140 => write!(f, "Gd140"),
            Self::Gd141 => write!(f, "Gd141"),
            Self::Gd142 => write!(f, "Gd142"),
            Self::Gd143 => write!(f, "Gd143"),
            Self::Gd144 => write!(f, "Gd144"),
            Self::Gd145 => write!(f, "Gd145"),
            Self::Gd146 => write!(f, "Gd146"),
            Self::Gd147 => write!(f, "Gd147"),
            Self::Gd148 => write!(f, "Gd148"),
            Self::Gd149 => write!(f, "Gd149"),
            Self::Gd150 => write!(f, "Gd150"),
            Self::Gd151 => write!(f, "Gd151"),
            Self::Gd152 => write!(f, "Gd152"),
            Self::Gd153 => write!(f, "Gd153"),
            Self::Gd154 => write!(f, "Gd154"),
            Self::Gd155 => write!(f, "Gd155"),
            Self::Gd156 => write!(f, "Gd156"),
            Self::Gd157 => write!(f, "Gd157"),
            Self::Gd158 => write!(f, "Gd158"),
            Self::Gd159 => write!(f, "Gd159"),
            Self::Gd160 => write!(f, "Gd160"),
            Self::Gd161 => write!(f, "Gd161"),
            Self::Gd162 => write!(f, "Gd162"),
            Self::Gd163 => write!(f, "Gd163"),
            Self::Gd164 => write!(f, "Gd164"),
            Self::Gd165 => write!(f, "Gd165"),
            Self::Gd166 => write!(f, "Gd166"),
            Self::Gd167 => write!(f, "Gd167"),
            Self::Gd168 => write!(f, "Gd168"),
            Self::Gd169 => write!(f, "Gd169"),
            Self::Gd170 => write!(f, "Gd170"),
            Self::Gd171 => write!(f, "Gd171"),
            Self::Gd172 => write!(f, "Gd172"),
        }
    }
}
#[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 GadoliniumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in GadoliniumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Gd, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in GadoliniumIsotope::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 GadoliniumIsotope::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 = GadoliniumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in GadoliniumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Gd(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in GadoliniumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Gd);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in GadoliniumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = GadoliniumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = GadoliniumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = GadoliniumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(GadoliniumIsotope::try_from(0_u16).is_err());
        assert!(GadoliniumIsotope::try_from(1000_u16).is_err());
        assert!(GadoliniumIsotope::try_from(0_u32).is_err());
        assert!(GadoliniumIsotope::try_from(1000_u32).is_err());
        assert!(GadoliniumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in GadoliniumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}