pychnosz 1.1.1__cp310-cp310-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.
- pychnosz/__init__.py +129 -0
- pychnosz/biomolecules/__init__.py +29 -0
- pychnosz/biomolecules/ionize_aa.py +197 -0
- pychnosz/biomolecules/proteins.py +595 -0
- pychnosz/core/__init__.py +46 -0
- pychnosz/core/affinity.py +1256 -0
- pychnosz/core/animation.py +593 -0
- pychnosz/core/balance.py +334 -0
- pychnosz/core/basis.py +716 -0
- pychnosz/core/diagram.py +3336 -0
- pychnosz/core/equilibrate.py +813 -0
- pychnosz/core/equilibrium.py +554 -0
- pychnosz/core/info.py +821 -0
- pychnosz/core/retrieve.py +364 -0
- pychnosz/core/speciation.py +580 -0
- pychnosz/core/species.py +599 -0
- pychnosz/core/subcrt.py +1700 -0
- pychnosz/core/thermo.py +593 -0
- pychnosz/core/unicurve.py +1226 -0
- pychnosz/data/__init__.py +11 -0
- pychnosz/data/add_obigt.py +327 -0
- pychnosz/data/extdata/Berman/BDat17_2017.csv +2 -0
- pychnosz/data/extdata/Berman/Ber88_1988.csv +68 -0
- pychnosz/data/extdata/Berman/Ber90_1990.csv +5 -0
- pychnosz/data/extdata/Berman/DS10_2010.csv +6 -0
- pychnosz/data/extdata/Berman/FDM+14_2014.csv +2 -0
- pychnosz/data/extdata/Berman/Got04_2004.csv +5 -0
- pychnosz/data/extdata/Berman/JUN92_1992.csv +3 -0
- pychnosz/data/extdata/Berman/SHD91_1991.csv +12 -0
- pychnosz/data/extdata/Berman/VGT92_1992.csv +2 -0
- pychnosz/data/extdata/Berman/VPT01_2001.csv +3 -0
- pychnosz/data/extdata/Berman/VPV05_2005.csv +2 -0
- pychnosz/data/extdata/Berman/ZS92_1992.csv +11 -0
- pychnosz/data/extdata/Berman/sympy.R +99 -0
- pychnosz/data/extdata/Berman/testing/BA96.bib +12 -0
- pychnosz/data/extdata/Berman/testing/BA96_Berman.csv +21 -0
- pychnosz/data/extdata/Berman/testing/BA96_OBIGT.csv +21 -0
- pychnosz/data/extdata/Berman/testing/BA96_refs.csv +6 -0
- pychnosz/data/extdata/OBIGT/AD.csv +25 -0
- pychnosz/data/extdata/OBIGT/Berman_cr.csv +93 -0
- pychnosz/data/extdata/OBIGT/DEW.csv +211 -0
- pychnosz/data/extdata/OBIGT/H2O_aq.csv +4 -0
- pychnosz/data/extdata/OBIGT/SLOP98.csv +411 -0
- pychnosz/data/extdata/OBIGT/SUPCRT92.csv +178 -0
- pychnosz/data/extdata/OBIGT/inorganic_aq.csv +729 -0
- pychnosz/data/extdata/OBIGT/inorganic_cr.csv +273 -0
- pychnosz/data/extdata/OBIGT/inorganic_gas.csv +20 -0
- pychnosz/data/extdata/OBIGT/organic_aq.csv +1104 -0
- pychnosz/data/extdata/OBIGT/organic_cr.csv +481 -0
- pychnosz/data/extdata/OBIGT/organic_gas.csv +268 -0
- pychnosz/data/extdata/OBIGT/organic_liq.csv +533 -0
- pychnosz/data/extdata/OBIGT/testing/GEMSFIT.csv +43 -0
- pychnosz/data/extdata/OBIGT/testing/IGEM.csv +17 -0
- pychnosz/data/extdata/OBIGT/testing/Sandia.csv +8 -0
- pychnosz/data/extdata/OBIGT/testing/SiO2.csv +4 -0
- pychnosz/data/extdata/misc/AD03_Fig1a.csv +69 -0
- pychnosz/data/extdata/misc/AD03_Fig1b.csv +43 -0
- pychnosz/data/extdata/misc/AD03_Fig1c.csv +89 -0
- pychnosz/data/extdata/misc/AD03_Fig1d.csv +30 -0
- pychnosz/data/extdata/misc/BZA10.csv +5 -0
- pychnosz/data/extdata/misc/HW97_Cp.csv +90 -0
- pychnosz/data/extdata/misc/HWM96_V.csv +229 -0
- pychnosz/data/extdata/misc/LA19_test.csv +7 -0
- pychnosz/data/extdata/misc/Mer75_Table4.csv +42 -0
- pychnosz/data/extdata/misc/OBIGT_check.csv +423 -0
- pychnosz/data/extdata/misc/PM90.csv +7 -0
- pychnosz/data/extdata/misc/RH95.csv +23 -0
- pychnosz/data/extdata/misc/RH98_Table15.csv +17 -0
- pychnosz/data/extdata/misc/SC10_Rainbow.csv +19 -0
- pychnosz/data/extdata/misc/SK95.csv +55 -0
- pychnosz/data/extdata/misc/SOJSH.csv +61 -0
- pychnosz/data/extdata/misc/SS98_Fig5a.csv +81 -0
- pychnosz/data/extdata/misc/SS98_Fig5b.csv +84 -0
- pychnosz/data/extdata/misc/TKSS14_Fig2.csv +25 -0
- pychnosz/data/extdata/misc/bluered.txt +1000 -0
- pychnosz/data/extdata/protein/Cas/Cas_aa.csv +177 -0
- pychnosz/data/extdata/protein/Cas/Cas_uniprot.csv +186 -0
- pychnosz/data/extdata/protein/Cas/download.R +34 -0
- pychnosz/data/extdata/protein/Cas/mkaa.R +34 -0
- pychnosz/data/extdata/protein/POLG.csv +12 -0
- pychnosz/data/extdata/protein/TBD+05.csv +393 -0
- pychnosz/data/extdata/protein/TBD+05_aa.csv +393 -0
- pychnosz/data/extdata/protein/rubisco.csv +28 -0
- pychnosz/data/extdata/protein/rubisco.fasta +239 -0
- pychnosz/data/extdata/protein/rubisco_aa.csv +28 -0
- pychnosz/data/extdata/src/H2O92D.f.orig +3457 -0
- pychnosz/data/extdata/src/README.txt +5 -0
- pychnosz/data/extdata/taxonomy/names.dmp +215 -0
- pychnosz/data/extdata/taxonomy/nodes.dmp +63 -0
- pychnosz/data/extdata/thermo/Bdot_acirc.csv +60 -0
- pychnosz/data/extdata/thermo/buffer.csv +40 -0
- pychnosz/data/extdata/thermo/element.csv +135 -0
- pychnosz/data/extdata/thermo/groups.csv +6 -0
- pychnosz/data/extdata/thermo/opt.csv +2 -0
- pychnosz/data/extdata/thermo/protein.csv +506 -0
- pychnosz/data/extdata/thermo/refs.csv +343 -0
- pychnosz/data/extdata/thermo/stoich.csv.xz +0 -0
- pychnosz/data/loader.py +431 -0
- pychnosz/data/mod_obigt.py +322 -0
- pychnosz/data/obigt.py +471 -0
- pychnosz/data/worm.py +228 -0
- pychnosz/fortran/__init__.py +16 -0
- pychnosz/fortran/h2o92.dll +0 -0
- pychnosz/fortran/h2o92_interface.py +527 -0
- pychnosz/geochemistry/__init__.py +21 -0
- pychnosz/geochemistry/minerals.py +514 -0
- pychnosz/geochemistry/redox.py +500 -0
- pychnosz/models/__init__.py +47 -0
- pychnosz/models/archer_wang.py +165 -0
- pychnosz/models/berman.py +309 -0
- pychnosz/models/cgl.py +381 -0
- pychnosz/models/dew.py +997 -0
- pychnosz/models/hkf.py +523 -0
- pychnosz/models/hkf_helpers.py +222 -0
- pychnosz/models/iapws95.py +1113 -0
- pychnosz/models/supcrt92_fortran.py +238 -0
- pychnosz/models/water.py +480 -0
- pychnosz/utils/__init__.py +27 -0
- pychnosz/utils/expression.py +1074 -0
- pychnosz/utils/formula.py +830 -0
- pychnosz/utils/formula_ox.py +227 -0
- pychnosz/utils/reset.py +33 -0
- pychnosz/utils/units.py +259 -0
- pychnosz-1.1.1.dist-info/METADATA +197 -0
- pychnosz-1.1.1.dist-info/RECORD +128 -0
- pychnosz-1.1.1.dist-info/WHEEL +5 -0
- pychnosz-1.1.1.dist-info/licenses/LICENSE.txt +19 -0
- pychnosz-1.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SUPCRT92 water model with Fortran backend.
|
|
3
|
+
|
|
4
|
+
This implementation uses the original H2O92 Fortran subroutine for exact
|
|
5
|
+
compatibility with R CHNOSZ. Falls back to Python approximations if
|
|
6
|
+
the Fortran library is not available.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
import warnings
|
|
11
|
+
from typing import Union, List, Optional, Dict, Any
|
|
12
|
+
|
|
13
|
+
# Try to import Fortran interface
|
|
14
|
+
try:
|
|
15
|
+
from ..fortran import get_h2o92_interface
|
|
16
|
+
HAS_FORTRAN = True
|
|
17
|
+
except (ImportError, FileNotFoundError, RuntimeError) as e:
|
|
18
|
+
HAS_FORTRAN = False
|
|
19
|
+
_fortran_error = str(e)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SUPCRT92Water:
|
|
23
|
+
"""
|
|
24
|
+
SUPCRT92 water model with Fortran backend.
|
|
25
|
+
|
|
26
|
+
This class provides an interface to the original SUPCRT92 Fortran
|
|
27
|
+
subroutines for calculating water properties. If the Fortran library
|
|
28
|
+
is not available, it falls back to Python approximations.
|
|
29
|
+
|
|
30
|
+
The Fortran implementation gives exact compatibility with R CHNOSZ
|
|
31
|
+
and includes all 23+ thermodynamic properties.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self):
|
|
35
|
+
"""
|
|
36
|
+
Initialize SUPCRT92 water model.
|
|
37
|
+
|
|
38
|
+
SUPCRT92 requires the compiled FORTRAN interface for accuracy and
|
|
39
|
+
compatibility with R CHNOSZ. No pure Python fallback is provided.
|
|
40
|
+
"""
|
|
41
|
+
if not HAS_FORTRAN:
|
|
42
|
+
raise ImportError(
|
|
43
|
+
f"SUPCRT92 water model requires compiled FORTRAN interface. "
|
|
44
|
+
f"Error: {_fortran_error}. "
|
|
45
|
+
f"Please compile the FORTRAN subroutines using: "
|
|
46
|
+
f"python compile_fortran.py. "
|
|
47
|
+
f"See setup_fortran_instructions.md for details."
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Initialize Fortran interface (required)
|
|
51
|
+
try:
|
|
52
|
+
self._fortran_interface = get_h2o92_interface()
|
|
53
|
+
except Exception as e:
|
|
54
|
+
raise RuntimeError(f"Failed to initialize FORTRAN interface: {e}") from e
|
|
55
|
+
|
|
56
|
+
def calculate(self,
|
|
57
|
+
properties: Union[str, List[str]],
|
|
58
|
+
T: Union[float, np.ndarray] = 298.15,
|
|
59
|
+
P: Union[float, np.ndarray, str] = 1.0,
|
|
60
|
+
**kwargs) -> Union[float, np.ndarray, Dict[str, Any]]:
|
|
61
|
+
"""
|
|
62
|
+
Calculate water properties using SUPCRT92 model.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
properties : str or list of str
|
|
67
|
+
Property or list of properties to calculate
|
|
68
|
+
T : float or array
|
|
69
|
+
Temperature in Kelvin
|
|
70
|
+
P : float, array, or 'Psat'
|
|
71
|
+
Pressure in bar, or 'Psat' for saturation pressure
|
|
72
|
+
**kwargs
|
|
73
|
+
Additional options (e.g., Psat_floor)
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
float, array, or dict
|
|
78
|
+
Calculated properties
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
# Handle input types
|
|
82
|
+
if isinstance(properties, str):
|
|
83
|
+
properties = [properties]
|
|
84
|
+
single_prop = True
|
|
85
|
+
else:
|
|
86
|
+
single_prop = False
|
|
87
|
+
|
|
88
|
+
# Convert inputs to arrays
|
|
89
|
+
T = np.atleast_1d(np.asarray(T, dtype=float))
|
|
90
|
+
|
|
91
|
+
# Always use FORTRAN backend (no fallback)
|
|
92
|
+
return self._calculate_fortran(properties, T, P, single_prop, **kwargs)
|
|
93
|
+
|
|
94
|
+
def _calculate_fortran(self, properties: List[str], T: np.ndarray,
|
|
95
|
+
P: Union[np.ndarray, str], single_prop: bool,
|
|
96
|
+
**kwargs) -> Union[float, np.ndarray, Dict[str, Any]]:
|
|
97
|
+
"""Calculate properties using Fortran backend."""
|
|
98
|
+
|
|
99
|
+
# Handle pressure input
|
|
100
|
+
if isinstance(P, str) and P == 'Psat':
|
|
101
|
+
P_vals = 'Psat'
|
|
102
|
+
else:
|
|
103
|
+
P = np.atleast_1d(np.asarray(P, dtype=float))
|
|
104
|
+
if len(P) < len(T):
|
|
105
|
+
P = np.resize(P, len(T))
|
|
106
|
+
elif len(T) < len(P):
|
|
107
|
+
T = np.resize(T, len(P))
|
|
108
|
+
P_vals = P
|
|
109
|
+
|
|
110
|
+
# Use batched calculation for better performance
|
|
111
|
+
try:
|
|
112
|
+
results = self._fortran_interface.calculate_properties_batch(
|
|
113
|
+
T, P_vals, properties
|
|
114
|
+
)
|
|
115
|
+
except Exception as e:
|
|
116
|
+
warnings.warn(f"Batch Fortran calculation failed: {e}")
|
|
117
|
+
# Fallback to individual calculations if batch fails
|
|
118
|
+
results = {}
|
|
119
|
+
for prop in properties:
|
|
120
|
+
results[prop] = np.full_like(T, np.nan)
|
|
121
|
+
|
|
122
|
+
for i in range(len(T)):
|
|
123
|
+
T_i = T[i]
|
|
124
|
+
|
|
125
|
+
# Skip invalid points
|
|
126
|
+
if np.isnan(T_i):
|
|
127
|
+
continue
|
|
128
|
+
|
|
129
|
+
if isinstance(P_vals, str):
|
|
130
|
+
P_i = P_vals
|
|
131
|
+
else:
|
|
132
|
+
P_i = P_vals[i]
|
|
133
|
+
if np.isnan(P_i):
|
|
134
|
+
continue
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
# Call Fortran interface
|
|
138
|
+
props_i = self._fortran_interface.calculate_properties(
|
|
139
|
+
T_i, P_i, properties
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Store results
|
|
143
|
+
for prop in properties:
|
|
144
|
+
if prop in props_i:
|
|
145
|
+
results[prop][i] = props_i[prop]
|
|
146
|
+
|
|
147
|
+
except Exception as e:
|
|
148
|
+
warnings.warn(f"Fortran calculation failed at T={T_i:.1f}K, P={P_i}: {e}")
|
|
149
|
+
continue
|
|
150
|
+
|
|
151
|
+
# Handle Psat_floor for saturation pressure
|
|
152
|
+
if 'Psat' in results and 'Psat_floor' in kwargs:
|
|
153
|
+
Psat_floor = kwargs['Psat_floor']
|
|
154
|
+
if Psat_floor is not None:
|
|
155
|
+
results['Psat'] = np.maximum(results['Psat'], Psat_floor)
|
|
156
|
+
|
|
157
|
+
# Return results
|
|
158
|
+
if single_prop:
|
|
159
|
+
result = results[properties[0]]
|
|
160
|
+
return result[0] if len(result) == 1 else result
|
|
161
|
+
else:
|
|
162
|
+
# Convert single-element arrays to scalars if appropriate
|
|
163
|
+
if len(T) == 1:
|
|
164
|
+
for key in results:
|
|
165
|
+
if len(results[key]) == 1:
|
|
166
|
+
results[key] = results[key][0]
|
|
167
|
+
return results
|
|
168
|
+
|
|
169
|
+
def available_properties(self) -> List[str]:
|
|
170
|
+
"""
|
|
171
|
+
Get list of available properties.
|
|
172
|
+
|
|
173
|
+
Returns
|
|
174
|
+
-------
|
|
175
|
+
List[str]
|
|
176
|
+
List of available property names
|
|
177
|
+
"""
|
|
178
|
+
if self._use_fortran:
|
|
179
|
+
return self._fortran_interface.available_properties()
|
|
180
|
+
else:
|
|
181
|
+
return self._python_backend.available_properties()
|
|
182
|
+
|
|
183
|
+
@property
|
|
184
|
+
def backend(self) -> str:
|
|
185
|
+
"""Get the active backend ('fortran' or 'python')."""
|
|
186
|
+
return 'fortran' if self._use_fortran else 'python'
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
def has_fortran(self) -> bool:
|
|
190
|
+
"""Check if Fortran backend is available."""
|
|
191
|
+
return HAS_FORTRAN
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
# Global instance - FORTRAN interface required
|
|
195
|
+
supcrt92_water = SUPCRT92Water()
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def water_SUPCRT92(property: Union[str, List[str]],
|
|
199
|
+
T: Union[float, np.ndarray] = 298.15,
|
|
200
|
+
P: Union[float, np.ndarray, str] = 1.0,
|
|
201
|
+
**kwargs) -> Union[float, np.ndarray, Dict[str, Any]]:
|
|
202
|
+
"""
|
|
203
|
+
Calculate water properties using SUPCRT92 model.
|
|
204
|
+
|
|
205
|
+
This function provides the same interface as the original Python
|
|
206
|
+
implementation but with Fortran backend support for high accuracy.
|
|
207
|
+
|
|
208
|
+
Parameters
|
|
209
|
+
----------
|
|
210
|
+
property : str or list of str
|
|
211
|
+
Property or list of properties to calculate
|
|
212
|
+
T : float or array
|
|
213
|
+
Temperature in Kelvin
|
|
214
|
+
P : float, array, or 'Psat'
|
|
215
|
+
Pressure in bar, or 'Psat' for saturation pressure
|
|
216
|
+
**kwargs
|
|
217
|
+
Additional options (e.g., Psat_floor)
|
|
218
|
+
|
|
219
|
+
Returns
|
|
220
|
+
-------
|
|
221
|
+
float, array, or dict
|
|
222
|
+
Calculated properties
|
|
223
|
+
|
|
224
|
+
Examples
|
|
225
|
+
--------
|
|
226
|
+
>>> # Basic usage
|
|
227
|
+
>>> rho = water_SUPCRT92('rho', 298.15, 1.0)
|
|
228
|
+
>>> print(f"Density: {rho:.3f} g/cm³")
|
|
229
|
+
|
|
230
|
+
>>> # Multiple properties
|
|
231
|
+
>>> props = water_SUPCRT92(['rho', 'epsilon'], 298.15, 1.0)
|
|
232
|
+
>>> print(f"ρ = {props['rho']:.3f}, ε = {props['epsilon']:.1f}")
|
|
233
|
+
|
|
234
|
+
>>> # Saturation pressure
|
|
235
|
+
>>> Psat = water_SUPCRT92('Psat', 373.15, 'Psat')
|
|
236
|
+
>>> print(f"Psat at 100°C: {Psat:.2f} bar")
|
|
237
|
+
"""
|
|
238
|
+
return supcrt92_water.calculate(property, T, P, **kwargs)
|