ExoGibbs 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ __version__ = "0.2.1"
exogibbs/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ try:
2
+ from .ExoGibbs_version import __version__
3
+ except Exception:
4
+ try:
5
+ from importlib.metadata import version as _pkg_version
6
+ __version__ = _pkg_version("ExoGibbs")
7
+ except Exception:
8
+ __version__ = "0.0.0.dev0"
File without changes
@@ -0,0 +1,38 @@
1
+ from exogibbs.io.load_data import load_molname
2
+ from exogibbs.io.load_data import load_JANAF_molecules
3
+ from exogibbs.io.load_data import load_formula_matrix
4
+ from exogibbs.io.load_data import load_JANAF_molecules
5
+ from exogibbs.equilibrium.gibbs import extract_and_pad_gibbs_data
6
+ from exogibbs.equilibrium.gibbs import robust_temperature_range
7
+
8
+
9
+
10
+ class ThermoChem:
11
+ """
12
+ A class to handle thermochemical equilibrium calculations.
13
+ """
14
+
15
+ def __init__(self):
16
+ """Initialize the ThermoChem class.
17
+ """
18
+ self.set_equations(path_JANAF_data = "/home/kawahara/thermochemical_equilibrium/Equilibrium/JANAF"):
19
+
20
+
21
+ def set_equations(self, path_JANAF_data):
22
+ """Set the molecules, elements, chemical_data (eq_setting in thermochemical_equilibrium package)
23
+ """
24
+ self.df_molname = load_molname()
25
+ self.gibbs_matrices = load_JANAF_molecules(
26
+ self.df_molname,
27
+ path_JANAF_data,
28
+ )
29
+ self.formula_matrix = load_formula_matrix()
30
+ self.molecules, self.T_table, self.G_table, self.grid_lens = extract_and_pad_gibbs_data(self.gibbs_matrices)
31
+ self.Tmin, self.Tmax = robust_temperature_range(self.T_table)
32
+
33
+
34
+ def set_initial_values(self):
35
+ """Set the initial values for the equilibrium calculation.
36
+ """
37
+ return
38
+
Binary file
@@ -0,0 +1,12 @@
1
+ SAMPLE (SAMP) SAMP2(ref)
2
+ T(K) Cp S -[G-H(Tr)]/T H-H(Tr) delta-f H delta-f G log Kf
3
+ 0 0. 0. INFINITE -8.467 0. 0. 0.
4
+ 100 28.154 100.727 155.408 -5.468 0. 0.1 0.
5
+ 200 27.447 119.412 133.284 -2.774 0. 0.2 0.
6
+ 250 28.344 125.640 131.152 -1.378 0. 0.3 0.
7
+ 298.15 28.836 130.680 130.680 0. 0. 0.4 0.
8
+ 300 28.849 130.858 130.680 0.053 0. 0.5 0.
9
+ 350 29.081 135.325 131.032 1.502 0. 0.6 0.
10
+ 400 29.181 139.216 131.817 2.959 0. 0.5 0.
11
+ 450 29.229 142.656 132.834 4.420 0. 0.4 0.
12
+ 500 29.260 145.737 133.973 5.882 0. 0.3 0.
@@ -0,0 +1,160 @@
1
+ 1 0 0 0 0 0 0 0 0 0 0 0
2
+ 0 2 0 0 0 0 0 0 0 0 0 0
3
+ 0 0 1 0 0 0 0 0 0 0 0 0
4
+ 0 0 0 1 0 0 0 0 0 0 0 0
5
+ 0 0 0 0 2 0 0 0 0 0 0 0
6
+ 0 0 0 0 0 1 0 0 0 0 0 0
7
+ 0 0 0 0 0 0 2 0 0 0 0 0
8
+ 0 0 0 0 0 0 0 1 0 0 0 0
9
+ 0 0 0 0 0 0 0 0 1 0 0 0
10
+ 0 0 0 0 0 0 0 0 0 1 0 0
11
+ 0 0 0 0 0 0 0 0 0 0 1 0
12
+ 0 0 0 0 0 0 0 0 0 0 0 1
13
+ 1 1 0 0 0 0 0 0 0 0 0 0
14
+ 1 1 0 0 1 0 0 0 0 0 0 0
15
+ 1 1 0 0 1 0 1 0 0 0 0 0
16
+ 1 1 0 0 0 0 1 0 0 0 0 0
17
+ 1 2 0 0 0 0 0 0 0 0 0 0
18
+ 1 2 0 0 0 0 1 0 0 0 0 0
19
+ 1 3 0 0 0 0 0 0 0 0 0 0
20
+ 1 4 0 0 0 0 0 0 0 0 0 0
21
+ 1 0 0 1 1 0 0 0 0 0 0 0
22
+ 1 0 0 0 1 0 0 0 0 0 0 0
23
+ 1 0 0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1
7
+ O2 aquamarine
8
+ Ti1 antiquewhite
9
+ V1 dark-plum
10
+ P1 0
11
+ S1 yellow4
12
+ e1- skyblue
13
+ C1H1 0
14
+ C1H1N1 dark-khaki
15
+ C1H1N1O1 0
16
+ C1H1O1 dark-chartreuse
17
+ C1H2 light-pink
18
+ C1H2O1 light-goldenrod
19
+ C1H3 light-green
20
+ C1H4 cyan
21
+ C1K1N1 midnight-blue
22
+ C1N1 0
23
+ C1N1Na1 dark-pink
24
+ C1N1O1 0
25
+ C1N2(CNN) 0
26
+ C1N2(NCN) 0
27
+ C1O1 orange
28
+ C1O2 green
29
+ C2 0
30
+ C2H1 0
31
+ C2H2 yellow
32
+ C2H4 spring-green
33
+ C2H4O1 0
34
+ C2K2N2 0
35
+ C2N1 0
36
+ C2N2 0
37
+ C2N2Na2 dark-olivegreen
38
+ C2O1 0
39
+ C3 0
40
+ C3O2 0
41
+ C4 0
42
+ C4N2 0
43
+ C5 0
44
+ H1 slateblue1
45
+ H1K1 light-blue
46
+ H1K1O1 royalblue
47
+ H1N1 violet
48
+ H1N1O1 0
49
+ H1N1O2(cis) 0
50
+ H1N1O2(trans) 0
51
+ H1N1O3 0
52
+ H1Na1 dark-salmon
53
+ H1Na1O1 orange-red
54
+ H1O1 navy
55
+ H1O2 0
56
+ H2K2O2 dark-turquoise
57
+ H2N1 gray
58
+ H2N2 0
59
+ H2Na2O2 plum
60
+ H2O1 blue
61
+ H2O2 0
62
+ H3N1 gray30
63
+ H4N2 0
64
+ K1O1 0
65
+ K2 0
66
+ N1 slategray
67
+ N1O1 0
68
+ N1O2 0
69
+ N1O3 0
70
+ N2O1 0
71
+ N2O3 0
72
+ N2O4 0
73
+ N2O5 0
74
+ N3 0
75
+ Na1O1 0
76
+ Na2 dark-goldenrod
77
+ O1 steelblue
78
+ O3 0
79
+ N1V1 0
80
+ O1Ti1 goldenrod
81
+ O1V1 olive
82
+ O2Ti1 dark-yellow
83
+ O2V1 bisque
84
+ C1H1P1 0
85
+ C1O1S1 medium-blue
86
+ C1P1 0
87
+ C1S1 0
88
+ C1S2 light-magenta
89
+ H1P1 0
90
+ H1S1 gold
91
+ H2O4S1 0
92
+ H2P1 0
93
+ H2S1 web-blue
94
+ H3P1 0
95
+ K2O4S1 0
96
+ N1P1 sandybrown
97
+ N1S1 0
98
+ Na2O4S1 0
99
+ O1P1 mediumpurple3
100
+ O1S1 chartreuse
101
+ O1S2 tan1
102
+ O2P1 dark-red
103
+ O2S1 turquoise
104
+ O3S1 0
105
+ O6P4 forest-green
106
+ O10P4 0
107
+ P1S1 orchid
108
+ P2 0
109
+ P4 0
110
+ P4S3 0
111
+ S2 dark-gray
112
+ S3 dark-spring-green
113
+ S4 0
114
+ S5 0
115
+ S6 0
116
+ S7 0
117
+ S8 0
118
+ C1+ 0
119
+ C1- 0
120
+ C1H1+ 0
121
+ C1H1O1+ 0
122
+ C1N1+ 0
123
+ C1N1- 0
124
+ C1O2- 0
125
+ C2- 0
126
+ H1+ 0
127
+ H1- 0
128
+ H1K1O1+ 0
129
+ H1Na1O1+ 0
130
+ H1O1+ 0
131
+ H1O1- 0
132
+ H2+ 0
133
+ H2- 0
134
+ H3O1+ 0
135
+ He1+ 0
136
+ K1+ purple
137
+ K1- 0
138
+ K1O1- 0
139
+ N1+ 0
140
+ N1- 0
141
+ N1O1+ 0
142
+ N1O2- 0
143
+ N2+ 0
144
+ N2- 0
145
+ N2O1+ 0
146
+ Na1+ 0
147
+ Na1- 0
148
+ Na1O1- 0
149
+ O1+ 0
150
+ O1- 0
151
+ O2+ 0
152
+ O2- 0
153
+ P1+ 0
154
+ P1- 0
155
+ S1+ 0
156
+ S1- 0
157
+ Ti1+ 0
158
+ Ti1- 0
159
+ V1+ 0
160
+ V1- 0
@@ -0,0 +1 @@
1
+ 4.8771844088134374E-004,0.83748832109661187,0.16143440365984060,2.4842019364382504E-007,6.7166286367535330E-005,3.9565195261941036E-006,4.8675855005686264E-004,1.6588401261773752E-007,1.8380646975815483E-008,5.6349288368902435E-007,3.0627107689945438E-005,0.0,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,4.9677424258960761E-010,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
@@ -0,0 +1 @@
1
+ #this is an empty test data for the unit testing
File without changes
@@ -0,0 +1,160 @@
1
+ from __future__ import annotations
2
+ import pandas as pd
3
+ import numpy as np
4
+ from typing import Dict
5
+ import jax
6
+ import jax.numpy as jnp
7
+ from jax import custom_jvp
8
+ from interpax import interp1d
9
+
10
+ from exogibbs.utils.constants import R_gas_constant_si
11
+
12
+ _INF_STRINGS = {"inf", "Inf", "INFINITE"}
13
+ _NINF_STRINGS = {"-inf", "-Inf", "-INFINITE"}
14
+ EPS = 1e-20
15
+ LOG_EPS = jnp.log(EPS)
16
+
17
+
18
+ def _coerce_to_float(a):
19
+ """convert "inf" string to np.inf and -inf"""
20
+ a = np.asarray(a, dtype=object)
21
+
22
+ is_str = np.vectorize(lambda x: isinstance(x, str))
23
+ str_mask = is_str(a)
24
+
25
+ if str_mask.any():
26
+ strs = a[str_mask]
27
+ lower = np.char.lower(strs.astype(str))
28
+
29
+ # inf / -inf
30
+ a[str_mask & np.isin(lower, list(_INF_STRINGS))] = np.inf
31
+ a[str_mask & np.isin(lower, list(_NINF_STRINGS))] = -np.inf
32
+
33
+ other_mask = str_mask & ~np.isin(lower, list(_INF_STRINGS | _NINF_STRINGS))
34
+ a[other_mask] = np.nan
35
+
36
+ return a.astype(np.float64)
37
+
38
+
39
+ def extract_and_pad_gibbs_data(
40
+ gibbs_matrices: Dict[str, pd.DataFrame],
41
+ temperature_key: str = "T(K)",
42
+ checmical_potential_key: str = "delta-f G",
43
+ unit_conversion_factor=1.0e3,
44
+ ):
45
+ """Extracting molar chemical potential from gibbs_matrices and perform padding to the same length
46
+
47
+ Args:
48
+ gibbs_matrices (Dict[str, pd.DataFrame]): chemical potential matrices, needs to have the key of temperature_key and checmecal_potential_key
49
+ temperature_key (str): key for temperature
50
+ checmical_potential_key (str): key for chemical potential, default to "delta-f G" (standard mol chemcical potential, Pst=1 bar IUPAC since 1982)
51
+ unit_conversion_factor (float): conversion factor for chemical potential, default to 1.e3 (kJ/mol -> J/mol), #44 in Kawashima's code (eq_subprog.f90)
52
+
53
+ Notes:
54
+ delta-f G (standard molar Gibbs free energy of formation or standard molar checmical potential) in JANAF is given in kJ/mol,
55
+ but in the code it is converted to J/mol. "unit_conversion_factor" is used to convert the unit of chemical potential from kJ/mol to J/mol.
56
+
57
+ Returns:
58
+ molecules (list): list of molecules
59
+ T_table (ndarray): temperature table in K (Nmolecules, Lmax)
60
+ mu_table (ndarray): standard molar chemical potential table in J/mol (Nmolecules, Lmax), standard state: Pref = 1 bar
61
+ grid_length (tuple): tuple of grid lengths for each molecule
62
+ """
63
+ molecules = list(gibbs_matrices.keys())
64
+ grid_lens = np.asarray(
65
+ [gibbs_matrices[m][temperature_key].size for m in molecules], dtype=np.int32
66
+ )
67
+ Lmax = int(grid_lens.max())
68
+
69
+ def _pad(arr, L):
70
+ arr = _coerce_to_float(arr)
71
+ return np.pad(arr, (0, L - arr.size), mode="edge")
72
+
73
+ T_table = np.stack(
74
+ [_pad(gibbs_matrices[m][temperature_key], Lmax) for m in molecules]
75
+ ).astype(np.float64)
76
+ mu_table = np.stack(
77
+ [_pad(gibbs_matrices[m][checmical_potential_key], Lmax) for m in molecules]
78
+ ).astype(np.float64)
79
+
80
+ mu_table = mu_table * unit_conversion_factor # from kJ/mol to J/mol
81
+
82
+ return (
83
+ molecules,
84
+ jnp.asarray(T_table), # shape (M, Lmax), float64
85
+ jnp.asarray(mu_table), # shape (M, Lmax), float64
86
+ tuple(grid_lens),
87
+ ) # shape (M,), int32
88
+
89
+
90
+ def interpolate_hvector_one(T_target, T_vec, mu_vec, method="linear"):
91
+ """interpolate one hvector = (chemical_potential/RT) at T_target
92
+ Args:
93
+ T_target (scalar or array): target temperature(s) (K)
94
+ T_vec (1D array): temeprature grid(Lmax)
95
+ mu_vec (1D array): chemical potential grid(Lmax)
96
+ method (str): method of interpolation used in interpax.interp1d
97
+ 'nearest': nearest neighbor interpolation
98
+ 'linear': linear interpolation
99
+ 'cubic': C1 cubic splines (aka local splines)
100
+ 'cubic2': C2 cubic splines (aka natural splines)
101
+ 'catmull-rom': C1 cubic centripetal “tension” splines
102
+ 'cardinal': C1 cubic general tension splines. If used, can also pass keyword parameter c in float[0,1] to specify tension
103
+ 'monotonic': C1 cubic splines that attempt to preserve monotonicity in the data, and will not introduce new extrema in the interpolated points
104
+ 'monotonic-0': same as 'monotonic' but with 0 first derivatives at both endpoints
105
+ 'akima': C1 cubic splines that appear smooth and natural
106
+
107
+ """
108
+ RT = R_gas_constant_si * T_vec
109
+ return interp1d(T_target, T_vec, mu_vec / RT, method=method)
110
+
111
+
112
+ def interpolate_hvector_all(T_target, T_table, mu_table):
113
+ """interpolate hvector = the chemical potential/RT at T_target for all molecules
114
+ Args:
115
+ T_target (scalar): target temperature (K)
116
+ T_table (ndarray): array of temeprature grid(Lmax)
117
+ mu_table (ndarray): array of chemical potential grid(Nmol, Lmax)
118
+
119
+ Returns:
120
+ chemical_potential_vec (ndarray): array of chemical potential at T_target (Nmol,Lmax)
121
+ """
122
+ return jax.lax.map(
123
+ lambda args: interpolate_hvector_one(T_target, *args),
124
+ (T_table, mu_table),
125
+ )
126
+
127
+
128
+ def robust_temperature_range(T_table):
129
+ """get the robust temperature range for all molecules
130
+ Args:
131
+ T_table (ndarray): array of temeprature grid(Lmax)
132
+ Returns:
133
+ Tmin (float): minimum temperature (K)
134
+ Tmax (float): maximum temperature (K)
135
+ """
136
+ Tmin = np.max(np.min(T_table, axis=1))
137
+ Tmax = np.min(np.max(T_table, axis=1))
138
+ return Tmin, Tmax
139
+
140
+
141
+ @custom_jvp
142
+ def safe_xlogx(x):
143
+ """"""
144
+ positive = x > EPS
145
+ # positive branch: as is
146
+ branch1 = jax.scipy.special.xlogy(x, x)
147
+ # non-positive: x*log(eps) + (x-eps) (first-order)
148
+ branch2 = x * LOG_EPS + (x - EPS)
149
+ return jnp.where(positive, branch1, branch2)
150
+
151
+
152
+ @safe_xlogx.defjvp
153
+ def safe_xlogx_jvp(primals, tangents):
154
+ (x,), (dx,) = primals, tangents
155
+ positive = x > EPS
156
+ y = safe_xlogx(x)
157
+ # gradient: 1 + log x (x>eps) / log(eps) const (x<=eps)
158
+ grad_pos = 1.0 + jnp.log(jnp.clip(x, a_min=EPS))
159
+ grad = jnp.where(positive, grad_pos, 1.0 + LOG_EPS)
160
+ return y, grad * dx
File without changes