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#include <string_view>
3#include <string>
4#include <iostream>
5#include <limits>
6
11namespace fourdst::atomic {
17 inline double convert_jpi_to_double(const std::string& jpi_string);
18
48 struct Species {
49 std::string m_name;
50 std::string m_el;
51 int m_nz;
52 int m_n;
53 int m_z;
54 int m_a;
56 std::string m_betaCode;
58 double m_halfLife_s;
59 std::string m_spinParity;
60 std::string m_decayModes;
61 double m_atomicMass;
63 double m_spin = 0.0;
64
86 const std::string_view name,
87 const std::string_view el,
88 const int nz,
89 const int n,
90 const int z,
91 const int a,
92 const double bindingEnergy,
93 const std::string_view betaCode,
94 const double betaDecayEnergy,
95 const double halfLife_s,
96 const std::string_view spinParity,
97 const std::string_view decayModes,
98 const double atomicMass,
99 const double atomicMassUnc
100 ) :
101 m_name(name),
102 m_el(el),
103 m_nz(nz),
104 m_n(n),
105 m_z(z),
106 m_a(a),
110 m_halfLife_s(halfLife_s),
113 m_atomicMass(atomicMass),
114 m_atomicMassUnc(atomicMassUnc) {
116 };
117
124 m_name = species.m_name;
125 m_el = species.m_el;
126 m_nz = species.m_nz;
127 m_n = species.m_n;
128 m_z = species.m_z;
129 m_a = species.m_a;
130 m_bindingEnergy = species.m_bindingEnergy;
131 m_betaCode = species.m_betaCode;
132 m_betaDecayEnergy = species.m_betaDecayEnergy;
133 m_halfLife_s = species.m_halfLife_s;
134 m_spinParity = species.m_spinParity;
135 m_decayModes = species.m_decayModes;
136 m_atomicMass = species.m_atomicMass;
137 m_atomicMassUnc = species.m_atomicMassUnc;
139 }
140
141
146 [[nodiscard]] double mass() const {
147 return m_atomicMass;
148 }
149
154 [[nodiscard]] double massUnc() const {
155 return m_atomicMassUnc;
156 }
157
162 [[nodiscard]] double halfLife() const {
163 return m_halfLife_s;
164 }
165
170 [[nodiscard]] std::string_view spinParity() const {
171 return m_spinParity;
172 }
173
178 [[nodiscard]] std::string_view decayModes() const {
179 return m_decayModes;
180 }
181
186 [[nodiscard]] double bindingEnergy() const {
187 return m_bindingEnergy;
188 }
189
194 [[nodiscard]] double betaDecayEnergy() const {
195 return m_betaDecayEnergy;
196 }
197
202 [[nodiscard]] std::string_view betaCode() const {
203 return m_betaCode;
204 }
205
210 [[nodiscard]] std::string_view name() const {
211 return m_name;
212 }
213
218 [[nodiscard]] std::string_view el() const {
219 return m_el;
220 }
221
226 [[nodiscard]] int nz() const {
227 return m_nz;
228 }
229
234 [[nodiscard]] int n() const {
235 return m_n;
236 }
237
242 [[nodiscard]] int z() const {
243 return m_z;
244 }
245
250 [[nodiscard]] int a() const {
251 return m_a;
252 }
253
258 [[nodiscard]] double spin() const {
259 return m_spin;
260 }
261
268 friend std::ostream& operator<<(std::ostream& os, const Species& species) {
269 os << species.m_name;
270 return os;
271 }
272
273 friend bool operator==(const Species& lhs, const Species& rhs);
274 friend bool operator!=(const Species& lhs, const Species& rhs);
275 friend bool operator<(const Species& lhs, const Species& rhs);
276 friend bool operator>(const Species& lhs, const Species& rhs);
277 };
278
284 inline bool operator==(const Species& lhs, const Species& rhs) {
285 return (lhs.m_name == rhs.m_name);
286 }
287
293 inline bool operator!=(const Species& lhs, const Species& rhs) {
294 return (lhs.m_name != rhs.m_name);
295 }
296
302 inline bool operator<(const Species& lhs, const Species& rhs) {
303 return (lhs.m_atomicMass < rhs.m_atomicMass);
304 }
305
311 inline bool operator>(const Species& lhs, const Species& rhs) {
312 return (lhs.m_atomicMass > rhs.m_atomicMass);
313 }
314
345 inline double convert_jpi_to_double(const std::string& jpi_string) {
346 std::string s = jpi_string;
347
348 if (s.empty()) {
349 return std::numeric_limits<double>::quiet_NaN();
350 }
351
352 std::erase_if(s, [](const char c) {
353 return c == '(' || c == ')' || c == '*' || c == '#';
354 });
355
356 if (s == "+" || s == "-") {
357 return 0.0;
358 }
359
360 if (const size_t comma_pos = s.find(','); comma_pos != std::string::npos) {
361 s = s.substr(0, comma_pos);
362 }
363
364 if (!s.empty() && (s.back() == '+' || s.back() == '-')) {
365 s.pop_back();
366 }
367
368 if (s.empty()) {
369 return std::numeric_limits<double>::quiet_NaN();
370 }
371
372 try {
373 if (size_t slash_pos = s.find('/'); slash_pos != std::string::npos) {
374 if (slash_pos == 0) {
375 s = "1" + s;
376 slash_pos = 1;
377 }
378 const std::string numerator_str = s.substr(0, slash_pos);
379 const std::string denominator_str = s.substr(slash_pos + 1);
380 if (denominator_str.empty()) {
381 return std::numeric_limits<double>::quiet_NaN();
382 }
383 const double numerator = std::stod(numerator_str);
384 const double denominator = std::stod(denominator_str);
385 if (denominator == 0.0) {
386 return std::numeric_limits<double>::quiet_NaN();
387 }
388 return numerator / denominator;
389 } else {
390 return std::stod(s);
391 }
392 } catch (const std::invalid_argument&) {
393 return std::numeric_limits<double>::quiet_NaN();
394 } catch (const std::out_of_range&) {
395 return std::numeric_limits<double>::quiet_NaN();
396 }
397 }
398
399}
400
424template<>
425struct std::hash<fourdst::atomic::Species> {
431 size_t operator()(const fourdst::atomic::Species& s) const noexcept {
432 return std::hash<std::string>()(s.m_name);
433 }
434}; // 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:3580
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.