35
35
36
36
# Load element data (periodic table) from JSON file
37
37
with open (Path (__file__ ).absolute ().parent / "periodic_table.json" , encoding = "utf-8" ) as ptable_json :
38
- _pt_data : dict = json .load (ptable_json )
38
+ _PT_DATA : dict = json .load (ptable_json )
39
39
40
- _pt_row_sizes : tuple [int , ...] = (2 , 8 , 8 , 18 , 18 , 32 , 32 )
40
+ _PT_ROW_SIZES : tuple [int , ...] = (2 , 8 , 8 , 18 , 18 , 32 , 32 )
41
41
42
- _madelung : list [tuple [int , str ]] = [
42
+ # Madelung energy ordering rule (lower to higher energy)
43
+ _MADELUNG : list [tuple [int , str ]] = [
43
44
(1 , "s" ),
44
45
(2 , "s" ),
45
46
(2 , "p" ),
@@ -137,21 +138,21 @@ def __init__(self, symbol: SpeciesLike) -> None:
137
138
Solid State Communications, 1984.
138
139
"""
139
140
self .symbol = str (symbol )
140
- data = _pt_data [symbol ]
141
+ data = _PT_DATA [symbol ]
141
142
142
143
# Store key variables for quick access
143
144
self .Z = data ["Atomic no" ]
144
145
145
146
self ._is_named_isotope = data .get ("Is named isotope" , False )
146
147
if self ._is_named_isotope :
147
- for sym , info in _pt_data .items ():
148
+ for sym , info in _PT_DATA .items ():
148
149
if info ["Atomic no" ] == self .Z and not info .get ("Is named isotope" , False ):
149
150
self .symbol = sym
150
151
break
151
152
# For specified/named isotopes, treat the same as named element
152
153
# (the most common isotope). Then we pad the data block with the
153
154
# entries for the named element.
154
- data = {** _pt_data [self .symbol ], ** data }
155
+ data = {** _PT_DATA [self .symbol ], ** data }
155
156
156
157
at_r = data .get ("Atomic radius" , "no data" )
157
158
if str (at_r ).startswith ("no data" ):
@@ -493,7 +494,7 @@ def parse_orbital(orb_str: str) -> str | tuple[int, str, int]:
493
494
data = list (Element (sym ).full_electronic_structure ) + data [1 :]
494
495
495
496
# Sort the final electronic structure by increasing energy level
496
- return sorted (data , key = lambda x : _madelung .index ((x [0 ], x [1 ])))
497
+ return sorted (data , key = lambda x : _MADELUNG .index ((x [0 ], x [1 ])))
497
498
498
499
@property
499
500
def n_electrons (self ) -> int :
@@ -610,7 +611,7 @@ def from_Z(Z: int, A: int | None = None) -> Element:
610
611
Returns:
611
612
Element with atomic number Z.
612
613
"""
613
- for sym , data in _pt_data .items ():
614
+ for sym , data in _PT_DATA .items ():
614
615
atomic_mass_num = data .get ("Atomic mass no" ) if A else None
615
616
if data ["Atomic no" ] == Z and atomic_mass_num == A :
616
617
return Element (sym )
@@ -631,7 +632,7 @@ def from_name(name: str) -> Element:
631
632
uk_to_us = {"aluminium" : "aluminum" , "caesium" : "cesium" }
632
633
name = uk_to_us .get (name .lower (), name )
633
634
634
- for sym , data in _pt_data .items ():
635
+ for sym , data in _PT_DATA .items ():
635
636
if data ["Name" ] == name .capitalize ():
636
637
return Element (sym )
637
638
@@ -658,7 +659,7 @@ def from_row_and_group(row: int, group: int) -> Element:
658
659
Note:
659
660
The 18 group number system is used, i.e. noble gases are group 18.
660
661
"""
661
- for sym in _pt_data :
662
+ for sym in _PT_DATA :
662
663
el = Element (sym )
663
664
if 57 <= el .Z <= 71 :
664
665
el_pseudo_row = 8
@@ -698,7 +699,7 @@ def row(self) -> int:
698
699
return 6
699
700
if 89 <= z <= 103 :
700
701
return 7
701
- for idx , size in enumerate (_pt_row_sizes , start = 1 ):
702
+ for idx , size in enumerate (_PT_ROW_SIZES , start = 1 ):
702
703
total += size
703
704
if total >= z :
704
705
return idx
@@ -1202,7 +1203,7 @@ def parse_orbital(orb_str):
1202
1203
sym = data [0 ].replace ("[" , "" ).replace ("]" , "" )
1203
1204
data = list (Element (sym ).full_electronic_structure ) + data [1 :]
1204
1205
# sort the final electronic structure by increasing energy level
1205
- return sorted (data , key = lambda x : _madelung .index ((x [0 ], x [1 ])))
1206
+ return sorted (data , key = lambda x : _MADELUNG .index ((x [0 ], x [1 ])))
1206
1207
1207
1208
# NOTE - copied exactly from Element. Refactoring / inheritance may improve
1208
1209
# robustness
0 commit comments