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
//! Isotopes of the element Lutetium
#[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 Lutetium
pub enum LutetiumIsotope {
    /// Isotope Lu150 of Lutetium
    Lu150,
    /// Isotope Lu151 of Lutetium
    Lu151,
    /// Isotope Lu152 of Lutetium
    Lu152,
    /// Isotope Lu153 of Lutetium
    Lu153,
    /// Isotope Lu154 of Lutetium
    Lu154,
    /// Isotope Lu155 of Lutetium
    Lu155,
    /// Isotope Lu156 of Lutetium
    Lu156,
    /// Isotope Lu157 of Lutetium
    Lu157,
    /// Isotope Lu158 of Lutetium
    Lu158,
    /// Isotope Lu159 of Lutetium
    Lu159,
    /// Isotope Lu160 of Lutetium
    Lu160,
    /// Isotope Lu161 of Lutetium
    Lu161,
    /// Isotope Lu162 of Lutetium
    Lu162,
    /// Isotope Lu163 of Lutetium
    Lu163,
    /// Isotope Lu164 of Lutetium
    Lu164,
    /// Isotope Lu165 of Lutetium
    Lu165,
    /// Isotope Lu166 of Lutetium
    Lu166,
    /// Isotope Lu167 of Lutetium
    Lu167,
    /// Isotope Lu168 of Lutetium
    Lu168,
    /// Isotope Lu169 of Lutetium
    Lu169,
    /// Isotope Lu170 of Lutetium
    Lu170,
    /// Isotope Lu171 of Lutetium
    Lu171,
    /// Isotope Lu172 of Lutetium
    Lu172,
    /// Isotope Lu173 of Lutetium
    Lu173,
    /// Isotope Lu174 of Lutetium
    Lu174,
    /// Isotope Lu175 of Lutetium
    Lu175,
    /// Isotope Lu176 of Lutetium
    Lu176,
    /// Isotope Lu177 of Lutetium
    Lu177,
    /// Isotope Lu178 of Lutetium
    Lu178,
    /// Isotope Lu179 of Lutetium
    Lu179,
    /// Isotope Lu180 of Lutetium
    Lu180,
    /// Isotope Lu181 of Lutetium
    Lu181,
    /// Isotope Lu182 of Lutetium
    Lu182,
    /// Isotope Lu183 of Lutetium
    Lu183,
    /// Isotope Lu184 of Lutetium
    Lu184,
    /// Isotope Lu185 of Lutetium
    Lu185,
    /// Isotope Lu186 of Lutetium
    Lu186,
    /// Isotope Lu187 of Lutetium
    Lu187,
    /// Isotope Lu188 of Lutetium
    Lu188,
}
impl super::RelativeAtomicMass for LutetiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Lu150 => 149.97355f64,
            Self::Lu151 => 150.96768f64,
            Self::Lu152 => 151.96412f64,
            Self::Lu153 => 152.95875f64,
            Self::Lu154 => 153.95736f64,
            Self::Lu155 => 154.954321f64,
            Self::Lu156 => 155.953033f64,
            Self::Lu157 => 156.950127f64,
            Self::Lu158 => 157.949316f64,
            Self::Lu159 => 158.946636f64,
            Self::Lu160 => 159.946033f64,
            Self::Lu161 => 160.943572f64,
            Self::Lu162 => 161.943283f64,
            Self::Lu163 => 162.941179f64,
            Self::Lu164 => 163.941339f64,
            Self::Lu165 => 164.939407f64,
            Self::Lu166 => 165.939859f64,
            Self::Lu167 => 166.93827f64,
            Self::Lu168 => 167.938736f64,
            Self::Lu169 => 168.9376441f64,
            Self::Lu170 => 169.938478f64,
            Self::Lu171 => 170.937917f64,
            Self::Lu172 => 171.9390891f64,
            Self::Lu173 => 172.938934f64,
            Self::Lu174 => 173.9403409f64,
            Self::Lu175 => 174.9407752f64,
            Self::Lu176 => 175.9426897f64,
            Self::Lu177 => 176.9437615f64,
            Self::Lu178 => 177.945958f64,
            Self::Lu179 => 178.9473309f64,
            Self::Lu180 => 179.949888f64,
            Self::Lu181 => 180.95191f64,
            Self::Lu182 => 181.95504f64,
            Self::Lu183 => 182.957363f64,
            Self::Lu184 => 183.96091f64,
            Self::Lu185 => 184.96362f64,
            Self::Lu186 => 185.96745f64,
            Self::Lu187 => 186.970188f64,
            Self::Lu188 => 187.974428f64,
        }
    }
}
impl super::ElementVariant for LutetiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Lu
    }
}
impl super::MassNumber for LutetiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Lu150 => 150u16,
            Self::Lu151 => 151u16,
            Self::Lu152 => 152u16,
            Self::Lu153 => 153u16,
            Self::Lu154 => 154u16,
            Self::Lu155 => 155u16,
            Self::Lu156 => 156u16,
            Self::Lu157 => 157u16,
            Self::Lu158 => 158u16,
            Self::Lu159 => 159u16,
            Self::Lu160 => 160u16,
            Self::Lu161 => 161u16,
            Self::Lu162 => 162u16,
            Self::Lu163 => 163u16,
            Self::Lu164 => 164u16,
            Self::Lu165 => 165u16,
            Self::Lu166 => 166u16,
            Self::Lu167 => 167u16,
            Self::Lu168 => 168u16,
            Self::Lu169 => 169u16,
            Self::Lu170 => 170u16,
            Self::Lu171 => 171u16,
            Self::Lu172 => 172u16,
            Self::Lu173 => 173u16,
            Self::Lu174 => 174u16,
            Self::Lu175 => 175u16,
            Self::Lu176 => 176u16,
            Self::Lu177 => 177u16,
            Self::Lu178 => 178u16,
            Self::Lu179 => 179u16,
            Self::Lu180 => 180u16,
            Self::Lu181 => 181u16,
            Self::Lu182 => 182u16,
            Self::Lu183 => 183u16,
            Self::Lu184 => 184u16,
            Self::Lu185 => 185u16,
            Self::Lu186 => 186u16,
            Self::Lu187 => 187u16,
            Self::Lu188 => 188u16,
        }
    }
}
impl super::IsotopicComposition for LutetiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Lu175 => Some(0.97401f64),
            Self::Lu176 => Some(0.02599f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for LutetiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Lu175
    }
}
impl From<LutetiumIsotope> for crate::Isotope {
    fn from(isotope: LutetiumIsotope) -> Self {
        crate::Isotope::Lu(isotope)
    }
}
impl From<LutetiumIsotope> for crate::Element {
    fn from(_isotope: LutetiumIsotope) -> Self {
        crate::Element::Lu
    }
}
impl TryFrom<u64> for LutetiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            150u64 => Ok(Self::Lu150),
            151u64 => Ok(Self::Lu151),
            152u64 => Ok(Self::Lu152),
            153u64 => Ok(Self::Lu153),
            154u64 => Ok(Self::Lu154),
            155u64 => Ok(Self::Lu155),
            156u64 => Ok(Self::Lu156),
            157u64 => Ok(Self::Lu157),
            158u64 => Ok(Self::Lu158),
            159u64 => Ok(Self::Lu159),
            160u64 => Ok(Self::Lu160),
            161u64 => Ok(Self::Lu161),
            162u64 => Ok(Self::Lu162),
            163u64 => Ok(Self::Lu163),
            164u64 => Ok(Self::Lu164),
            165u64 => Ok(Self::Lu165),
            166u64 => Ok(Self::Lu166),
            167u64 => Ok(Self::Lu167),
            168u64 => Ok(Self::Lu168),
            169u64 => Ok(Self::Lu169),
            170u64 => Ok(Self::Lu170),
            171u64 => Ok(Self::Lu171),
            172u64 => Ok(Self::Lu172),
            173u64 => Ok(Self::Lu173),
            174u64 => Ok(Self::Lu174),
            175u64 => Ok(Self::Lu175),
            176u64 => Ok(Self::Lu176),
            177u64 => Ok(Self::Lu177),
            178u64 => Ok(Self::Lu178),
            179u64 => Ok(Self::Lu179),
            180u64 => Ok(Self::Lu180),
            181u64 => Ok(Self::Lu181),
            182u64 => Ok(Self::Lu182),
            183u64 => Ok(Self::Lu183),
            184u64 => Ok(Self::Lu184),
            185u64 => Ok(Self::Lu185),
            186u64 => Ok(Self::Lu186),
            187u64 => Ok(Self::Lu187),
            188u64 => Ok(Self::Lu188),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Lu, value)),
        }
    }
}
impl TryFrom<u8> for LutetiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for LutetiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for LutetiumIsotope {
    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 LutetiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Lu150 => write!(f, "Lu150"),
            Self::Lu151 => write!(f, "Lu151"),
            Self::Lu152 => write!(f, "Lu152"),
            Self::Lu153 => write!(f, "Lu153"),
            Self::Lu154 => write!(f, "Lu154"),
            Self::Lu155 => write!(f, "Lu155"),
            Self::Lu156 => write!(f, "Lu156"),
            Self::Lu157 => write!(f, "Lu157"),
            Self::Lu158 => write!(f, "Lu158"),
            Self::Lu159 => write!(f, "Lu159"),
            Self::Lu160 => write!(f, "Lu160"),
            Self::Lu161 => write!(f, "Lu161"),
            Self::Lu162 => write!(f, "Lu162"),
            Self::Lu163 => write!(f, "Lu163"),
            Self::Lu164 => write!(f, "Lu164"),
            Self::Lu165 => write!(f, "Lu165"),
            Self::Lu166 => write!(f, "Lu166"),
            Self::Lu167 => write!(f, "Lu167"),
            Self::Lu168 => write!(f, "Lu168"),
            Self::Lu169 => write!(f, "Lu169"),
            Self::Lu170 => write!(f, "Lu170"),
            Self::Lu171 => write!(f, "Lu171"),
            Self::Lu172 => write!(f, "Lu172"),
            Self::Lu173 => write!(f, "Lu173"),
            Self::Lu174 => write!(f, "Lu174"),
            Self::Lu175 => write!(f, "Lu175"),
            Self::Lu176 => write!(f, "Lu176"),
            Self::Lu177 => write!(f, "Lu177"),
            Self::Lu178 => write!(f, "Lu178"),
            Self::Lu179 => write!(f, "Lu179"),
            Self::Lu180 => write!(f, "Lu180"),
            Self::Lu181 => write!(f, "Lu181"),
            Self::Lu182 => write!(f, "Lu182"),
            Self::Lu183 => write!(f, "Lu183"),
            Self::Lu184 => write!(f, "Lu184"),
            Self::Lu185 => write!(f, "Lu185"),
            Self::Lu186 => write!(f, "Lu186"),
            Self::Lu187 => write!(f, "Lu187"),
            Self::Lu188 => write!(f, "Lu188"),
        }
    }
}
#[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 LutetiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in LutetiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Lu, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in LutetiumIsotope::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 LutetiumIsotope::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 = LutetiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in LutetiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Lu(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in LutetiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Lu);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in LutetiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = LutetiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = LutetiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = LutetiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(LutetiumIsotope::try_from(0_u16).is_err());
        assert!(LutetiumIsotope::try_from(1000_u16).is_err());
        assert!(LutetiumIsotope::try_from(0_u32).is_err());
        assert!(LutetiumIsotope::try_from(1000_u32).is_err());
        assert!(LutetiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in LutetiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}