Skip to content

Commit c3ed3a3

Browse files
committed
fix site solution model names
1 parent ed383fb commit c3ed3a3

File tree

7 files changed

+1146
-511
lines changed

7 files changed

+1146
-511
lines changed

burnman/data/input_raw_endmember_datasets/hpx_eos_to_burnman.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
from sympy.parsing.sympy_parser import parse_expr
1919
from burnman.constants import gas_constant
2020
from datetime import date
21+
import importlib
22+
import re
23+
import subprocess
24+
from pathlib import Path
2125

2226
ds = [
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+
122145
for 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

Comments
 (0)