pychnosz 1.1.4__cp311-cp311-win_amd64.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.
Files changed (128) hide show
  1. pychnosz/__init__.py +129 -0
  2. pychnosz/biomolecules/__init__.py +29 -0
  3. pychnosz/biomolecules/ionize_aa.py +197 -0
  4. pychnosz/biomolecules/proteins.py +595 -0
  5. pychnosz/core/__init__.py +46 -0
  6. pychnosz/core/affinity.py +1256 -0
  7. pychnosz/core/animation.py +593 -0
  8. pychnosz/core/balance.py +334 -0
  9. pychnosz/core/basis.py +716 -0
  10. pychnosz/core/diagram.py +3336 -0
  11. pychnosz/core/equilibrate.py +813 -0
  12. pychnosz/core/equilibrium.py +554 -0
  13. pychnosz/core/info.py +821 -0
  14. pychnosz/core/retrieve.py +364 -0
  15. pychnosz/core/speciation.py +580 -0
  16. pychnosz/core/species.py +599 -0
  17. pychnosz/core/subcrt.py +1700 -0
  18. pychnosz/core/thermo.py +593 -0
  19. pychnosz/core/unicurve.py +1226 -0
  20. pychnosz/data/__init__.py +11 -0
  21. pychnosz/data/add_obigt.py +327 -0
  22. pychnosz/data/extdata/Berman/BDat17_2017.csv +2 -0
  23. pychnosz/data/extdata/Berman/Ber88_1988.csv +68 -0
  24. pychnosz/data/extdata/Berman/Ber90_1990.csv +5 -0
  25. pychnosz/data/extdata/Berman/DS10_2010.csv +6 -0
  26. pychnosz/data/extdata/Berman/FDM+14_2014.csv +2 -0
  27. pychnosz/data/extdata/Berman/Got04_2004.csv +5 -0
  28. pychnosz/data/extdata/Berman/JUN92_1992.csv +3 -0
  29. pychnosz/data/extdata/Berman/SHD91_1991.csv +12 -0
  30. pychnosz/data/extdata/Berman/VGT92_1992.csv +2 -0
  31. pychnosz/data/extdata/Berman/VPT01_2001.csv +3 -0
  32. pychnosz/data/extdata/Berman/VPV05_2005.csv +2 -0
  33. pychnosz/data/extdata/Berman/ZS92_1992.csv +11 -0
  34. pychnosz/data/extdata/Berman/sympy.R +99 -0
  35. pychnosz/data/extdata/Berman/testing/BA96.bib +12 -0
  36. pychnosz/data/extdata/Berman/testing/BA96_Berman.csv +21 -0
  37. pychnosz/data/extdata/Berman/testing/BA96_OBIGT.csv +21 -0
  38. pychnosz/data/extdata/Berman/testing/BA96_refs.csv +6 -0
  39. pychnosz/data/extdata/OBIGT/AD.csv +25 -0
  40. pychnosz/data/extdata/OBIGT/Berman_cr.csv +93 -0
  41. pychnosz/data/extdata/OBIGT/DEW.csv +211 -0
  42. pychnosz/data/extdata/OBIGT/H2O_aq.csv +4 -0
  43. pychnosz/data/extdata/OBIGT/SLOP98.csv +411 -0
  44. pychnosz/data/extdata/OBIGT/SUPCRT92.csv +178 -0
  45. pychnosz/data/extdata/OBIGT/inorganic_aq.csv +729 -0
  46. pychnosz/data/extdata/OBIGT/inorganic_cr.csv +273 -0
  47. pychnosz/data/extdata/OBIGT/inorganic_gas.csv +20 -0
  48. pychnosz/data/extdata/OBIGT/organic_aq.csv +1104 -0
  49. pychnosz/data/extdata/OBIGT/organic_cr.csv +481 -0
  50. pychnosz/data/extdata/OBIGT/organic_gas.csv +268 -0
  51. pychnosz/data/extdata/OBIGT/organic_liq.csv +533 -0
  52. pychnosz/data/extdata/OBIGT/testing/GEMSFIT.csv +43 -0
  53. pychnosz/data/extdata/OBIGT/testing/IGEM.csv +17 -0
  54. pychnosz/data/extdata/OBIGT/testing/Sandia.csv +8 -0
  55. pychnosz/data/extdata/OBIGT/testing/SiO2.csv +4 -0
  56. pychnosz/data/extdata/misc/AD03_Fig1a.csv +69 -0
  57. pychnosz/data/extdata/misc/AD03_Fig1b.csv +43 -0
  58. pychnosz/data/extdata/misc/AD03_Fig1c.csv +89 -0
  59. pychnosz/data/extdata/misc/AD03_Fig1d.csv +30 -0
  60. pychnosz/data/extdata/misc/BZA10.csv +5 -0
  61. pychnosz/data/extdata/misc/HW97_Cp.csv +90 -0
  62. pychnosz/data/extdata/misc/HWM96_V.csv +229 -0
  63. pychnosz/data/extdata/misc/LA19_test.csv +7 -0
  64. pychnosz/data/extdata/misc/Mer75_Table4.csv +42 -0
  65. pychnosz/data/extdata/misc/OBIGT_check.csv +423 -0
  66. pychnosz/data/extdata/misc/PM90.csv +7 -0
  67. pychnosz/data/extdata/misc/RH95.csv +23 -0
  68. pychnosz/data/extdata/misc/RH98_Table15.csv +17 -0
  69. pychnosz/data/extdata/misc/SC10_Rainbow.csv +19 -0
  70. pychnosz/data/extdata/misc/SK95.csv +55 -0
  71. pychnosz/data/extdata/misc/SOJSH.csv +61 -0
  72. pychnosz/data/extdata/misc/SS98_Fig5a.csv +81 -0
  73. pychnosz/data/extdata/misc/SS98_Fig5b.csv +84 -0
  74. pychnosz/data/extdata/misc/TKSS14_Fig2.csv +25 -0
  75. pychnosz/data/extdata/misc/bluered.txt +1000 -0
  76. pychnosz/data/extdata/protein/Cas/Cas_aa.csv +177 -0
  77. pychnosz/data/extdata/protein/Cas/Cas_uniprot.csv +186 -0
  78. pychnosz/data/extdata/protein/Cas/download.R +34 -0
  79. pychnosz/data/extdata/protein/Cas/mkaa.R +34 -0
  80. pychnosz/data/extdata/protein/POLG.csv +12 -0
  81. pychnosz/data/extdata/protein/TBD+05.csv +393 -0
  82. pychnosz/data/extdata/protein/TBD+05_aa.csv +393 -0
  83. pychnosz/data/extdata/protein/rubisco.csv +28 -0
  84. pychnosz/data/extdata/protein/rubisco.fasta +239 -0
  85. pychnosz/data/extdata/protein/rubisco_aa.csv +28 -0
  86. pychnosz/data/extdata/src/H2O92D.f.orig +3457 -0
  87. pychnosz/data/extdata/src/README.txt +5 -0
  88. pychnosz/data/extdata/taxonomy/names.dmp +215 -0
  89. pychnosz/data/extdata/taxonomy/nodes.dmp +63 -0
  90. pychnosz/data/extdata/thermo/Bdot_acirc.csv +60 -0
  91. pychnosz/data/extdata/thermo/buffer.csv +40 -0
  92. pychnosz/data/extdata/thermo/element.csv +135 -0
  93. pychnosz/data/extdata/thermo/groups.csv +6 -0
  94. pychnosz/data/extdata/thermo/opt.csv +2 -0
  95. pychnosz/data/extdata/thermo/protein.csv +506 -0
  96. pychnosz/data/extdata/thermo/refs.csv +343 -0
  97. pychnosz/data/extdata/thermo/stoich.csv.xz +0 -0
  98. pychnosz/data/loader.py +431 -0
  99. pychnosz/data/mod_obigt.py +322 -0
  100. pychnosz/data/obigt.py +471 -0
  101. pychnosz/data/worm.py +228 -0
  102. pychnosz/fortran/__init__.py +16 -0
  103. pychnosz/fortran/h2o92.dll +0 -0
  104. pychnosz/fortran/h2o92_interface.py +527 -0
  105. pychnosz/geochemistry/__init__.py +21 -0
  106. pychnosz/geochemistry/minerals.py +514 -0
  107. pychnosz/geochemistry/redox.py +500 -0
  108. pychnosz/models/__init__.py +47 -0
  109. pychnosz/models/archer_wang.py +165 -0
  110. pychnosz/models/berman.py +309 -0
  111. pychnosz/models/cgl.py +381 -0
  112. pychnosz/models/dew.py +997 -0
  113. pychnosz/models/hkf.py +523 -0
  114. pychnosz/models/hkf_helpers.py +222 -0
  115. pychnosz/models/iapws95.py +1113 -0
  116. pychnosz/models/supcrt92_fortran.py +238 -0
  117. pychnosz/models/water.py +480 -0
  118. pychnosz/utils/__init__.py +27 -0
  119. pychnosz/utils/expression.py +1074 -0
  120. pychnosz/utils/formula.py +830 -0
  121. pychnosz/utils/formula_ox.py +227 -0
  122. pychnosz/utils/reset.py +33 -0
  123. pychnosz/utils/units.py +259 -0
  124. pychnosz-1.1.4.dist-info/METADATA +197 -0
  125. pychnosz-1.1.4.dist-info/RECORD +128 -0
  126. pychnosz-1.1.4.dist-info/WHEEL +5 -0
  127. pychnosz-1.1.4.dist-info/licenses/LICENSE.txt +19 -0
  128. pychnosz-1.1.4.dist-info/top_level.txt +1 -0
@@ -0,0 +1,222 @@
1
+ """
2
+ Helper functions for HKF calculations, integrated from HKF_cgl.py.
3
+
4
+ This module contains the tested helper functions from the HKF_cgl.py notebook,
5
+ including calc_logK, calc_G_TP, G2logK, dissrxn2logK, and OBIGT2eos functions.
6
+ """
7
+
8
+ import pandas as pd
9
+ import numpy as np
10
+ import math
11
+ import copy
12
+ import warnings
13
+ from .hkf import hkf
14
+ from .cgl import cgl
15
+ from .water import water
16
+ from ..utils.formula import entropy
17
+
18
+ def calc_logK(OBIGT_df, Tc, P, TP_i, water_model):
19
+
20
+ OBIGT_TP, rows_added = calc_G_TP(OBIGT_df, Tc, P, water_model)
21
+
22
+ dissrxn2logK_out = []
23
+ for i in OBIGT_TP.index:
24
+ dissrxn2logK_out.append(dissrxn2logK(OBIGT_TP, i, Tc))
25
+ assert len(dissrxn2logK_out) == OBIGT_TP.shape[0]
26
+
27
+ OBIGT_TP['dissrxn_logK_'+str(TP_i)] = dissrxn2logK_out
28
+
29
+ # remove any rows added by calc_G_TP
30
+ OBIGT_TP.drop(OBIGT_TP.tail(rows_added).index, inplace = True)
31
+
32
+ return OBIGT_TP
33
+
34
+
35
+ def calc_G_TP(OBIGT, Tc, P, water_model):
36
+
37
+ aq_out, H2O_Pt = hkf(property=["G"], parameters=OBIGT,
38
+ T=273.15+Tc, P=P, contrib=["n", "s", "o"],
39
+ H2O_props=["rho"], water_model=water_model)
40
+
41
+ cgl_out = cgl(property=["G"], parameters=OBIGT, T=273.15+Tc, P=P)
42
+
43
+ aq_col = pd.DataFrame.from_dict(aq_out, orient="index")
44
+ cgl_col = pd.DataFrame.from_dict(cgl_out, orient="index")
45
+
46
+ G_TP_df = pd.concat([aq_col, cgl_col], axis=1)
47
+ G_TP_df.columns = ['aq','cgl']
48
+
49
+ OBIGT["G_TP"] = G_TP_df['aq'].combine_first(G_TP_df['cgl'])
50
+
51
+ rows_added = 0
52
+
53
+ # add a row for water
54
+ if "H2O" not in list(OBIGT["name"]):
55
+ # Set the water model (without printing messages)
56
+ water(water_model, messages=False)
57
+ # water() returns a scalar when called with single property and scalar T, P
58
+ # The result is in J/mol, need to convert to cal/mol by dividing by 4.184
59
+ G_water = water("G", T=Tc+273.15, P=P, messages=False)
60
+ # Handle both scalar and DataFrame returns
61
+ if isinstance(G_water, pd.DataFrame):
62
+ G_water_cal = G_water.iloc[0]["G"] / 4.184
63
+ else:
64
+ G_water_cal = float(G_water) / 4.184
65
+ OBIGT = pd.concat([OBIGT, pd.DataFrame({"name": "H2O", "tag": "nan", "G_TP": G_water_cal}, index=[OBIGT.shape[0]])], ignore_index=True)
66
+ rows_added += 1
67
+
68
+ # add a row for protons
69
+ if "H+" not in list(OBIGT["name"]):
70
+ OBIGT = pd.concat([OBIGT, pd.DataFrame({"name": "H+", "tag": "nan", "G_TP": 0}, index=[OBIGT.shape[0]])], ignore_index=True)
71
+ rows_added += 1
72
+
73
+ return OBIGT, rows_added
74
+
75
+
76
+ def G2logK(G, Tc):
77
+ # Gas constant R is in cal/mol K
78
+ return G / (-math.log(10) * 1.9872 * (273.15+Tc))
79
+
80
+
81
+ def dissrxn2logK(OBIGT, i, Tc):
82
+
83
+ this_dissrxn = OBIGT.iloc[i, OBIGT.columns.get_loc('dissrxn')]
84
+
85
+ if this_dissrxn == "nan":
86
+ this_dissrxn = OBIGT.iloc[i, OBIGT.columns.get_loc('regenerate_dissrxn')]
87
+
88
+ # print(OBIGT["name"][i], this_dissrxn)
89
+
90
+ try:
91
+ this_dissrxn = this_dissrxn.strip()
92
+ split_dissrxn = this_dissrxn.split(" ")
93
+ except:
94
+ return float('NaN')
95
+
96
+
97
+
98
+ coeff = [float(n) for n in split_dissrxn[::2]]
99
+ species = split_dissrxn[1::2]
100
+ try:
101
+ G = sum([float(c*OBIGT.loc[OBIGT["name"]==sp, "G_TP"].iloc[0]) for c,sp in zip(coeff, species)])
102
+ except:
103
+ G_list = []
104
+ for ii, sp in enumerate(species):
105
+ G_TP = OBIGT.loc[OBIGT["name"]==sp, "G_TP"]
106
+ if len(G_TP) == 1:
107
+ G_list.append(float(coeff[ii]*OBIGT.loc[OBIGT["name"]==sp, "G_TP"]))
108
+ else:
109
+ ### check valid polymorph T
110
+
111
+ # get polymorph entries of OBIGT that match mineral
112
+ poly_df = copy.copy(OBIGT.loc[OBIGT["name"]==sp,:])
113
+ # ensure polymorph df is sorted according to cr, cr2, cr3... etc.
114
+ poly_df = poly_df.sort_values("state")
115
+
116
+ z_Ts = list(poly_df.loc[poly_df["name"]==sp, "z.T"])
117
+
118
+ last_t = float('-inf')
119
+ appended=False
120
+ for iii,t in enumerate(z_Ts):
121
+
122
+ if Tc+273.15 > last_t and Tc+273.15 < t:
123
+ G_list.append(float(coeff[ii]*list(poly_df.loc[poly_df["name"]==sp, "G_TP"])[iii]))
124
+ appended=True
125
+ if not appended and z_Ts[-1] == t:
126
+ G_list.append(float(coeff[ii]*list(poly_df.loc[poly_df["name"]==sp, "G_TP"])[iii]))
127
+ last_t = t
128
+
129
+ G = sum(G_list)
130
+
131
+ return G2logK(G, Tc)
132
+
133
+
134
+ def convert_cm3bar(value):
135
+ return value*4.184 * 10
136
+
137
+
138
+ def OBIGT2eos(OBIGT, fixGHS=True, tocal=True, messages=True):
139
+ """
140
+ Convert OBIGT dataframe to equation of state parameters.
141
+
142
+ This function processes the OBIGT thermodynamic database to prepare it for
143
+ equation of state calculations. It handles energy unit conversions and
144
+ optionally fills in missing G, H, or S values.
145
+
146
+ Parameters
147
+ ----------
148
+ OBIGT : pd.DataFrame
149
+ OBIGT thermodynamic database
150
+ fixGHS : bool, default True
151
+ Fill in one missing value among G, H, S using thermodynamic relations
152
+ tocal : bool, default True
153
+ Convert energy units from Joules to calories
154
+ messages : bool, default True
155
+ Print informational messages (currently not used, reserved for future)
156
+
157
+ Returns
158
+ -------
159
+ pd.DataFrame
160
+ Modified OBIGT dataframe with converted parameters
161
+ """
162
+ OBIGT_out = OBIGT.copy()
163
+
164
+ # Get column indices for named columns (to handle varying column positions)
165
+ G_idx = OBIGT.columns.get_loc('G')
166
+ H_idx = OBIGT.columns.get_loc('H')
167
+ S_idx = OBIGT.columns.get_loc('S')
168
+ Cp_idx = OBIGT.columns.get_loc('Cp')
169
+ V_idx = OBIGT.columns.get_loc('V')
170
+ omega_lambda_idx = OBIGT.columns.get_loc('omega.lambda')
171
+
172
+ for i in range(0, OBIGT.shape[0]):
173
+
174
+ # we only convert omega for aqueous species, not lambda for cgl species
175
+ if tocal and OBIGT.iloc[i, :]["E_units"] == "J" and OBIGT.iloc[i, :]["state"] == "aq":
176
+ # Convert G, H, S, Cp
177
+ OBIGT_out.iloc[i, G_idx:Cp_idx+1] = OBIGT.iloc[i, G_idx:Cp_idx+1]/4.184
178
+ # Convert V through omega (includes omega for aq species)
179
+ OBIGT_out.iloc[i, V_idx:omega_lambda_idx+1] = OBIGT.iloc[i, V_idx:omega_lambda_idx+1]/4.184
180
+ OBIGT_out.iloc[i, OBIGT.columns.get_loc('E_units')] = "cal"
181
+
182
+ elif tocal and OBIGT.iloc[i, :]["E_units"] == "J":
183
+ # Convert G, H, S, Cp
184
+ OBIGT_out.iloc[i, G_idx:Cp_idx+1] = OBIGT.iloc[i, G_idx:Cp_idx+1]/4.184
185
+ # Convert V through c2.f (exclude omega.lambda for non-aq species)
186
+ OBIGT_out.iloc[i, V_idx:omega_lambda_idx] = OBIGT.iloc[i, V_idx:omega_lambda_idx]/4.184
187
+ OBIGT_out.iloc[i, OBIGT.columns.get_loc('E_units')] = "cal"
188
+
189
+ # fill in one of missing G, H, S
190
+ # for use esp. by subcrt because NA for one of G, H or S
191
+ # will preclude calculations at high T
192
+ if fixGHS:
193
+ # which entries are missing just one
194
+ GHS_values = [OBIGT.iloc[i, G_idx], OBIGT.iloc[i, H_idx], OBIGT.iloc[i, S_idx]]
195
+ imiss = [pd.isna(v) for v in GHS_values]
196
+ if sum(imiss) == 1:
197
+
198
+ ii = imiss.index(True)
199
+
200
+ if ii == 0: # G is missing
201
+ H = OBIGT_out.iloc[i, H_idx]
202
+ S = OBIGT_out.iloc[i, S_idx]
203
+ Selem = entropy(OBIGT_out.iloc[i, OBIGT_out.columns.get_loc('formula')])
204
+ T = 298.15
205
+ G = H - T*(S - Selem)
206
+ OBIGT_out.iloc[i, G_idx] = G
207
+ elif ii == 1: # H is missing
208
+ G = OBIGT_out.iloc[i, G_idx]
209
+ S = OBIGT_out.iloc[i, S_idx]
210
+ Selem = entropy(OBIGT_out.iloc[i, OBIGT_out.columns.get_loc('formula')])
211
+ T = 298.15
212
+ H = G + T*(S - Selem)
213
+ OBIGT_out.iloc[i, H_idx] = H
214
+ elif ii == 2: # S is missing
215
+ G = OBIGT_out.iloc[i, G_idx]
216
+ H = OBIGT_out.iloc[i, H_idx]
217
+ Selem = entropy(OBIGT_out.iloc[i, OBIGT_out.columns.get_loc('formula')])
218
+ T = 298.15
219
+ S = Selem + (H - G)/T
220
+ OBIGT_out.iloc[i, S_idx] = S
221
+
222
+ return OBIGT_out