musica 0.11.1.3__cp311-cp311-win32.whl → 0.12.0__cp311-cp311-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.
- musica/CMakeLists.txt +35 -40
- musica/__init__.py +51 -3
- musica/_musica.cp311-win32.pyd +0 -0
- musica/_version.py +1 -1
- musica/binding_common.cpp +16 -0
- musica/binding_common.hpp +7 -0
- musica/constants.py +3 -0
- musica/cpu_binding.cpp +10 -0
- musica/cuda.cpp +12 -0
- musica/cuda.py +10 -0
- musica/gpu_binding.cpp +10 -0
- musica/mechanism_configuration/__init__.py +1 -0
- musica/mechanism_configuration/aqueous_equilibrium.py +101 -0
- musica/mechanism_configuration/arrhenius.py +121 -0
- musica/mechanism_configuration/branched.py +116 -0
- musica/mechanism_configuration/condensed_phase_arrhenius.py +116 -0
- musica/mechanism_configuration/condensed_phase_photolysis.py +91 -0
- musica/mechanism_configuration/emission.py +67 -0
- musica/mechanism_configuration/first_order_loss.py +67 -0
- musica/mechanism_configuration/henrys_law.py +85 -0
- musica/mechanism_configuration/mechanism_configuration.py +161 -0
- musica/mechanism_configuration/phase.py +43 -0
- musica/mechanism_configuration/photolysis.py +83 -0
- musica/mechanism_configuration/reactions.py +61 -0
- musica/mechanism_configuration/simpol_phase_transfer.py +88 -0
- musica/mechanism_configuration/species.py +72 -0
- musica/mechanism_configuration/surface.py +89 -0
- musica/mechanism_configuration/troe.py +137 -0
- musica/mechanism_configuration/tunneling.py +103 -0
- musica/mechanism_configuration/user_defined.py +83 -0
- musica/mechanism_configuration/utils.py +10 -0
- musica/mechanism_configuration/wet_deposition.py +49 -0
- musica/mechanism_configuration.cpp +0 -1
- musica/musica.cpp +1 -1
- musica/test/examples/v1/{full_configuration.json → full_configuration/full_configuration.json} +30 -15
- musica/test/examples/v1/{full_configuration.yaml → full_configuration/full_configuration.yaml} +16 -1
- musica/test/test_analytical.py +14 -12
- musica/test/test_chapman.py +18 -2
- musica/test/test_parser.py +4 -640
- musica/test/test_serializer.py +69 -0
- musica/test/test_util_full_mechanism.py +668 -0
- musica/tools/prepare_build_environment_linux.sh +8 -6
- musica/tools/repair_wheel_gpu.sh +25 -16
- musica/types.py +4 -6
- {musica-0.11.1.3.dist-info → musica-0.12.0.dist-info}/METADATA +179 -43
- musica-0.12.0.dist-info/RECORD +57 -0
- {musica-0.11.1.3.dist-info → musica-0.12.0.dist-info}/WHEEL +1 -1
- musica-0.12.0.dist-info/licenses/AUTHORS.md +59 -0
- musica/binding.cpp +0 -19
- musica/lib/musica.lib +0 -0
- musica/lib/yaml-cpp.lib +0 -0
- musica/mechanism_configuration.py +0 -1291
- musica-0.11.1.3.dist-info/RECORD +0 -30
- {musica-0.11.1.3.dist-info → musica-0.12.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
2
|
+
from musica import _CondensedPhaseArrhenius, _ReactionComponent
|
|
3
|
+
from .phase import Phase
|
|
4
|
+
from .species import Species
|
|
5
|
+
from .reactions import ReactionComponentSerializer
|
|
6
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
7
|
+
from musica.constants import BOLTZMANN
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CondensedPhaseArrhenius(_CondensedPhaseArrhenius):
|
|
11
|
+
"""
|
|
12
|
+
A class representing a condensed phase Arrhenius rate constant.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
name (str): The name of the condensed phase Arrhenius rate constant.
|
|
16
|
+
A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1].
|
|
17
|
+
B (float): Temperature exponent [unitless].
|
|
18
|
+
C (float): Exponential term [K-1].
|
|
19
|
+
Ea (float): Activation energy [J molecule-1].
|
|
20
|
+
D (float): Reference Temperature [K].
|
|
21
|
+
E (float): Pressure scaling term [Pa-1].
|
|
22
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
23
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
24
|
+
aerosol_phase (Phase): The aerosol phase in which the reaction occurs.
|
|
25
|
+
aerosol_phase_water (Species): The water species in the aerosol phase.
|
|
26
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase Arrhenius rate constant.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
name: Optional[str] = None,
|
|
32
|
+
A: Optional[float] = None,
|
|
33
|
+
B: Optional[float] = None,
|
|
34
|
+
C: Optional[float] = None,
|
|
35
|
+
Ea: Optional[float] = None,
|
|
36
|
+
D: Optional[float] = None,
|
|
37
|
+
E: Optional[float] = None,
|
|
38
|
+
reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
39
|
+
products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
40
|
+
aerosol_phase: Optional[Phase] = None,
|
|
41
|
+
aerosol_phase_water: Optional[Species] = None,
|
|
42
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
43
|
+
):
|
|
44
|
+
"""
|
|
45
|
+
Initializes the CondensedPhaseArrhenius object with the given parameters.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
name (str): The name of the condensed phase Arrhenius rate constant.
|
|
49
|
+
A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1].
|
|
50
|
+
B (float): Temperature exponent [unitless].
|
|
51
|
+
C (float): Exponential term [K-1].
|
|
52
|
+
Ea (float): Activation energy [J molecule-1].
|
|
53
|
+
D (float): Reference Temperature [K].
|
|
54
|
+
E (float): Pressure scaling term [Pa-1].
|
|
55
|
+
reactants (List[Union[Species, Tuple[float, Species]]]]: A list of reactants involved in the reaction.
|
|
56
|
+
products (List[Union[Species, Tuple[float, Species]]]]: A list of products formed in the reaction.
|
|
57
|
+
aerosol_phase (Phase): The aerosol phase in which the reaction occurs.
|
|
58
|
+
aerosol_phase_water (Species): The water species in the aerosol phase.
|
|
59
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase Arrhenius rate constant.
|
|
60
|
+
"""
|
|
61
|
+
super().__init__()
|
|
62
|
+
self.name = name if name is not None else self.name
|
|
63
|
+
self.A = A if A is not None else self.A
|
|
64
|
+
self.B = B if B is not None else self.B
|
|
65
|
+
if C is not None and Ea is not None:
|
|
66
|
+
raise ValueError("Cannot specify both C and Ea.")
|
|
67
|
+
self.C = -Ea / BOLTZMANN if Ea is not None else C if C is not None else self.C
|
|
68
|
+
self.D = D if D is not None else self.D
|
|
69
|
+
self.E = E if E is not None else self.E
|
|
70
|
+
self.reactants = (
|
|
71
|
+
[
|
|
72
|
+
(
|
|
73
|
+
_ReactionComponent(r.name)
|
|
74
|
+
if isinstance(r, Species)
|
|
75
|
+
else _ReactionComponent(r[1].name, r[0])
|
|
76
|
+
)
|
|
77
|
+
for r in reactants
|
|
78
|
+
]
|
|
79
|
+
if reactants is not None
|
|
80
|
+
else self.reactants
|
|
81
|
+
)
|
|
82
|
+
self.products = (
|
|
83
|
+
[
|
|
84
|
+
(
|
|
85
|
+
_ReactionComponent(p.name)
|
|
86
|
+
if isinstance(p, Species)
|
|
87
|
+
else _ReactionComponent(p[1].name, p[0])
|
|
88
|
+
)
|
|
89
|
+
for p in products
|
|
90
|
+
]
|
|
91
|
+
if products is not None
|
|
92
|
+
else self.products
|
|
93
|
+
)
|
|
94
|
+
self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase
|
|
95
|
+
self.aerosol_phase_water = (
|
|
96
|
+
aerosol_phase_water.name if aerosol_phase_water is not None else self.aerosol_phase_water
|
|
97
|
+
)
|
|
98
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
99
|
+
|
|
100
|
+
@staticmethod
|
|
101
|
+
def serialize(instance) -> Dict:
|
|
102
|
+
serialize_dict = {
|
|
103
|
+
"type": "CONDENSED_PHASE_ARRHENIUS",
|
|
104
|
+
"name": instance.name,
|
|
105
|
+
"A": instance.A,
|
|
106
|
+
"B": instance.B,
|
|
107
|
+
"C": instance.C,
|
|
108
|
+
"D": instance.D,
|
|
109
|
+
"E": instance.E,
|
|
110
|
+
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
|
|
111
|
+
"products": ReactionComponentSerializer.serialize_list_reaction_components(instance.products),
|
|
112
|
+
"aerosol phase": instance.aerosol_phase,
|
|
113
|
+
"aerosol-phase water": instance.aerosol_phase_water,
|
|
114
|
+
}
|
|
115
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
116
|
+
return _remove_empty_keys(serialize_dict)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
2
|
+
from musica import _CondensedPhasePhotolysis, _ReactionComponent
|
|
3
|
+
from .phase import Phase
|
|
4
|
+
from .species import Species
|
|
5
|
+
from .reactions import ReactionComponentSerializer
|
|
6
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CondensedPhasePhotolysis(_CondensedPhasePhotolysis):
|
|
11
|
+
"""
|
|
12
|
+
A class representing a condensed phase photolysis reaction rate constant.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
name (str): The name of the condensed phase photolysis reaction rate constant.
|
|
16
|
+
scaling_factor (float): The scaling factor for the photolysis rate constant.
|
|
17
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
18
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
19
|
+
aerosol_phase (Phase): The aerosol phase in which the reaction occurs.
|
|
20
|
+
aerosol_phase_water (float): The water species in the aerosol phase [unitless].
|
|
21
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase photolysis reaction rate constant.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
name: Optional[str] = None,
|
|
27
|
+
scaling_factor: Optional[float] = None,
|
|
28
|
+
reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
29
|
+
products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
30
|
+
aerosol_phase: Optional[Phase] = None,
|
|
31
|
+
aerosol_phase_water: Optional[Species] = None,
|
|
32
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
33
|
+
):
|
|
34
|
+
"""
|
|
35
|
+
Initializes the CondensedPhasePhotolysis object with the given parameters.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
name (str): The name of the condensed phase photolysis reaction rate constant.
|
|
39
|
+
scaling_factor (float): The scaling factor for the photolysis rate constant.
|
|
40
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
41
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
42
|
+
aerosol_phase (Phase): The aerosol phase in which the reaction occurs.
|
|
43
|
+
aerosol_phase_water (Species): The water species in the aerosol phase [unitless].
|
|
44
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase photolysis reaction rate constant.
|
|
45
|
+
"""
|
|
46
|
+
super().__init__()
|
|
47
|
+
self.name = name if name is not None else self.name
|
|
48
|
+
self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
|
|
49
|
+
self.reactants = (
|
|
50
|
+
[
|
|
51
|
+
(
|
|
52
|
+
_ReactionComponent(r.name)
|
|
53
|
+
if isinstance(r, Species)
|
|
54
|
+
else _ReactionComponent(r[1].name, r[0])
|
|
55
|
+
)
|
|
56
|
+
for r in reactants
|
|
57
|
+
]
|
|
58
|
+
if reactants is not None
|
|
59
|
+
else self.reactants
|
|
60
|
+
)
|
|
61
|
+
self.products = (
|
|
62
|
+
[
|
|
63
|
+
(
|
|
64
|
+
_ReactionComponent(p.name)
|
|
65
|
+
if isinstance(p, Species)
|
|
66
|
+
else _ReactionComponent(p[1].name, p[0])
|
|
67
|
+
)
|
|
68
|
+
for p in products
|
|
69
|
+
]
|
|
70
|
+
if products is not None
|
|
71
|
+
else self.products
|
|
72
|
+
)
|
|
73
|
+
self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase
|
|
74
|
+
self.aerosol_phase_water = (
|
|
75
|
+
aerosol_phase_water.name if aerosol_phase_water is not None else self.aerosol_phase_water
|
|
76
|
+
)
|
|
77
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def serialize(instance) -> Dict:
|
|
81
|
+
serialize_dict = {
|
|
82
|
+
"type": "CONDENSED_PHASE_PHOTOLYSIS",
|
|
83
|
+
"name": instance.name,
|
|
84
|
+
"scaling factor": instance.scaling_factor,
|
|
85
|
+
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
|
|
86
|
+
"products": ReactionComponentSerializer.serialize_list_reaction_components(instance.products),
|
|
87
|
+
"aerosol phase": instance.aerosol_phase,
|
|
88
|
+
"aerosol-phase water": instance.aerosol_phase_water,
|
|
89
|
+
}
|
|
90
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
91
|
+
return _remove_empty_keys(serialize_dict)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
2
|
+
from musica import _Emission, _ReactionComponent
|
|
3
|
+
from .phase import Phase
|
|
4
|
+
from .species import Species
|
|
5
|
+
from .reactions import ReactionComponentSerializer
|
|
6
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Emission(_Emission):
|
|
10
|
+
"""
|
|
11
|
+
A class representing an emission reaction rate constant.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
name (str): The name of the emission reaction rate constant.
|
|
15
|
+
scaling_factor (float): The scaling factor for the emission rate constant.
|
|
16
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
17
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
18
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the emission reaction rate constant.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
name: Optional[str] = None,
|
|
24
|
+
scaling_factor: Optional[float] = 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
|
+
):
|
|
29
|
+
"""
|
|
30
|
+
Initializes the Emission object with the given parameters.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
name (str): The name of the emission reaction rate constant.
|
|
34
|
+
scaling_factor (float): The scaling factor for the emission rate constant.
|
|
35
|
+
products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
|
|
36
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
37
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the emission reaction rate constant.
|
|
38
|
+
"""
|
|
39
|
+
super().__init__()
|
|
40
|
+
self.name = name if name is not None else self.name
|
|
41
|
+
self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
|
|
42
|
+
self.products = (
|
|
43
|
+
[
|
|
44
|
+
(
|
|
45
|
+
_ReactionComponent(p.name)
|
|
46
|
+
if isinstance(p, Species)
|
|
47
|
+
else _ReactionComponent(p[1].name, p[0])
|
|
48
|
+
)
|
|
49
|
+
for p in products
|
|
50
|
+
]
|
|
51
|
+
if products is not None
|
|
52
|
+
else self.products
|
|
53
|
+
)
|
|
54
|
+
self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
|
|
55
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def serialize(instance) -> Dict:
|
|
59
|
+
serialize_dict = {
|
|
60
|
+
"type": "EMISSION",
|
|
61
|
+
"name": instance.name,
|
|
62
|
+
"scaling factor": instance.scaling_factor,
|
|
63
|
+
"products": ReactionComponentSerializer.serialize_list_reaction_components(instance.products),
|
|
64
|
+
"gas phase": instance.gas_phase,
|
|
65
|
+
}
|
|
66
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
67
|
+
return _remove_empty_keys(serialize_dict)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, List, Union, Tuple
|
|
2
|
+
from musica import _FirstOrderLoss, _ReactionComponent
|
|
3
|
+
from .phase import Phase
|
|
4
|
+
from .species import Species
|
|
5
|
+
from .reactions import ReactionComponentSerializer
|
|
6
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FirstOrderLoss(_FirstOrderLoss):
|
|
10
|
+
"""
|
|
11
|
+
A class representing a first-order loss reaction rate constant.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
name (str): The name of the first-order loss reaction rate constant.
|
|
15
|
+
scaling_factor (float): The scaling factor for the first-order loss rate constant.
|
|
16
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
17
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
18
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the first-order loss reaction rate constant.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
name: Optional[str] = None,
|
|
24
|
+
scaling_factor: Optional[float] = None,
|
|
25
|
+
reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
|
|
26
|
+
gas_phase: Optional[Phase] = None,
|
|
27
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
28
|
+
):
|
|
29
|
+
"""
|
|
30
|
+
Initializes the FirstOrderLoss object with the given parameters.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
name (str): The name of the first-order loss reaction rate constant.
|
|
34
|
+
scaling_factor (float): The scaling factor for the first-order loss rate constant.
|
|
35
|
+
reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
|
|
36
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
37
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the first-order loss reaction rate constant.
|
|
38
|
+
"""
|
|
39
|
+
super().__init__()
|
|
40
|
+
self.name = name if name is not None else self.name
|
|
41
|
+
self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
|
|
42
|
+
self.reactants = (
|
|
43
|
+
[
|
|
44
|
+
(
|
|
45
|
+
_ReactionComponent(r.name)
|
|
46
|
+
if isinstance(r, Species)
|
|
47
|
+
else _ReactionComponent(r[1].name, r[0])
|
|
48
|
+
)
|
|
49
|
+
for r in reactants
|
|
50
|
+
]
|
|
51
|
+
if reactants is not None
|
|
52
|
+
else self.reactants
|
|
53
|
+
)
|
|
54
|
+
self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
|
|
55
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def serialize(instance) -> Dict:
|
|
59
|
+
serialize_dict = {
|
|
60
|
+
"type": "FIRST_ORDER_LOSS",
|
|
61
|
+
"name": instance.name,
|
|
62
|
+
"scaling factor": instance.scaling_factor,
|
|
63
|
+
"reactants": ReactionComponentSerializer.serialize_list_reaction_components(instance.reactants),
|
|
64
|
+
"gas phase": instance.gas_phase,
|
|
65
|
+
}
|
|
66
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
67
|
+
return _remove_empty_keys(serialize_dict)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, Union, Tuple
|
|
2
|
+
from musica import _HenrysLaw, _ReactionComponent
|
|
3
|
+
from .phase import Phase
|
|
4
|
+
from .species import Species
|
|
5
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class HenrysLaw(_HenrysLaw):
|
|
9
|
+
"""
|
|
10
|
+
A class representing a Henry's law reaction rate constant.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
name (str): The name of the Henry's law reaction rate constant.
|
|
14
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
15
|
+
gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction.
|
|
16
|
+
aerosol_phase (Phase): The aerosol phase in which the reaction occurs.
|
|
17
|
+
aerosol_phase_water (Species): The water species in the aerosol phase.
|
|
18
|
+
aerosol_phase_species (Union[Species, Tuple[float, Species]]): The aerosol phase species involved in the reaction.
|
|
19
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the Henry's law reaction rate constant.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
name: Optional[str] = None,
|
|
25
|
+
gas_phase: Optional[Phase] = None,
|
|
26
|
+
gas_phase_species: Optional[Union[Species, Tuple[float, Species]]] = None,
|
|
27
|
+
aerosol_phase: Optional[Phase] = None,
|
|
28
|
+
aerosol_phase_water: Optional[Species] = None,
|
|
29
|
+
aerosol_phase_species: Optional[Union[Species, Tuple[float, Species]]] = None,
|
|
30
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
31
|
+
):
|
|
32
|
+
"""
|
|
33
|
+
Initializes the HenrysLaw object with the given parameters.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
name (str): The name of the Henry's law reaction rate constant.
|
|
37
|
+
gas_phase (Phase): The gas phase in which the reaction occurs.
|
|
38
|
+
gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction.
|
|
39
|
+
aerosol_phase (Phase): The aerosol phase in which the reaction occurs.
|
|
40
|
+
aerosol_phase_water (Species): The water species in the aerosol phase.
|
|
41
|
+
aerosol_phase_species (Union[Species, Tuple[float, Species]]): The aerosol phase species involved in the reaction.
|
|
42
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the Henry's law reaction rate constant.
|
|
43
|
+
"""
|
|
44
|
+
super().__init__()
|
|
45
|
+
self.name = name if name is not None else self.name
|
|
46
|
+
self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
|
|
47
|
+
self.gas_phase_species = (
|
|
48
|
+
(
|
|
49
|
+
_ReactionComponent(gas_phase_species.name)
|
|
50
|
+
if isinstance(gas_phase_species, Species)
|
|
51
|
+
else _ReactionComponent(gas_phase_species[1].name, gas_phase_species[0])
|
|
52
|
+
)
|
|
53
|
+
if gas_phase_species is not None
|
|
54
|
+
else self.gas_phase_species
|
|
55
|
+
)
|
|
56
|
+
self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase
|
|
57
|
+
self.aerosol_phase_water = (
|
|
58
|
+
aerosol_phase_water.name if aerosol_phase_water is not None else self.aerosol_phase_water
|
|
59
|
+
)
|
|
60
|
+
self.aerosol_phase_species = (
|
|
61
|
+
(
|
|
62
|
+
_ReactionComponent(aerosol_phase_species.name)
|
|
63
|
+
if isinstance(aerosol_phase_species, Species)
|
|
64
|
+
else _ReactionComponent(
|
|
65
|
+
aerosol_phase_species[1].name, aerosol_phase_species[0]
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
if aerosol_phase_species is not None
|
|
69
|
+
else self.aerosol_phase_species
|
|
70
|
+
)
|
|
71
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
72
|
+
|
|
73
|
+
@staticmethod
|
|
74
|
+
def serialize(instance) -> Dict:
|
|
75
|
+
serialize_dict = {
|
|
76
|
+
"type": "HL_PHASE_TRANSFER",
|
|
77
|
+
"name": instance.name,
|
|
78
|
+
"gas phase": instance.gas_phase,
|
|
79
|
+
"gas-phase species": instance.gas_phase_species.species_name,
|
|
80
|
+
"aerosol phase": instance.aerosol_phase,
|
|
81
|
+
"aerosol-phase water": instance.aerosol_phase_water,
|
|
82
|
+
"aerosol-phase species": instance.aerosol_phase_species.species_name,
|
|
83
|
+
}
|
|
84
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
85
|
+
return _remove_empty_keys(serialize_dict)
|
|
@@ -0,0 +1,161 @@
|
|
|
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 musica import _Mechanism, _Version, _Parser
|
|
11
|
+
from .species import Species
|
|
12
|
+
from .phase import Phase
|
|
13
|
+
from .arrhenius import Arrhenius, _Arrhenius
|
|
14
|
+
from .condensed_phase_arrhenius import CondensedPhaseArrhenius, _CondensedPhaseArrhenius
|
|
15
|
+
from .troe import Troe, _Troe
|
|
16
|
+
from .branched import Branched, _Branched
|
|
17
|
+
from .tunneling import Tunneling, _Tunneling
|
|
18
|
+
from .surface import Surface, _Surface
|
|
19
|
+
from .photolysis import Photolysis, _Photolysis
|
|
20
|
+
from .condensed_phase_photolysis import CondensedPhasePhotolysis, _CondensedPhasePhotolysis
|
|
21
|
+
from .emission import Emission, _Emission
|
|
22
|
+
from .first_order_loss import FirstOrderLoss, _FirstOrderLoss
|
|
23
|
+
from .aqueous_equilibrium import AqueousEquilibrium, _AqueousEquilibrium
|
|
24
|
+
from .wet_deposition import WetDeposition, _WetDeposition
|
|
25
|
+
from .henrys_law import HenrysLaw, _HenrysLaw
|
|
26
|
+
from .simpol_phase_transfer import SimpolPhaseTransfer, _SimpolPhaseTransfer
|
|
27
|
+
from .user_defined import UserDefined, _UserDefined
|
|
28
|
+
from .reactions import Reactions, ReactionType
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Version(_Version):
|
|
32
|
+
"""
|
|
33
|
+
A class representing the version of the mechanism.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Mechanism(_Mechanism):
|
|
38
|
+
"""
|
|
39
|
+
A class representing a chemical mechanism.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
name (str): The name of the mechanism.
|
|
43
|
+
reactions (List[Reaction]): A list of reactions in the mechanism.
|
|
44
|
+
species (List[Species]): A list of species in the mechanism.
|
|
45
|
+
phases (List[Phase]): A list of phases in the mechanism.
|
|
46
|
+
version (Version): The version of the mechanism.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
name: Optional[str] = None,
|
|
52
|
+
reactions: Optional[List[Any]] = None,
|
|
53
|
+
species: Optional[List[Species]] = None,
|
|
54
|
+
phases: Optional[List[Phase]] = None,
|
|
55
|
+
version: Optional[Version] = None,
|
|
56
|
+
):
|
|
57
|
+
"""
|
|
58
|
+
Initializes the Mechanism object with the given parameters.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
name (str): The name of the mechanism.
|
|
62
|
+
reactions (List[]): A list of reactions in the mechanism.
|
|
63
|
+
species (List[Species]): A list of species in the mechanism.
|
|
64
|
+
phases (List[Phase]): A list of phases in the mechanism.
|
|
65
|
+
version (Version): The version of the mechanism.
|
|
66
|
+
"""
|
|
67
|
+
super().__init__()
|
|
68
|
+
self.name = name
|
|
69
|
+
self.species = species if species is not None else []
|
|
70
|
+
self.phases = phases if phases is not None else []
|
|
71
|
+
self.reactions = Reactions(reactions=reactions if reactions is not None else [])
|
|
72
|
+
self.version = version if version is not None else Version()
|
|
73
|
+
|
|
74
|
+
def to_dict(self) -> Dict:
|
|
75
|
+
species_list = []
|
|
76
|
+
for species in self.species:
|
|
77
|
+
species_list.append(Species.serialize(species))
|
|
78
|
+
|
|
79
|
+
phases_list = []
|
|
80
|
+
for phase in self.phases:
|
|
81
|
+
phases_list.append(Phase.serialize(phase))
|
|
82
|
+
|
|
83
|
+
reactions_list = []
|
|
84
|
+
for reaction in self.reactions:
|
|
85
|
+
if isinstance(reaction, (_Arrhenius, Arrhenius)):
|
|
86
|
+
reactions_list.append(Arrhenius.serialize(reaction))
|
|
87
|
+
elif isinstance(reaction, (_Branched, Branched)):
|
|
88
|
+
reactions_list.append(Branched.serialize(reaction))
|
|
89
|
+
elif isinstance(reaction, (_CondensedPhaseArrhenius, CondensedPhaseArrhenius)):
|
|
90
|
+
reactions_list.append(CondensedPhaseArrhenius.serialize(reaction))
|
|
91
|
+
elif isinstance(reaction, (_CondensedPhasePhotolysis, CondensedPhasePhotolysis)):
|
|
92
|
+
reactions_list.append(CondensedPhasePhotolysis.serialize(reaction))
|
|
93
|
+
elif isinstance(reaction, (_Emission, Emission)):
|
|
94
|
+
reactions_list.append(Emission.serialize(reaction))
|
|
95
|
+
elif isinstance(reaction, (_FirstOrderLoss, FirstOrderLoss)):
|
|
96
|
+
reactions_list.append(FirstOrderLoss.serialize(reaction))
|
|
97
|
+
elif isinstance(reaction, (_SimpolPhaseTransfer, SimpolPhaseTransfer)):
|
|
98
|
+
reactions_list.append(SimpolPhaseTransfer.serialize(reaction))
|
|
99
|
+
elif isinstance(reaction, (_AqueousEquilibrium, AqueousEquilibrium)):
|
|
100
|
+
reactions_list.append(AqueousEquilibrium.serialize(reaction))
|
|
101
|
+
elif isinstance(reaction, (_WetDeposition, WetDeposition)):
|
|
102
|
+
reactions_list.append(WetDeposition.serialize(reaction))
|
|
103
|
+
elif isinstance(reaction, (_HenrysLaw, HenrysLaw)):
|
|
104
|
+
reactions_list.append(HenrysLaw.serialize(reaction))
|
|
105
|
+
elif isinstance(reaction, (_Photolysis, Photolysis)):
|
|
106
|
+
reactions_list.append(Photolysis.serialize(reaction))
|
|
107
|
+
elif isinstance(reaction, (_Surface, Surface)):
|
|
108
|
+
reactions_list.append(Surface.serialize(reaction))
|
|
109
|
+
elif isinstance(reaction, (_Troe, Troe)):
|
|
110
|
+
reactions_list.append(Troe.serialize(reaction))
|
|
111
|
+
elif isinstance(reaction, (_Tunneling, Tunneling)):
|
|
112
|
+
reactions_list.append(Tunneling.serialize(reaction))
|
|
113
|
+
elif isinstance(reaction, (_UserDefined, UserDefined)):
|
|
114
|
+
reactions_list.append(UserDefined.serialize(reaction))
|
|
115
|
+
else:
|
|
116
|
+
raise TypeError(f'Reaction type {type(reaction)} is not supported for export.')
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
"name": self.name,
|
|
120
|
+
"reactions": reactions_list,
|
|
121
|
+
"species": species_list,
|
|
122
|
+
"phases": phases_list,
|
|
123
|
+
"version": self.version.to_string(),
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
def export(self, file_path: str) -> None:
|
|
127
|
+
MechanismSerializer.serialize(self, file_path)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class Parser(_Parser):
|
|
131
|
+
"""
|
|
132
|
+
A class for parsing a chemical mechanism.
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class MechanismSerializer():
|
|
137
|
+
"""
|
|
138
|
+
A class for exporting a chemical mechanism.
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
@staticmethod
|
|
142
|
+
def serialize(mechanism: Mechanism, file_path: str = "./mechanism.json") -> None:
|
|
143
|
+
if not isinstance(mechanism, Mechanism):
|
|
144
|
+
raise TypeError(f"Object {mechanism} is not of type Mechanism.")
|
|
145
|
+
|
|
146
|
+
directory, file = os.path.split(file_path)
|
|
147
|
+
if directory:
|
|
148
|
+
os.makedirs(directory, exist_ok=True)
|
|
149
|
+
dictionary = mechanism.to_dict()
|
|
150
|
+
|
|
151
|
+
_, file_ext = os.path.splitext(file)
|
|
152
|
+
file_ext = file_ext.lower()
|
|
153
|
+
if file_ext in ['.yaml', '.yml']:
|
|
154
|
+
with open(file_path, 'w') as file:
|
|
155
|
+
yaml.dump(dictionary, file)
|
|
156
|
+
elif '.json' == file_ext:
|
|
157
|
+
json_str = json.dumps(dictionary, indent=4)
|
|
158
|
+
with open(file_path, 'w') as file:
|
|
159
|
+
file.write(json_str)
|
|
160
|
+
else:
|
|
161
|
+
raise Exception('Allowable write formats are .json, .yaml, and .yml')
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from typing import Optional, Any, Dict, List
|
|
2
|
+
from musica import _Phase
|
|
3
|
+
from .species import Species
|
|
4
|
+
from .utils import _add_other_properties, _remove_empty_keys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Phase(_Phase):
|
|
8
|
+
"""
|
|
9
|
+
A class representing a phase in a chemical mechanism.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
name (str): The name of the phase.
|
|
13
|
+
species (List[Species]): A list of species in the phase.
|
|
14
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the phase.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
name: Optional[str] = None,
|
|
20
|
+
species: Optional[List[Species]] = None,
|
|
21
|
+
other_properties: Optional[Dict[str, Any]] = None,
|
|
22
|
+
):
|
|
23
|
+
"""
|
|
24
|
+
Initializes the Phase object with the given parameters.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
name (str): The name of the phase.
|
|
28
|
+
species (List[Species]): A list of species in the phase.
|
|
29
|
+
other_properties (Dict[str, Any]): A dictionary of other properties of the phase.
|
|
30
|
+
"""
|
|
31
|
+
super().__init__()
|
|
32
|
+
self.name = name if name is not None else self.name
|
|
33
|
+
self.species = [s.name for s in species] if species is not None else self.species
|
|
34
|
+
self.other_properties = other_properties if other_properties is not None else self.other_properties
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def serialize(instance):
|
|
38
|
+
serialize_dict = {
|
|
39
|
+
"name": instance.name,
|
|
40
|
+
"species": instance.species,
|
|
41
|
+
}
|
|
42
|
+
_add_other_properties(serialize_dict, instance.other_properties)
|
|
43
|
+
return _remove_empty_keys(serialize_dict)
|