11#!/usr/bin/env python3
2+ import typing as t
23from collections import defaultdict
34from collections import namedtuple
45from pathlib import Path
1920h_in_ev_seconds = 4.135667696923859e-15
2021lchars = "SPDFGHIKLMNOPQRSTUVWXYZ"
2122
22- qub_energy_level_row = namedtuple (
23- "qub_energy_level_row" , "levelname qub_id twosplusone l j energyabovegsinpercm g parity"
24- )
23+
24+ class QUBEnergyLevel (t .NamedTuple ):
25+ levelname : str
26+ qub_id : int
27+ twosplusone : int
28+ l : int
29+ j : float
30+ energyabovegsinpercm : float
31+ g : float
32+ parity : int
33+
2534
2635qubpath = (Path (__file__ ).parent .resolve () / ".." / "atomic-data-qub" ).resolve ()
2736
@@ -34,10 +43,12 @@ def extend_ion_list(ion_handlers):
3443 return ion_handlers
3544
3645
37- def read_adf04 (filepath , atomic_number , ion_stage , flog ):
46+ def read_adf04 (
47+ filepath : str | Path , atomic_number : int , ion_stage : int , flog
48+ ) -> tuple [float , list [QUBEnergyLevel | None ], dict [tuple [int , int ], float ]]:
3849 if not Path (filepath ).is_file () and Path (f"{ filepath } .gz" ).is_file ():
3950 filepath = f"{ filepath } .gz"
40- energylevels = [None ]
51+ energylevels : list [ QUBEnergyLevel | None ] = [None ]
4152 upsilondict = {}
4253 ionization_energy_ev = 0.0
4354 artisatomic .log_and_print (flog , f"Reading { filepath } " )
@@ -61,7 +72,7 @@ def read_adf04(filepath, atomic_number, ion_stage, flog):
6172
6273 if atomic_number == 27 :
6374 config = line [5 :21 ].strip ()
64- energylevel = qub_energy_level_row (
75+ energylevel = QUBEnergyLevel (
6576 config ,
6677 int (line [:5 ]),
6778 int (line [25 :26 ]),
@@ -79,7 +90,7 @@ def read_adf04(filepath, atomic_number, ion_stage, flog):
7990 config_parts = config_full .split (")" )
8091 relevant_config = config_parts [- 2 ].strip () + ")" if len (config_parts ) > 1 else config_full
8192 config = relevant_config
82- energylevel = qub_energy_level_row (
93+ energylevel = QUBEnergyLevel (
8394 config ,
8495 int (line [:5 ]),
8596 int (line [29 :30 ]),
@@ -112,7 +123,7 @@ def read_adf04(filepath, atomic_number, ion_stage, flog):
112123 sep = r"\s+" ,
113124 comment = "C" ,
114125 names = list_headers ,
115- dtype = {"lower" : int , "upper" : int }. update ( dict .fromkeys (list_headers [2 :], float ) ),
126+ dtype = {"lower" : int , "upper" : int } | dict .fromkeys (list_headers [2 :], float ),
116127 on_bad_lines = "skip" ,
117128 skip_blank_lines = True ,
118129 keep_default_na = False ,
@@ -219,11 +230,11 @@ def read_qub_levels_and_transitions(atomic_number, ion_stage, flog):
219230
220231 elif (atomic_number == 27 ) and (ion_stage == 4 ):
221232 transition_count_of_level_name = defaultdict (int )
222- qub_energylevels = [None ]
233+ qub_energylevels : list [ QUBEnergyLevel | None ] = [None ]
223234 qub_transitions = pl .DataFrame (schema = {"lowerlevel" : pl .Int64 , "upperlevel" : pl .Int64 , "A" : pl .Float64 })
224235 upsilondict = {}
225236 ionization_energy_ev = 54.9000015
226- qub_energylevels .append (qub_energy_level_row ("groundstate" , 1 , 0 , 0 , 0 , 0.0 , 10 , 0 ))
237+ qub_energylevels .append (QUBEnergyLevel ("groundstate" , 1 , 0 , 0 , 0 , 0.0 , 10 , 0 ))
227238
228239 elif (atomic_number , ion_stage ) in new_qub_calculations :
229240 atom_file = f"{ atomic_number } _{ ion_stage } .adf04"
0 commit comments