musica 0.12.2__cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.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.
Potentially problematic release.
This version of musica might be problematic. Click here for more details.
- musica/CMakeLists.txt +68 -0
- musica/__init__.py +11 -0
- musica/_musica.cpython-39-aarch64-linux-gnu.so +0 -0
- musica/_version.py +1 -0
- musica/backend.py +41 -0
- musica/binding_common.cpp +33 -0
- musica/binding_common.hpp +7 -0
- musica/carma.cpp +911 -0
- musica/carma.py +1729 -0
- musica/constants.py +3 -0
- musica/cpu_binding.cpp +11 -0
- musica/cuda.cpp +12 -0
- musica/cuda.py +13 -0
- musica/examples/__init__.py +1 -0
- musica/examples/carma_aluminum.py +124 -0
- musica/examples/carma_sulfate.py +246 -0
- musica/examples/examples.py +165 -0
- musica/examples/sulfate_box_model.py +439 -0
- musica/examples/ts1_latin_hypercube.py +245 -0
- musica/gpu_binding.cpp +11 -0
- musica/main.py +89 -0
- musica/mechanism_configuration/__init__.py +1 -0
- musica/mechanism_configuration/aqueous_equilibrium.py +274 -0
- musica/mechanism_configuration/arrhenius.py +307 -0
- musica/mechanism_configuration/branched.py +299 -0
- musica/mechanism_configuration/condensed_phase_arrhenius.py +309 -0
- musica/mechanism_configuration/condensed_phase_photolysis.py +88 -0
- musica/mechanism_configuration/emission.py +71 -0
- musica/mechanism_configuration/first_order_loss.py +174 -0
- musica/mechanism_configuration/henrys_law.py +44 -0
- musica/mechanism_configuration/mechanism_configuration.py +234 -0
- musica/mechanism_configuration/phase.py +47 -0
- musica/mechanism_configuration/photolysis.py +88 -0
- musica/mechanism_configuration/reactions.py +73 -0
- musica/mechanism_configuration/simpol_phase_transfer.py +217 -0
- musica/mechanism_configuration/species.py +91 -0
- musica/mechanism_configuration/surface.py +94 -0
- musica/mechanism_configuration/ternary_chemical_activation.py +352 -0
- musica/mechanism_configuration/troe.py +352 -0
- musica/mechanism_configuration/tunneling.py +250 -0
- musica/mechanism_configuration/user_defined.py +88 -0
- musica/mechanism_configuration/utils.py +10 -0
- musica/mechanism_configuration/wet_deposition.py +52 -0
- musica/mechanism_configuration.cpp +607 -0
- musica/musica.cpp +201 -0
- musica/test/examples/v1/full_configuration/full_configuration.json +466 -0
- musica/test/examples/v1/full_configuration/full_configuration.yaml +295 -0
- musica/test/integration/test_analytical.py +324 -0
- musica/test/integration/test_carma.py +227 -0
- musica/test/integration/test_carma_aluminum.py +12 -0
- musica/test/integration/test_carma_sulfate.py +17 -0
- musica/test/integration/test_chapman.py +139 -0
- musica/test/integration/test_sulfate_box_model.py +34 -0
- musica/test/integration/test_tuvx.py +62 -0
- musica/test/unit/test_parser.py +64 -0
- musica/test/unit/test_serializer.py +69 -0
- musica/test/unit/test_state.py +325 -0
- musica/test/unit/test_util_full_mechanism.py +698 -0
- musica/tools/prepare_build_environment_linux.sh +32 -0
- musica/tools/prepare_build_environment_macos.sh +1 -0
- musica/tools/repair_wheel_gpu.sh +40 -0
- musica/tuvx.cpp +93 -0
- musica/tuvx.py +199 -0
- musica/types.py +407 -0
- musica-0.12.2.dist-info/METADATA +473 -0
- musica-0.12.2.dist-info/RECORD +105 -0
- musica-0.12.2.dist-info/WHEEL +6 -0
- musica-0.12.2.dist-info/entry_points.txt +3 -0
- musica-0.12.2.dist-info/licenses/AUTHORS.md +59 -0
- musica-0.12.2.dist-info/licenses/LICENSE +201 -0
- musica.libs/libaec-34bb4966.so.0.0.8 +0 -0
- musica.libs/libblas-8ed0a6f9.so.3.8.0 +0 -0
- musica.libs/libbrotlicommon-b6e6c8bd.so.1.0.6 +0 -0
- musica.libs/libbrotlidec-5094ef0a.so.1.0.6 +0 -0
- musica.libs/libcom_err-4b53f6ce.so.2.1 +0 -0
- musica.libs/libcrypt-258f54d5.so.1.1.0 +0 -0
- musica.libs/libcrypto-3dc39733.so.1.1.1k +0 -0
- musica.libs/libcurl-37295c13.so.4.5.0 +0 -0
- musica.libs/libdf-9661c601.so.0.0.0 +0 -0
- musica.libs/libgfortran-e1b7dfc8.so.5.0.0 +0 -0
- musica.libs/libgssapi_krb5-fe951f80.so.2.2 +0 -0
- musica.libs/libhdf5-463e48d5.so.103.1.0 +0 -0
- musica.libs/libhdf5_hl-74316838.so.100.1.2 +0 -0
- musica.libs/libidn2-1b2a13b7.so.0.3.6 +0 -0
- musica.libs/libjpeg-ee25248c.so.62.2.0 +0 -0
- musica.libs/libk5crypto-84470bb3.so.3.1 +0 -0
- musica.libs/libkeyutils-fe6e95a9.so.1.6 +0 -0
- musica.libs/libkrb5-26ef5d84.so.3.3 +0 -0
- musica.libs/libkrb5support-875e89dc.so.0.1 +0 -0
- musica.libs/liblapack-8d137073.so.3.8.0 +0 -0
- musica.libs/liblber-2-86b08e65.4.so.2.10.9 +0 -0
- musica.libs/libldap-2-5c1dd279.4.so.2.10.9 +0 -0
- musica.libs/libmfhdf-9c336c5f.so.0.0.0 +0 -0
- musica.libs/libnetcdf-71a067be.so.15.0.1 +0 -0
- musica.libs/libnetcdff-6a455dd4.so.7.0.0 +0 -0
- musica.libs/libnghttp2-3a94c239.so.14.17.0 +0 -0
- musica.libs/libpcre2-8-8701a61e.so.0.7.1 +0 -0
- musica.libs/libpsl-130094ea.so.5.3.1 +0 -0
- musica.libs/libsasl2-076b3c1f.so.3.0.0 +0 -0
- musica.libs/libselinux-5700a1fd.so.1 +0 -0
- musica.libs/libssh-5abd6818.so.4.8.7 +0 -0
- musica.libs/libssl-b6e07dfa.so.1.1.1k +0 -0
- musica.libs/libsz-81b556a2.so.2.0.1 +0 -0
- musica.libs/libtirpc-1fa9018c.so.3.0.0 +0 -0
- musica.libs/libunistring-be03fd41.so.2.1.0 +0 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
2
|
+
from .. import backend
|
|
3
|
+
from .phase import Phase
|
|
4
|
+
from .species import Species
|
|
5
|
+
from .reactions import ReactionComponentSerializer
|
|
6
|
+
from .utils import _add_other_properties
|
|
7
|
+
|
|
8
|
+
_backend = backend.get_backend()
|
|
9
|
+
_Troe = _backend._mechanism_configuration._Troe
|
|
10
|
+
_ReactionComponent = _backend._mechanism_configuration._ReactionComponent
|
|
11
|
+
ReactionType = _backend._mechanism_configuration._ReactionType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Troe:
|
|
15
|
+
"""
|
|
16
|
+
A class representing a Troe rate constant.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
name (str): The name of the Troe rate constant.
|
|
20
|
+
k0_A (float): Pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1].
|
|
21
|
+
k0_B (float): Temperature exponent for the low-pressure limit [unitless].
|
|
22
|
+
k0_C (float): Exponential term for the low-pressure limit [K-1].
|
|
23
|
+
kinf_A (float): Pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1].
|
|
24
|
+
kinf_B (float): Temperature exponent for the high-pressure limit [unitless].
|
|
25
|
+
kinf_C (float): Exponential term for the high-pressure limit [K-1].
|
|
26
|
+
Fc (float): Troe parameter [unitless].
|
|
27
|
+
N (float): Troe parameter [unitless].
|
|
28
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
29
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
30
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
31
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the Troe rate constant.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
name: Optional[str] = None,
|
|
37
|
+
k0_A: Optional[float] = None,
|
|
38
|
+
k0_B: Optional[float] = None,
|
|
39
|
+
k0_C: Optional[float] = None,
|
|
40
|
+
kinf_A: Optional[float] = None,
|
|
41
|
+
kinf_B: Optional[float] = None,
|
|
42
|
+
kinf_C: Optional[float] = None,
|
|
43
|
+
Fc: Optional[float] = None,
|
|
44
|
+
N: Optional[float] = None,
|
|
45
|
+
reactants: Optional[List[Union[Species,
|
|
46
|
+
Tuple[float, Species]]]] = None,
|
|
47
|
+
products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
48
|
+
gas_phase: Optional[Phase] = None,
|
|
49
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
50
|
+
):
|
|
51
|
+
"""
|
|
52
|
+
Initializes the Troe object with the given parameters.
|
|
53
|
+
|
|
54
|
+
k0 = k0_A * exp( k0_C / T ) * ( T / 300.0 )^k0_B
|
|
55
|
+
kinf = kinf_A * exp( kinf_C / T ) * ( T / 300.0 )^kinf_B
|
|
56
|
+
k = k0[M] / ( 1 + k0[M] / kinf ) * Fc^(1 + 1/N*(log10(k0[M]/kinf))^2)^-1
|
|
57
|
+
|
|
58
|
+
where:
|
|
59
|
+
k = rate constant
|
|
60
|
+
k0 = low-pressure limit rate constant
|
|
61
|
+
kinf = high-pressure limit rate constant
|
|
62
|
+
k0_A = pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1]
|
|
63
|
+
k0_B = temperature exponent for the low-pressure limit [unitless]
|
|
64
|
+
k0_C = exponential term for the low-pressure limit [K-1]
|
|
65
|
+
kinf_A = pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1]
|
|
66
|
+
kinf_B = temperature exponent for the high-pressure limit [unitless]
|
|
67
|
+
kinf_C = exponential term for the high-pressure limit [K-1]
|
|
68
|
+
Fc = Troe parameter [unitless]
|
|
69
|
+
N = Troe parameter [unitless]
|
|
70
|
+
T = temperature [K]
|
|
71
|
+
M = concentration of the third body [mol m-3]
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
name (str): The name of the Troe rate constant.
|
|
75
|
+
k0_A (float): Pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1].
|
|
76
|
+
k0_B (float): Temperature exponent for the low-pressure limit [unitless].
|
|
77
|
+
k0_C (float): Exponential term for the low-pressure limit [K-1].
|
|
78
|
+
kinf_A (float): Pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1].
|
|
79
|
+
kinf_B (float): Temperature exponent for the high-pressure limit [unitless].
|
|
80
|
+
kinf_C (float): Exponential term for the high-pressure limit [K-1].
|
|
81
|
+
Fc (float): Troe parameter [unitless].
|
|
82
|
+
N (float): Troe parameter [unitless].
|
|
83
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
84
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
85
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
86
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the Troe rate constant.
|
|
87
|
+
"""
|
|
88
|
+
# Create the internal C++ instance
|
|
89
|
+
self._instance = _Troe()
|
|
90
|
+
|
|
91
|
+
# Set all parameters using properties
|
|
92
|
+
if name is not None:
|
|
93
|
+
self.name = name
|
|
94
|
+
if k0_A is not None:
|
|
95
|
+
self.k0_A = k0_A
|
|
96
|
+
if k0_B is not None:
|
|
97
|
+
self.k0_B = k0_B
|
|
98
|
+
if k0_C is not None:
|
|
99
|
+
self.k0_C = k0_C
|
|
100
|
+
if kinf_A is not None:
|
|
101
|
+
self.kinf_A = kinf_A
|
|
102
|
+
if kinf_B is not None:
|
|
103
|
+
self.kinf_B = kinf_B
|
|
104
|
+
if kinf_C is not None:
|
|
105
|
+
self.kinf_C = kinf_C
|
|
106
|
+
if Fc is not None:
|
|
107
|
+
self.Fc = Fc
|
|
108
|
+
if N is not None:
|
|
109
|
+
self.N = N
|
|
110
|
+
if reactants is not None:
|
|
111
|
+
self.reactants = reactants
|
|
112
|
+
if products is not None:
|
|
113
|
+
self.products = products
|
|
114
|
+
if gas_phase is not None:
|
|
115
|
+
self.gas_phase = gas_phase
|
|
116
|
+
if other_properties is not None:
|
|
117
|
+
self.other_properties = other_properties
|
|
118
|
+
|
|
119
|
+
# Property delegation to self._instance
|
|
120
|
+
@property
|
|
121
|
+
def name(self) -> str:
|
|
122
|
+
"""Get the name of the Troe rate constant."""
|
|
123
|
+
return self._instance.name
|
|
124
|
+
|
|
125
|
+
@name.setter
|
|
126
|
+
def name(self, value: str):
|
|
127
|
+
"""Set the name of the Troe rate constant."""
|
|
128
|
+
self._instance.name = value
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def k0_A(self) -> float:
|
|
132
|
+
"""Get the pre-exponential factor for the low-pressure limit."""
|
|
133
|
+
return self._instance.k0_A
|
|
134
|
+
|
|
135
|
+
@k0_A.setter
|
|
136
|
+
def k0_A(self, value: float):
|
|
137
|
+
"""Set the pre-exponential factor for the low-pressure limit."""
|
|
138
|
+
self._instance.k0_A = value
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def k0_B(self) -> float:
|
|
142
|
+
"""Get the temperature exponent for the low-pressure limit."""
|
|
143
|
+
return self._instance.k0_B
|
|
144
|
+
|
|
145
|
+
@k0_B.setter
|
|
146
|
+
def k0_B(self, value: float):
|
|
147
|
+
"""Set the temperature exponent for the low-pressure limit."""
|
|
148
|
+
self._instance.k0_B = value
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def k0_C(self) -> float:
|
|
152
|
+
"""Get the exponential term for the low-pressure limit."""
|
|
153
|
+
return self._instance.k0_C
|
|
154
|
+
|
|
155
|
+
@k0_C.setter
|
|
156
|
+
def k0_C(self, value: float):
|
|
157
|
+
"""Set the exponential term for the low-pressure limit."""
|
|
158
|
+
self._instance.k0_C = value
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def kinf_A(self) -> float:
|
|
162
|
+
"""Get the pre-exponential factor for the high-pressure limit."""
|
|
163
|
+
return self._instance.kinf_A
|
|
164
|
+
|
|
165
|
+
@kinf_A.setter
|
|
166
|
+
def kinf_A(self, value: float):
|
|
167
|
+
"""Set the pre-exponential factor for the high-pressure limit."""
|
|
168
|
+
self._instance.kinf_A = value
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def kinf_B(self) -> float:
|
|
172
|
+
"""Get the temperature exponent for the high-pressure limit."""
|
|
173
|
+
return self._instance.kinf_B
|
|
174
|
+
|
|
175
|
+
@kinf_B.setter
|
|
176
|
+
def kinf_B(self, value: float):
|
|
177
|
+
"""Set the temperature exponent for the high-pressure limit."""
|
|
178
|
+
self._instance.kinf_B = value
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
def kinf_C(self) -> float:
|
|
182
|
+
"""Get the exponential term for the high-pressure limit."""
|
|
183
|
+
return self._instance.kinf_C
|
|
184
|
+
|
|
185
|
+
@kinf_C.setter
|
|
186
|
+
def kinf_C(self, value: float):
|
|
187
|
+
"""Set the exponential term for the high-pressure limit."""
|
|
188
|
+
self._instance.kinf_C = value
|
|
189
|
+
|
|
190
|
+
@property
|
|
191
|
+
def Fc(self) -> float:
|
|
192
|
+
"""Get the Troe parameter Fc."""
|
|
193
|
+
return self._instance.Fc
|
|
194
|
+
|
|
195
|
+
@Fc.setter
|
|
196
|
+
def Fc(self, value: float):
|
|
197
|
+
"""Set the Troe parameter Fc."""
|
|
198
|
+
self._instance.Fc = value
|
|
199
|
+
|
|
200
|
+
@property
|
|
201
|
+
def N(self) -> float:
|
|
202
|
+
"""Get the Troe parameter N."""
|
|
203
|
+
return self._instance.N
|
|
204
|
+
|
|
205
|
+
@N.setter
|
|
206
|
+
def N(self, value: float):
|
|
207
|
+
"""Set the Troe parameter N."""
|
|
208
|
+
self._instance.N = value
|
|
209
|
+
|
|
210
|
+
@property
|
|
211
|
+
def reactants(self) -> List[Union[Species, Tuple[float, Species]]]:
|
|
212
|
+
"""Get the reactants as Python objects."""
|
|
213
|
+
# Convert from C++ _ReactionComponent objects to Python Species objects
|
|
214
|
+
result = []
|
|
215
|
+
for rc in self._instance.reactants:
|
|
216
|
+
if hasattr(rc, 'coefficient') and rc.coefficient != 1.0:
|
|
217
|
+
# Create a tuple with coefficient and species
|
|
218
|
+
species = Species(name=rc.species_name)
|
|
219
|
+
result.append((rc.coefficient, species))
|
|
220
|
+
else:
|
|
221
|
+
# Just the species
|
|
222
|
+
species = Species(name=rc.species_name)
|
|
223
|
+
result.append(species)
|
|
224
|
+
return result
|
|
225
|
+
|
|
226
|
+
@reactants.setter
|
|
227
|
+
def reactants(self, value: List[Union[Species, Tuple[float, Species]]]):
|
|
228
|
+
"""Set the reactants, converting from Python to C++ objects."""
|
|
229
|
+
cpp_reactants = []
|
|
230
|
+
for r in value:
|
|
231
|
+
if isinstance(r, Species):
|
|
232
|
+
cpp_reactants.append(_ReactionComponent(r.name))
|
|
233
|
+
elif isinstance(r, tuple) and len(r) == 2:
|
|
234
|
+
coefficient, species = r
|
|
235
|
+
cpp_reactants.append(_ReactionComponent(species.name, coefficient))
|
|
236
|
+
else:
|
|
237
|
+
raise ValueError(f"Invalid reactant format: {r}")
|
|
238
|
+
self._instance.reactants = cpp_reactants
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def products(self) -> List[Union[Species, Tuple[float, Species]]]:
|
|
242
|
+
"""Get the products as Python objects."""
|
|
243
|
+
# Convert from C++ _ReactionComponent objects to Python Species objects
|
|
244
|
+
result = []
|
|
245
|
+
for rc in self._instance.products:
|
|
246
|
+
if hasattr(rc, 'coefficient') and rc.coefficient != 1.0:
|
|
247
|
+
# Create a tuple with coefficient and species
|
|
248
|
+
species = Species(name=rc.species_name)
|
|
249
|
+
result.append((rc.coefficient, species))
|
|
250
|
+
else:
|
|
251
|
+
# Just the species
|
|
252
|
+
species = Species(name=rc.species_name)
|
|
253
|
+
result.append(species)
|
|
254
|
+
return result
|
|
255
|
+
|
|
256
|
+
@products.setter
|
|
257
|
+
def products(self, value: List[Union[Species, Tuple[float, Species]]]):
|
|
258
|
+
"""Set the products, converting from Python to C++ objects."""
|
|
259
|
+
cpp_products = []
|
|
260
|
+
for p in value:
|
|
261
|
+
if isinstance(p, Species):
|
|
262
|
+
cpp_products.append(_ReactionComponent(p.name))
|
|
263
|
+
elif isinstance(p, tuple) and len(p) == 2:
|
|
264
|
+
coefficient, species = p
|
|
265
|
+
cpp_products.append(_ReactionComponent(species.name, coefficient))
|
|
266
|
+
else:
|
|
267
|
+
raise ValueError(f"Invalid product format: {p}")
|
|
268
|
+
self._instance.products = cpp_products
|
|
269
|
+
|
|
270
|
+
@property
|
|
271
|
+
def gas_phase(self) -> str:
|
|
272
|
+
"""Get the gas phase name."""
|
|
273
|
+
return self._instance.gas_phase
|
|
274
|
+
|
|
275
|
+
@gas_phase.setter
|
|
276
|
+
def gas_phase(self, value: Union[Phase, str]):
|
|
277
|
+
"""Set the gas phase."""
|
|
278
|
+
if isinstance(value, Phase):
|
|
279
|
+
self._instance.gas_phase = value.name
|
|
280
|
+
elif isinstance(value, str):
|
|
281
|
+
self._instance.gas_phase = value
|
|
282
|
+
else:
|
|
283
|
+
raise ValueError(f"Invalid gas_phase type: {type(value)}")
|
|
284
|
+
|
|
285
|
+
@property
|
|
286
|
+
def other_properties(self) -> Dict[str, Any]:
|
|
287
|
+
"""Get the other properties."""
|
|
288
|
+
return self._instance.other_properties
|
|
289
|
+
|
|
290
|
+
@other_properties.setter
|
|
291
|
+
def other_properties(self, value: Dict[str, Any]):
|
|
292
|
+
"""Set the other properties."""
|
|
293
|
+
self._instance.other_properties = value
|
|
294
|
+
|
|
295
|
+
@property
|
|
296
|
+
def type(self):
|
|
297
|
+
"""Get the reaction type."""
|
|
298
|
+
return ReactionType.Troe
|
|
299
|
+
|
|
300
|
+
def _create_serialize_dict(self, instance) -> Dict:
|
|
301
|
+
"""
|
|
302
|
+
Helper method to create the serialization dictionary.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
instance: The instance to serialize (either self._instance or a _Troe object).
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
Dict: Base serialization dictionary.
|
|
309
|
+
"""
|
|
310
|
+
return {
|
|
311
|
+
"type": "TROE",
|
|
312
|
+
"name": instance.name,
|
|
313
|
+
"k0_A": instance.k0_A,
|
|
314
|
+
"k0_B": instance.k0_B,
|
|
315
|
+
"k0_C": instance.k0_C,
|
|
316
|
+
"kinf_A": instance.kinf_A,
|
|
317
|
+
"kinf_B": instance.kinf_B,
|
|
318
|
+
"kinf_C": instance.kinf_C,
|
|
319
|
+
"Fc": instance.Fc,
|
|
320
|
+
"N": instance.N,
|
|
321
|
+
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
|
|
322
|
+
"products": ReactionComponentSerializer.serialize_list_reaction_components(instance.products),
|
|
323
|
+
"gas phase": instance.gas_phase,
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
def serialize(self) -> Dict:
|
|
327
|
+
"""
|
|
328
|
+
Serialize the Troe object to a dictionary using only Python-visible data.
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
Dict: A dictionary representation of the Troe object.
|
|
332
|
+
"""
|
|
333
|
+
serialize_dict = self._create_serialize_dict(self._instance)
|
|
334
|
+
_add_other_properties(serialize_dict, self.other_properties)
|
|
335
|
+
return serialize_dict
|
|
336
|
+
|
|
337
|
+
@staticmethod
|
|
338
|
+
def serialize_static(instance) -> Dict:
|
|
339
|
+
"""
|
|
340
|
+
Static serialize method for compatibility with C++ _Troe objects.
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
instance: The _Troe instance to serialize.
|
|
344
|
+
|
|
345
|
+
Returns:
|
|
346
|
+
Dict: A dictionary representation of the Troe object.
|
|
347
|
+
"""
|
|
348
|
+
# Create a temporary Troe object to use the helper method
|
|
349
|
+
temp_troe = Troe()
|
|
350
|
+
serialize_dict = temp_troe._create_serialize_dict(instance)
|
|
351
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
352
|
+
return serialize_dict
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
from .utils import _add_other_properties
|
|
2
|
+
from .reactions import ReactionComponentSerializer
|
|
3
|
+
from .species import Species
|
|
4
|
+
from .phase import Phase
|
|
5
|
+
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
6
|
+
from .. import backend
|
|
7
|
+
|
|
8
|
+
_backend = backend.get_backend()
|
|
9
|
+
_Tunneling = _backend._mechanism_configuration._Tunneling
|
|
10
|
+
_ReactionComponent = _backend._mechanism_configuration._ReactionComponent
|
|
11
|
+
ReactionType = _backend._mechanism_configuration._ReactionType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Tunneling:
|
|
15
|
+
"""
|
|
16
|
+
A class representing a quantum tunneling reaction rate constant.
|
|
17
|
+
|
|
18
|
+
k = A * exp( -B / T ) * exp( C / T^3 )
|
|
19
|
+
|
|
20
|
+
where:
|
|
21
|
+
k = rate constant
|
|
22
|
+
A = pre-exponential factor [(mol m-3)^(n-1)s-1]
|
|
23
|
+
B = tunneling parameter [K^-1]
|
|
24
|
+
C = tunneling parameter [K^-3]
|
|
25
|
+
T = temperature [K]
|
|
26
|
+
n = number of reactants
|
|
27
|
+
|
|
28
|
+
Attributes:
|
|
29
|
+
name (str): The name of the tunneling reaction rate constant.
|
|
30
|
+
A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1].
|
|
31
|
+
B (float): Tunneling parameter [K^-1].
|
|
32
|
+
C (float): Tunneling parameter [K^-3].
|
|
33
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
34
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
35
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
36
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the tunneling reaction rate constant.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
name: Optional[str] = None,
|
|
42
|
+
A: Optional[float] = None,
|
|
43
|
+
B: Optional[float] = None,
|
|
44
|
+
C: Optional[float] = None,
|
|
45
|
+
reactants: Optional[List[Union[Species,
|
|
46
|
+
Tuple[float, Species]]]] = None,
|
|
47
|
+
products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
48
|
+
gas_phase: Optional[Phase] = None,
|
|
49
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
50
|
+
):
|
|
51
|
+
"""
|
|
52
|
+
Initializes the Tunneling object with the given parameters.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
name (str): The name of the tunneling reaction rate constant.
|
|
56
|
+
A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1].
|
|
57
|
+
B (float): Tunneling parameter [K^-1].
|
|
58
|
+
C (float): Tunneling parameter [K^-3].
|
|
59
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
60
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
61
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
62
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the tunneling reaction rate constant.
|
|
63
|
+
"""
|
|
64
|
+
# Create the internal C++ instance
|
|
65
|
+
self._instance = _Tunneling()
|
|
66
|
+
|
|
67
|
+
# Set all parameters
|
|
68
|
+
if name is not None:
|
|
69
|
+
self.name = name
|
|
70
|
+
if A is not None:
|
|
71
|
+
self.A = A
|
|
72
|
+
if B is not None:
|
|
73
|
+
self.B = B
|
|
74
|
+
if C is not None:
|
|
75
|
+
self.C = C
|
|
76
|
+
if reactants is not None:
|
|
77
|
+
self.reactants = reactants
|
|
78
|
+
if products is not None:
|
|
79
|
+
self.products = products
|
|
80
|
+
if gas_phase is not None:
|
|
81
|
+
self.gas_phase = gas_phase
|
|
82
|
+
if other_properties is not None:
|
|
83
|
+
self.other_properties = other_properties
|
|
84
|
+
|
|
85
|
+
# Property delegation to self._instance
|
|
86
|
+
@property
|
|
87
|
+
def name(self) -> str:
|
|
88
|
+
"""Get the name of the tunneling reaction rate constant."""
|
|
89
|
+
return self._instance.name
|
|
90
|
+
|
|
91
|
+
@name.setter
|
|
92
|
+
def name(self, value: str):
|
|
93
|
+
"""Set the name of the tunneling reaction rate constant."""
|
|
94
|
+
self._instance.name = value
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def A(self) -> float:
|
|
98
|
+
"""Get the pre-exponential factor."""
|
|
99
|
+
return self._instance.A
|
|
100
|
+
|
|
101
|
+
@A.setter
|
|
102
|
+
def A(self, value: float):
|
|
103
|
+
"""Set the pre-exponential factor."""
|
|
104
|
+
self._instance.A = value
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def B(self) -> float:
|
|
108
|
+
"""Get the tunneling parameter B."""
|
|
109
|
+
return self._instance.B
|
|
110
|
+
|
|
111
|
+
@B.setter
|
|
112
|
+
def B(self, value: float):
|
|
113
|
+
"""Set the tunneling parameter B."""
|
|
114
|
+
self._instance.B = value
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def C(self) -> float:
|
|
118
|
+
"""Get the tunneling parameter C."""
|
|
119
|
+
return self._instance.C
|
|
120
|
+
|
|
121
|
+
@C.setter
|
|
122
|
+
def C(self, value: float):
|
|
123
|
+
"""Set the tunneling parameter C."""
|
|
124
|
+
self._instance.C = value
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def reactants(self) -> List[Union[Species, Tuple[float, Species]]]:
|
|
128
|
+
"""Get the reactants as Python objects."""
|
|
129
|
+
# Convert from C++ _ReactionComponent objects to Python Species objects
|
|
130
|
+
result = []
|
|
131
|
+
for rc in self._instance.reactants:
|
|
132
|
+
if hasattr(rc, 'coefficient') and rc.coefficient != 1.0:
|
|
133
|
+
# Create a tuple with coefficient and species
|
|
134
|
+
species = Species(name=rc.species_name)
|
|
135
|
+
result.append((rc.coefficient, species))
|
|
136
|
+
else:
|
|
137
|
+
# Just the species
|
|
138
|
+
species = Species(name=rc.species_name)
|
|
139
|
+
result.append(species)
|
|
140
|
+
return result
|
|
141
|
+
|
|
142
|
+
@reactants.setter
|
|
143
|
+
def reactants(self, value: List[Union[Species, Tuple[float, Species]]]):
|
|
144
|
+
"""Set the reactants, converting from Python to C++ objects."""
|
|
145
|
+
cpp_reactants = []
|
|
146
|
+
for r in value:
|
|
147
|
+
if isinstance(r, Species):
|
|
148
|
+
cpp_reactants.append(_ReactionComponent(r.name))
|
|
149
|
+
elif isinstance(r, tuple) and len(r) == 2:
|
|
150
|
+
coefficient, species = r
|
|
151
|
+
cpp_reactants.append(_ReactionComponent(species.name, coefficient))
|
|
152
|
+
else:
|
|
153
|
+
raise ValueError(f"Invalid reactant format: {r}")
|
|
154
|
+
self._instance.reactants = cpp_reactants
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def products(self) -> List[Union[Species, Tuple[float, Species]]]:
|
|
158
|
+
"""Get the products as Python objects."""
|
|
159
|
+
# Convert from C++ _ReactionComponent objects to Python Species objects
|
|
160
|
+
result = []
|
|
161
|
+
for rc in self._instance.products:
|
|
162
|
+
if hasattr(rc, 'coefficient') and rc.coefficient != 1.0:
|
|
163
|
+
# Create a tuple with coefficient and species
|
|
164
|
+
species = Species(name=rc.species_name)
|
|
165
|
+
result.append((rc.coefficient, species))
|
|
166
|
+
else:
|
|
167
|
+
# Just the species
|
|
168
|
+
species = Species(name=rc.species_name)
|
|
169
|
+
result.append(species)
|
|
170
|
+
return result
|
|
171
|
+
|
|
172
|
+
@products.setter
|
|
173
|
+
def products(self, value: List[Union[Species, Tuple[float, Species]]]):
|
|
174
|
+
"""Set the products, converting from Python to C++ objects."""
|
|
175
|
+
cpp_products = []
|
|
176
|
+
for p in value:
|
|
177
|
+
if isinstance(p, Species):
|
|
178
|
+
cpp_products.append(_ReactionComponent(p.name))
|
|
179
|
+
elif isinstance(p, tuple) and len(p) == 2:
|
|
180
|
+
coefficient, species = p
|
|
181
|
+
cpp_products.append(_ReactionComponent(species.name, coefficient))
|
|
182
|
+
else:
|
|
183
|
+
raise ValueError(f"Invalid product format: {p}")
|
|
184
|
+
self._instance.products = cpp_products
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def gas_phase(self) -> str:
|
|
188
|
+
"""Get the gas phase name."""
|
|
189
|
+
return self._instance.gas_phase
|
|
190
|
+
|
|
191
|
+
@gas_phase.setter
|
|
192
|
+
def gas_phase(self, value: Union[Phase, str]):
|
|
193
|
+
"""Set the gas phase."""
|
|
194
|
+
if isinstance(value, Phase):
|
|
195
|
+
self._instance.gas_phase = value.name
|
|
196
|
+
elif isinstance(value, str):
|
|
197
|
+
self._instance.gas_phase = value
|
|
198
|
+
else:
|
|
199
|
+
raise ValueError(f"Invalid gas_phase type: {type(value)}")
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def other_properties(self) -> Dict[str, Any]:
|
|
203
|
+
"""Get the other properties."""
|
|
204
|
+
return self._instance.other_properties
|
|
205
|
+
|
|
206
|
+
@other_properties.setter
|
|
207
|
+
def other_properties(self, value: Dict[str, Any]):
|
|
208
|
+
"""Set the other properties."""
|
|
209
|
+
self._instance.other_properties = value
|
|
210
|
+
|
|
211
|
+
@property
|
|
212
|
+
def type(self):
|
|
213
|
+
"""Get the reaction type."""
|
|
214
|
+
return ReactionType.Tunneling
|
|
215
|
+
|
|
216
|
+
def serialize(self) -> Dict:
|
|
217
|
+
"""
|
|
218
|
+
Serialize the Tunneling object to a dictionary using only Python-visible data.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
Dict: A dictionary representation of the Tunneling object.
|
|
222
|
+
"""
|
|
223
|
+
serialize_dict = {
|
|
224
|
+
"type": "TUNNELING",
|
|
225
|
+
"name": self._instance.name,
|
|
226
|
+
"A": self._instance.A,
|
|
227
|
+
"B": self._instance.B,
|
|
228
|
+
"C": self._instance.C,
|
|
229
|
+
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(self._instance.reactants),
|
|
230
|
+
"products": ReactionComponentSerializer.serialize_list_reaction_components(self._instance.products),
|
|
231
|
+
"gas phase": self._instance.gas_phase,
|
|
232
|
+
}
|
|
233
|
+
_add_other_properties(serialize_dict, self.other_properties)
|
|
234
|
+
return serialize_dict
|
|
235
|
+
|
|
236
|
+
@staticmethod
|
|
237
|
+
def serialize_static(instance) -> Dict:
|
|
238
|
+
"""
|
|
239
|
+
Static serialize method for compatibility with C++ _Tunneling objects.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
instance: The _Tunneling instance to serialize.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
Dict: A dictionary representation of the Tunneling object.
|
|
246
|
+
"""
|
|
247
|
+
# Create a temporary Tunneling object and use its serialize method
|
|
248
|
+
temp_tunneling = Tunneling()
|
|
249
|
+
temp_tunneling._instance = instance
|
|
250
|
+
return temp_tunneling.serialize()
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
2
|
+
from .. import backend
|
|
3
|
+
from .phase import Phase
|
|
4
|
+
from .species import Species
|
|
5
|
+
from .reactions import ReactionComponentSerializer
|
|
6
|
+
from .utils import _add_other_properties
|
|
7
|
+
|
|
8
|
+
_backend = backend.get_backend()
|
|
9
|
+
_UserDefined = _backend._mechanism_configuration._UserDefined
|
|
10
|
+
_ReactionComponent = _backend._mechanism_configuration._ReactionComponent
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class UserDefined(_UserDefined):
|
|
14
|
+
"""
|
|
15
|
+
A class representing a user-defined reaction rate constant.
|
|
16
|
+
|
|
17
|
+
Attributes:
|
|
18
|
+
name (str): The name of the photolysis reaction rate constant.
|
|
19
|
+
scaling_factor (float): The scaling factor for the photolysis rate constant.
|
|
20
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
21
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
22
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
23
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
name: Optional[str] = None,
|
|
29
|
+
scaling_factor: Optional[float] = None,
|
|
30
|
+
reactants: Optional[List[Union[Species,
|
|
31
|
+
Tuple[float, Species]]]] = None,
|
|
32
|
+
products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
33
|
+
gas_phase: Optional[Phase] = None,
|
|
34
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
35
|
+
):
|
|
36
|
+
"""
|
|
37
|
+
Initializes the UserDefined object with the given parameters.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
name (str): The name of the photolysis reaction rate constant.
|
|
41
|
+
scaling_factor (float): The scaling factor for the photolysis rate constant.
|
|
42
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
43
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
44
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
45
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant.
|
|
46
|
+
"""
|
|
47
|
+
super().__init__()
|
|
48
|
+
self.name = name if name is not None else self.name
|
|
49
|
+
self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
|
|
50
|
+
self.reactants = (
|
|
51
|
+
[
|
|
52
|
+
(
|
|
53
|
+
_ReactionComponent(r.name)
|
|
54
|
+
if isinstance(r, Species)
|
|
55
|
+
else _ReactionComponent(r[1].name, r[0])
|
|
56
|
+
)
|
|
57
|
+
for r in reactants
|
|
58
|
+
]
|
|
59
|
+
if reactants is not None
|
|
60
|
+
else self.reactants
|
|
61
|
+
)
|
|
62
|
+
self.products = (
|
|
63
|
+
[
|
|
64
|
+
(
|
|
65
|
+
_ReactionComponent(p.name)
|
|
66
|
+
if isinstance(p, Species)
|
|
67
|
+
else _ReactionComponent(p[1].name, p[0])
|
|
68
|
+
)
|
|
69
|
+
for p in products
|
|
70
|
+
]
|
|
71
|
+
if products is not None
|
|
72
|
+
else self.products
|
|
73
|
+
)
|
|
74
|
+
self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
|
|
75
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
76
|
+
|
|
77
|
+
@staticmethod
|
|
78
|
+
def serialize(instance) -> Dict:
|
|
79
|
+
serialize_dict = {
|
|
80
|
+
"type": "USER_DEFINED",
|
|
81
|
+
"name": instance.name,
|
|
82
|
+
"scaling factor": instance.scaling_factor,
|
|
83
|
+
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
|
|
84
|
+
"products": ReactionComponentSerializer.serialize_list_reaction_components(instance.products),
|
|
85
|
+
"gas phase": instance.gas_phase,
|
|
86
|
+
}
|
|
87
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
88
|
+
return serialize_dict
|