-
Notifications
You must be signed in to change notification settings - Fork 41
/
table_mineral_library.py
105 lines (86 loc) · 4.81 KB
/
table_mineral_library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This file is part of BurnMan - a thermoelastic and thermodynamic toolkit for the Earth and Planetary Sciences
# Copyright (C) 2012 - 2015 by the BurnMan team, released under the GNU
# GPL v2 or later.
"""
Generates a text table with mineral properties.
Run 'python table.py latex' to write a tex version of the table to mytable.tex
"""
from __future__ import absolute_import
from __future__ import print_function
import sys
import burnman_path # adds the local burnman directory to the path
import burnman
import inspect
from burnman import minerals
from burnman import tools
assert burnman_path # silence pyflakes warning
if __name__ == "__main__":
def create_list(name, mineral):
ownname = mineral.to_string().replace(
"'", "").replace("burnman.minerals.", "")
if name != ownname:
name = name + " (" + ownname + ")"
row = [name]
for param in params:
row.append(str(p.params[param] if param in p.params else ""))
return row
# Create a dictionary of the equation of state parameters to insert into the table
# Equations of state not included in this dictionary will be ignored
eos_params = {'hp_tmt': ['V_0', 'K_0', 'Kprime_0', 'Kdprime_0', 'molar_mass', 'n', 'Cp'],
'slb2': ['V_0', 'K_0', 'Kprime_0', 'G_0', 'Gprime_0',
'molar_mass', 'n', 'Debye_0', 'grueneisen_0', 'q_0', 'eta_s_0'],
'slb3': ['V_0', 'K_0', 'Kprime_0', 'G_0', 'Gprime_0',
'molar_mass', 'n', 'Debye_0', 'grueneisen_0', 'q_0', 'eta_s_0'],
'mgd2': ['V_0', 'K_0', 'Kprime_0', 'G_0', 'Gprime_0',
'molar_mass', 'n', 'Debye_0', 'grueneisen_0', 'q_0', 'eta_s_0'],
'mgd3': ['V_0', 'K_0', 'Kprime_0', 'G_0', 'Gprime_0',
'molar_mass', 'n', 'Debye_0', 'grueneisen_0', 'q_0', 'eta_s_0'],
'cork': ['cork_params', 'cork_T', 'cork_P', 'Cp'],
'dks_s': ['V_0', 'T_0', 'E_0', 'S_0', 'K_0',
'Kprime_0', 'Kdprime_0', 'n', 'Cv', 'grueneisen_0', 'q_0'],
'dks_l': ['V_0', 'T_0', 'O_theta', 'O_f', 'm', 'zeta_0', 'xi', 'Tel_0', 'eta'],
'aa': ['T_0', 'S_0', 'V_0', 'K_S', 'Kprime_S', 'Kprime_prime_S', 'grueneisen_0', 'grueneisen_prime', 'grueneisen_n']}
libs = dir(minerals)
for l in libs:
names = set()
phasenames = []
mineralgroup = getattr(minerals, l)
if mineralgroup.__class__.__name__ == "module":
for m in dir(mineralgroup):
mineral = getattr(mineralgroup, m)
if inspect.isclass(mineral) and mineral != burnman.Mineral and mineral != burnman.CombinedMineral and issubclass(mineral, burnman.Mineral) \
and not issubclass(mineral, burnman.classes.mineral_helpers.HelperSpinTransition):
if issubclass(mineral, burnman.SolidSolution):
continue
# print mineral.__module__ + mineral.__name__
name1 = str(mineralgroup.__name__) + "." + str(m)
name = name1.replace("burnman.minerals.", "")
# name = mineral.__module__.replace("minlib_","").replace("burnman.","").replace("minerals.","") + "." + mineral.__name__
# print mineral, name, name1
if name not in names:
names.add(name)
try:
x = mineral()
phasenames.append((name, x))
except:
print("Could not create '%s'" % name)
# The following groups minerals from each module into groups based on eos and
# prints a separate table for each eos group.
list_eoses = [phasename[1].params['equation_of_state'] for phasename in phasenames]
for (eos, params) in sorted(eos_params.items(), key=lambda x: x[0]):
eos_phasenames = [phasenames[i] for i, e in enumerate(list_eoses) if e == eos]
if len(eos_phasenames) > 0:
table = []
tablel = []
table.append(['Name ({0} equation of state)'.format(eos)] + params)
tablel.append([])
sortedlist = sorted(eos_phasenames, key=lambda x: x[0])
for (name, p) in sortedlist:
p.set_state(1e9, 300)
row = create_list(name, p)
table.append(row)
tablel.append(row)
if (len(sys.argv) == 1):
tools.misc.pretty_print_table(table, False)
elif sys.argv[1] == "tab":
tools.misc.pretty_print_table(table, True)