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
426
427
428
429
430
431
432
//! Isotopes of the element Indium
#[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 Indium
pub enum IndiumIsotope {
    /// Isotope In96 of Indium
    In96,
    /// Isotope In97 of Indium
    In97,
    /// Isotope In98 of Indium
    In98,
    /// Isotope In99 of Indium
    In99,
    /// Isotope In100 of Indium
    In100,
    /// Isotope In101 of Indium
    In101,
    /// Isotope In102 of Indium
    In102,
    /// Isotope In103 of Indium
    In103,
    /// Isotope In104 of Indium
    In104,
    /// Isotope In105 of Indium
    In105,
    /// Isotope In106 of Indium
    In106,
    /// Isotope In107 of Indium
    In107,
    /// Isotope In108 of Indium
    In108,
    /// Isotope In109 of Indium
    In109,
    /// Isotope In110 of Indium
    In110,
    /// Isotope In111 of Indium
    In111,
    /// Isotope In112 of Indium
    In112,
    /// Isotope In113 of Indium
    In113,
    /// Isotope In114 of Indium
    In114,
    /// Isotope In115 of Indium
    In115,
    /// Isotope In116 of Indium
    In116,
    /// Isotope In117 of Indium
    In117,
    /// Isotope In118 of Indium
    In118,
    /// Isotope In119 of Indium
    In119,
    /// Isotope In120 of Indium
    In120,
    /// Isotope In121 of Indium
    In121,
    /// Isotope In122 of Indium
    In122,
    /// Isotope In123 of Indium
    In123,
    /// Isotope In124 of Indium
    In124,
    /// Isotope In125 of Indium
    In125,
    /// Isotope In126 of Indium
    In126,
    /// Isotope In127 of Indium
    In127,
    /// Isotope In128 of Indium
    In128,
    /// Isotope In129 of Indium
    In129,
    /// Isotope In130 of Indium
    In130,
    /// Isotope In131 of Indium
    In131,
    /// Isotope In132 of Indium
    In132,
    /// Isotope In133 of Indium
    In133,
    /// Isotope In134 of Indium
    In134,
    /// Isotope In135 of Indium
    In135,
    /// Isotope In136 of Indium
    In136,
    /// Isotope In137 of Indium
    In137,
}
impl super::RelativeAtomicMass for IndiumIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::In96 => 95.959109f64,
            Self::In97 => 96.94934f64,
            Self::In98 => 97.94214f64,
            Self::In99 => 98.93411f64,
            Self::In100 => 99.93096f64,
            Self::In101 => 100.92634f64,
            Self::In102 => 101.9241071f64,
            Self::In103 => 102.9198819f64,
            Self::In104 => 103.9182145f64,
            Self::In105 => 104.914502f64,
            Self::In106 => 105.913464f64,
            Self::In107 => 106.91029f64,
            Self::In108 => 107.9096935f64,
            Self::In109 => 108.9071514f64,
            Self::In110 => 109.90717f64,
            Self::In111 => 110.9051085f64,
            Self::In112 => 111.9055377f64,
            Self::In113 => 112.90406184f64,
            Self::In114 => 113.90491791f64,
            Self::In115 => 114.903878776f64,
            Self::In116 => 115.90525999f64,
            Self::In117 => 116.9045157f64,
            Self::In118 => 117.9063566f64,
            Self::In119 => 118.9058507f64,
            Self::In120 => 119.907967f64,
            Self::In121 => 120.907851f64,
            Self::In122 => 121.910281f64,
            Self::In123 => 122.910434f64,
            Self::In124 => 123.913182f64,
            Self::In125 => 124.913605f64,
            Self::In126 => 125.916507f64,
            Self::In127 => 126.917446f64,
            Self::In128 => 127.9204f64,
            Self::In129 => 128.9218053f64,
            Self::In130 => 129.924977f64,
            Self::In131 => 130.9269715f64,
            Self::In132 => 131.933001f64,
            Self::In133 => 132.93831f64,
            Self::In134 => 133.94454f64,
            Self::In135 => 134.95005f64,
            Self::In136 => 135.956017f64,
            Self::In137 => 136.961535f64,
        }
    }
}
impl super::ElementVariant for IndiumIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::In
    }
}
impl super::MassNumber for IndiumIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::In96 => 96u16,
            Self::In97 => 97u16,
            Self::In98 => 98u16,
            Self::In99 => 99u16,
            Self::In100 => 100u16,
            Self::In101 => 101u16,
            Self::In102 => 102u16,
            Self::In103 => 103u16,
            Self::In104 => 104u16,
            Self::In105 => 105u16,
            Self::In106 => 106u16,
            Self::In107 => 107u16,
            Self::In108 => 108u16,
            Self::In109 => 109u16,
            Self::In110 => 110u16,
            Self::In111 => 111u16,
            Self::In112 => 112u16,
            Self::In113 => 113u16,
            Self::In114 => 114u16,
            Self::In115 => 115u16,
            Self::In116 => 116u16,
            Self::In117 => 117u16,
            Self::In118 => 118u16,
            Self::In119 => 119u16,
            Self::In120 => 120u16,
            Self::In121 => 121u16,
            Self::In122 => 122u16,
            Self::In123 => 123u16,
            Self::In124 => 124u16,
            Self::In125 => 125u16,
            Self::In126 => 126u16,
            Self::In127 => 127u16,
            Self::In128 => 128u16,
            Self::In129 => 129u16,
            Self::In130 => 130u16,
            Self::In131 => 131u16,
            Self::In132 => 132u16,
            Self::In133 => 133u16,
            Self::In134 => 134u16,
            Self::In135 => 135u16,
            Self::In136 => 136u16,
            Self::In137 => 137u16,
        }
    }
}
impl super::IsotopicComposition for IndiumIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::In113 => Some(0.0429f64),
            Self::In115 => Some(0.9571f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for IndiumIsotope {
    fn most_abundant_isotope() -> Self {
        Self::In115
    }
}
impl From<IndiumIsotope> for crate::Isotope {
    fn from(isotope: IndiumIsotope) -> Self {
        crate::Isotope::In(isotope)
    }
}
impl From<IndiumIsotope> for crate::Element {
    fn from(_isotope: IndiumIsotope) -> Self {
        crate::Element::In
    }
}
impl TryFrom<u64> for IndiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            96u64 => Ok(Self::In96),
            97u64 => Ok(Self::In97),
            98u64 => Ok(Self::In98),
            99u64 => Ok(Self::In99),
            100u64 => Ok(Self::In100),
            101u64 => Ok(Self::In101),
            102u64 => Ok(Self::In102),
            103u64 => Ok(Self::In103),
            104u64 => Ok(Self::In104),
            105u64 => Ok(Self::In105),
            106u64 => Ok(Self::In106),
            107u64 => Ok(Self::In107),
            108u64 => Ok(Self::In108),
            109u64 => Ok(Self::In109),
            110u64 => Ok(Self::In110),
            111u64 => Ok(Self::In111),
            112u64 => Ok(Self::In112),
            113u64 => Ok(Self::In113),
            114u64 => Ok(Self::In114),
            115u64 => Ok(Self::In115),
            116u64 => Ok(Self::In116),
            117u64 => Ok(Self::In117),
            118u64 => Ok(Self::In118),
            119u64 => Ok(Self::In119),
            120u64 => Ok(Self::In120),
            121u64 => Ok(Self::In121),
            122u64 => Ok(Self::In122),
            123u64 => Ok(Self::In123),
            124u64 => Ok(Self::In124),
            125u64 => Ok(Self::In125),
            126u64 => Ok(Self::In126),
            127u64 => Ok(Self::In127),
            128u64 => Ok(Self::In128),
            129u64 => Ok(Self::In129),
            130u64 => Ok(Self::In130),
            131u64 => Ok(Self::In131),
            132u64 => Ok(Self::In132),
            133u64 => Ok(Self::In133),
            134u64 => Ok(Self::In134),
            135u64 => Ok(Self::In135),
            136u64 => Ok(Self::In136),
            137u64 => Ok(Self::In137),
            _ => Err(crate::errors::Error::Isotope(crate::Element::In, value)),
        }
    }
}
impl TryFrom<u8> for IndiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for IndiumIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for IndiumIsotope {
    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 IndiumIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::In96 => write!(f, "In96"),
            Self::In97 => write!(f, "In97"),
            Self::In98 => write!(f, "In98"),
            Self::In99 => write!(f, "In99"),
            Self::In100 => write!(f, "In100"),
            Self::In101 => write!(f, "In101"),
            Self::In102 => write!(f, "In102"),
            Self::In103 => write!(f, "In103"),
            Self::In104 => write!(f, "In104"),
            Self::In105 => write!(f, "In105"),
            Self::In106 => write!(f, "In106"),
            Self::In107 => write!(f, "In107"),
            Self::In108 => write!(f, "In108"),
            Self::In109 => write!(f, "In109"),
            Self::In110 => write!(f, "In110"),
            Self::In111 => write!(f, "In111"),
            Self::In112 => write!(f, "In112"),
            Self::In113 => write!(f, "In113"),
            Self::In114 => write!(f, "In114"),
            Self::In115 => write!(f, "In115"),
            Self::In116 => write!(f, "In116"),
            Self::In117 => write!(f, "In117"),
            Self::In118 => write!(f, "In118"),
            Self::In119 => write!(f, "In119"),
            Self::In120 => write!(f, "In120"),
            Self::In121 => write!(f, "In121"),
            Self::In122 => write!(f, "In122"),
            Self::In123 => write!(f, "In123"),
            Self::In124 => write!(f, "In124"),
            Self::In125 => write!(f, "In125"),
            Self::In126 => write!(f, "In126"),
            Self::In127 => write!(f, "In127"),
            Self::In128 => write!(f, "In128"),
            Self::In129 => write!(f, "In129"),
            Self::In130 => write!(f, "In130"),
            Self::In131 => write!(f, "In131"),
            Self::In132 => write!(f, "In132"),
            Self::In133 => write!(f, "In133"),
            Self::In134 => write!(f, "In134"),
            Self::In135 => write!(f, "In135"),
            Self::In136 => write!(f, "In136"),
            Self::In137 => write!(f, "In137"),
        }
    }
}
#[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 IndiumIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in IndiumIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::In, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in IndiumIsotope::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 IndiumIsotope::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 = IndiumIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in IndiumIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::In(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in IndiumIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::In);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in IndiumIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = IndiumIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = IndiumIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = IndiumIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(IndiumIsotope::try_from(0_u16).is_err());
        assert!(IndiumIsotope::try_from(1000_u16).is_err());
        assert!(IndiumIsotope::try_from(0_u32).is_err());
        assert!(IndiumIsotope::try_from(1000_u32).is_err());
        assert!(IndiumIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in IndiumIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}