Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Nuclide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ readme = "README.md"

[dependencies]
Pion = "0.0.2"
strum = { version = "0.27.2" }
strum_macros = "0.27.2"
45 changes: 42 additions & 3 deletions Nuclide/src/element.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

use std::str::FromStr;
use crate::Nuclide;
use crate::nuclidedata::element_translation::{NAME_PL, NAME_DE};
use crate::traits::ChemElement;
use crate::nuclidedata::index::SYMBOL;
use crate::nuclidedata::index::{NAME, SYMBOL};
use crate::nuclidedata::elemental::*;
use crate::nuclidedata::ionization::IONIZATION_ENERGIES;

use strum_macros::EnumString;

// TODO
// - calculate element mass const for each element
Expand Down Expand Up @@ -130,6 +131,20 @@ impl ChemElement for NuclideFraction {
}
}

/// Enum for language of choice, e.g. for elements' names.
#[derive(EnumString)]
pub enum Lang {
#[strum(serialize = "Eng", serialize = "eng", serialize = "ENG", serialize = "en", serialize = "EN")]
/// English - default. In `from_str` can be used any of the following: `Eng|eng|ENG|en|EN`
Eng,
#[strum(serialize = "De", serialize = "de", serialize = "DE")]
/// German. In `from_str` can be used any of the following: `De|de|DE`
De,
#[strum(serialize = "Pol", serialize = "pol", serialize = "POL", serialize = "pl", serialize = "PL")]
/// Polish. In `from_str` can be used any of the following: `Pol|pol|POL|pl|PL`
Pol,
}

/// Enum for general chemical element properties
///
/// ```
Expand Down Expand Up @@ -538,6 +553,30 @@ impl Element {
SYMBOL[*self as usize - 1]
}

/// Returns the element name.
pub fn element_name(&self) -> String {
NAME[self.atomic_num() as usize - 1].to_string()
}

/// Returns the element name in a given language. If the language code is not recognized
/// (no data exists for such a translation), the original English name is returned.
pub fn element_name_by_lang(&self, lang: Lang) -> String {
let el_idx = self.atomic_num() as usize - 1;
match lang {
Lang::De => NAME_DE[el_idx].to_string(),
Lang::Pol => NAME_PL[el_idx].to_string(),
_ => NAME[el_idx].to_string()
}
}

/// Uses [`element_name_by_lang`](#method.element_name_by_lang) with prior conversion of the provided
/// string representation of the language into appropriate enum value. In case of unrecognized
/// (erroneous or not supported) language representation, [`Lang::En`](Lang) (English) is used.
/// Should prove useful for Nuclide's "clients" using only string representations of languages.
pub fn element_name_by_lang_str(&self, lang: &str) -> String {
self.element_name_by_lang(Lang::from_str(lang).unwrap_or(Lang::Eng))
}

/// Fraction as measured from samples on Earth. For non-abundant elements,
/// returns only the most stable isotope.
pub fn abundant_nuclides(&self) -> NuclideFraction {
Expand Down
7 changes: 5 additions & 2 deletions Nuclide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#![allow(non_snake_case)]

mod traits;
mod periodicity;
pub(crate) mod nuclidedata;
pub(crate) mod nstruct;
pub mod decay;
Expand All @@ -32,8 +33,10 @@ mod rng;
mod mmodel;
pub(crate) mod constant;
pub(crate) mod element;
pub mod quantum_electron;

pub use crate::traits::{ChemElement,Isotope};
pub use crate::traits::{ChemElement, Isotope};
pub use crate::periodicity::{Periodicity, ElectronConfig, Group, Period};
pub use crate::nstruct::Nuclide;
pub use crate::particle::Particle;
pub use crate::element::{Element,NuclideFraction};
pub use crate::element::{Element,NuclideFraction,Lang};
2 changes: 1 addition & 1 deletion Nuclide/src/nuclidedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pub(crate) mod half_life;
pub(crate) mod index;
pub(crate) mod ionization;
pub(crate) mod spinparity;

pub(crate) mod element_translation;
69 changes: 69 additions & 0 deletions Nuclide/src/nuclidedata/element_translation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#[rustfmt::skip]
pub(crate) const NAME_PL: [&str; 118] = [

"Wodór" , "Hel" , "Lit" , "Beryl" ,
"Bor" , "Węgiel" , "Azot" , "Tlen" ,
"Fluor" , "Neon" , "Sód" , "Magnez" ,
"Glin" , "Krzem" , "Fosfor" , "Siarka" ,
"Chlor" , "Argon" , "Potas" , "Wapń" ,
"Skand" , "Tytan" , "Wanad" , "Chrom" ,
"Mangan" , "Żelazo" , "Kobalt" , "Nikiel" ,
"Miedź" , "Cynk" , "Gal" , "German" ,
"Arsen" , "Selenium" , "Bromine" , "Krypton" ,
"Rubid" , "Stront" , "Itr" , "Cyrkon" ,
"Niob" , "Molibden" , "Technet " , "Ruten" ,
"Rod" , "Pallad" , "Srebro" , "Kadm" ,
"Ind" , "Cyna" , "Antymon" , "Tellur" ,
"Jod" , "Ksenon" , "Cez" , "Bar" ,
"Lantan" , "Cer" , "Prazeodym" , "Neodym" ,
"Promet" , "Samar" , "Europ" , "Gadolin" ,
"Terb" , "Dysproz" , "Holm" , "Erb" ,
"Thul" , "Iterb" , "Lutet" , "Hafn" ,
"Tantal" , "Wolfram" , "Ren" , "Osm " ,
"Iryd" , "Platyna" , "Złoto" , "Rtęć" ,
"Tal" , "Ołów" , "Bizmut" , "Polon" ,
"Astat" , "Radon" , "Frans" , "Rad" ,
"Aktyn" , "Tor" , "Protaktyn" , "Uran" ,
"Neptun" , "Pluton" , "Ameryk" , "Kiur" ,
"Berkel" , "Kaliforn" , "Einstein" , "Ferm" ,
"Mendelew" , "Nobel" , "Lorens" , "Rutherford" ,
"Dubn" , "Seaborg" , "Bohr" , "Has" ,
"Meitner" , "Darmsztadt" , "Roentgen" , "Kopernik" ,
"Nihon" , "Flerow" , "Moscow" , "Liwermor" ,
"Tenes" , "Oganeson" ,
];

#[rustfmt::skip]
pub(crate) const NAME_DE: [&str; 118] = [

"Hydrogen" , "Helium" , "Lithium" , "Beryllium" ,
"Bor" , "Kohlenstoff" , "Stickstoff" , "Sauerstoff" ,
"Fluor" , "Neon" , "Natrium" , "Magnesium" ,
"Aluminium" , "Silicium" , "Phosphor" , "Schwefel" ,
"Chlor" , "Argon" , "Kalium" , "Calcium" ,
"Scandium" , "Titan" , "Vanadium" , "Chrom" ,
"Mangan" , "Eisen" , "Cobalt" , "Nickel" ,
"Kupfer" , "Zink" , "Gallium" , "Germanium" ,
"Arsen" , "Selen" , "Brom" , "Krypton" ,
"Rubidium" , "Strontium" , "Yttrium" , "Zirkonium" ,
"Niob" , "Molybdän" , "Technetium" , "Ruthenium" ,
"Rhodium" , "Palladium" , "Silber" , "Cadmium" ,
"Indium" , "Zinn" , "Antimon" , "Tellur" ,
"Iod" , "Xenon" , "Cesium" , "Barium" ,
"Lanthan" , "Cer" , "Praseodym" , "Neodym" ,
"Promethium" , "Samarium" , "Europium" , "Gadolinium" ,
"Terbium" , "Dysprosium" , "Holmium" , "Erbium" ,
"Thulium" , "Ytterbium" , "Lutetium" , "Hafnium" ,
"Tantal" , "Wolfram" , "Rhenium" , "Osmium" ,
"Iridium" , "Platin" , "Gold" , "Quecksilber" ,
"Thallium" , "Blei" , "Bismut" , "Polonium" ,
"Astat" , "Radon" , "Francium" , "Radium" ,
"Actinium" , "Thorium" , "Protactinium" , "Uran" ,
"Neptunium" , "Plutonium" , "Americium" , "Curium" ,
"Berkelium" , "Californium" , "Einsteinium" , "Fermium" ,
"Mendelevium" , "Nobelium" , "Lawrencium" , "Rutherfordium" ,
"Dubnium" , "Seaborgium" , "Bohrium" , "Hassium" ,
"Meitnerium" , "Darmstadtium" , "Roentgenium" , "Copernicium" ,
"Nihonium" , "Flerovium" , "Moscovium" , "Livermorium" ,
"Tennessine" , "Oganesson"
];
Loading