musica 0.12.2__cp310-cp310-win32.whl → 0.13.0__cp310-cp310-win32.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.cp310-win32.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,18 +2,120 @@ 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
7
6
  from ..constants import BOLTZMANN
7
+ from .reaction_component import ReactionComponent
8
+ from .ancillary import ReactionType
8
9
 
9
10
  _backend = backend.get_backend()
10
- _Arrhenius = _backend._mechanism_configuration._Arrhenius
11
- _ReactionComponent = _backend._mechanism_configuration._ReactionComponent
12
- ReactionType = _backend._mechanism_configuration._ReactionType
11
+ Arrhenius = _backend._mechanism_configuration._Arrhenius
12
+
13
+ original_init = Arrhenius.__init__
14
+
15
+
16
+ @property
17
+ def type(self):
18
+ """Get the reaction type."""
19
+ return ReactionType.Arrhenius
20
+
21
+
22
+ def __init__(
23
+ self,
24
+ name: Optional[str] = None,
25
+ A: Optional[float] = None,
26
+ B: Optional[float] = None,
27
+ C: Optional[float] = None,
28
+ Ea: Optional[float] = None,
29
+ D: Optional[float] = None,
30
+ E: 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
+ ):
37
+ """
38
+ Initializes the Arrhenius object with the given parameters.
13
39
 
40
+ Args:
41
+ name (str): The name of the Arrhenius rate constant.
42
+ A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1] where n is the number of reactants.
43
+ B (float): Temperature exponent [unitless].
44
+ C (float): Exponential term [K-1].
45
+ Ea (float): Activation energy [J molecule-1].
46
+ D (float): Reference Temperature [K].
47
+ E (float): Pressure scaling term [Pa-1].
48
+ reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
49
+ products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
50
+ gas_phase (Phase): The gas phase in which the reaction occurs.
51
+ other_properties (Dict[str, Any]): A dictionary of other properties of the Arrhenius rate constant.
52
+ """
53
+ original_init(self)
54
+
55
+ # Validate mutually exclusive parameters
56
+ if C is not None and Ea is not None:
57
+ raise ValueError("Cannot specify both C and Ea.")
58
+ if Ea is not None:
59
+ C = -Ea / BOLTZMANN
60
+
61
+ self.name = name if name is not None else self.name
62
+ self.A = A if A is not None else self.A
63
+ self.B = B if B is not None else self.B
64
+ self.C = C if C is not None else self.C
65
+ self.D = D if D is not None else self.D
66
+ self.E = E if E is not None else self.E
67
+ self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
68
+ self.other_properties = other_properties if other_properties is not None else self.other_properties
69
+ self.reactants = (
70
+ [
71
+ (
72
+ ReactionComponent(r.name)
73
+ if isinstance(r, Species)
74
+ else ReactionComponent(r[1].name, r[0])
75
+ )
76
+ for r in reactants
77
+ ]
78
+ if reactants is not None
79
+ else self.reactants
80
+ )
81
+ self.products = (
82
+ [
83
+ (
84
+ ReactionComponent(p.name)
85
+ if isinstance(p, Species)
86
+ else ReactionComponent(p[1].name, p[0])
87
+ )
88
+ for p in products
89
+ ]
90
+ if products is not None
91
+ else self.products
92
+ )
93
+
94
+
95
+ def serialize(self) -> Dict:
96
+ """
97
+ Serialize the Arrhenius object to a dictionary using only Python-visible data.
14
98
 
15
- class Arrhenius:
99
+ Returns:
100
+ Dict: A dictionary representation of the Arrhenius object.
16
101
  """
102
+ serialize_dict = {
103
+ "type": "ARRHENIUS",
104
+ "name": self.name,
105
+ "A": self.A,
106
+ "B": self.B,
107
+ "C": self.C,
108
+ "D": self.D,
109
+ "E": self.E,
110
+ "reactants": [r.serialize() for r in self.reactants],
111
+ "products": [r.serialize() for r in self.products],
112
+ "gas phase": self.gas_phase,
113
+ }
114
+ _add_other_properties(serialize_dict, self.other_properties)
115
+ return _remove_empty_keys(serialize_dict)
116
+
117
+
118
+ Arrhenius.__doc__ = """
17
119
  A class representing an Arrhenius rate constant.
18
120
 
19
121
  k = A * exp( C / T ) * ( T / D )^B * exp( 1 - E * P )
@@ -42,266 +144,6 @@ class Arrhenius:
42
144
  other_properties (Dict[str, Any]): A dictionary of other properties of the Arrhenius rate constant.
43
145
  """
44
146
 
45
- def __init__(
46
- self,
47
- name: Optional[str] = None,
48
- A: Optional[float] = None,
49
- B: Optional[float] = None,
50
- C: Optional[float] = None,
51
- Ea: Optional[float] = None,
52
- D: Optional[float] = None,
53
- E: Optional[float] = None,
54
- reactants: Optional[List[Union[Species,
55
- Tuple[float, Species]]]] = None,
56
- products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
57
- gas_phase: Optional[Phase] = None,
58
- other_properties: Optional[Dict[str, Any]] = None,
59
- ):
60
- """
61
- Initializes the Arrhenius object with the given parameters.
62
-
63
- Args:
64
- name (str): The name of the Arrhenius rate constant.
65
- A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1] where n is the number of reactants.
66
- B (float): Temperature exponent [unitless].
67
- C (float): Exponential term [K-1].
68
- Ea (float): Activation energy [J molecule-1].
69
- D (float): Reference Temperature [K].
70
- E (float): Pressure scaling term [Pa-1].
71
- reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
72
- products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
73
- gas_phase (Phase): The gas phase in which the reaction occurs.
74
- other_properties (Dict[str, Any]): A dictionary of other properties of the Arrhenius rate constant.
75
- """
76
- # Create the internal C++ instance
77
- self._instance = _Arrhenius()
78
-
79
- # Validate mutually exclusive parameters
80
- if C is not None and Ea is not None:
81
- raise ValueError("Cannot specify both C and Ea.")
82
-
83
- # Set all parameters
84
- if name is not None:
85
- self.name = name
86
- if A is not None:
87
- self.A = A
88
- if B is not None:
89
- self.B = B
90
- if Ea is not None:
91
- self.C = -Ea / BOLTZMANN
92
- elif C is not None:
93
- self.C = C
94
- if D is not None:
95
- self.D = D
96
- if E is not None:
97
- self.E = E
98
- if reactants is not None:
99
- self.reactants = reactants
100
- if products is not None:
101
- self.products = products
102
- if gas_phase is not None:
103
- self.gas_phase = gas_phase
104
- if other_properties is not None:
105
- self.other_properties = other_properties
106
-
107
- # Property delegation to self._instance
108
- @property
109
- def name(self) -> str:
110
- """Get the name of the Arrhenius rate constant."""
111
- return self._instance.name
112
-
113
- @name.setter
114
- def name(self, value: str):
115
- """Set the name of the Arrhenius rate constant."""
116
- self._instance.name = value
117
-
118
- @property
119
- def A(self) -> float:
120
- """Get the pre-exponential factor."""
121
- return self._instance.A
122
-
123
- @A.setter
124
- def A(self, value: float):
125
- """Set the pre-exponential factor."""
126
- self._instance.A = value
127
-
128
- @property
129
- def B(self) -> float:
130
- """Get the temperature exponent."""
131
- return self._instance.B
132
-
133
- @B.setter
134
- def B(self, value: float):
135
- """Set the temperature exponent."""
136
- self._instance.B = value
137
-
138
- @property
139
- def C(self) -> float:
140
- """Get the exponential term."""
141
- return self._instance.C
142
-
143
- @C.setter
144
- def C(self, value: float):
145
- """Set the exponential term."""
146
- self._instance.C = value
147
-
148
- @property
149
- def D(self) -> float:
150
- """Get the reference temperature."""
151
- return self._instance.D
152
-
153
- @D.setter
154
- def D(self, value: float):
155
- """Set the reference temperature."""
156
- self._instance.D = value
157
-
158
- @property
159
- def E(self) -> float:
160
- """Get the pressure scaling term."""
161
- return self._instance.E
162
-
163
- @E.setter
164
- def E(self, value: float):
165
- """Set the pressure scaling term."""
166
- self._instance.E = value
167
-
168
- @property
169
- def reactants(self) -> List[Union[Species, Tuple[float, Species]]]:
170
- """Get the reactants as Python objects."""
171
- # Convert from C++ _ReactionComponent objects to Python Species objects
172
- result = []
173
- for rc in self._instance.reactants:
174
- if hasattr(rc, 'coefficient') and rc.coefficient != 1.0:
175
- # Create a tuple with coefficient and species
176
- species = Species(name=rc.species_name)
177
- result.append((rc.coefficient, species))
178
- else:
179
- # Just the species
180
- species = Species(name=rc.species_name)
181
- result.append(species)
182
- return result
183
-
184
- @reactants.setter
185
- def reactants(self, value: List[Union[Species, Tuple[float, Species]]]):
186
- """Set the reactants, converting from Python to C++ objects."""
187
- cpp_reactants = []
188
- for r in value:
189
- if isinstance(r, Species):
190
- cpp_reactants.append(_ReactionComponent(r.name))
191
- elif isinstance(r, tuple) and len(r) == 2:
192
- coefficient, species = r
193
- cpp_reactants.append(_ReactionComponent(species.name, coefficient))
194
- else:
195
- raise ValueError(f"Invalid reactant format: {r}")
196
- self._instance.reactants = cpp_reactants
197
-
198
- @property
199
- def products(self) -> List[Union[Species, Tuple[float, Species]]]:
200
- """Get the products as Python objects."""
201
- # Convert from C++ _ReactionComponent objects to Python Species objects
202
- result = []
203
- for rc in self._instance.products:
204
- if hasattr(rc, 'coefficient') and rc.coefficient != 1.0:
205
- # Create a tuple with coefficient and species
206
- species = Species(name=rc.species_name)
207
- result.append((rc.coefficient, species))
208
- else:
209
- # Just the species
210
- species = Species(name=rc.species_name)
211
- result.append(species)
212
- return result
213
-
214
- @products.setter
215
- def products(self, value: List[Union[Species, Tuple[float, Species]]]):
216
- """Set the products, converting from Python to C++ objects."""
217
- cpp_products = []
218
- for p in value:
219
- if isinstance(p, Species):
220
- cpp_products.append(_ReactionComponent(p.name))
221
- elif isinstance(p, tuple) and len(p) == 2:
222
- coefficient, species = p
223
- cpp_products.append(_ReactionComponent(species.name, coefficient))
224
- else:
225
- raise ValueError(f"Invalid product format: {p}")
226
- self._instance.products = cpp_products
227
-
228
- @property
229
- def gas_phase(self) -> str:
230
- """Get the gas phase name."""
231
- return self._instance.gas_phase
232
-
233
- @gas_phase.setter
234
- def gas_phase(self, value: Union[Phase, str]):
235
- """Set the gas phase."""
236
- if isinstance(value, Phase):
237
- self._instance.gas_phase = value.name
238
- elif isinstance(value, str):
239
- self._instance.gas_phase = value
240
- else:
241
- raise ValueError(f"Invalid gas_phase type: {type(value)}")
242
-
243
- @property
244
- def other_properties(self) -> Dict[str, Any]:
245
- """Get the other properties."""
246
- return self._instance.other_properties
247
-
248
- @other_properties.setter
249
- def other_properties(self, value: Dict[str, Any]):
250
- """Set the other properties."""
251
- self._instance.other_properties = value
252
-
253
- @property
254
- def type(self):
255
- """Get the reaction type."""
256
- return ReactionType.Arrhenius
257
-
258
- def _create_serialize_dict(self, instance) -> Dict:
259
- """
260
- Helper method to create the serialization dictionary.
261
-
262
- Args:
263
- instance: The instance to serialize (either self._instance or a _Arrhenius object).
264
-
265
- Returns:
266
- Dict: Base serialization dictionary.
267
- """
268
- return {
269
- "type": "ARRHENIUS",
270
- "name": instance.name,
271
- "A": instance.A,
272
- "B": instance.B,
273
- "C": instance.C,
274
- "D": instance.D,
275
- "E": instance.E,
276
- "reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
277
- "products": ReactionComponentSerializer.serialize_list_reaction_components(instance.products),
278
- "gas phase": instance.gas_phase,
279
- }
280
-
281
- def serialize(self) -> Dict:
282
- """
283
- Serialize the Arrhenius object to a dictionary using only Python-visible data.
284
-
285
- Returns:
286
- Dict: A dictionary representation of the Arrhenius object.
287
- """
288
- serialize_dict = self._create_serialize_dict(self._instance)
289
- _add_other_properties(serialize_dict, self.other_properties)
290
- return serialize_dict
291
-
292
- @staticmethod
293
- def serialize_static(instance) -> Dict:
294
- """
295
- Static serialize method for compatibility with C++ _Arrhenius objects.
296
-
297
- Args:
298
- instance: The _Arrhenius instance to serialize.
299
-
300
- Returns:
301
- Dict: A dictionary representation of the Arrhenius object.
302
- """
303
- # Create a temporary Arrhenius object to use the helper method
304
- temp_arrhenius = Arrhenius()
305
- serialize_dict = temp_arrhenius._create_serialize_dict(instance)
306
- _add_other_properties(serialize_dict, instance.other_properties)
307
- return serialize_dict
147
+ Arrhenius.__init__ = __init__
148
+ Arrhenius.serialize = serialize
149
+ Arrhenius.type = type