1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub enum SeaborgiumIsotope {
6 Sg258,
8 Sg259,
10 Sg260,
12 Sg261,
14 Sg262,
16 Sg263,
18 Sg264,
20 Sg265,
22 Sg266,
24 Sg267,
26 Sg268,
28 Sg269,
30 Sg270,
32 Sg271,
34 Sg272,
36 Sg273,
38}
39impl super::RelativeAtomicMass for SeaborgiumIsotope {
40 #[inline]
41 fn relative_atomic_mass(&self) -> f64 {
42 match self {
43 Self::Sg258 => 258.11298f64,
44 Self::Sg259 => 259.1144f64,
45 Self::Sg260 => 260.114384f64,
46 Self::Sg261 => 261.115949f64,
47 Self::Sg262 => 262.116337f64,
48 Self::Sg263 => 263.11829f64,
49 Self::Sg264 => 264.11893f64,
50 Self::Sg265 => 265.12109f64,
51 Self::Sg266 => 266.12198f64,
52 Self::Sg267 => 267.12436f64,
53 Self::Sg268 => 268.12539f64,
54 Self::Sg269 => 269.12863f64,
55 Self::Sg270 => 270.13043f64,
56 Self::Sg271 => 271.13393f64,
57 Self::Sg272 => 272.13589f64,
58 Self::Sg273 => 273.13958f64,
59 }
60 }
61}
62impl super::ElementVariant for SeaborgiumIsotope {
63 #[inline]
64 fn element(&self) -> crate::Element {
65 crate::Element::Sg
66 }
67}
68impl super::MassNumber for SeaborgiumIsotope {
69 #[inline]
70 fn mass_number(&self) -> u16 {
71 match self {
72 Self::Sg258 => 258u16,
73 Self::Sg259 => 259u16,
74 Self::Sg260 => 260u16,
75 Self::Sg261 => 261u16,
76 Self::Sg262 => 262u16,
77 Self::Sg263 => 263u16,
78 Self::Sg264 => 264u16,
79 Self::Sg265 => 265u16,
80 Self::Sg266 => 266u16,
81 Self::Sg267 => 267u16,
82 Self::Sg268 => 268u16,
83 Self::Sg269 => 269u16,
84 Self::Sg270 => 270u16,
85 Self::Sg271 => 271u16,
86 Self::Sg272 => 272u16,
87 Self::Sg273 => 273u16,
88 }
89 }
90}
91impl super::IsotopicComposition for SeaborgiumIsotope {
92 #[inline]
93 fn isotopic_composition(&self) -> Option<f64> {
94 None
95 }
96}
97impl super::MostAbundantIsotope for SeaborgiumIsotope {
98 fn most_abundant_isotope() -> Self {
99 Self::Sg273
100 }
101}
102impl From<SeaborgiumIsotope> for crate::Isotope {
103 fn from(isotope: SeaborgiumIsotope) -> Self {
104 crate::Isotope::Sg(isotope)
105 }
106}
107impl From<SeaborgiumIsotope> for crate::Element {
108 fn from(_isotope: SeaborgiumIsotope) -> Self {
109 crate::Element::Sg
110 }
111}
112impl TryFrom<u64> for SeaborgiumIsotope {
113 type Error = crate::errors::Error;
114 fn try_from(value: u64) -> Result<Self, Self::Error> {
115 match value {
116 258u64 => Ok(Self::Sg258),
117 259u64 => Ok(Self::Sg259),
118 260u64 => Ok(Self::Sg260),
119 261u64 => Ok(Self::Sg261),
120 262u64 => Ok(Self::Sg262),
121 263u64 => Ok(Self::Sg263),
122 264u64 => Ok(Self::Sg264),
123 265u64 => Ok(Self::Sg265),
124 266u64 => Ok(Self::Sg266),
125 267u64 => Ok(Self::Sg267),
126 268u64 => Ok(Self::Sg268),
127 269u64 => Ok(Self::Sg269),
128 270u64 => Ok(Self::Sg270),
129 271u64 => Ok(Self::Sg271),
130 272u64 => Ok(Self::Sg272),
131 273u64 => Ok(Self::Sg273),
132 _ => Err(crate::errors::Error::Isotope(crate::Element::Sg, value)),
133 }
134 }
135}
136impl TryFrom<u8> for SeaborgiumIsotope {
137 type Error = crate::errors::Error;
138 fn try_from(value: u8) -> Result<Self, Self::Error> {
139 Self::try_from(u64::from(value))
140 }
141}
142impl TryFrom<u16> for SeaborgiumIsotope {
143 type Error = crate::errors::Error;
144 fn try_from(value: u16) -> Result<Self, Self::Error> {
145 Self::try_from(u64::from(value))
146 }
147}
148impl TryFrom<u32> for SeaborgiumIsotope {
149 type Error = crate::errors::Error;
150 fn try_from(value: u32) -> Result<Self, Self::Error> {
151 Self::try_from(u64::from(value))
152 }
153}
154impl core::fmt::Display for SeaborgiumIsotope {
155 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
156 match self {
157 Self::Sg258 => write!(f, "Sg258"),
158 Self::Sg259 => write!(f, "Sg259"),
159 Self::Sg260 => write!(f, "Sg260"),
160 Self::Sg261 => write!(f, "Sg261"),
161 Self::Sg262 => write!(f, "Sg262"),
162 Self::Sg263 => write!(f, "Sg263"),
163 Self::Sg264 => write!(f, "Sg264"),
164 Self::Sg265 => write!(f, "Sg265"),
165 Self::Sg266 => write!(f, "Sg266"),
166 Self::Sg267 => write!(f, "Sg267"),
167 Self::Sg268 => write!(f, "Sg268"),
168 Self::Sg269 => write!(f, "Sg269"),
169 Self::Sg270 => write!(f, "Sg270"),
170 Self::Sg271 => write!(f, "Sg271"),
171 Self::Sg272 => write!(f, "Sg272"),
172 Self::Sg273 => write!(f, "Sg273"),
173 }
174 }
175}
176#[cfg(test)]
177mod tests {
178 use strum::IntoEnumIterator;
179
180 use super::*;
181 use crate::isotopes::{
182 ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
183 };
184 #[test]
185 fn test_relative_atomic_mass() {
186 for isotope in SeaborgiumIsotope::iter() {
187 let mass = isotope.relative_atomic_mass();
188 assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
189 }
190 }
191 #[test]
192 fn test_element() {
193 for isotope in SeaborgiumIsotope::iter() {
194 let element = isotope.element();
195 assert_eq!(element, crate::Element::Sg, "Element should be correct for {isotope:?}");
196 }
197 }
198 #[test]
199 fn test_mass_number() {
200 for isotope in SeaborgiumIsotope::iter() {
201 let mass_number = isotope.mass_number();
202 assert!(
203 mass_number > 0 && mass_number < 300,
204 "Mass number should be reasonable for {isotope:?}"
205 );
206 }
207 }
208 #[test]
209 fn test_isotopic_composition() {
210 for isotope in SeaborgiumIsotope::iter() {
211 let comp = isotope.isotopic_composition();
212 if let Some(c) = comp {
213 assert!(
214 (0.0..=1.0).contains(&c),
215 "Composition should be between 0 and 1 for {isotope:?}"
216 );
217 }
218 }
219 }
220 #[test]
221 fn test_most_abundant() {
222 let most_abundant = SeaborgiumIsotope::most_abundant_isotope();
223 let _ = most_abundant.relative_atomic_mass();
224 }
225 #[test]
226 fn test_from_isotope() {
227 for isotope in SeaborgiumIsotope::iter() {
228 let iso: crate::Isotope = isotope.into();
229 match iso {
230 crate::Isotope::Sg(i) => assert_eq!(i, isotope),
231 _ => panic!("Wrong isotope type"),
232 }
233 }
234 }
235 #[test]
236 fn test_from_element() {
237 for isotope in SeaborgiumIsotope::iter() {
238 let elem: crate::Element = isotope.into();
239 assert_eq!(elem, crate::Element::Sg);
240 }
241 }
242 #[test]
243 fn test_try_from_mass_number() {
244 for isotope in SeaborgiumIsotope::iter() {
245 let mass = isotope.mass_number();
246 let iso = SeaborgiumIsotope::try_from(mass).unwrap();
247 assert_eq!(iso, isotope);
248 let iso_u32 = SeaborgiumIsotope::try_from(u32::from(mass)).unwrap();
249 assert_eq!(iso_u32, isotope);
250 if let Ok(mass_u8) = u8::try_from(mass) {
251 let iso_u8 = SeaborgiumIsotope::try_from(mass_u8).unwrap();
252 assert_eq!(iso_u8, isotope);
253 }
254 }
255 assert!(SeaborgiumIsotope::try_from(0_u16).is_err());
256 assert!(SeaborgiumIsotope::try_from(1000_u16).is_err());
257 assert!(SeaborgiumIsotope::try_from(0_u32).is_err());
258 assert!(SeaborgiumIsotope::try_from(1000_u32).is_err());
259 assert!(SeaborgiumIsotope::try_from(0_u8).is_err());
260 }
261 #[test]
262 fn test_display() {
263 for isotope in SeaborgiumIsotope::iter() {
264 let s = alloc::format!("{isotope}");
265 assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
266 }
267 }
268}