Skip to content

Commit

Permalink
fix typo of 'radioactive' and minor code refined
Browse files Browse the repository at this point in the history
  • Loading branch information
mhfan committed Nov 18, 2024
1 parent d88d267 commit 666eb2b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 67 deletions.
87 changes: 41 additions & 46 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@
//! module/crate level documentation
// src/lib.rs (default library entry point)

/* https://github.com/lmmentel/mendeleev
/* https://en.wikipedia.org/wiki/Periodic_table
https://www.webelements.com/periodicity/contents/
https://en.wikipedia.org/wiki/Category:Chemical_element_data_pages
https://en.wikipedia.org/wiki/List_of_data_references_for_chemical_elements
https://physics.nist.gov/PhysRefData/ASD/ionEnergy.html
https://pubchem.ncbi.nlm.nih.gov/periodic-table/
https://www.nist.gov/pml/periodic-table-elements
https://ciaaw.org/atomic-weights.htm
https://github.com/lmmentel/mendeleev
https://github.com/baotlake/periodic-table-pro
https://github.com/Bowserinator/Periodic-Table-JSON
https://periodictable.com/Properties/A/HumanAbundance.html
https://commons.wikimedia.org/wiki/File:元素周期表.png
https://commons.wikimedia.org/wiki/File:Periodic_table_large.svg
https://www.futurity.org/periodic-table-new-elements-1087782-2/
https://www.vertex42.com/Files/pdfs/2/periodic-table_color.pdf
https://www.vertex42.com/ExcelTemplates/periodic-table-of-elements.html
https://commons.wikimedia.org/wiki/File:Nucleosynthesis_periodic_table.svg
https://iupac.org/what-we-do/periodic-table-of-elements/, https://svs.gsfc.nasa.gov/13873/
https://commons.wikimedia.org/wiki/File:Periodic_Table_-_Atomic_Properties_of_the_Elements.png
https://commons.wikimedia.org/wiki/File:Periodic_Table_of_the_elements.jpg
https://commons.wikimedia.org/wiki/File:Periodic_table_detailed_enwp.svg
https://elements.wlonk.com/index.htm, https://ptable.com
https://en.wikipedia.org/wiki/Periodic_table */
https://www.futurity.org/periodic-table-new-elements-1087782-2/
https://elements.wlonk.com/index.htm, https://ptable.com */

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)] pub enum ChemElem { // #[non_exhaustive]
Expand Down Expand Up @@ -249,10 +248,10 @@ impl ChemElem {
/// https://en.wikipedia.org/wiki/Periodic_table#Classification_of_elements
pub const fn category(&self) -> ElemClass {
match self.atomic_number() {
1|6|7|8|15|16|34 => ElemClass::OtherNonmetals,
1|6|7|8|15|16|34 => ElemClass::OtherNonmetals, // reactive nonmetals
5|14|32|33|51|52 => ElemClass::Metalloids, // semi-metals
//109..=118 if !matches!(self.atomic_number(), 112|114) => ElemClass::Unknown,
13|31|49|50|81..=84|113..117 => ElemClass::PoorMetals, // post-transition metals
//109..=118 if self.atomic_number() != 112 => ElemClass::Unknown("Unknown"),

// Rare earth metals (Lanthanoids plus Sc and Y)
57..=70 => ElemClass::Lanthanoids, // Lanthanides (include Lu)
Expand All @@ -275,13 +274,19 @@ impl ChemElem {
}

pub const fn block(&self) -> u8 {
match self.group() { 1|2 => b's', 3..=12 => b'd', 13..=18 => b'p', _ => b'f', }
match self.group() { 1|2 => b's', 3..=12 => b'd', 13..18 => b'p',
18 => if self.atomic_number() == 2 { b's' } else { b'p' }, _ => b'f',
}
}

//pub const fn atomic_mass(&self) -> AtomicWeight { self.atomic_weight() }

/// https://ciaaw.org/radioactive-elements.htm
pub const fn is_ratioactive(&self) -> bool { matches!(self.atomic_number(), 43|61|84..=118) }
pub const fn is_radioactive(&self) -> bool { matches!(self.atomic_number(), 43|61|84..=118)
//matches!(self.atomic_weight(), AtomicWeight::MassNumber(_))
}

/// XXX: https://en.wikipedia.org/wiki/Periodic_table_(crystal_structure)
/// TODO: https://en.wikipedia.org/wiki/Periodic_table_(crystal_structure)
// https://github.com/baotlake/periodic-table-pro/blob/37239360e6f5daa605b3fd947895ed2dfdce0cd7/packages/data/json/crystalStructure.json
// https://environmentalchemistry.com/yogi/periodic/crystal.html
// https://periodictable.com/Properties/A/CrystalStructure.html
Expand Down Expand Up @@ -310,17 +315,29 @@ impl ChemElem {
})
}

/// https://en.wikipedia.org/wiki/Term_symbol
/// https://www.nist.gov/pml/periodic-table-elements
/// https://physics.nist.gov/PhysRefData/ASD/ionEnergy.html
pub const fn ground_state(&self) -> Option<(&'static str, &'static str, &'static str)> {
self.ground_level()
}

/* pub const fn term_symbol(&self) -> Option<(&'static str, &'static str, &'static str)> {
self.ground_level()
} */

/// https://en.wikipedia.org/wiki/Electronegativity // XXX: other EN scaling?
/// https://en.wikipedia.org/wiki/Electronegativities_of_the_elements_(data_page)
pub const fn en_pauling(&self) -> Option<f32> { self.electronegativity() }

// TODO: abundance, origin
/// https://svs.gsfc.nasa.gov/13873/
/// https://royalsocietypublishing.org/doi/10.1098/rsta.2019.0301
/// https://commons.wikimedia.org/wiki/File:Nucleosynthesis_periodic_table.svg
pub const fn cosmic_origin(&self) { todo!() }

/// https://en.wikipedia.org/wiki/Abundance_of_the_chemical_elements
/// https://en.wikipedia.org/wiki/Abundances_of_the_elements_(data_page)
pub const fn abundance(&self) { todo!() } // TODO:
}

pub mod ciaaw;
Expand Down Expand Up @@ -460,7 +477,7 @@ impl fmt::Display for Subshell {
write!(f, "{}{}", self.level, self.orbital as char)?;
if 1 < self.ecount {
let mut ecount = self.ecount as usize;
if 9 < ecount { // XXX: max two digits
if 9 < ecount { // max two digits
write!(f, "{}", UNICODE_SUPERS[ecount / 10])?;
ecount %= 10;
} write!(f, "{}", UNICODE_SUPERS[ecount])?;
Expand Down Expand Up @@ -520,6 +537,16 @@ impl From<(u8, u8, u8)> for Subshell {
($l:expr, $t:literal, $n:expr) => { Subshell { level: $l, orbital: $t, ecount: $n, } };
}

#[repr(u8)] #[derive(Debug)] pub enum Cosmological {
BigBangFusion = 0,
CosmicRayFission, // 宇宙射线裂变
DyingLowMassStars,
ExplodingMassiveStars,
ExplodingWhiteDwarfs, // supernovae
MergingNeutronStars,
HumanSynthesis, // No stable isotopes
}

#[repr(u8)] #[derive(Debug)] pub enum ElemClass {
Unknown = 0,
AlkaliMetals,
Expand Down Expand Up @@ -576,6 +603,7 @@ const ELEM_NAME: [&str; ChemElem::MAX as usize] = [ "", // placeholder
"Livermorium", "Tennessine", "Oganesson",
];

/// https://en.wikipedia.org/wiki/Chemical_elements_in_East_Asian_languages
const ELEM_CH: [char; ChemElem::MAX as usize] = [ ' ', // placeholder
'氢', '氦', '锂', '铍', '硼', '碳', '氮', '氧', '氟', '氖',
'钠', '镁', '铝', '硅', '磷', '硫', '氯', '氩', '钾', '钙',
Expand Down Expand Up @@ -607,39 +635,6 @@ const ELEM_PY: [&str; ChemElem::MAX as usize] = [ "", // placeholder
"lún", "gē", "nǐ", "fū", "mò", "lì", "tián", "ào",
];

//#[derive(PartialEq, Clone, Props)] // Owned props must implement `PartialEq`!
/* #[allow(unused)] pub struct ElemProps {
group: u8, // max: 18 (column)
period: u8, // max: 7 (row)
block: u8, // s, f, d, p
// metals (alkali, alkali-earth, lanthanoids, actinoids, transition, poor/other),
// metalloids/semi-metals and nonmetals (other, halogens, noble-gases)
class: u8,
ordinal: u8, // max: 118
mass: f32, // weight
radioactive: bool,
symbol: [u8; 2],
name_ch: char, //pinying: String, // https://github.com/mozillazg/rust-pinyin
name: [u8; 24], //String,
// shell capacity: 4 * n^2, subshell capacity: 4 * (l + 1) - 2
// orbital: s/p/d/f/g/h/i (l: 0 ~ 6)
config_e: [u8; 8], // enengy level
oxidation: [i8; 10], // valence
ionisation: f32, electroneg: f32, e_affinity: f32,
density: f32, ground_s: String, radius: f32, m_v: bool, // metallic/covalent
crystal_s: u8, melting: f32, boiling: f32, phase: u8,
//discoverer: String, year: u16, //origin: u8,
// The Big-Bang, Dying low-mass stars, Exploding massive stars, Cosmic ray fission,
// White dwarf supernovae, Merging neutron stars, Radioactive decay, synthetic/human-made
//abundance: f32, // universe/galaxy, solar, crust, ocean, human body
} */

#[cfg(test)] mod tests { use super::*;
#[test] fn electron() {
fn electron_count(elem: ChemElem) -> u8 {
Expand Down
26 changes: 13 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn App() -> Element {
//let mut group_sel = use_context::<Signal<Selection>>(); // move to ahead of rsx!
div { class: "grid grid-cols-[auto_repeat(18,1fr)_auto] w-[181rem]
grid-rows-[auto_repeat(7,1fr)_auto_1fr_1fr_auto] p-6 gap-0.5 relative",
//style: "transform: scale(0.5); transform-origin: 0 0;",
//style: "zoom: 0.5;", // FIXME: malformed in Safari, which works well scaling on <html>
//style: "transform: scale(0.5); transform-origin: 0 0;", // use js script in index.html
//style: "zoom: 0.5;", // malformed in Safari, which works well scaling on <html>

p { class: "font-bold relative -bottom-4 rotate-180",
style: "writing-mode: vertical-rl;", "PERIOD" }
Expand Down Expand Up @@ -127,7 +127,7 @@ fn App() -> Element {
p { class: "content-center rounded-sm bg-transition",
"Transition Metals" br{} "过渡金属" }
p { class: "content-center rounded-sm bg-non-metal",
"Other nonmetals" br{} "其它非金属" }
"Other nonmetals" br{} "其它非金属" } // 活泼非金属

p { class: "content-center rounded-sm bg-poor-metal", "Poor Metals 贫金属" }
p { class: "content-center rounded-sm bg-metalloid", "Metalloids 类金属" }
Expand All @@ -141,7 +141,7 @@ fn App() -> Element {
}
}
div { class: "absolute flex w-full h-full pb-8", style: "grid-area: 2 / 8 / 3 / 19;",
} // XXX:
} // XXX: show legend for origin/abundance?

for i in 13..=56 { ElemTile { ordinal: i, annote: false } }
div { class: "flex flex-col text-2xl rounded-sm p-1
Expand Down Expand Up @@ -268,7 +268,7 @@ use inperiod::{ChemElem, ElemClass::*, ROMAN_NUM, UNICODE_SUPERS};
//onmouseover: move |evt| evt.stop_propagation(), // XXX: not work for :hover
a { class: "absolute font-bold text-lg/6 text-amber-600",
href: "https://ciaaw.org/radioactive-elements.htm",
style: "top: -1.5rem; right: 1rem;", "ratioactive" }
style: "top: -1.5rem; right: 1rem;", "radioactive" }
div { class: "absolute text-lg leading-tight text-nowrap text-right",
style: "right: calc(100% + 0.4rem);",
p { a { href: "https://ciaaw.org/atomic-weights.htm",
Expand All @@ -277,7 +277,7 @@ use inperiod::{ChemElem, ElemClass::*, ROMAN_NUM, UNICODE_SUPERS};
"1st ionization energy (eV)" }
p { class: "mt-3 mb-5", "symbol" } p { "name" }
p { span { class: "text-blue-700", "melting" } "/"
span { class: "text-red-700", "boiling" } " point (°C)" }
span { class: "text-red-700", "boiling" } " point ()" }
p { "*density" } a {
href: "https://en.wikipedia.org/wiki/Electron_configuration",
"electron configuration" }
Expand All @@ -293,7 +293,7 @@ use inperiod::{ChemElem, ElemClass::*, ROMAN_NUM, UNICODE_SUPERS};
"electronegativity (pauling)*" }
p { a { href: "https://en.wikipedia.org/wiki/Periodic_table_(crystal_structure)", "crystal structure" } }
a { href: "https://www.nist.gov/pml/periodic-table-elements",
"ground-state level" }
"ground-state level" } // "term symbol"
p { span { class: "text-purple-700 font-bold",
a { href: "https://en.wikipedia.org/wiki/Atomic_radius",
"atomic radius" } } " (pm)*" }
Expand All @@ -303,7 +303,7 @@ use inperiod::{ChemElem, ElemClass::*, ROMAN_NUM, UNICODE_SUPERS};
div { class: "flex",
div { class: "grow",
p { class: "flex text-lg/6 font-bold", { elem.atomic_weight().to_string() }
if elem.is_ratioactive() { span { class: "ml-1 text-center grow", "☢️" } }
if elem.is_radioactive() { span { class: "ml-1 text-center grow", "☢️" } }
}
p { class: "flex text-base/5", {
elem.ionization_energy().map_or_else(|| "-".to_string(),
Expand Down Expand Up @@ -368,7 +368,7 @@ use inperiod::{ChemElem, ElemClass::*, ROMAN_NUM, UNICODE_SUPERS};
89..=103|2|10|18|36|54|71|86|118 =>
"right: calc(100% + 0.4rem); bottom: 0px;",
_ => "left: calc(100% + 0.4rem);", }),
//figcaption {} // XXX: title/desc
//figcaption {} // TODO: title/desc
img { class: "w-full", src: format!("crystal-s/{file}"), }
} }
) }
Expand Down Expand Up @@ -521,9 +521,6 @@ use inperiod::{ChemElem, ElemClass::*, ROMAN_NUM, UNICODE_SUPERS};
} }
}

#[component] fn ElemDetail() -> Element { rsx! { // TODO: https://pt.ziziyi.com/
} }

/// https://physics.nist.gov/cuu/Constants/index.html
#[component] fn PhysConsts() -> Element { rsx! {
p { class: "flex text-lg/6 justify-between px-1",
Expand Down Expand Up @@ -600,11 +597,14 @@ use inperiod::{ChemElem, ElemClass::*, ROMAN_NUM, UNICODE_SUPERS};
p { "speed of light in vacuum" } span { class: "text-xl leading-none", "𝑐" }
p { "299 792 458 m/s" }

p { class: "col-span-3", "STP: 𝑇 = 273.15 K, 𝑝 = 101.325 kPa" }
p { class: "col-span-3", "STP: 𝑇 = 273.15 K (0 ℃), 𝑝 = 101.325 kPa" }
}
}
} }

#[component] fn ElemDetail() -> Element { rsx! { // TODO: https://pt.ziziyi.com/
} }

/* for fullstack web renderer
#[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
enum Route {
Expand Down
18 changes: 10 additions & 8 deletions src/syncd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reqwest::blocking::get as reqwest_get; // TODO: reqwest::get(url).await?.te
use scraper::{Html, Selector};

fn main() -> Result<(), Box<dyn Error>> { // cargo r --bin syncd -F syncdep
//parse_electronegativity()?; // use data from pubchem
//parse_electronegativity()?; // use the data from pubchem instead
parse_nist_asd()?;
parse_oxstates()?;
parse_pubchem()?;
Expand Down Expand Up @@ -128,7 +128,7 @@ fn parse_nist_asd() -> Result<(), Box<dyn Error>> {
let mut reader = csv::ReaderBuilder::new()
.flexible(true).from_reader(content.as_bytes());
for result in reader.records() {
let record = result?; // XXX: extract and store data of all levels?
let record = result?; // TODO: extract and store data of all levels?
if record.get(1).is_none_or(|x| !x.ends_with(" I\"")) { continue }

let fields = record.iter().map(|x|
Expand All @@ -149,6 +149,8 @@ fn parse_nist_asd() -> Result<(), Box<dyn Error>> {
&state[..1], s1.replace('*', "°"), if s1.len() == 1 { " " } else { "" }))?;
} else { eprintln!("{an}: {state:?} ?") } // 106 ~ 108
}

// XXX: show predication for 106~118? https://en.wikipedia.org/wiki/Term_symbol
//fil2.write_all(b" 106 => (\"5\", \"D\" , \"0\"),\n")?;
//fil2.write_all(b" 107 => (\"6\", \"S\" , \"5/2\"),\n")?;
//fil2.write_all(b" 108 => (\"5\", \"D\" , \"4\"),\n")?;
Expand All @@ -158,7 +160,7 @@ fn parse_nist_asd() -> Result<(), Box<dyn Error>> {
fil2.flush(); file.flush()?; Ok(())
}

/// https://ciaaw.org/atomic-weights.htm
/// XXX: https://ciaaw.org/atomic-weights.htm
fn parse_ciaaw() -> Result<(), Box<dyn Error>> {
let tr_selector = Selector::parse("tr")?;
let td_selector = Selector::parse("td")?;
Expand Down Expand Up @@ -210,15 +212,15 @@ fn parse_ciaaw() -> Result<(), Box<dyn Error>> {

if let Some(table) = document.select(&Selector::parse("table")?).next() {
for row in table.select(&tr_selector) {
let cells: Vec<_> = row.select(&td_selector).collect();
let cells = row.select(&td_selector).collect::<Vec<_>>();
if cells.len() < 4 { continue }

let an = cells[0].text().next().unwrap_or("").trim().parse::<usize>()?;
let atomic_weight = cells[3].text().next().unwrap_or("").trim();
let atomic_weight = cells[3].text().next().unwrap_or("").trim();
if let Some((value, uncerntainty)) = atomic_weight.split_once('±') {
file.write_fmt(format_args!(" Abridged {{ value: {:6}, uncertainty: {} }},\n",
value.trim_end(), uncerntainty.trim_start()))?;
} else {
let an: usize = cells[0].text().next().unwrap_or("").trim().parse()?;
file.write_fmt(format_args!(" MassNumber({}),\n", am_all[an].trim()))?;
}
}
Expand Down Expand Up @@ -288,8 +290,8 @@ fn parse_pubchem() -> Result<(), Box<dyn Error>> {
file.write_all(b" _ => return None\n })\n }\n\n")?; Ok(())
};

extract_data("AtomicRadius")?; // u16?
//extract_data("IonizationEnergy")?;
extract_data("AtomicRadius")?; // u16?
//extract_data("IonizationEnergy")?; // use NIST/ASD instead
extract_data("ElectronAffinity")?;
extract_data("Electronegativity")?;
extract_data("MeltingPoint")?;
Expand Down

0 comments on commit 666eb2b

Please sign in to comment.