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
//! Isotopes of the element Tantalum
#[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 Tantalum
pub enum TantalumIsotope {
    /// Isotope Ta155 of Tantalum
    Ta155,
    /// Isotope Ta156 of Tantalum
    Ta156,
    /// Isotope Ta157 of Tantalum
    Ta157,
    /// Isotope Ta158 of Tantalum
    Ta158,
    /// Isotope Ta159 of Tantalum
    Ta159,
    /// Isotope Ta160 of Tantalum
    Ta160,
    /// Isotope Ta161 of Tantalum
    Ta161,
    /// Isotope Ta162 of Tantalum
    Ta162,
    /// Isotope Ta163 of Tantalum
    Ta163,
    /// Isotope Ta164 of Tantalum
    Ta164,
    /// Isotope Ta165 of Tantalum
    Ta165,
    /// Isotope Ta166 of Tantalum
    Ta166,
    /// Isotope Ta167 of Tantalum
    Ta167,
    /// Isotope Ta168 of Tantalum
    Ta168,
    /// Isotope Ta169 of Tantalum
    Ta169,
    /// Isotope Ta170 of Tantalum
    Ta170,
    /// Isotope Ta171 of Tantalum
    Ta171,
    /// Isotope Ta172 of Tantalum
    Ta172,
    /// Isotope Ta173 of Tantalum
    Ta173,
    /// Isotope Ta174 of Tantalum
    Ta174,
    /// Isotope Ta175 of Tantalum
    Ta175,
    /// Isotope Ta176 of Tantalum
    Ta176,
    /// Isotope Ta177 of Tantalum
    Ta177,
    /// Isotope Ta178 of Tantalum
    Ta178,
    /// Isotope Ta179 of Tantalum
    Ta179,
    /// Isotope Ta180 of Tantalum
    Ta180,
    /// Isotope Ta181 of Tantalum
    Ta181,
    /// Isotope Ta182 of Tantalum
    Ta182,
    /// Isotope Ta183 of Tantalum
    Ta183,
    /// Isotope Ta184 of Tantalum
    Ta184,
    /// Isotope Ta185 of Tantalum
    Ta185,
    /// Isotope Ta186 of Tantalum
    Ta186,
    /// Isotope Ta187 of Tantalum
    Ta187,
    /// Isotope Ta188 of Tantalum
    Ta188,
    /// Isotope Ta189 of Tantalum
    Ta189,
    /// Isotope Ta190 of Tantalum
    Ta190,
    /// Isotope Ta191 of Tantalum
    Ta191,
    /// Isotope Ta192 of Tantalum
    Ta192,
    /// Isotope Ta193 of Tantalum
    Ta193,
    /// Isotope Ta194 of Tantalum
    Ta194,
}
impl super::RelativeAtomicMass for TantalumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Ta155 => 154.97424f64,
            Self::Ta156 => 155.97203f64,
            Self::Ta157 => 156.96818f64,
            Self::Ta158 => 157.96654f64,
            Self::Ta159 => 158.963023f64,
            Self::Ta160 => 159.961488f64,
            Self::Ta161 => 160.958452f64,
            Self::Ta162 => 161.957294f64,
            Self::Ta163 => 162.954337f64,
            Self::Ta164 => 163.953534f64,
            Self::Ta165 => 164.950781f64,
            Self::Ta166 => 165.950512f64,
            Self::Ta167 => 166.948093f64,
            Self::Ta168 => 167.948047f64,
            Self::Ta169 => 168.946011f64,
            Self::Ta170 => 169.946175f64,
            Self::Ta171 => 170.944476f64,
            Self::Ta172 => 171.944895f64,
            Self::Ta173 => 172.94375f64,
            Self::Ta174 => 173.944454f64,
            Self::Ta175 => 174.943737f64,
            Self::Ta176 => 175.944857f64,
            Self::Ta177 => 176.9444795f64,
            Self::Ta178 => 177.945678f64,
            Self::Ta179 => 178.9459366f64,
            Self::Ta180 => 179.9474648f64,
            Self::Ta181 => 180.9479958f64,
            Self::Ta182 => 181.9501519f64,
            Self::Ta183 => 182.9513726f64,
            Self::Ta184 => 183.954008f64,
            Self::Ta185 => 184.955559f64,
            Self::Ta186 => 185.958551f64,
            Self::Ta187 => 186.960386f64,
            Self::Ta188 => 187.963916f64,
            Self::Ta189 => 188.96583f64,
            Self::Ta190 => 189.96939f64,
            Self::Ta191 => 190.97156f64,
            Self::Ta192 => 191.97514f64,
            Self::Ta193 => 192.97766f64,
            Self::Ta194 => 193.98161f64,
        }
    }
}
impl super::ElementVariant for TantalumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Ta
    }
}
impl super::MassNumber for TantalumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Ta155 => 155u16,
            Self::Ta156 => 156u16,
            Self::Ta157 => 157u16,
            Self::Ta158 => 158u16,
            Self::Ta159 => 159u16,
            Self::Ta160 => 160u16,
            Self::Ta161 => 161u16,
            Self::Ta162 => 162u16,
            Self::Ta163 => 163u16,
            Self::Ta164 => 164u16,
            Self::Ta165 => 165u16,
            Self::Ta166 => 166u16,
            Self::Ta167 => 167u16,
            Self::Ta168 => 168u16,
            Self::Ta169 => 169u16,
            Self::Ta170 => 170u16,
            Self::Ta171 => 171u16,
            Self::Ta172 => 172u16,
            Self::Ta173 => 173u16,
            Self::Ta174 => 174u16,
            Self::Ta175 => 175u16,
            Self::Ta176 => 176u16,
            Self::Ta177 => 177u16,
            Self::Ta178 => 178u16,
            Self::Ta179 => 179u16,
            Self::Ta180 => 180u16,
            Self::Ta181 => 181u16,
            Self::Ta182 => 182u16,
            Self::Ta183 => 183u16,
            Self::Ta184 => 184u16,
            Self::Ta185 => 185u16,
            Self::Ta186 => 186u16,
            Self::Ta187 => 187u16,
            Self::Ta188 => 188u16,
            Self::Ta189 => 189u16,
            Self::Ta190 => 190u16,
            Self::Ta191 => 191u16,
            Self::Ta192 => 192u16,
            Self::Ta193 => 193u16,
            Self::Ta194 => 194u16,
        }
    }
}
impl super::IsotopicComposition for TantalumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Ta180 => Some(0.0001201f64),
            Self::Ta181 => Some(0.9998799f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for TantalumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Ta181
    }
}
impl From<TantalumIsotope> for crate::Isotope {
    fn from(isotope: TantalumIsotope) -> Self {
        crate::Isotope::Ta(isotope)
    }
}
impl From<TantalumIsotope> for crate::Element {
    fn from(_isotope: TantalumIsotope) -> Self {
        crate::Element::Ta
    }
}
impl TryFrom<u64> for TantalumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            155u64 => Ok(Self::Ta155),
            156u64 => Ok(Self::Ta156),
            157u64 => Ok(Self::Ta157),
            158u64 => Ok(Self::Ta158),
            159u64 => Ok(Self::Ta159),
            160u64 => Ok(Self::Ta160),
            161u64 => Ok(Self::Ta161),
            162u64 => Ok(Self::Ta162),
            163u64 => Ok(Self::Ta163),
            164u64 => Ok(Self::Ta164),
            165u64 => Ok(Self::Ta165),
            166u64 => Ok(Self::Ta166),
            167u64 => Ok(Self::Ta167),
            168u64 => Ok(Self::Ta168),
            169u64 => Ok(Self::Ta169),
            170u64 => Ok(Self::Ta170),
            171u64 => Ok(Self::Ta171),
            172u64 => Ok(Self::Ta172),
            173u64 => Ok(Self::Ta173),
            174u64 => Ok(Self::Ta174),
            175u64 => Ok(Self::Ta175),
            176u64 => Ok(Self::Ta176),
            177u64 => Ok(Self::Ta177),
            178u64 => Ok(Self::Ta178),
            179u64 => Ok(Self::Ta179),
            180u64 => Ok(Self::Ta180),
            181u64 => Ok(Self::Ta181),
            182u64 => Ok(Self::Ta182),
            183u64 => Ok(Self::Ta183),
            184u64 => Ok(Self::Ta184),
            185u64 => Ok(Self::Ta185),
            186u64 => Ok(Self::Ta186),
            187u64 => Ok(Self::Ta187),
            188u64 => Ok(Self::Ta188),
            189u64 => Ok(Self::Ta189),
            190u64 => Ok(Self::Ta190),
            191u64 => Ok(Self::Ta191),
            192u64 => Ok(Self::Ta192),
            193u64 => Ok(Self::Ta193),
            194u64 => Ok(Self::Ta194),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Ta, value)),
        }
    }
}
impl TryFrom<u8> for TantalumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for TantalumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for TantalumIsotope {
    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 TantalumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Ta155 => write!(f, "Ta155"),
            Self::Ta156 => write!(f, "Ta156"),
            Self::Ta157 => write!(f, "Ta157"),
            Self::Ta158 => write!(f, "Ta158"),
            Self::Ta159 => write!(f, "Ta159"),
            Self::Ta160 => write!(f, "Ta160"),
            Self::Ta161 => write!(f, "Ta161"),
            Self::Ta162 => write!(f, "Ta162"),
            Self::Ta163 => write!(f, "Ta163"),
            Self::Ta164 => write!(f, "Ta164"),
            Self::Ta165 => write!(f, "Ta165"),
            Self::Ta166 => write!(f, "Ta166"),
            Self::Ta167 => write!(f, "Ta167"),
            Self::Ta168 => write!(f, "Ta168"),
            Self::Ta169 => write!(f, "Ta169"),
            Self::Ta170 => write!(f, "Ta170"),
            Self::Ta171 => write!(f, "Ta171"),
            Self::Ta172 => write!(f, "Ta172"),
            Self::Ta173 => write!(f, "Ta173"),
            Self::Ta174 => write!(f, "Ta174"),
            Self::Ta175 => write!(f, "Ta175"),
            Self::Ta176 => write!(f, "Ta176"),
            Self::Ta177 => write!(f, "Ta177"),
            Self::Ta178 => write!(f, "Ta178"),
            Self::Ta179 => write!(f, "Ta179"),
            Self::Ta180 => write!(f, "Ta180"),
            Self::Ta181 => write!(f, "Ta181"),
            Self::Ta182 => write!(f, "Ta182"),
            Self::Ta183 => write!(f, "Ta183"),
            Self::Ta184 => write!(f, "Ta184"),
            Self::Ta185 => write!(f, "Ta185"),
            Self::Ta186 => write!(f, "Ta186"),
            Self::Ta187 => write!(f, "Ta187"),
            Self::Ta188 => write!(f, "Ta188"),
            Self::Ta189 => write!(f, "Ta189"),
            Self::Ta190 => write!(f, "Ta190"),
            Self::Ta191 => write!(f, "Ta191"),
            Self::Ta192 => write!(f, "Ta192"),
            Self::Ta193 => write!(f, "Ta193"),
            Self::Ta194 => write!(f, "Ta194"),
        }
    }
}
#[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 TantalumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in TantalumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Ta, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in TantalumIsotope::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 TantalumIsotope::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 = TantalumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in TantalumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Ta(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in TantalumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Ta);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in TantalumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = TantalumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = TantalumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = TantalumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(TantalumIsotope::try_from(0_u16).is_err());
        assert!(TantalumIsotope::try_from(1000_u16).is_err());
        assert!(TantalumIsotope::try_from(0_u32).is_err());
        assert!(TantalumIsotope::try_from(1000_u32).is_err());
        assert!(TantalumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in TantalumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}