1818from sympy .parsing .sympy_parser import parse_expr
1919from burnman .constants import gas_constant
2020from datetime import date
21+ import importlib
22+ import re
23+ import subprocess
24+ from pathlib import Path
2125
2226ds = [
2327 ["tc-thermoinput-igneous-2022-01-23/tc-ig50NCKFMASHTOCr.txt" , "HGP_2018_ds633" ],
@@ -119,9 +123,29 @@ def ordering_modifier(property_modifier, ordered):
119123 return np .array ([E_disord , S_disord , V_disord ])
120124
121125
126+ digit_map = {
127+ "0" : "zero" ,
128+ "1" : "one" ,
129+ "2" : "two" ,
130+ "3" : "three" ,
131+ "4" : "four" ,
132+ "5" : "five" ,
133+ "6" : "six" ,
134+ "7" : "seven" ,
135+ "8" : "eight" ,
136+ "9" : "nine" ,
137+ }
138+
139+
140+ def replace_numbers (match ):
141+ num_str = match .group ()
142+ return "" .join (digit_map [d ] for d in num_str )
143+
144+
122145for solution_file , mbr_dataset in ds :
123146 logging .debug (f"{ solution_file } , { mbr_dataset } " )
124- dataset = eval (mbr_dataset )
147+
148+ dataset = importlib .import_module (f"burnman.minerals.{ mbr_dataset } " )
125149 out_ss = ""
126150 out_make = ""
127151
@@ -332,6 +356,7 @@ def ordering_modifier(property_modifier, ordered):
332356 # rename for insertion into string
333357 if site_sp [0 ] == "x" :
334358 site_sp = site_sp [1 :]
359+ site_sp = re .sub (r"\d+(\.\d+)?" , replace_numbers , site_sp )
335360 site_sp = "" .join (filter (str .isalpha , site_sp )).title ()
336361
337362 ss [i_site ].append (site_sp )
@@ -405,8 +430,9 @@ def ordering_modifier(property_modifier, ordered):
405430 f"dataset { mbr_dataset } .\n "
406431 "The values in this document are all in S.I. units,\n "
407432 "unlike those in the original THERMOCALC file.\n "
408- "This file is autogenerated using process_HPX_eos .py\n "
433+ "This file is autogenerated using hpx_eos_to_burnman .py\n "
409434 '"""\n \n '
435+ f"import numpy as np\n "
410436 f"from numpy import array, nan\n "
411437 f"from . import { mbr_dataset } \n "
412438 "from ..classes.mineral import Mineral\n "
@@ -424,4 +450,7 @@ def ordering_modifier(property_modifier, ordered):
424450 print (f"from . import { solution_dataset } " )
425451 text_file .write (output_string )
426452
427- print ("Copy the above to ../../minerals/__init__.py:" )
453+ print ("Copy the above to ../../minerals/__init__.py.\n " )
454+
455+ directory = Path ("../../minerals/" )
456+ subprocess .run (["black" , str (directory )])
0 commit comments