musica 0.12.0__cp39-cp39-win32.whl → 0.12.2__cp39-cp39-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 (76) hide show
  1. musica/CMakeLists.txt +28 -2
  2. musica/__init__.py +9 -49
  3. musica/_musica.cp39-win32.pyd +0 -0
  4. musica/_version.py +1 -1
  5. musica/backend.py +41 -0
  6. musica/binding_common.cpp +23 -6
  7. musica/carma.cpp +911 -0
  8. musica/carma.py +1729 -0
  9. musica/constants.py +1 -1
  10. musica/cpu_binding.cpp +2 -1
  11. musica/cuda.py +4 -1
  12. musica/examples/__init__.py +1 -0
  13. musica/examples/carma_aluminum.py +124 -0
  14. musica/examples/carma_sulfate.py +246 -0
  15. musica/examples/examples.py +165 -0
  16. musica/examples/sulfate_box_model.py +439 -0
  17. musica/examples/ts1_latin_hypercube.py +245 -0
  18. musica/gpu_binding.cpp +2 -1
  19. musica/main.py +89 -0
  20. musica/mechanism_configuration/__init__.py +1 -1
  21. musica/mechanism_configuration/aqueous_equilibrium.py +227 -54
  22. musica/mechanism_configuration/arrhenius.py +228 -42
  23. musica/mechanism_configuration/branched.py +249 -66
  24. musica/mechanism_configuration/condensed_phase_arrhenius.py +243 -50
  25. musica/mechanism_configuration/condensed_phase_photolysis.py +16 -19
  26. musica/mechanism_configuration/emission.py +10 -6
  27. musica/mechanism_configuration/first_order_loss.py +133 -26
  28. musica/mechanism_configuration/henrys_law.py +7 -48
  29. musica/mechanism_configuration/mechanism_configuration.py +114 -41
  30. musica/mechanism_configuration/phase.py +6 -2
  31. musica/mechanism_configuration/photolysis.py +12 -7
  32. musica/mechanism_configuration/reactions.py +20 -8
  33. musica/mechanism_configuration/simpol_phase_transfer.py +180 -51
  34. musica/mechanism_configuration/species.py +23 -4
  35. musica/mechanism_configuration/surface.py +14 -9
  36. musica/mechanism_configuration/ternary_chemical_activation.py +352 -0
  37. musica/mechanism_configuration/troe.py +259 -44
  38. musica/mechanism_configuration/tunneling.py +196 -49
  39. musica/mechanism_configuration/user_defined.py +9 -4
  40. musica/mechanism_configuration/wet_deposition.py +11 -8
  41. musica/mechanism_configuration.cpp +184 -95
  42. musica/musica.cpp +48 -61
  43. musica/test/examples/v1/full_configuration/full_configuration.json +39 -22
  44. musica/test/examples/v1/full_configuration/full_configuration.yaml +29 -20
  45. musica/test/{test_analytical.py → integration/test_analytical.py} +0 -1
  46. musica/test/integration/test_carma.py +227 -0
  47. musica/test/integration/test_carma_aluminum.py +12 -0
  48. musica/test/integration/test_carma_sulfate.py +17 -0
  49. musica/test/integration/test_sulfate_box_model.py +34 -0
  50. musica/test/integration/test_tuvx.py +62 -0
  51. musica/test/unit/test_parser.py +64 -0
  52. musica/test/{test_serializer.py → unit/test_serializer.py} +2 -2
  53. musica/test/unit/test_state.py +325 -0
  54. musica/test/{test_util_full_mechanism.py → unit/test_util_full_mechanism.py} +152 -122
  55. musica/tools/prepare_build_environment_linux.sh +23 -34
  56. musica/tools/prepare_build_environment_macos.sh +1 -0
  57. musica/tuvx.cpp +93 -0
  58. musica/tuvx.py +199 -0
  59. musica/types.py +120 -73
  60. {musica-0.12.0.dist-info → musica-0.12.2.dist-info}/METADATA +41 -39
  61. musica-0.12.2.dist-info/RECORD +70 -0
  62. {musica-0.12.0.dist-info → musica-0.12.2.dist-info}/WHEEL +1 -1
  63. musica-0.12.2.dist-info/entry_points.txt +3 -0
  64. musica/test/examples/v0/config.json +0 -7
  65. musica/test/examples/v0/config.yaml +0 -3
  66. musica/test/examples/v0/reactions.json +0 -193
  67. musica/test/examples/v0/reactions.yaml +0 -142
  68. musica/test/examples/v0/species.json +0 -40
  69. musica/test/examples/v0/species.yaml +0 -19
  70. musica/test/test_parser.py +0 -57
  71. musica/test/tuvx.py +0 -10
  72. musica/tools/prepare_build_environment_windows.sh +0 -22
  73. musica-0.12.0.dist-info/RECORD +0 -57
  74. /musica/test/{test_chapman.py → integration/test_chapman.py} +0 -0
  75. {musica-0.12.0.dist-info → musica-0.12.2.dist-info}/licenses/AUTHORS.md +0 -0
  76. {musica-0.12.0.dist-info → musica-0.12.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,12 +1,17 @@
1
- from typing import Optional, Any, Dict, List, Union, Tuple
2
- from musica import _Tunneling, _ReactionComponent
3
- from .phase import Phase
4
- from .species import Species
1
+ from .utils import _add_other_properties
5
2
  from .reactions import ReactionComponentSerializer
6
- from .utils import _add_other_properties, _remove_empty_keys
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
7
12
 
8
13
 
9
- class Tunneling(_Tunneling):
14
+ class Tunneling:
10
15
  """
11
16
  A class representing a quantum tunneling reaction rate constant.
12
17
 
@@ -37,7 +42,8 @@ class Tunneling(_Tunneling):
37
42
  A: Optional[float] = None,
38
43
  B: Optional[float] = None,
39
44
  C: Optional[float] = None,
40
- reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
45
+ reactants: Optional[List[Union[Species,
46
+ Tuple[float, Species]]]] = None,
41
47
  products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
42
48
  gas_phase: Optional[Phase] = None,
43
49
  other_properties: Optional[Dict[str, Any]] = None,
@@ -55,49 +61,190 @@ class Tunneling(_Tunneling):
55
61
  gas_phase (Phase): The gas phase in which the reaction occurs.
56
62
  other_properties (Dict[str, Any]): A dictionary of other properties of the tunneling reaction rate constant.
57
63
  """
58
- super().__init__()
59
- self.name = name if name is not None else self.name
60
- self.A = A if A is not None else self.A
61
- self.B = B if B is not None else self.B
62
- self.C = C if C is not None else self.C
63
- self.reactants = (
64
- [
65
- (
66
- _ReactionComponent(r.name)
67
- if isinstance(r, Species)
68
- else _ReactionComponent(r[1].name, r[0])
69
- )
70
- for r in reactants
71
- ]
72
- if reactants is not None
73
- else self.reactants
74
- )
75
- self.products = (
76
- [
77
- (
78
- _ReactionComponent(p.name)
79
- if isinstance(p, Species)
80
- else _ReactionComponent(p[1].name, p[0])
81
- )
82
- for p in products
83
- ]
84
- if products is not None
85
- else self.products
86
- )
87
- self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
88
- self.other_properties = other_properties if other_properties is not None else self.other_properties
64
+ # Create the internal C++ instance
65
+ self._instance = _Tunneling()
89
66
 
90
- @staticmethod
91
- def serialize(instance) -> Dict:
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
+ """
92
223
  serialize_dict = {
93
224
  "type": "TUNNELING",
94
- "name": instance.name,
95
- "A": instance.A,
96
- "B": instance.B,
97
- "C": instance.C,
98
- "reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
99
- "products": ReactionComponentSerializer.serialize_list_reaction_components(instance.products),
100
- "gas phase": instance.gas_phase,
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,
101
232
  }
102
- _add_other_properties(serialize_dict, instance.other_properties)
103
- return _remove_empty_keys(serialize_dict)
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()
@@ -1,9 +1,13 @@
1
1
  from typing import Optional, Any, Dict, List, Union, Tuple
2
- from musica import _UserDefined, _ReactionComponent
2
+ from .. import backend
3
3
  from .phase import Phase
4
4
  from .species import Species
5
5
  from .reactions import ReactionComponentSerializer
6
- from .utils import _add_other_properties, _remove_empty_keys
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
7
11
 
8
12
 
9
13
  class UserDefined(_UserDefined):
@@ -23,7 +27,8 @@ class UserDefined(_UserDefined):
23
27
  self,
24
28
  name: Optional[str] = None,
25
29
  scaling_factor: Optional[float] = None,
26
- reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
30
+ reactants: Optional[List[Union[Species,
31
+ Tuple[float, Species]]]] = None,
27
32
  products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
28
33
  gas_phase: Optional[Phase] = None,
29
34
  other_properties: Optional[Dict[str, Any]] = None,
@@ -80,4 +85,4 @@ class UserDefined(_UserDefined):
80
85
  "gas phase": instance.gas_phase,
81
86
  }
82
87
  _add_other_properties(serialize_dict, instance.other_properties)
83
- return _remove_empty_keys(serialize_dict)
88
+ return serialize_dict
@@ -1,7 +1,10 @@
1
1
  from typing import Optional, Any, Dict
2
- from musica import _WetDeposition
2
+ from .. import backend
3
3
  from .phase import Phase
4
- from .utils import _add_other_properties, _remove_empty_keys
4
+ from .utils import _add_other_properties
5
+
6
+ _backend = backend.get_backend()
7
+ _WetDeposition = _backend._mechanism_configuration._WetDeposition
5
8
 
6
9
 
7
10
  class WetDeposition(_WetDeposition):
@@ -11,7 +14,7 @@ class WetDeposition(_WetDeposition):
11
14
  Attributes:
12
15
  name (str): The name of the wet deposition reaction rate constant.
13
16
  scaling_factor (float): The scaling factor for the wet deposition rate constant.
14
- aerosol_phase (Phase): The aerosol phase which undergoes wet deposition.
17
+ condensed_phase (Phase): The condensed phase which undergoes wet deposition.
15
18
  unknown_properties (Dict[str, Any]): A dictionary of other properties of the wet deposition reaction rate constant.
16
19
  """
17
20
 
@@ -19,7 +22,7 @@ class WetDeposition(_WetDeposition):
19
22
  self,
20
23
  name: Optional[str] = None,
21
24
  scaling_factor: Optional[float] = None,
22
- aerosol_phase: Optional[Phase] = None,
25
+ condensed_phase: Optional[Phase] = None,
23
26
  other_properties: Optional[Dict[str, Any]] = None,
24
27
  ):
25
28
  """
@@ -28,13 +31,13 @@ class WetDeposition(_WetDeposition):
28
31
  Args:
29
32
  name (str): The name of the wet deposition reaction rate constant.
30
33
  scaling_factor (float): The scaling factor for the wet deposition rate constant.
31
- aerosol_phase (Phase): The aerosol phase which undergoes wet deposition.
34
+ condensed_phase (Phase): The condensed phase which undergoes wet deposition.
32
35
  other_properties (Dict[str, Any]): A dictionary of other properties of the wet deposition reaction rate constant.
33
36
  """
34
37
  super().__init__()
35
38
  self.name = name if name is not None else self.name
36
39
  self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
37
- self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase
40
+ self.condensed_phase = condensed_phase.name if condensed_phase is not None else self.condensed_phase
38
41
  self.other_properties = other_properties if other_properties is not None else self.other_properties
39
42
 
40
43
  @staticmethod
@@ -43,7 +46,7 @@ class WetDeposition(_WetDeposition):
43
46
  "type": "WET_DEPOSITION",
44
47
  "name": instance.name,
45
48
  "scaling factor": instance.scaling_factor,
46
- "aerosol phase": instance.aerosol_phase,
49
+ "condensed phase": instance.condensed_phase,
47
50
  }
48
51
  _add_other_properties(serialize_dict, instance.other_properties)
49
- return _remove_empty_keys(serialize_dict)
52
+ return serialize_dict