Skip to content

Commit

Permalink
add tests and IPs for all elements in NIST database
Browse files Browse the repository at this point in the history
- previous list was incomplete
- remove iniabu from requirements
  • Loading branch information
trappitsch committed Feb 29, 2024
1 parent 9656ab1 commit 7c8303a
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 10 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dev-dependencies = [
"hypothesis>=6.97.1",
"pytest-cov>=4.1.0",
"requests>=2.31.0",
"iniabu>=1.1.2",
]

[tool.rye.scripts]
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fonttools==4.49.0
hypothesis==6.98.13
idna==3.6
# via requests
iniabu==1.1.2
iniconfig==2.0.0
# via pytest
kiwisolver==1.4.5
Expand All @@ -34,7 +33,6 @@ matplotlib==3.8.3
# via rimsschemedrawer
numpy==1.26.4
# via contourpy
# via iniabu
# via matplotlib
# via rimsschemedrawer
packaging==23.2
Expand Down
37 changes: 36 additions & 1 deletion scripts/ip_nist.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Zr": 53507.832,
"Nb": 54513.8,
"Mo": 57204.3,
"Tc": 57421.68,
"Ru": 59366.4,
"Rh": 60160.1,
"Pd": 67241.14,
Expand All @@ -58,6 +59,7 @@
"Ce": 44672.0,
"Pr": 44120.0,
"Nd": 44562.0,
"Pm": 45020.8,
"Sm": 45519.69,
"Eu": 45734.74,
"Gd": 49601.45,
Expand All @@ -80,6 +82,39 @@
"Tl": 49266.66,
"Pb": 59819.558,
"Bi": 58761.65,
"Po": 67896.31,
"At": 75150.8,
"Rn": 86692.5,
"Fr": 32848.872,
"Ra": 42573.36,
"Ac": 43394.52,
"Th": 50867.0,
"U": 49958.4
"Pa": 47500.0,
"U": 49958.4,
"Np": 50535.0,
"Pu": 48601.0,
"Am": 48182.0,
"Cm": 48330.68,
"Bk": 49989.0,
"Cf": 50666.76,
"Es": 51364.58,
"Fm": 52400.0,
"Md": 53100.0,
"No": 53444.0,
"Lr": 40005.0,
"Rf": 48580.0,
"Db": 55000.0,
"Sg": 63000.0,
"Bh": 62000.0,
"Hs": 61000.0,
"Mt": null,
"Ds": null,
"Rg": null,
"Cn": null,
"Nh": null,
"Fl": null,
"Mc": null,
"Lv": null,
"Ts": null,
"Og": null
}
157 changes: 151 additions & 6 deletions scripts/ip_nist_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
"""Create json file with all ionization potentials.
Elemental data read from the NIST database, which can be found here:
https://physics.nist.gov/PhysRefData/ASD/levels_form.html
2024-02-29: Currently, the following elements have no IP data associated with them:
- Mt
- Ds
- Rg
- Cn
- Nh
- Fl
- Mc
- Lv
- Ts
- Og
"""


import json

from iniabu import ini
import requests


Expand Down Expand Up @@ -31,11 +49,20 @@ def get_ip(ele: str) -> float:
data = data.split("\n")

# find limit line in data
limit_found = False
for it, line in enumerate(data):
if "Limit" in line:
idx = it
limit_found = True
break

if not limit_found:
try:
return manual_ips[ele]
except KeyError:
print(f"Could not find limit for {ele}")
return None

line = data[idx].replace('"', "").replace("=", "").split(",")
# print(line)
ip = line[4]
Expand All @@ -44,12 +71,130 @@ def get_ip(ele: str) -> float:
return float(ip)


elements = ini.ele_dict.keys() # list of all elements
ele_ips = {}

# print(elements)
manual_ips = {}

elements = [
"H",
"He",
"Li",
"Be",
"B",
"C",
"N",
"O",
"F",
"Ne",
"Na",
"Mg",
"Al",
"Si",
"P",
"S",
"Cl",
"Ar",
"K",
"Ca",
"Sc",
"Ti",
"V",
"Cr",
"Mn",
"Fe",
"Co",
"Ni",
"Cu",
"Zn",
"Ga",
"Ge",
"As",
"Se",
"Br",
"Kr",
"Rb",
"Sr",
"Y",
"Zr",
"Nb",
"Mo",
"Tc",
"Ru",
"Rh",
"Pd",
"Ag",
"Cd",
"In",
"Sn",
"Sb",
"Te",
"I",
"Xe",
"Cs",
"Ba",
"La",
"Ce",
"Pr",
"Nd",
"Pm",
"Sm",
"Eu",
"Gd",
"Tb",
"Dy",
"Ho",
"Er",
"Tm",
"Yb",
"Lu",
"Hf",
"Ta",
"W",
"Re",
"Os",
"Ir",
"Pt",
"Au",
"Hg",
"Tl",
"Pb",
"Bi",
"Po",
"At",
"Rn",
"Fr",
"Ra",
"Ac",
"Th",
"Pa",
"U",
"Np",
"Pu",
"Am",
"Cm",
"Bk",
"Cf",
"Es",
"Fm",
"Md",
"No",
"Lr",
"Rf",
"Db",
"Sg",
"Bh",
"Hs",
"Mt",
"Ds",
"Rg",
"Cn",
"Nh",
"Fl",
"Mc",
"Lv",
"Ts",
"Og",
]

# print(get_ip("Tb"))
ele_ips = {}

for ele in elements:
print(f"{ele} is up")
Expand Down
25 changes: 25 additions & 0 deletions src/rimsschemedrawer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"Zr": 53507.832,
"Nb": 54513.8,
"Mo": 57204.3,
"Tc": 57421.68,
"Ru": 59366.4,
"Rh": 60160.1,
"Pd": 67241.14,
Expand All @@ -93,6 +94,7 @@
"Ce": 44672.0,
"Pr": 44120.0,
"Nd": 44562.0,
"Pm": 45020.8,
"Sm": 45519.69,
"Eu": 45734.74,
"Gd": 49601.45,
Expand All @@ -115,8 +117,31 @@
"Tl": 49266.66,
"Pb": 59819.558,
"Bi": 58761.65,
"Po": 67896.31,
"At": 75150.8,
"Rn": 86692.5,
"Fr": 32848.872,
"Ra": 42573.36,
"Ac": 43394.52,
"Th": 50867.0,
"Pa": 47500.0,
"U": 49958.4,
"Np": 50535.0,
"Pu": 48601.0,
"Am": 48182.0,
"Cm": 48330.68,
"Bk": 49989.0,
"Cf": 50666.76,
"Es": 51364.58,
"Fm": 52400.0,
"Md": 53100.0,
"No": 53444.0,
"Lr": 40005.0,
"Rf": 48580.0,
"Db": 55000.0,
"Sg": 63000.0,
"Bh": 62000.0,
"Hs": 61000.0,
}


Expand Down
40 changes: 40 additions & 0 deletions tests/data/ti_old_style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"scheme": {
"gs_level": "0",
"gs_term": "3F2",
"ip_level": "55070",
"ip_term": "",
"step_level0": "170.15",
"step_level1": "386.88",
"step_level2": "21469.5",
"step_level3": "45498.85",
"step_level4": "56844.45",
"step_lowlying0": true,
"step_lowlying1": true,
"step_lowlying2": false,
"step_lowlying3": false,
"step_lowlying4": false,
"step_term0": "3F3",
"step_term1": "3F4",
"step_term2": "3G3",
"step_term3": "3G4",
"step_term4": "",
"unit": "cm<sup>-1</sup>"
},
"settings": {
"arrow_head_width": "0.6",
"arrow_width": "0.2",
"fig_height": "8",
"fig_width": "5",
"fs_axes": "12",
"fs_axes_labels": "14",
"fs_labels": "12",
"fs_title": "14",
"headspace": "2700",
"ip_label_pos": "Top",
"line_breaks": false,
"plot_title": "",
"prec_level": "0",
"prec_wavelength": "3"
}
}
11 changes: 11 additions & 0 deletions tests/test_plotter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Test the plotter
import pytest

import rimsschemedrawer.json_parser
from rimsschemedrawer.plotter import Plotter

Expand All @@ -13,3 +15,12 @@ def test_plotter(data_path, tmp_path):
fig.savefig(fname)

assert fname.exists()


def test_plotter_old_style(data_path):
"""Raise warning when old style file is detected."""
fin = data_path.joinpath("ti_old_style.json")
data = rimsschemedrawer.json_parser.json_reader(fin)

with pytest.warns(UserWarning, match="Ti"):
_ = Plotter(data)
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ def test_cm_2_to_nm():
assert ut.cm_2_to_nm(3.3333333333333335e6) == 3


def test_get_elements():
"""Check that elements are in list."""
eles = ut.get_elements()
assert "H" in eles
assert "He" in eles
assert "U" in eles
assert "Pu" in eles


def test_get_ip():
"""Check that the ionization potentials are correct."""
assert ut.get_ip("H") == 109678.77174307
Expand Down

0 comments on commit 7c8303a

Please sign in to comment.