21
21
22
22
23
23
def test_yaml ():
24
- with open ("periodic_table.yaml" ) as file :
25
- data = yaml .load (file )
26
- print (data )
24
+ loadfn ("periodic_table.yaml" )
27
25
28
26
29
27
def test_json ():
30
- with open ("periodic_table.json" ) as file :
28
+ with open ("../pymatgen/core/ periodic_table.json" ) as file :
31
29
data = json .load (file )
32
30
print (data )
33
31
34
32
35
33
def parse_oxi_state ():
36
- with open ("periodic_table.yaml" ) as file :
37
- data = yaml .load (file )
34
+ data = loadfn ("periodic_table.yaml" )
38
35
with open ("oxidation_states.txt" ) as file :
39
36
oxi_data = file .read ()
40
37
oxi_data = re .sub ("[\n \r ]" , "" , oxi_data )
@@ -72,8 +69,7 @@ def parse_oxi_state():
72
69
73
70
74
71
def parse_ionic_radii ():
75
- with open ("periodic_table.yaml" ) as f :
76
- data = yaml .load (f )
72
+ data = loadfn ("periodic_table.yaml" )
77
73
with open ("ionic_radii.csv" ) as f :
78
74
radii_data = f .read ()
79
75
radii_data = radii_data .split ("\r " )
@@ -104,8 +100,7 @@ def parse_ionic_radii():
104
100
105
101
106
102
def parse_radii ():
107
- with open ("periodic_table.yaml" ) as f :
108
- data = yaml .load (f )
103
+ data = loadfn ("periodic_table.yaml" )
109
104
with open ("radii.csv" ) as f :
110
105
radii_data = f .read ()
111
106
radii_data = radii_data .split ("\r " )
@@ -136,13 +131,12 @@ def parse_radii():
136
131
print (el )
137
132
with open ("periodic_table2.yaml" , "w" ) as f :
138
133
yaml .dump (data , f )
139
- with open ("periodic_table.json" , "w" ) as f :
134
+ with open ("../pymatgen/core/ periodic_table.json" , "w" ) as f :
140
135
json .dump (data , f )
141
136
142
137
143
138
def update_ionic_radii ():
144
- with open ("periodic_table.yaml" ) as f :
145
- data = yaml .load (f )
139
+ data = loadfn ("periodic_table.yaml" )
146
140
147
141
for d in data .values ():
148
142
if "Ionic_radii" in d :
@@ -156,13 +150,12 @@ def update_ionic_radii():
156
150
del d ["Ionic_radii_ls" ]
157
151
with open ("periodic_table2.yaml" , "w" ) as f :
158
152
yaml .dump (data , f )
159
- with open ("periodic_table.json" , "w" ) as f :
153
+ with open ("../pymatgen/core/ periodic_table.json" , "w" ) as f :
160
154
json .dump (data , f )
161
155
162
156
163
157
def parse_shannon_radii ():
164
- with open ("periodic_table.yaml" ) as f :
165
- data = yaml .load (f )
158
+ data = loadfn ("periodic_table.yaml" )
166
159
167
160
from openpyxl import load_workbook
168
161
@@ -194,22 +187,20 @@ def parse_shannon_radii():
194
187
if el in data :
195
188
data [el ]["Shannon radii" ] = dict (radii [el ])
196
189
197
- with open ("periodic_table.yaml" , "w" ) as f :
198
- yaml .safe_dump (data , f )
199
- with open ("periodic_table.json" , "w" ) as f :
190
+ dumpfn (data , "periodic_table.yaml" )
191
+ with open ("../pymatgen/core/periodic_table.json" , "w" ) as f :
200
192
json .dump (data , f )
201
193
202
194
203
195
def gen_periodic_table ():
204
- with open ("periodic_table.yaml" ) as f :
205
- data = yaml .load (f )
196
+ data = loadfn ("periodic_table.yaml" )
206
197
207
- with open ("periodic_table.json" , "w" ) as f :
198
+ with open ("../pymatgen/core/ periodic_table.json" , "w" ) as f :
208
199
json .dump (data , f )
209
200
210
201
211
202
def gen_iupac_ordering ():
212
- periodic_table = loadfn ("periodic_table.json" )
203
+ periodic_table = loadfn ("../pymatgen/core/ periodic_table.json" )
213
204
order = [
214
205
([18 ], range (6 , 0 , - 1 )), # noble gasses
215
206
([1 ], range (7 , 1 , - 1 )), # alkali metals
@@ -265,12 +256,24 @@ def add_electron_affinities():
265
256
row .append (td .get_text ().strip ())
266
257
data .append (row )
267
258
data .pop (0 )
268
- ea = {int (r [0 ]): float (re .sub (r"[\s\(\)]" , "" , r [3 ].strip ("()[]" ))) for r in data }
269
- assert set (ea ).issuperset (range (1 , 93 )) # Ensure that we have data for up to U.
259
+
260
+ ea = {}
261
+ max_Z = max (Element (element ).Z for element in Element .__members__ )
262
+ for r in data :
263
+ # don't want superheavy elements or less common isotopes
264
+ if int (r [0 ]) > max_Z or r [2 ] in ea :
265
+ continue
266
+ tempstr = re .sub (r"[\s\(\)]" , "" , r [3 ].strip ("()[]" ))
267
+ # hyphen-like characters used that can't be parsed by .float
268
+ bytesrep = tempstr .encode ("unicode_escape" ).replace (b"\\ u2212" , b"-" )
269
+ ea [r [2 ]] = float (bytesrep .decode ("unicode_escape" ))
270
+
271
+ Z_set = {Element .from_name (element ).Z for element in ea }
272
+ assert Z_set .issuperset (range (1 , 93 )) # Ensure that we have data for up to U.
270
273
print (ea )
271
274
pt = loadfn ("../pymatgen/core/periodic_table.json" )
272
275
for k , v in pt .items ():
273
- v ["Electron affinity" ] = ea .get (Element (k ).Z )
276
+ v ["Electron affinity" ] = ea .get (Element (k ).long_name )
274
277
dumpfn (pt , "../pymatgen/core/periodic_table.json" )
275
278
276
279
@@ -296,12 +299,12 @@ def add_ionization_energies():
296
299
pt = loadfn ("../pymatgen/core/periodic_table.json" )
297
300
for k , v in pt .items ():
298
301
del v ["Ionization energy" ]
299
- v ["Ionization energies" ] = data .get (Element (k ).Z , [])
302
+ v ["Ionization energies" ] = data .get (Element (k ).long_name , [])
300
303
dumpfn (pt , "../pymatgen/core/periodic_table.json" )
301
304
302
305
303
306
if __name__ == "__main__" :
304
- # parse_shannon_radii()
307
+ parse_shannon_radii ()
305
308
# add_ionization_energies()
306
309
add_electron_affinities ()
307
310
# gen_periodic_table()
0 commit comments