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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
//! Isotopes of the element Platinum
#[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 Platinum
pub enum PlatinumIsotope {
    /// Isotope Pt165 of Platinum
    Pt165,
    /// Isotope Pt166 of Platinum
    Pt166,
    /// Isotope Pt167 of Platinum
    Pt167,
    /// Isotope Pt168 of Platinum
    Pt168,
    /// Isotope Pt169 of Platinum
    Pt169,
    /// Isotope Pt170 of Platinum
    Pt170,
    /// Isotope Pt171 of Platinum
    Pt171,
    /// Isotope Pt172 of Platinum
    Pt172,
    /// Isotope Pt173 of Platinum
    Pt173,
    /// Isotope Pt174 of Platinum
    Pt174,
    /// Isotope Pt175 of Platinum
    Pt175,
    /// Isotope Pt176 of Platinum
    Pt176,
    /// Isotope Pt177 of Platinum
    Pt177,
    /// Isotope Pt178 of Platinum
    Pt178,
    /// Isotope Pt179 of Platinum
    Pt179,
    /// Isotope Pt180 of Platinum
    Pt180,
    /// Isotope Pt181 of Platinum
    Pt181,
    /// Isotope Pt182 of Platinum
    Pt182,
    /// Isotope Pt183 of Platinum
    Pt183,
    /// Isotope Pt184 of Platinum
    Pt184,
    /// Isotope Pt185 of Platinum
    Pt185,
    /// Isotope Pt186 of Platinum
    Pt186,
    /// Isotope Pt187 of Platinum
    Pt187,
    /// Isotope Pt188 of Platinum
    Pt188,
    /// Isotope Pt189 of Platinum
    Pt189,
    /// Isotope Pt190 of Platinum
    Pt190,
    /// Isotope Pt191 of Platinum
    Pt191,
    /// Isotope Pt192 of Platinum
    Pt192,
    /// Isotope Pt193 of Platinum
    Pt193,
    /// Isotope Pt194 of Platinum
    Pt194,
    /// Isotope Pt195 of Platinum
    Pt195,
    /// Isotope Pt196 of Platinum
    Pt196,
    /// Isotope Pt197 of Platinum
    Pt197,
    /// Isotope Pt198 of Platinum
    Pt198,
    /// Isotope Pt199 of Platinum
    Pt199,
    /// Isotope Pt200 of Platinum
    Pt200,
    /// Isotope Pt201 of Platinum
    Pt201,
    /// Isotope Pt202 of Platinum
    Pt202,
    /// Isotope Pt203 of Platinum
    Pt203,
    /// Isotope Pt204 of Platinum
    Pt204,
    /// Isotope Pt205 of Platinum
    Pt205,
    /// Isotope Pt206 of Platinum
    Pt206,
    /// Isotope Pt207 of Platinum
    Pt207,
    /// Isotope Pt208 of Platinum
    Pt208,
}
impl super::RelativeAtomicMass for PlatinumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Pt165 => 164.999658f64,
            Self::Pt166 => 165.99486f64,
            Self::Pt167 => 166.99269f64,
            Self::Pt168 => 167.98813f64,
            Self::Pt169 => 168.98657f64,
            Self::Pt170 => 169.982496f64,
            Self::Pt171 => 170.981245f64,
            Self::Pt172 => 171.977351f64,
            Self::Pt173 => 172.976443f64,
            Self::Pt174 => 173.97282f64,
            Self::Pt175 => 174.97241f64,
            Self::Pt176 => 175.968938f64,
            Self::Pt177 => 176.96847f64,
            Self::Pt178 => 177.96565f64,
            Self::Pt179 => 178.965359f64,
            Self::Pt180 => 179.963032f64,
            Self::Pt181 => 180.963098f64,
            Self::Pt182 => 181.961172f64,
            Self::Pt183 => 182.961597f64,
            Self::Pt184 => 183.959915f64,
            Self::Pt185 => 184.960614f64,
            Self::Pt186 => 185.959351f64,
            Self::Pt187 => 186.960617f64,
            Self::Pt188 => 187.9593889f64,
            Self::Pt189 => 188.960831f64,
            Self::Pt190 => 189.9599297f64,
            Self::Pt191 => 190.9616729f64,
            Self::Pt192 => 191.9610387f64,
            Self::Pt193 => 192.9629824f64,
            Self::Pt194 => 193.9626809f64,
            Self::Pt195 => 194.9647917f64,
            Self::Pt196 => 195.96495209f64,
            Self::Pt197 => 196.96734069f64,
            Self::Pt198 => 197.9678949f64,
            Self::Pt199 => 198.9705952f64,
            Self::Pt200 => 199.971443f64,
            Self::Pt201 => 200.974513f64,
            Self::Pt202 => 201.975639f64,
            Self::Pt203 => 202.97893f64,
            Self::Pt204 => 203.98076f64,
            Self::Pt205 => 204.98608f64,
            Self::Pt206 => 205.98966f64,
            Self::Pt207 => 206.995556f64,
            Self::Pt208 => 207.999463f64,
        }
    }
}
impl super::ElementVariant for PlatinumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Pt
    }
}
impl super::MassNumber for PlatinumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Pt165 => 165u16,
            Self::Pt166 => 166u16,
            Self::Pt167 => 167u16,
            Self::Pt168 => 168u16,
            Self::Pt169 => 169u16,
            Self::Pt170 => 170u16,
            Self::Pt171 => 171u16,
            Self::Pt172 => 172u16,
            Self::Pt173 => 173u16,
            Self::Pt174 => 174u16,
            Self::Pt175 => 175u16,
            Self::Pt176 => 176u16,
            Self::Pt177 => 177u16,
            Self::Pt178 => 178u16,
            Self::Pt179 => 179u16,
            Self::Pt180 => 180u16,
            Self::Pt181 => 181u16,
            Self::Pt182 => 182u16,
            Self::Pt183 => 183u16,
            Self::Pt184 => 184u16,
            Self::Pt185 => 185u16,
            Self::Pt186 => 186u16,
            Self::Pt187 => 187u16,
            Self::Pt188 => 188u16,
            Self::Pt189 => 189u16,
            Self::Pt190 => 190u16,
            Self::Pt191 => 191u16,
            Self::Pt192 => 192u16,
            Self::Pt193 => 193u16,
            Self::Pt194 => 194u16,
            Self::Pt195 => 195u16,
            Self::Pt196 => 196u16,
            Self::Pt197 => 197u16,
            Self::Pt198 => 198u16,
            Self::Pt199 => 199u16,
            Self::Pt200 => 200u16,
            Self::Pt201 => 201u16,
            Self::Pt202 => 202u16,
            Self::Pt203 => 203u16,
            Self::Pt204 => 204u16,
            Self::Pt205 => 205u16,
            Self::Pt206 => 206u16,
            Self::Pt207 => 207u16,
            Self::Pt208 => 208u16,
        }
    }
}
impl super::IsotopicComposition for PlatinumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Pt190 => Some(0.00012f64),
            Self::Pt192 => Some(0.00782f64),
            Self::Pt194 => Some(0.3286f64),
            Self::Pt195 => Some(0.3378f64),
            Self::Pt196 => Some(0.2521f64),
            Self::Pt198 => Some(0.07356f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for PlatinumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Pt195
    }
}
impl From<PlatinumIsotope> for crate::Isotope {
    fn from(isotope: PlatinumIsotope) -> Self {
        crate::Isotope::Pt(isotope)
    }
}
impl From<PlatinumIsotope> for crate::Element {
    fn from(_isotope: PlatinumIsotope) -> Self {
        crate::Element::Pt
    }
}
impl TryFrom<u64> for PlatinumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            165u64 => Ok(Self::Pt165),
            166u64 => Ok(Self::Pt166),
            167u64 => Ok(Self::Pt167),
            168u64 => Ok(Self::Pt168),
            169u64 => Ok(Self::Pt169),
            170u64 => Ok(Self::Pt170),
            171u64 => Ok(Self::Pt171),
            172u64 => Ok(Self::Pt172),
            173u64 => Ok(Self::Pt173),
            174u64 => Ok(Self::Pt174),
            175u64 => Ok(Self::Pt175),
            176u64 => Ok(Self::Pt176),
            177u64 => Ok(Self::Pt177),
            178u64 => Ok(Self::Pt178),
            179u64 => Ok(Self::Pt179),
            180u64 => Ok(Self::Pt180),
            181u64 => Ok(Self::Pt181),
            182u64 => Ok(Self::Pt182),
            183u64 => Ok(Self::Pt183),
            184u64 => Ok(Self::Pt184),
            185u64 => Ok(Self::Pt185),
            186u64 => Ok(Self::Pt186),
            187u64 => Ok(Self::Pt187),
            188u64 => Ok(Self::Pt188),
            189u64 => Ok(Self::Pt189),
            190u64 => Ok(Self::Pt190),
            191u64 => Ok(Self::Pt191),
            192u64 => Ok(Self::Pt192),
            193u64 => Ok(Self::Pt193),
            194u64 => Ok(Self::Pt194),
            195u64 => Ok(Self::Pt195),
            196u64 => Ok(Self::Pt196),
            197u64 => Ok(Self::Pt197),
            198u64 => Ok(Self::Pt198),
            199u64 => Ok(Self::Pt199),
            200u64 => Ok(Self::Pt200),
            201u64 => Ok(Self::Pt201),
            202u64 => Ok(Self::Pt202),
            203u64 => Ok(Self::Pt203),
            204u64 => Ok(Self::Pt204),
            205u64 => Ok(Self::Pt205),
            206u64 => Ok(Self::Pt206),
            207u64 => Ok(Self::Pt207),
            208u64 => Ok(Self::Pt208),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Pt, value)),
        }
    }
}
impl TryFrom<u8> for PlatinumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for PlatinumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for PlatinumIsotope {
    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 PlatinumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Pt165 => write!(f, "Pt165"),
            Self::Pt166 => write!(f, "Pt166"),
            Self::Pt167 => write!(f, "Pt167"),
            Self::Pt168 => write!(f, "Pt168"),
            Self::Pt169 => write!(f, "Pt169"),
            Self::Pt170 => write!(f, "Pt170"),
            Self::Pt171 => write!(f, "Pt171"),
            Self::Pt172 => write!(f, "Pt172"),
            Self::Pt173 => write!(f, "Pt173"),
            Self::Pt174 => write!(f, "Pt174"),
            Self::Pt175 => write!(f, "Pt175"),
            Self::Pt176 => write!(f, "Pt176"),
            Self::Pt177 => write!(f, "Pt177"),
            Self::Pt178 => write!(f, "Pt178"),
            Self::Pt179 => write!(f, "Pt179"),
            Self::Pt180 => write!(f, "Pt180"),
            Self::Pt181 => write!(f, "Pt181"),
            Self::Pt182 => write!(f, "Pt182"),
            Self::Pt183 => write!(f, "Pt183"),
            Self::Pt184 => write!(f, "Pt184"),
            Self::Pt185 => write!(f, "Pt185"),
            Self::Pt186 => write!(f, "Pt186"),
            Self::Pt187 => write!(f, "Pt187"),
            Self::Pt188 => write!(f, "Pt188"),
            Self::Pt189 => write!(f, "Pt189"),
            Self::Pt190 => write!(f, "Pt190"),
            Self::Pt191 => write!(f, "Pt191"),
            Self::Pt192 => write!(f, "Pt192"),
            Self::Pt193 => write!(f, "Pt193"),
            Self::Pt194 => write!(f, "Pt194"),
            Self::Pt195 => write!(f, "Pt195"),
            Self::Pt196 => write!(f, "Pt196"),
            Self::Pt197 => write!(f, "Pt197"),
            Self::Pt198 => write!(f, "Pt198"),
            Self::Pt199 => write!(f, "Pt199"),
            Self::Pt200 => write!(f, "Pt200"),
            Self::Pt201 => write!(f, "Pt201"),
            Self::Pt202 => write!(f, "Pt202"),
            Self::Pt203 => write!(f, "Pt203"),
            Self::Pt204 => write!(f, "Pt204"),
            Self::Pt205 => write!(f, "Pt205"),
            Self::Pt206 => write!(f, "Pt206"),
            Self::Pt207 => write!(f, "Pt207"),
            Self::Pt208 => write!(f, "Pt208"),
        }
    }
}
#[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 PlatinumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in PlatinumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Pt, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in PlatinumIsotope::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 PlatinumIsotope::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 = PlatinumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in PlatinumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Pt(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in PlatinumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Pt);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in PlatinumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = PlatinumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = PlatinumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = PlatinumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(PlatinumIsotope::try_from(0_u16).is_err());
        assert!(PlatinumIsotope::try_from(1000_u16).is_err());
        assert!(PlatinumIsotope::try_from(0_u32).is_err());
        assert!(PlatinumIsotope::try_from(1000_u32).is_err());
        assert!(PlatinumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in PlatinumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}