fourdst::libcomposition v1.5.2
Robust atomic species information library
Loading...
Searching...
No Matches
atomicSpecies.h
Go to the documentation of this file.
1#pragma once
2
3
4#include <string_view>
5#include <string>
6#include <iostream>
7#include <limits>
8
9
14namespace fourdst::atomic {
20 inline double convert_jpi_to_double(const std::string& jpi_string);
21
51 struct Species {
52 std::string m_name;
53 std::string m_el;
54 int m_nz;
55 int m_n;
56 int m_z;
57 int m_a;
59 std::string m_betaCode;
61 double m_halfLife_s;
62 std::string m_spinParity;
63 std::string m_decayModes;
64 double m_atomicMass;
66 double m_spin = 0.0;
67
89 const std::string_view name,
90 const std::string_view el,
91 const int nz,
92 const int n,
93 const int z,
94 const int a,
95 const double bindingEnergy,
96 const std::string_view betaCode,
97 const double betaDecayEnergy,
98 const double halfLife_s,
99 const std::string_view spinParity,
100 const std::string_view decayModes,
101 const double atomicMass,
102 const double atomicMassUnc
103 ) :
104 m_name(name),
105 m_el(el),
106 m_nz(nz),
107 m_n(n),
108 m_z(z),
109 m_a(a),
113 m_halfLife_s(halfLife_s),
116 m_atomicMass(atomicMass),
117 m_atomicMassUnc(atomicMassUnc) {
119 };
120
127 m_name = species.m_name;
128 m_el = species.m_el;
129 m_nz = species.m_nz;
130 m_n = species.m_n;
131 m_z = species.m_z;
132 m_a = species.m_a;
133 m_bindingEnergy = species.m_bindingEnergy;
134 m_betaCode = species.m_betaCode;
135 m_betaDecayEnergy = species.m_betaDecayEnergy;
136 m_halfLife_s = species.m_halfLife_s;
137 m_spinParity = species.m_spinParity;
138 m_decayModes = species.m_decayModes;
139 m_atomicMass = species.m_atomicMass;
140 m_atomicMassUnc = species.m_atomicMassUnc;
142 }
143
144
149 [[nodiscard]] double mass() const {
150 return m_atomicMass;
151 }
152
157 [[nodiscard]] double massUnc() const {
158 return m_atomicMassUnc;
159 }
160
165 [[nodiscard]] double halfLife() const {
166 return m_halfLife_s;
167 }
168
173 [[nodiscard]] std::string_view spinParity() const {
174 return m_spinParity;
175 }
176
181 [[nodiscard]] std::string_view decayModes() const {
182 return m_decayModes;
183 }
184
189 [[nodiscard]] double bindingEnergy() const {
190 return m_bindingEnergy;
191 }
192
197 [[nodiscard]] double betaDecayEnergy() const {
198 return m_betaDecayEnergy;
199 }
200
205 [[nodiscard]] std::string_view betaCode() const {
206 return m_betaCode;
207 }
208
213 [[nodiscard]] std::string_view name() const {
214 return m_name;
215 }
216
221 [[nodiscard]] std::string_view el() const {
222 return m_el;
223 }
224
229 [[nodiscard]] int nz() const {
230 return m_nz;
231 }
232
237 [[nodiscard]] int n() const {
238 return m_n;
239 }
240
245 [[nodiscard]] int z() const {
246 return m_z;
247 }
248
253 [[nodiscard]] int a() const {
254 return m_a;
255 }
256
261 [[nodiscard]] double spin() const {
262 return m_spin;
263 }
264
271 friend std::ostream& operator<<(std::ostream& os, const Species& species) {
272 os << species.m_name;
273 return os;
274 }
275
276 friend bool operator==(const Species& lhs, const Species& rhs);
277 friend bool operator!=(const Species& lhs, const Species& rhs);
278 friend bool operator<(const Species& lhs, const Species& rhs);
279 friend bool operator>(const Species& lhs, const Species& rhs);
280 };
281
287 inline bool operator==(const Species& lhs, const Species& rhs) {
288 return (lhs.m_name == rhs.m_name);
289 }
290
296 inline bool operator!=(const Species& lhs, const Species& rhs) {
297 return (lhs.m_name != rhs.m_name);
298 }
299
305 inline bool operator<(const Species& lhs, const Species& rhs) {
306 return (lhs.m_atomicMass < rhs.m_atomicMass);
307 }
308
314 inline bool operator>(const Species& lhs, const Species& rhs) {
315 return (lhs.m_atomicMass > rhs.m_atomicMass);
316 }
317
348 inline double convert_jpi_to_double(const std::string& jpi_string) {
349 std::string s = jpi_string;
350
351 if (s.empty()) {
352 return std::numeric_limits<double>::quiet_NaN();
353 }
354
355 std::erase_if(s, [](const char c) {
356 return c == '(' || c == ')' || c == '*' || c == '#';
357 });
358
359 if (s == "+" || s == "-") {
360 return 0.0;
361 }
362
363 if (const size_t comma_pos = s.find(','); comma_pos != std::string::npos) {
364 s = s.substr(0, comma_pos);
365 }
366
367 if (!s.empty() && (s.back() == '+' || s.back() == '-')) {
368 s.pop_back();
369 }
370
371 if (s.empty()) {
372 return std::numeric_limits<double>::quiet_NaN();
373 }
374
375 try {
376 if (size_t slash_pos = s.find('/'); slash_pos != std::string::npos) {
377 if (slash_pos == 0) {
378 s = "1" + s;
379 slash_pos = 1;
380 }
381 const std::string numerator_str = s.substr(0, slash_pos);
382 const std::string denominator_str = s.substr(slash_pos + 1);
383 if (denominator_str.empty()) {
384 return std::numeric_limits<double>::quiet_NaN();
385 }
386 const double numerator = std::stod(numerator_str);
387 const double denominator = std::stod(denominator_str);
388 if (denominator == 0.0) {
389 return std::numeric_limits<double>::quiet_NaN();
390 }
391 return numerator / denominator;
392 } else {
393 return std::stod(s);
394 }
395 } catch (const std::invalid_argument&) {
396 return std::numeric_limits<double>::quiet_NaN();
397 } catch (const std::out_of_range&) {
398 return std::numeric_limits<double>::quiet_NaN();
399 }
400 }
401
402}
403
427template<>
428struct std::hash<fourdst::atomic::Species> {
434 size_t operator()(const fourdst::atomic::Species& s) const noexcept {
435 return std::hash<std::string>()(s.m_name);
436 }
437}; // namespace std
Contains classes and functions related to atomic data, such as properties of atomic species.
bool operator==(const Species &lhs, const Species &rhs)
Equality operator for Species. Compares based on name.
bool operator>(const Species &lhs, const Species &rhs)
Greater-than operator for Species. Compares based on atomic mass.
bool operator!=(const Species &lhs, const Species &rhs)
Inequality operator for Species. Compares based on name.
bool operator<(const Species &lhs, const Species &rhs)
Less-than operator for Species. Compares based on atomic mass.
static const std::unordered_map< std::string, const Species & > species
Definition species.h:3581
double convert_jpi_to_double(const std::string &jpi_string)
Converts a spin-parity string (JPI string) to a double-precision floating-point number.
Represents an atomic species (isotope) with its fundamental physical properties.
double spin() const
Gets the nuclear spin as a numeric value.
double m_betaDecayEnergy
Beta decay energy in keV.
int z() const
Gets the atomic number (number of protons).
std::string_view name() const
Gets the name of the species.
std::string_view el() const
Gets the element symbol of the species.
double halfLife() const
Gets the half-life of the species.
Species(const std::string_view name, const std::string_view el, const int nz, const int n, const int z, const int a, const double bindingEnergy, const std::string_view betaCode, const double betaDecayEnergy, const double halfLife_s, const std::string_view spinParity, const std::string_view decayModes, const double atomicMass, const double atomicMassUnc)
Constructs a Species object with detailed properties.
double m_atomicMassUnc
Uncertainty in the atomic mass.
std::string m_name
Name of the species (e.g., "Fe56").
int m_nz
NZ identifier, typically 1000*Z + A.
std::string m_decayModes
Decay modes as a string.
std::string_view betaCode() const
Gets the beta decay code.
int m_a
Mass number (N + Z).
std::string m_el
Element symbol (e.g., "Fe").
friend bool operator==(const Species &lhs, const Species &rhs)
Equality operator for Species. Compares based on name.
double betaDecayEnergy() const
Gets the beta decay energy of the species.
Species(const Species &species)
Copy constructor for Species.
std::string m_spinParity
Spin and parity as a string (e.g., "1/2-").
int m_n
Number of neutrons.
int n() const
Gets the number of neutrons.
int nz() const
Gets the NZ identifier of the species.
std::string_view decayModes() const
Gets the decay modes as a string.
int m_z
Atomic number (number of protons).
double m_atomicMass
Atomic mass in atomic mass units (u).
friend bool operator>(const Species &lhs, const Species &rhs)
Greater-than operator for Species. Compares based on atomic mass.
std::string m_betaCode
Beta decay code.
double bindingEnergy() const
Gets the binding energy of the species.
double massUnc() const
Gets the uncertainty in the atomic mass.
double m_bindingEnergy
Binding energy in keV.
friend std::ostream & operator<<(std::ostream &os, const Species &species)
Overloads the stream insertion operator for easy printing of a Species object.
int a() const
Gets the mass number.
friend bool operator!=(const Species &lhs, const Species &rhs)
Inequality operator for Species. Compares based on name.
double m_spin
Nuclear spin as a double, derived from m_spinParity.
double mass() const
Gets the atomic mass of the species.
double m_halfLife_s
Half-life in seconds. A value of -1.0 typically indicates stability.
friend bool operator<(const Species &lhs, const Species &rhs)
Less-than operator for Species. Compares based on atomic mass.
std::string_view spinParity() const
Gets the spin and parity as a string.
size_t operator()(const fourdst::atomic::Species &s) const noexcept
Computes the hash for a Species object.