musica 0.12.2__cp39-cp39-macosx_15_0_arm64.whl → 0.13.0__cp39-cp39-macosx_15_0_arm64.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/.dylibs/libgcc_s.1.1.dylib +0 -0
- musica/.dylibs/libgfortran.5.dylib +0 -0
- musica/.dylibs/libquadmath.0.dylib +0 -0
- musica/CMakeLists.txt +4 -0
- musica/_musica.cpython-39-darwin.so +0 -0
- musica/_version.py +1 -1
- musica/binding_common.cpp +6 -9
- musica/binding_common.hpp +17 -1
- musica/grid.cpp +206 -0
- musica/grid.py +98 -0
- musica/grid_map.cpp +117 -0
- musica/grid_map.py +167 -0
- musica/mechanism_configuration/__init__.py +18 -1
- musica/mechanism_configuration/ancillary.py +6 -0
- musica/mechanism_configuration/arrhenius.py +111 -269
- musica/mechanism_configuration/branched.py +116 -275
- musica/mechanism_configuration/emission.py +63 -52
- musica/mechanism_configuration/first_order_loss.py +73 -157
- musica/mechanism_configuration/mechanism.py +93 -0
- musica/mechanism_configuration/phase.py +44 -33
- musica/mechanism_configuration/phase_species.py +58 -0
- musica/mechanism_configuration/photolysis.py +77 -67
- musica/mechanism_configuration/reaction_component.py +54 -0
- musica/mechanism_configuration/reactions.py +17 -58
- musica/mechanism_configuration/species.py +45 -71
- musica/mechanism_configuration/surface.py +78 -74
- musica/mechanism_configuration/taylor_series.py +136 -0
- musica/mechanism_configuration/ternary_chemical_activation.py +138 -330
- musica/mechanism_configuration/troe.py +138 -330
- musica/mechanism_configuration/tunneling.py +105 -229
- musica/mechanism_configuration/user_defined.py +79 -68
- musica/mechanism_configuration.cpp +54 -162
- musica/musica.cpp +2 -5
- musica/profile.cpp +294 -0
- musica/profile.py +93 -0
- musica/profile_map.cpp +117 -0
- musica/profile_map.py +167 -0
- musica/test/examples/v1/full_configuration/full_configuration.json +91 -233
- musica/test/examples/v1/full_configuration/full_configuration.yaml +191 -290
- musica/test/integration/test_chapman.py +2 -2
- musica/test/integration/test_tuvx.py +72 -15
- musica/test/unit/test_grid.py +137 -0
- musica/test/unit/test_grid_map.py +126 -0
- musica/test/unit/test_parser.py +10 -10
- musica/test/unit/test_profile.py +169 -0
- musica/test/unit/test_profile_map.py +137 -0
- musica/test/unit/test_serializer.py +17 -16
- musica/test/unit/test_state.py +17 -4
- musica/test/unit/test_util_full_mechanism.py +78 -298
- musica/tuvx.cpp +94 -15
- musica/tuvx.py +92 -22
- musica/types.py +13 -5
- {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/METADATA +14 -14
- musica-0.13.0.dist-info/RECORD +90 -0
- musica/mechanism_configuration/aqueous_equilibrium.py +0 -274
- musica/mechanism_configuration/condensed_phase_arrhenius.py +0 -309
- musica/mechanism_configuration/condensed_phase_photolysis.py +0 -88
- musica/mechanism_configuration/henrys_law.py +0 -44
- musica/mechanism_configuration/mechanism_configuration.py +0 -234
- musica/mechanism_configuration/simpol_phase_transfer.py +0 -217
- musica/mechanism_configuration/wet_deposition.py +0 -52
- musica-0.12.2.dist-info/RECORD +0 -80
- {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/WHEEL +0 -0
- {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/entry_points.txt +0 -0
- {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/licenses/AUTHORS.md +0 -0
- {musica-0.12.2.dist-info → musica-0.13.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,174 +1,90 @@
|
|
|
1
|
-
from .utils import _add_other_properties
|
|
2
|
-
from .reactions import ReactionComponentSerializer
|
|
1
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
3
2
|
from .species import Species
|
|
4
3
|
from .phase import Phase
|
|
5
4
|
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
6
5
|
from .. import backend
|
|
6
|
+
from .reaction_component import ReactionComponent
|
|
7
|
+
from .ancillary import ReactionType
|
|
7
8
|
|
|
8
9
|
_backend = backend.get_backend()
|
|
9
|
-
|
|
10
|
-
_ReactionComponent = _backend._mechanism_configuration._ReactionComponent
|
|
11
|
-
ReactionType = _backend._mechanism_configuration._ReactionType
|
|
10
|
+
FirstOrderLoss = _backend._mechanism_configuration._FirstOrderLoss
|
|
12
11
|
|
|
12
|
+
original_init = FirstOrderLoss.__init__
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def type(self):
|
|
17
|
+
return ReactionType.FirstOrderLoss
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
name: Optional[str] = None,
|
|
23
|
+
scaling_factor: Optional[float] = None,
|
|
24
|
+
reactants: Optional[List[Union[Species,
|
|
25
|
+
Tuple[float, Species]]]] = None,
|
|
26
|
+
gas_phase: Optional[Phase] = None,
|
|
27
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
28
|
+
):
|
|
15
29
|
"""
|
|
16
|
-
|
|
30
|
+
Initializes the FirstOrderLoss object with the given parameters.
|
|
17
31
|
|
|
18
|
-
|
|
32
|
+
Args:
|
|
19
33
|
name (str): The name of the first-order loss reaction rate constant.
|
|
20
34
|
scaling_factor (float): The scaling factor for the first-order loss rate constant.
|
|
21
35
|
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
22
36
|
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
23
37
|
other_properties (Dict[str, Any]): A dictionary of other properties of the first-order loss reaction rate constant.
|
|
24
38
|
"""
|
|
39
|
+
original_init(self)
|
|
40
|
+
|
|
41
|
+
self.name = name if name is not None else self.name
|
|
42
|
+
self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
|
|
43
|
+
self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
|
|
44
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
45
|
+
self.reactants = (
|
|
46
|
+
[
|
|
47
|
+
(
|
|
48
|
+
ReactionComponent(r.name)
|
|
49
|
+
if isinstance(r, Species)
|
|
50
|
+
else ReactionComponent(r[1].name, r[0])
|
|
51
|
+
)
|
|
52
|
+
for r in reactants
|
|
53
|
+
]
|
|
54
|
+
if reactants is not None
|
|
55
|
+
else self.reactants
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def serialize(self) -> Dict:
|
|
60
|
+
"""
|
|
61
|
+
Serialize the FirstOrderLoss object to a dictionary using only Python-visible data.
|
|
25
62
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
self.reactants = reactants
|
|
55
|
-
if gas_phase is not None:
|
|
56
|
-
self.gas_phase = gas_phase
|
|
57
|
-
if other_properties is not None:
|
|
58
|
-
self.other_properties = other_properties
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
def name(self) -> str:
|
|
62
|
-
"""Get the name."""
|
|
63
|
-
return self._instance.name
|
|
64
|
-
|
|
65
|
-
@name.setter
|
|
66
|
-
def name(self, value: str):
|
|
67
|
-
"""Set the name."""
|
|
68
|
-
self._instance.name = value
|
|
69
|
-
|
|
70
|
-
@property
|
|
71
|
-
def scaling_factor(self) -> float:
|
|
72
|
-
"""Get the scaling factor."""
|
|
73
|
-
return self._instance.scaling_factor
|
|
74
|
-
|
|
75
|
-
@scaling_factor.setter
|
|
76
|
-
def scaling_factor(self, value: float):
|
|
77
|
-
"""Set the scaling factor."""
|
|
78
|
-
self._instance.scaling_factor = value
|
|
79
|
-
|
|
80
|
-
@property
|
|
81
|
-
def reactants(self) -> List[Union[Species, Tuple[float, Species]]]:
|
|
82
|
-
"""Get the reactants as Python objects."""
|
|
83
|
-
# Convert from C++ _ReactionComponent objects to Python Species objects
|
|
84
|
-
result = []
|
|
85
|
-
for rc in self._instance.reactants:
|
|
86
|
-
if hasattr(rc, 'coefficient') and rc.coefficient != 1.0:
|
|
87
|
-
# Create a tuple with coefficient and species
|
|
88
|
-
species = Species(name=rc.species_name)
|
|
89
|
-
result.append((rc.coefficient, species))
|
|
90
|
-
else:
|
|
91
|
-
# Just the species
|
|
92
|
-
species = Species(name=rc.species_name)
|
|
93
|
-
result.append(species)
|
|
94
|
-
return result
|
|
95
|
-
|
|
96
|
-
@reactants.setter
|
|
97
|
-
def reactants(self, value: List[Union[Species, Tuple[float, Species]]]):
|
|
98
|
-
"""Set the reactants, converting from Python to C++ objects."""
|
|
99
|
-
cpp_reactants = []
|
|
100
|
-
for r in value:
|
|
101
|
-
if isinstance(r, Species):
|
|
102
|
-
cpp_reactants.append(_ReactionComponent(r.name))
|
|
103
|
-
elif isinstance(r, tuple) and len(r) == 2:
|
|
104
|
-
coefficient, species = r
|
|
105
|
-
cpp_reactants.append(_ReactionComponent(species.name, coefficient))
|
|
106
|
-
else:
|
|
107
|
-
raise ValueError(f"Invalid reactant format: {r}")
|
|
108
|
-
self._instance.reactants = cpp_reactants
|
|
109
|
-
|
|
110
|
-
@property
|
|
111
|
-
def gas_phase(self) -> str:
|
|
112
|
-
"""Get the gas phase name."""
|
|
113
|
-
return self._instance.gas_phase
|
|
114
|
-
|
|
115
|
-
@gas_phase.setter
|
|
116
|
-
def gas_phase(self, value: Union[Phase, str]):
|
|
117
|
-
"""Set the gas phase."""
|
|
118
|
-
if isinstance(value, Phase):
|
|
119
|
-
self._instance.gas_phase = value.name
|
|
120
|
-
else:
|
|
121
|
-
self._instance.gas_phase = value
|
|
122
|
-
|
|
123
|
-
@property
|
|
124
|
-
def other_properties(self) -> Dict[str, Any]:
|
|
125
|
-
"""Get the other properties."""
|
|
126
|
-
return self._instance.other_properties
|
|
127
|
-
|
|
128
|
-
@other_properties.setter
|
|
129
|
-
def other_properties(self, value: Dict[str, Any]):
|
|
130
|
-
"""Set the other properties."""
|
|
131
|
-
self._instance.other_properties = value
|
|
132
|
-
|
|
133
|
-
@property
|
|
134
|
-
def type(self):
|
|
135
|
-
"""Get the reaction type."""
|
|
136
|
-
return ReactionType.FirstOrderLoss
|
|
137
|
-
|
|
138
|
-
def serialize(self) -> Dict:
|
|
139
|
-
"""
|
|
140
|
-
Serialize the FirstOrderLoss object to a dictionary using only Python-visible data.
|
|
141
|
-
|
|
142
|
-
Returns:
|
|
143
|
-
Dict: A dictionary representation of the FirstOrderLoss object.
|
|
144
|
-
"""
|
|
145
|
-
serialize_dict = {
|
|
146
|
-
"type": "FIRST_ORDER_LOSS",
|
|
147
|
-
"name": self.name,
|
|
148
|
-
"scaling factor": self.scaling_factor,
|
|
149
|
-
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(self._instance.reactants),
|
|
150
|
-
"gas phase": self.gas_phase,
|
|
151
|
-
}
|
|
152
|
-
_add_other_properties(serialize_dict, self.other_properties)
|
|
153
|
-
return _remove_empty_keys(serialize_dict)
|
|
154
|
-
|
|
155
|
-
@staticmethod
|
|
156
|
-
def serialize_static(instance) -> Dict:
|
|
157
|
-
"""
|
|
158
|
-
Static serialize method for compatibility with C++ _FirstOrderLoss objects.
|
|
159
|
-
|
|
160
|
-
Args:
|
|
161
|
-
instance: The _FirstOrderLoss instance to serialize.
|
|
162
|
-
|
|
163
|
-
Returns:
|
|
164
|
-
Dict: A dictionary representation of the FirstOrderLoss object.
|
|
165
|
-
"""
|
|
166
|
-
serialize_dict = {
|
|
167
|
-
"type": "FIRST_ORDER_LOSS",
|
|
168
|
-
"name": instance.name,
|
|
169
|
-
"scaling factor": instance.scaling_factor,
|
|
170
|
-
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
|
|
171
|
-
"gas phase": instance.gas_phase,
|
|
172
|
-
}
|
|
173
|
-
_add_other_properties(serialize_dict, instance.other_properties)
|
|
174
|
-
return serialize_dict
|
|
63
|
+
Returns:
|
|
64
|
+
Dict: A dictionary representation of the FirstOrderLoss object.
|
|
65
|
+
"""
|
|
66
|
+
serialize_dict = {
|
|
67
|
+
"type": "FIRST_ORDER_LOSS",
|
|
68
|
+
"name": self.name,
|
|
69
|
+
"scaling factor": self.scaling_factor,
|
|
70
|
+
"reactants": [r.serialize() for r in self.reactants],
|
|
71
|
+
"gas phase": self.gas_phase,
|
|
72
|
+
}
|
|
73
|
+
_add_other_properties(serialize_dict, self.other_properties)
|
|
74
|
+
return _remove_empty_keys(serialize_dict)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
FirstOrderLoss.__doc__ = """
|
|
78
|
+
A class representing a first-order loss reaction rate constant.
|
|
79
|
+
|
|
80
|
+
Attributes:
|
|
81
|
+
name (str): The name of the first-order loss reaction rate constant.
|
|
82
|
+
scaling_factor (float): The scaling factor for the first-order loss rate constant.
|
|
83
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
84
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
85
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the first-order loss reaction rate constant.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
FirstOrderLoss.__init__ = __init__
|
|
89
|
+
FirstOrderLoss.serialize = serialize
|
|
90
|
+
FirstOrderLoss.type = type
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Copyright (C) 2025 University Corporation for Atmospheric Research
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the musica Python package.
|
|
5
|
+
# For more information, see the LICENSE file in the top-level directory of this distribution.
|
|
6
|
+
import os
|
|
7
|
+
import json
|
|
8
|
+
import yaml
|
|
9
|
+
from typing import Optional, Any, Dict, List
|
|
10
|
+
from .. import backend
|
|
11
|
+
|
|
12
|
+
from .species import Species
|
|
13
|
+
from .phase import Phase
|
|
14
|
+
from .reactions import Reactions
|
|
15
|
+
from .ancillary import Version
|
|
16
|
+
|
|
17
|
+
_backend = backend.get_backend()
|
|
18
|
+
Mechanism = _backend._mechanism_configuration._Mechanism
|
|
19
|
+
|
|
20
|
+
original_init = Mechanism.__init__
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def export(self, file_path: str) -> None:
|
|
24
|
+
directory, file = os.path.split(file_path)
|
|
25
|
+
if directory:
|
|
26
|
+
os.makedirs(directory, exist_ok=True)
|
|
27
|
+
|
|
28
|
+
dictionary = self.serialize()
|
|
29
|
+
|
|
30
|
+
_, file_ext = os.path.splitext(file)
|
|
31
|
+
file_ext = file_ext.lower()
|
|
32
|
+
if file_ext in ['.yaml', '.yml']:
|
|
33
|
+
with open(file_path, 'w') as file:
|
|
34
|
+
yaml.dump(dictionary, file)
|
|
35
|
+
elif '.json' == file_ext:
|
|
36
|
+
json_str = json.dumps(dictionary, indent=4)
|
|
37
|
+
with open(file_path, 'w') as file:
|
|
38
|
+
file.write(json_str)
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError(
|
|
41
|
+
'Allowable write formats are .json, .yaml, and .yml')
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
name: Optional[str] = None,
|
|
47
|
+
reactions: Optional[List[Any]] = None,
|
|
48
|
+
species: Optional[List[Species]] = None,
|
|
49
|
+
phases: Optional[List[Phase]] = None,
|
|
50
|
+
version: Optional[Version] = None,
|
|
51
|
+
):
|
|
52
|
+
"""
|
|
53
|
+
Initializes the Mechanism object with the given parameters.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
name (str): The name of the mechanism.
|
|
57
|
+
reactions (List[]): A list of reactions in the mechanism.
|
|
58
|
+
species (List[Species]): A list of species in the mechanism.
|
|
59
|
+
phases (List[Phase]): A list of phases in the mechanism.
|
|
60
|
+
version (Version): The version of the mechanism.
|
|
61
|
+
"""
|
|
62
|
+
original_init(self)
|
|
63
|
+
self.name = name
|
|
64
|
+
self.species = species if species is not None else []
|
|
65
|
+
self.phases = phases if phases is not None else []
|
|
66
|
+
self.reactions = Reactions(reactions=reactions if reactions is not None else [])
|
|
67
|
+
self.version = version if version is not None else Version()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def serialize(self) -> Dict:
|
|
71
|
+
return {
|
|
72
|
+
"name": self.name,
|
|
73
|
+
"reactions": [r.serialize() for r in self.reactions],
|
|
74
|
+
"species": [s.serialize() for s in self.species],
|
|
75
|
+
"phases": [p.serialize() for p in self.phases],
|
|
76
|
+
"version": self.version.to_string(),
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
Mechanism.__doc__ = """
|
|
81
|
+
A class representing a chemical mechanism.
|
|
82
|
+
|
|
83
|
+
Attributes:
|
|
84
|
+
name (str): The name of the mechanism.
|
|
85
|
+
reactions (List[Reaction]): A list of reactions in the mechanism.
|
|
86
|
+
species (List[Species]): A list of species in the mechanism.
|
|
87
|
+
phases (List[Phase]): A list of phases in the mechanism.
|
|
88
|
+
version (Version): The version of the mechanism.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
Mechanism.__init__ = __init__
|
|
92
|
+
Mechanism.serialize = serialize
|
|
93
|
+
Mechanism.export = export
|
|
@@ -1,47 +1,58 @@
|
|
|
1
|
-
from typing import Optional, Any, Dict, List
|
|
1
|
+
from typing import Optional, Any, Dict, List, Union
|
|
2
2
|
from .. import backend
|
|
3
3
|
from .species import Species
|
|
4
|
+
from .phase_species import PhaseSpecies
|
|
4
5
|
from .utils import _add_other_properties, _remove_empty_keys
|
|
5
6
|
|
|
6
7
|
_backend = backend.get_backend()
|
|
7
|
-
|
|
8
|
+
Phase = _backend._mechanism_configuration._Phase
|
|
9
|
+
Phase.__doc__ = """
|
|
10
|
+
A class representing a phase in a chemical mechanism.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
name (str): The name of the phase.
|
|
14
|
+
species (List[Species]): A list of species in the phase.
|
|
15
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the phase.
|
|
16
|
+
"""
|
|
8
17
|
|
|
18
|
+
original_init = Phase.__init__
|
|
9
19
|
|
|
10
|
-
|
|
20
|
+
|
|
21
|
+
def init(
|
|
22
|
+
self,
|
|
23
|
+
name: Optional[str] = None,
|
|
24
|
+
species: Optional[Union[List[Species], List[PhaseSpecies]]] = None,
|
|
25
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
26
|
+
):
|
|
11
27
|
"""
|
|
12
|
-
|
|
28
|
+
Initializes the Phase object with the given parameters.
|
|
13
29
|
|
|
14
|
-
|
|
30
|
+
Args:
|
|
15
31
|
name (str): The name of the phase.
|
|
16
32
|
species (List[Species]): A list of species in the phase.
|
|
17
33
|
other_properties (Dict[str, Any]): A dictionary of other properties of the phase.
|
|
18
34
|
"""
|
|
35
|
+
original_init(self)
|
|
36
|
+
self.name = name if name is not None else self.name
|
|
37
|
+
converted_species = []
|
|
38
|
+
if species is not None:
|
|
39
|
+
for s in species:
|
|
40
|
+
if isinstance(s, PhaseSpecies):
|
|
41
|
+
converted_species.append(s)
|
|
42
|
+
elif isinstance(s, Species):
|
|
43
|
+
converted_species.append(PhaseSpecies(name=s.name))
|
|
44
|
+
self.species = converted_species
|
|
45
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def serialize(instance):
|
|
49
|
+
serialize_dict = {
|
|
50
|
+
"name": instance.name,
|
|
51
|
+
"species": [s.serialize() for s in instance.species],
|
|
52
|
+
}
|
|
53
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
54
|
+
return _remove_empty_keys(serialize_dict)
|
|
55
|
+
|
|
19
56
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
name: Optional[str] = None,
|
|
23
|
-
species: Optional[List[Species]] = None,
|
|
24
|
-
other_properties: Optional[Dict[str, Any]] = None,
|
|
25
|
-
):
|
|
26
|
-
"""
|
|
27
|
-
Initializes the Phase object with the given parameters.
|
|
28
|
-
|
|
29
|
-
Args:
|
|
30
|
-
name (str): The name of the phase.
|
|
31
|
-
species (List[Species]): A list of species in the phase.
|
|
32
|
-
other_properties (Dict[str, Any]): A dictionary of other properties of the phase.
|
|
33
|
-
"""
|
|
34
|
-
super().__init__()
|
|
35
|
-
self.name = name if name is not None else self.name
|
|
36
|
-
self.species = [
|
|
37
|
-
s.name for s in species] if species is not None else self.species
|
|
38
|
-
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
39
|
-
|
|
40
|
-
@staticmethod
|
|
41
|
-
def serialize(instance):
|
|
42
|
-
serialize_dict = {
|
|
43
|
-
"name": instance.name,
|
|
44
|
-
"species": instance.species,
|
|
45
|
-
}
|
|
46
|
-
_add_other_properties(serialize_dict, instance.other_properties)
|
|
47
|
-
return _remove_empty_keys(serialize_dict)
|
|
57
|
+
Phase.__init__ = init
|
|
58
|
+
Phase.serialize = serialize
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict
|
|
2
|
+
from .. import backend
|
|
3
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
4
|
+
|
|
5
|
+
_backend = backend.get_backend()
|
|
6
|
+
PhaseSpecies = _backend._mechanism_configuration._PhaseSpecies
|
|
7
|
+
original_init = PhaseSpecies.__init__
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
name: Optional[str] = None,
|
|
13
|
+
diffusion_coefficient_m2_s: Optional[float] = None,
|
|
14
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
15
|
+
):
|
|
16
|
+
"""
|
|
17
|
+
Initializes the PhaseSpecies object with the given parameters.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
name (str): The name of the species.
|
|
21
|
+
diffusion_coefficient_m2_s (float): Diffusion coefficient [m2 s-1]
|
|
22
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the species.
|
|
23
|
+
"""
|
|
24
|
+
original_init(self)
|
|
25
|
+
self.name = name if name is not None else self.name
|
|
26
|
+
self.diffusion_coefficient_m2_s = diffusion_coefficient_m2_s if diffusion_coefficient_m2_s is not None else self.diffusion_coefficient_m2_s
|
|
27
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def serialize(self) -> Dict:
|
|
31
|
+
serialize_dict = {
|
|
32
|
+
"name": self.name,
|
|
33
|
+
"diffusion coefficient [m2 s-1]": self.diffusion_coefficient_m2_s,
|
|
34
|
+
}
|
|
35
|
+
_add_other_properties(serialize_dict, self.other_properties)
|
|
36
|
+
return _remove_empty_keys(serialize_dict)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def equals(self, other):
|
|
40
|
+
return self.name == other.name and self.diffusion_coefficient_m2_s == other.diffusion_coefficient_m2_s
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
PhaseSpecies.__doc__ = """
|
|
44
|
+
Represents a chemical species within a specific phase of a mechanism,
|
|
45
|
+
including phase-specific properties such as diffusion coefficients.
|
|
46
|
+
|
|
47
|
+
This class is distinct from a regular Species class in that it models
|
|
48
|
+
properties relevant to the species' behavior in a particular phase
|
|
49
|
+
(e.g., gas, liquid, or solid), such as the diffusion coefficient.
|
|
50
|
+
|
|
51
|
+
Attributes:
|
|
52
|
+
name (str): The name of the species.
|
|
53
|
+
diffusion_coefficient_m2_s (float): Diffusion coefficient in the phase [m2 s-1].
|
|
54
|
+
other_properties (Dict[str, Any]): A dictionary of other phase-specific properties of the species.
|
|
55
|
+
"""
|
|
56
|
+
PhaseSpecies.__init__ = __init__
|
|
57
|
+
PhaseSpecies.serialize = serialize
|
|
58
|
+
PhaseSpecies.__eq__ = equals
|
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
from .utils import _add_other_properties
|
|
2
|
-
from .reactions import ReactionComponentSerializer
|
|
3
2
|
from .species import Species
|
|
4
3
|
from .phase import Phase
|
|
5
4
|
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
6
5
|
from .. import backend
|
|
6
|
+
from .reaction_component import ReactionComponent
|
|
7
|
+
from .ancillary import ReactionType
|
|
7
8
|
|
|
8
9
|
_backend = backend.get_backend()
|
|
9
|
-
|
|
10
|
-
_ReactionComponent = _backend._mechanism_configuration._ReactionComponent
|
|
10
|
+
Photolysis = _backend._mechanism_configuration._Photolysis
|
|
11
11
|
|
|
12
|
+
original_init = Photolysis.__init__
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def type(self):
|
|
17
|
+
return ReactionType.Photolysis
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
name: Optional[str] = None,
|
|
23
|
+
scaling_factor: Optional[float] = None,
|
|
24
|
+
reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
25
|
+
products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
26
|
+
gas_phase: Optional[Phase] = None,
|
|
27
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
28
|
+
):
|
|
14
29
|
"""
|
|
15
|
-
|
|
30
|
+
Initializes the Photolysis object with the given parameters.
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
Args:
|
|
18
33
|
name (str): The name of the photolysis reaction rate constant.
|
|
19
34
|
scaling_factor (float): The scaling factor for the photolysis rate constant.
|
|
20
35
|
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
@@ -22,67 +37,62 @@ class Photolysis(_Photolysis):
|
|
|
22
37
|
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
23
38
|
other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant.
|
|
24
39
|
"""
|
|
40
|
+
original_init(self)
|
|
41
|
+
self.name = name if name is not None else self.name
|
|
42
|
+
self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
|
|
43
|
+
self.reactants = (
|
|
44
|
+
[
|
|
45
|
+
(
|
|
46
|
+
ReactionComponent(r.name)
|
|
47
|
+
if isinstance(r, Species)
|
|
48
|
+
else ReactionComponent(r[1].name, r[0])
|
|
49
|
+
)
|
|
50
|
+
for r in reactants
|
|
51
|
+
]
|
|
52
|
+
if reactants is not None
|
|
53
|
+
else self.reactants
|
|
54
|
+
)
|
|
55
|
+
self.products = (
|
|
56
|
+
[
|
|
57
|
+
(
|
|
58
|
+
ReactionComponent(p.name)
|
|
59
|
+
if isinstance(p, Species)
|
|
60
|
+
else ReactionComponent(p[1].name, p[0])
|
|
61
|
+
)
|
|
62
|
+
for p in products
|
|
63
|
+
]
|
|
64
|
+
if products is not None
|
|
65
|
+
else self.products
|
|
66
|
+
)
|
|
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
|
+
|
|
70
|
+
|
|
71
|
+
def serialize(self) -> Dict:
|
|
72
|
+
serialize_dict = {
|
|
73
|
+
"type": "PHOTOLYSIS",
|
|
74
|
+
"name": self.name,
|
|
75
|
+
"scaling factor": self.scaling_factor,
|
|
76
|
+
"reactants": [r.serialize() for r in self.reactants],
|
|
77
|
+
"products": [r.serialize() for r in self.products],
|
|
78
|
+
"gas phase": self.gas_phase,
|
|
79
|
+
}
|
|
80
|
+
_add_other_properties(serialize_dict, self.other_properties)
|
|
81
|
+
return serialize_dict
|
|
82
|
+
|
|
25
83
|
|
|
26
|
-
|
|
27
|
-
|
|
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 Photolysis object with the given parameters.
|
|
84
|
+
Photolysis.__doc__ = """
|
|
85
|
+
A class representing a photolysis reaction rate constant.
|
|
38
86
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
87
|
+
Attributes:
|
|
88
|
+
name (str): The name of the photolysis reaction rate constant.
|
|
89
|
+
scaling_factor (float): The scaling factor for the photolysis rate constant.
|
|
90
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
91
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
92
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
93
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant.
|
|
94
|
+
"""
|
|
76
95
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"type": "PHOTOLYSIS",
|
|
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
|
|
96
|
+
Photolysis.__init__ = __init__
|
|
97
|
+
Photolysis.serialize = serialize
|
|
98
|
+
Photolysis.type = type
|