musica 0.12.2__cp313-cp313-win_amd64.whl → 0.13.0__cp313-cp313-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.

Potentially problematic release.


This version of musica might be problematic. Click here for more details.

Files changed (63) hide show
  1. musica/CMakeLists.txt +4 -0
  2. musica/_musica.cp313-win_amd64.pyd +0 -0
  3. musica/_version.py +1 -1
  4. musica/binding_common.cpp +6 -9
  5. musica/binding_common.hpp +17 -1
  6. musica/grid.cpp +206 -0
  7. musica/grid.py +98 -0
  8. musica/grid_map.cpp +117 -0
  9. musica/grid_map.py +167 -0
  10. musica/mechanism_configuration/__init__.py +18 -1
  11. musica/mechanism_configuration/ancillary.py +6 -0
  12. musica/mechanism_configuration/arrhenius.py +111 -269
  13. musica/mechanism_configuration/branched.py +116 -275
  14. musica/mechanism_configuration/emission.py +63 -52
  15. musica/mechanism_configuration/first_order_loss.py +73 -157
  16. musica/mechanism_configuration/mechanism.py +93 -0
  17. musica/mechanism_configuration/phase.py +44 -33
  18. musica/mechanism_configuration/phase_species.py +58 -0
  19. musica/mechanism_configuration/photolysis.py +77 -67
  20. musica/mechanism_configuration/reaction_component.py +54 -0
  21. musica/mechanism_configuration/reactions.py +17 -58
  22. musica/mechanism_configuration/species.py +45 -71
  23. musica/mechanism_configuration/surface.py +78 -74
  24. musica/mechanism_configuration/taylor_series.py +136 -0
  25. musica/mechanism_configuration/ternary_chemical_activation.py +138 -330
  26. musica/mechanism_configuration/troe.py +138 -330
  27. musica/mechanism_configuration/tunneling.py +105 -229
  28. musica/mechanism_configuration/user_defined.py +79 -68
  29. musica/mechanism_configuration.cpp +54 -162
  30. musica/musica.cpp +2 -5
  31. musica/profile.cpp +294 -0
  32. musica/profile.py +93 -0
  33. musica/profile_map.cpp +117 -0
  34. musica/profile_map.py +167 -0
  35. musica/test/examples/v1/full_configuration/full_configuration.json +91 -233
  36. musica/test/examples/v1/full_configuration/full_configuration.yaml +191 -290
  37. musica/test/integration/test_chapman.py +2 -2
  38. musica/test/integration/test_tuvx.py +72 -15
  39. musica/test/unit/test_grid.py +137 -0
  40. musica/test/unit/test_grid_map.py +126 -0
  41. musica/test/unit/test_parser.py +10 -10
  42. musica/test/unit/test_profile.py +169 -0
  43. musica/test/unit/test_profile_map.py +137 -0
  44. musica/test/unit/test_serializer.py +17 -16
  45. musica/test/unit/test_state.py +17 -4
  46. musica/test/unit/test_util_full_mechanism.py +78 -298
  47. musica/tuvx.cpp +94 -15
  48. musica/tuvx.py +92 -22
  49. musica/types.py +13 -5
  50. {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/METADATA +14 -14
  51. musica-0.13.0.dist-info/RECORD +80 -0
  52. musica/mechanism_configuration/aqueous_equilibrium.py +0 -274
  53. musica/mechanism_configuration/condensed_phase_arrhenius.py +0 -309
  54. musica/mechanism_configuration/condensed_phase_photolysis.py +0 -88
  55. musica/mechanism_configuration/henrys_law.py +0 -44
  56. musica/mechanism_configuration/mechanism_configuration.py +0 -234
  57. musica/mechanism_configuration/simpol_phase_transfer.py +0 -217
  58. musica/mechanism_configuration/wet_deposition.py +0 -52
  59. musica-0.12.2.dist-info/RECORD +0 -70
  60. {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/WHEEL +0 -0
  61. {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/entry_points.txt +0 -0
  62. {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/licenses/AUTHORS.md +0 -0
  63. {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/licenses/LICENSE +0 -0
@@ -2,20 +2,61 @@ from typing import Optional, Any, Dict, List, Union, Tuple
2
2
  from .. import backend
3
3
  from .phase import Phase
4
4
  from .species import Species
5
- from .reactions import ReactionComponentSerializer
6
- from .utils import _add_other_properties
5
+ from .utils import _add_other_properties, _remove_empty_keys
6
+ from .reaction_component import ReactionComponent
7
+ from .ancillary import ReactionType
7
8
 
8
9
  _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:
10
+ Troe = _backend._mechanism_configuration._Troe
11
+
12
+ original_init = Troe.__init__
13
+
14
+
15
+ @property
16
+ def type(self):
17
+ return ReactionType.Troe
18
+
19
+
20
+ def __init__(
21
+ self,
22
+ name: Optional[str] = None,
23
+ k0_A: Optional[float] = None,
24
+ k0_B: Optional[float] = None,
25
+ k0_C: Optional[float] = None,
26
+ kinf_A: Optional[float] = None,
27
+ kinf_B: Optional[float] = None,
28
+ kinf_C: Optional[float] = None,
29
+ Fc: Optional[float] = None,
30
+ N: Optional[float] = None,
31
+ reactants: Optional[List[Union[Species,
32
+ Tuple[float, Species]]]] = None,
33
+ products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
34
+ gas_phase: Optional[Phase] = None,
35
+ other_properties: Optional[Dict[str, Any]] = None,
36
+ ):
15
37
  """
16
- A class representing a Troe rate constant.
17
-
18
- Attributes:
38
+ Initializes the Troe object with the given parameters.
39
+
40
+ k0 = k0_A * exp( k0_C / T ) * ( T / 300.0 )^k0_B
41
+ kinf = kinf_A * exp( kinf_C / T ) * ( T / 300.0 )^kinf_B
42
+ k = k0[M] / ( 1 + k0[M] / kinf ) * Fc^(1 + 1/N*(log10(k0[M]/kinf))^2)^-1
43
+
44
+ where:
45
+ k = rate constant
46
+ k0 = low-pressure limit rate constant
47
+ kinf = high-pressure limit rate constant
48
+ k0_A = pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1]
49
+ k0_B = temperature exponent for the low-pressure limit [unitless]
50
+ k0_C = exponential term for the low-pressure limit [K-1]
51
+ kinf_A = pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1]
52
+ kinf_B = temperature exponent for the high-pressure limit [unitless]
53
+ kinf_C = exponential term for the high-pressure limit [K-1]
54
+ Fc = Troe parameter [unitless]
55
+ N = Troe parameter [unitless]
56
+ T = temperature [K]
57
+ M = concentration of the third body [mol m-3]
58
+
59
+ Args:
19
60
  name (str): The name of the Troe rate constant.
20
61
  k0_A (float): Pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1].
21
62
  k0_B (float): Temperature exponent for the low-pressure limit [unitless].
@@ -30,323 +71,90 @@ class Troe:
30
71
  gas_phase (Phase): The gas phase in which the reaction occurs.
31
72
  other_properties (Dict[str, Any]): A dictionary of other properties of the Troe rate constant.
32
73
  """
74
+ original_init(self)
75
+
76
+ self.name = name if name is not None else self.name
77
+ self.k0_A = k0_A if k0_A is not None else self.k0_A
78
+ self.k0_B = k0_B if k0_B is not None else self.k0_B
79
+ self.k0_C = k0_C if k0_C is not None else self.k0_C
80
+ self.kinf_A = kinf_A if kinf_A is not None else self.kinf_A
81
+ self.kinf_B = kinf_B if kinf_B is not None else self.kinf_B
82
+ self.kinf_C = kinf_C if kinf_C is not None else self.kinf_C
83
+ self.Fc = Fc if Fc is not None else self.Fc
84
+ self.N = N if N is not None else self.N
85
+ self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
86
+ self.other_properties = other_properties if other_properties is not None else self.other_properties
87
+ self.reactants = (
88
+ [
89
+ (
90
+ ReactionComponent(r.name)
91
+ if isinstance(r, Species)
92
+ else ReactionComponent(r[1].name, r[0])
93
+ )
94
+ for r in reactants
95
+ ]
96
+ if reactants is not None
97
+ else self.reactants
98
+ )
99
+ self.products = (
100
+ [
101
+ (
102
+ ReactionComponent(p.name)
103
+ if isinstance(p, Species)
104
+ else ReactionComponent(p[1].name, p[0])
105
+ )
106
+ for p in products
107
+ ]
108
+ if products is not None
109
+ else self.products
110
+ )
111
+
112
+
113
+ def serialize(self) -> Dict:
114
+ """
115
+ Serialize the Troe object to a dictionary using only Python-visible data.
33
116
 
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
117
+ Returns:
118
+ Dict: A dictionary representation of the Troe object.
119
+ """
120
+ serialize_dict = {
121
+ "type": "TROE",
122
+ "name": self.name,
123
+ "k0_A": self.k0_A,
124
+ "k0_B": self.k0_B,
125
+ "k0_C": self.k0_C,
126
+ "kinf_A": self.kinf_A,
127
+ "kinf_B": self.kinf_B,
128
+ "kinf_C": self.kinf_C,
129
+ "Fc": self.Fc,
130
+ "N": self.N,
131
+ "reactants": [r.serialize() for r in self.reactants],
132
+ "products": [r.serialize() for r in self.products],
133
+ "gas phase": self.gas_phase,
134
+ }
135
+ _add_other_properties(serialize_dict, self.other_properties)
136
+ return _remove_empty_keys(serialize_dict)
137
+
138
+
139
+ Troe.__doc__ = """
140
+ A class representing a Troe rate constant.
141
+
142
+ Attributes:
143
+ name (str): The name of the Troe rate constant.
144
+ k0_A (float): Pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1].
145
+ k0_B (float): Temperature exponent for the low-pressure limit [unitless].
146
+ k0_C (float): Exponential term for the low-pressure limit [K-1].
147
+ kinf_A (float): Pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1].
148
+ kinf_B (float): Temperature exponent for the high-pressure limit [unitless].
149
+ kinf_C (float): Exponential term for the high-pressure limit [K-1].
150
+ Fc (float): Troe parameter [unitless].
151
+ N (float): Troe parameter [unitless].
152
+ reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
153
+ products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
154
+ gas_phase (Phase): The gas phase in which the reaction occurs.
155
+ other_properties (Dict[str, Any]): A dictionary of other properties of the Troe rate constant.
156
+ """
157
+
158
+ Troe.__init__ = __init__
159
+ Troe.serialize = serialize
160
+ Troe.type = type