musica 0.14.4__cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.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.
Files changed (92) hide show
  1. musica/__init__.py +11 -0
  2. musica/_musica.cpython-310-aarch64-linux-gnu.so +0 -0
  3. musica/_version.py +1 -0
  4. musica/backend.py +58 -0
  5. musica/carma/__init__.py +20 -0
  6. musica/carma/carma.py +1727 -0
  7. musica/constants.py +3 -0
  8. musica/cuda.py +13 -0
  9. musica/examples/__init__.py +1 -0
  10. musica/examples/carma_aluminum.py +124 -0
  11. musica/examples/carma_sulfate.py +246 -0
  12. musica/examples/examples.py +175 -0
  13. musica/examples/lorenz.py +295 -0
  14. musica/examples/sulfate_box_model.py +439 -0
  15. musica/examples/ts1_latin_hypercube.py +245 -0
  16. musica/main.py +128 -0
  17. musica/mechanism_configuration/__init__.py +18 -0
  18. musica/mechanism_configuration/ancillary.py +6 -0
  19. musica/mechanism_configuration/arrhenius.py +149 -0
  20. musica/mechanism_configuration/branched.py +140 -0
  21. musica/mechanism_configuration/emission.py +82 -0
  22. musica/mechanism_configuration/first_order_loss.py +90 -0
  23. musica/mechanism_configuration/mechanism.py +93 -0
  24. musica/mechanism_configuration/phase.py +58 -0
  25. musica/mechanism_configuration/phase_species.py +58 -0
  26. musica/mechanism_configuration/photolysis.py +98 -0
  27. musica/mechanism_configuration/reaction_component.py +54 -0
  28. musica/mechanism_configuration/reactions.py +32 -0
  29. musica/mechanism_configuration/species.py +65 -0
  30. musica/mechanism_configuration/surface.py +98 -0
  31. musica/mechanism_configuration/taylor_series.py +136 -0
  32. musica/mechanism_configuration/ternary_chemical_activation.py +160 -0
  33. musica/mechanism_configuration/troe.py +160 -0
  34. musica/mechanism_configuration/tunneling.py +126 -0
  35. musica/mechanism_configuration/user_defined.py +99 -0
  36. musica/mechanism_configuration/utils.py +10 -0
  37. musica/micm/__init__.py +10 -0
  38. musica/micm/conditions.py +49 -0
  39. musica/micm/micm.py +135 -0
  40. musica/micm/solver.py +8 -0
  41. musica/micm/solver_result.py +24 -0
  42. musica/micm/state.py +220 -0
  43. musica/micm/utils.py +18 -0
  44. musica/tuvx/__init__.py +11 -0
  45. musica/tuvx/grid.py +98 -0
  46. musica/tuvx/grid_map.py +167 -0
  47. musica/tuvx/profile.py +130 -0
  48. musica/tuvx/profile_map.py +167 -0
  49. musica/tuvx/radiator.py +95 -0
  50. musica/tuvx/radiator_map.py +173 -0
  51. musica/tuvx/tuvx.py +283 -0
  52. musica-0.14.4.dist-info/METADATA +427 -0
  53. musica-0.14.4.dist-info/RECORD +92 -0
  54. musica-0.14.4.dist-info/WHEEL +6 -0
  55. musica-0.14.4.dist-info/entry_points.txt +3 -0
  56. musica-0.14.4.dist-info/licenses/AUTHORS.md +59 -0
  57. musica-0.14.4.dist-info/licenses/LICENSE +201 -0
  58. musica.libs/libaec-34bb4966.so.0.0.8 +0 -0
  59. musica.libs/libblas-8ed0a6f9.so.3.8.0 +0 -0
  60. musica.libs/libbrotlicommon-b6e6c8bd.so.1.0.6 +0 -0
  61. musica.libs/libbrotlidec-5094ef0a.so.1.0.6 +0 -0
  62. musica.libs/libcom_err-6d8d18aa.so.2.1 +0 -0
  63. musica.libs/libcrypt-258f54d5.so.1.1.0 +0 -0
  64. musica.libs/libcrypto-3eda328c.so.1.1.1k +0 -0
  65. musica.libs/libcurl-7faeef02.so.4.5.0 +0 -0
  66. musica.libs/libdf-9661c601.so.0.0.0 +0 -0
  67. musica.libs/libgfortran-e1b7dfc8.so.5.0.0 +0 -0
  68. musica.libs/libgssapi_krb5-fe951f80.so.2.2 +0 -0
  69. musica.libs/libhdf5-463e48d5.so.103.1.0 +0 -0
  70. musica.libs/libhdf5_hl-74316838.so.100.1.2 +0 -0
  71. musica.libs/libidn2-1b2a13b7.so.0.3.6 +0 -0
  72. musica.libs/libjpeg-ee25248c.so.62.2.0 +0 -0
  73. musica.libs/libk5crypto-84470bb3.so.3.1 +0 -0
  74. musica.libs/libkeyutils-fe6e95a9.so.1.6 +0 -0
  75. musica.libs/libkrb5-26ef5d84.so.3.3 +0 -0
  76. musica.libs/libkrb5support-875e89dc.so.0.1 +0 -0
  77. musica.libs/liblapack-8d137073.so.3.8.0 +0 -0
  78. musica.libs/liblber-2-86b08e65.4.so.2.10.9 +0 -0
  79. musica.libs/libldap-2-5c1dd279.4.so.2.10.9 +0 -0
  80. musica.libs/libmfhdf-9c336c5f.so.0.0.0 +0 -0
  81. musica.libs/libnetcdf-71a067be.so.15.0.1 +0 -0
  82. musica.libs/libnetcdff-6a455dd4.so.7.0.0 +0 -0
  83. musica.libs/libnghttp2-3a94c239.so.14.17.0 +0 -0
  84. musica.libs/libpcre2-8-8701a61e.so.0.7.1 +0 -0
  85. musica.libs/libpsl-130094ea.so.5.3.1 +0 -0
  86. musica.libs/libsasl2-076b3c1f.so.3.0.0 +0 -0
  87. musica.libs/libselinux-5700a1fd.so.1 +0 -0
  88. musica.libs/libssh-e0d3bd94.so.4.8.7 +0 -0
  89. musica.libs/libssl-f60bf0e2.so.1.1.1k +0 -0
  90. musica.libs/libsz-81b556a2.so.2.0.1 +0 -0
  91. musica.libs/libtirpc-1fa9018c.so.3.0.0 +0 -0
  92. musica.libs/libunistring-be03fd41.so.2.1.0 +0 -0
musica/main.py ADDED
@@ -0,0 +1,128 @@
1
+ import argparse
2
+ import datetime
3
+ import logging
4
+ import shutil
5
+ import os
6
+ from musica import Examples
7
+ from musica import __version__
8
+ import musica.examples
9
+ import importlib.resources as ir
10
+ import musica
11
+
12
+
13
+ def versions():
14
+ return f"musica {musica.__version__} (MICM {musica.micm.__version__}, TUV-x {musica.tuvx.__version__}, CARMA {musica.carma.__version__})"
15
+
16
+
17
+ def format_examples_help(examples):
18
+ return '\n'.join(f"{e.short_name}: {e.description}" for e in examples)
19
+
20
+
21
+ def parse_arguments():
22
+ parser = argparse.ArgumentParser(
23
+ description='musica CLI',
24
+ formatter_class=argparse.RawTextHelpFormatter
25
+ )
26
+ parser.add_argument(
27
+ '-e', '--example',
28
+ type=str,
29
+ choices=[e.short_name for e in Examples],
30
+ help=f'Name of the example to copy out.\nAvailable examples:\n{format_examples_help(Examples)}'
31
+ )
32
+ parser.add_argument(
33
+ '-o', '--output',
34
+ type=str,
35
+ help=("Path to save the output to.")
36
+ )
37
+ parser.add_argument(
38
+ '-v', '--verbose',
39
+ action='count',
40
+ default=0,
41
+ help='Increase logging verbosity. Use -v for info, -vv for debug.'
42
+ )
43
+ parser.add_argument(
44
+ '--version',
45
+ action='version',
46
+ version=versions(),
47
+ )
48
+ parser.add_argument(
49
+ '--convert',
50
+ type=str,
51
+ help='Path to a musica v0 configuration to convert to v1 format.'
52
+ )
53
+ return parser.parse_args()
54
+
55
+
56
+ def setup_logging(verbosity):
57
+ log_level = logging.DEBUG if verbosity >= 2 else logging.INFO if verbosity == 1 else logging.CRITICAL
58
+ datefmt = '%Y-%m-%d %H:%M:%S'
59
+ format_string = '%(asctime)s - %(levelname)s - %(module)s.%(funcName)s - %(message)s'
60
+ formatter = logging.Formatter(format_string, datefmt=datefmt)
61
+ console_handler = logging.StreamHandler()
62
+ console_handler.setFormatter(formatter)
63
+ console_handler.setLevel(log_level)
64
+ logging.basicConfig(level=log_level, handlers=[console_handler])
65
+
66
+
67
+ def copy_example(logger, example_arg, output_path):
68
+ example = next((e for e in Examples if e.short_name == example_arg), None)
69
+ if not example:
70
+ raise ValueError(f"Example '{example_arg}' not found.")
71
+
72
+ logger.info(f"Copying example: {example} to {output_path}")
73
+
74
+ with ir.path(musica.examples, example.path) as example_path:
75
+ logger.info(f"Copying example from {example_path} to {output_path}")
76
+ shutil.copy(example_path, output_path)
77
+
78
+
79
+ def convert_configuration(logger, configuration, output_path):
80
+ logger.info(f"Converting configuration: {configuration} to {output_path}")
81
+ if not os.path.exists(configuration):
82
+ raise ValueError(f"Configuration file '{configuration}' does not exist.")
83
+
84
+ parser = musica.mechanism_configuration.Parser()
85
+ mechanism = parser.parse_and_convert_v0(configuration)
86
+ mechanism.export(output_path)
87
+
88
+
89
+ def main():
90
+ start = datetime.datetime.now()
91
+
92
+ args = parse_arguments()
93
+ setup_logging(args.verbose)
94
+
95
+ logger = logging.getLogger(__name__)
96
+
97
+ logger.debug(f"{__file__}")
98
+ logger.info(f"Start time: {start}")
99
+
100
+ logger.debug(f"Working directory = {os.getcwd()}")
101
+
102
+ # Figure out what action we are doing. We are either converting or copying an example.
103
+ convert = args.convert
104
+ example_arg = args.example
105
+ output = args.output
106
+
107
+ if not convert and not example_arg:
108
+ raise ValueError("Either --convert or --example must be specified.")
109
+
110
+ if convert and example_arg:
111
+ raise ValueError("Cannot specify both --convert and --example. Choose one.")
112
+
113
+ if not output:
114
+ logger.debug("No output path specified, using current directory.")
115
+ output = '.'
116
+
117
+ if convert:
118
+ convert_configuration(logger, convert, output)
119
+ else:
120
+ copy_example(logger, example_arg, output)
121
+
122
+ end = datetime.datetime.now()
123
+ logger.info(f"End time: {end}")
124
+ logger.info(f"Elapsed time: {end - start} seconds")
125
+
126
+
127
+ if __name__ == "__main__":
128
+ main()
@@ -0,0 +1,18 @@
1
+ from .arrhenius import Arrhenius
2
+ from .branched import Branched
3
+ from .emission import Emission
4
+ from .first_order_loss import FirstOrderLoss
5
+ from .mechanism import Mechanism
6
+ from .ancillary import Version, Parser, ReactionType
7
+ from .phase import Phase
8
+ from .phase_species import PhaseSpecies
9
+ from .photolysis import Photolysis
10
+ from .reaction_component import ReactionComponent
11
+ from .reactions import Reactions
12
+ from .species import Species
13
+ from .surface import Surface
14
+ from .taylor_series import TaylorSeries
15
+ from .ternary_chemical_activation import TernaryChemicalActivation
16
+ from .troe import Troe
17
+ from .tunneling import Tunneling
18
+ from .user_defined import UserDefined
@@ -0,0 +1,6 @@
1
+ from .. import backend
2
+
3
+ _backend = backend.get_backend()
4
+ Version = _backend._mechanism_configuration._Version
5
+ Parser = _backend._mechanism_configuration._Parser
6
+ ReactionType = _backend._mechanism_configuration._ReactionType
@@ -0,0 +1,149 @@
1
+ from typing import Optional, Any, Dict, List, Union, Tuple
2
+ from .. import backend
3
+ from .phase import Phase
4
+ from .species import Species
5
+ from .utils import _add_other_properties, _remove_empty_keys
6
+ from ..constants import BOLTZMANN
7
+ from .reaction_component import ReactionComponent
8
+ from .ancillary import ReactionType
9
+
10
+ _backend = backend.get_backend()
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.
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.
98
+
99
+ Returns:
100
+ Dict: A dictionary representation of the Arrhenius object.
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__ = """
119
+ A class representing an Arrhenius rate constant.
120
+
121
+ k = A * exp( C / T ) * ( T / D )^B * exp( 1 - E * P )
122
+
123
+ where:
124
+ k = rate constant
125
+ A = pre-exponential factor [(mol m-3)^(n-1)s-1]
126
+ B = temperature exponent [unitless]
127
+ C = exponential term [K-1]
128
+ D = reference temperature [K]
129
+ E = pressure scaling term [Pa-1]
130
+ T = temperature [K]
131
+ P = pressure [Pa]
132
+ n = number of reactants
133
+
134
+ Attributes:
135
+ name (str): The name of the Arrhenius rate constant.
136
+ A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1] where n is the number of reactants.
137
+ B (float): Temperature exponent [unitless].
138
+ C (float): Exponential term [K-1].
139
+ D (float): Reference Temperature [K].
140
+ E (float): Pressure scaling term [Pa-1].
141
+ reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
142
+ products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
143
+ gas_phase (Phase): The gas phase in which the reaction occurs.
144
+ other_properties (Dict[str, Any]): A dictionary of other properties of the Arrhenius rate constant.
145
+ """
146
+
147
+ Arrhenius.__init__ = __init__
148
+ Arrhenius.serialize = serialize
149
+ Arrhenius.type = type
@@ -0,0 +1,140 @@
1
+ from .utils import _add_other_properties, _remove_empty_keys
2
+ from .species import Species
3
+ from .phase import Phase
4
+ from typing import Optional, Any, Dict, List, Union, Tuple
5
+ from .. import backend
6
+ from .reaction_component import ReactionComponent
7
+ from .ancillary import ReactionType
8
+
9
+ _backend = backend.get_backend()
10
+ Branched = _backend._mechanism_configuration._Branched
11
+
12
+ original_init = Branched.__init__
13
+
14
+
15
+ @property
16
+ def type(self):
17
+ """Get the reaction type."""
18
+ return ReactionType.Branched
19
+
20
+
21
+ def __init__(
22
+ self,
23
+ name: Optional[str] = None,
24
+ X: Optional[float] = None,
25
+ Y: Optional[float] = None,
26
+ a0: Optional[float] = None,
27
+ n: Optional[float] = None,
28
+ reactants: Optional[List[Union[Species,
29
+ Tuple[float, Species]]]] = None,
30
+ nitrate_products: Optional[List[Union[Species,
31
+ Tuple[float, Species]]]] = None,
32
+ alkoxy_products: Optional[List[Union[Species,
33
+ Tuple[float, Species]]]] = None,
34
+ gas_phase: Optional[Phase] = None,
35
+ other_properties: Optional[Dict[str, Any]] = None,
36
+ ):
37
+ """
38
+ Initializes the Branched object with the given parameters.
39
+
40
+ Args:
41
+ name (str): The name of the branched reaction rate constant.
42
+ X (float): Pre-exponential branching factor [(mol m-3)^-(n-1)s-1].
43
+ Y (float): Exponential branching factor [K-1].
44
+ a0 (float): Z parameter [unitless].
45
+ n (float): A parameter [unitless].
46
+ reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
47
+ nitrate_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the nitrate branch.
48
+ alkoxy_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the alkoxy branch.
49
+ gas_phase (Phase): The gas phase in which the reaction occurs.
50
+ other_properties (Dict[str, Any]): A dictionary of other properties of the branched reaction rate constant.
51
+ """
52
+ original_init(self)
53
+
54
+ self.name = name if name is not None else self.name
55
+ self.X = X if X is not None else self.X
56
+ self.Y = Y if Y is not None else self.Y
57
+ self.a0 = a0 if a0 is not None else self.a0
58
+ self.n = n if n is not None else self.n
59
+ self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
60
+ self.other_properties = other_properties if other_properties is not None else self.other_properties
61
+ self.reactants = (
62
+ [
63
+ (
64
+ ReactionComponent(r.name)
65
+ if isinstance(r, Species)
66
+ else ReactionComponent(r[1].name, r[0])
67
+ )
68
+ for r in reactants
69
+ ]
70
+ if reactants is not None
71
+ else self.reactants
72
+ )
73
+ self.nitrate_products = (
74
+ [
75
+ (
76
+ ReactionComponent(p.name)
77
+ if isinstance(p, Species)
78
+ else ReactionComponent(p[1].name, p[0])
79
+ )
80
+ for p in nitrate_products
81
+ ]
82
+ if nitrate_products is not None
83
+ else self.nitrate_products
84
+ )
85
+ self.alkoxy_products = (
86
+ [
87
+ (
88
+ ReactionComponent(p.name)
89
+ if isinstance(p, Species)
90
+ else ReactionComponent(p[1].name, p[0])
91
+ )
92
+ for p in alkoxy_products
93
+ ]
94
+ if alkoxy_products is not None
95
+ else self.alkoxy_products
96
+ )
97
+
98
+
99
+ def serialize(self) -> Dict:
100
+ """
101
+ Serialize the Branched object to a dictionary using only Python-visible data.
102
+
103
+ Returns:
104
+ Dict: A dictionary representation of the Branched object.
105
+ """
106
+ serialize_dict = {
107
+ "type": "BRANCHED_NO_RO2",
108
+ "name": self.name,
109
+ "X": self.X,
110
+ "Y": self.Y,
111
+ "a0": self.a0,
112
+ "n": self.n,
113
+ "reactants": [r.serialize() for r in self.reactants],
114
+ "nitrate products": [r.serialize() for r in self.nitrate_products],
115
+ "alkoxy products": [r.serialize() for r in self.alkoxy_products],
116
+ "gas phase": self.gas_phase,
117
+ }
118
+ _add_other_properties(serialize_dict, self.other_properties)
119
+ return _remove_empty_keys(serialize_dict)
120
+
121
+
122
+ Branched.__doc__ = """
123
+ A class representing a branched reaction rate constant.
124
+
125
+ Attributes:
126
+ name (str): The name of the branched reaction rate constant.
127
+ X (float): Pre-exponential branching factor [(mol m-3)^-(n-1)s-1].
128
+ Y (float): Exponential branching factor [K-1].
129
+ a0 (float): Z parameter [unitless].
130
+ n (float): A parameter [unitless].
131
+ reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction.
132
+ nitrate_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the nitrate branch.
133
+ alkoxy_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the alkoxy branch.
134
+ gas_phase (Phase): The gas phase in which the reaction occurs.
135
+ other_properties (Dict[str, Any]): A dictionary of other properties of the branched reaction rate constant.
136
+ """
137
+
138
+ Branched.__init__ = __init__
139
+ Branched.serialize = serialize
140
+ Branched.type = type
@@ -0,0 +1,82 @@
1
+ from .utils import _add_other_properties, _remove_empty_keys
2
+ from .species import Species
3
+ from .phase import Phase
4
+ from typing import Optional, Any, Dict, List, Union, Tuple
5
+ from .. import backend
6
+ from .reaction_component import ReactionComponent
7
+ from .ancillary import ReactionType
8
+
9
+ _backend = backend.get_backend()
10
+ Emission = _backend._mechanism_configuration._Emission
11
+
12
+ original_init = Emission.__init__
13
+
14
+
15
+ @property
16
+ def type(self):
17
+ return ReactionType.Emission
18
+
19
+
20
+ def __init__(
21
+ self,
22
+ name: Optional[str] = None,
23
+ scaling_factor: Optional[float] = None,
24
+ products: Optional[List[Union[Species, Tuple[float, Species]]]] = None,
25
+ gas_phase: Optional[Phase] = None,
26
+ other_properties: Optional[Dict[str, Any]] = None,
27
+ ):
28
+ """
29
+ Initializes the Emission object with the given parameters.
30
+
31
+ Args:
32
+ name (str): The name of the emission reaction rate constant.
33
+ scaling_factor (float): The scaling factor for the emission rate constant.
34
+ products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
35
+ gas_phase (Phase): The gas phase in which the reaction occurs.
36
+ other_properties (Dict[str, Any]): A dictionary of other properties of the emission reaction rate constant.
37
+ """
38
+ original_init(self)
39
+ self.name = name if name is not None else self.name
40
+ self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor
41
+ self.products = (
42
+ [
43
+ (
44
+ ReactionComponent(p.name)
45
+ if isinstance(p, Species)
46
+ else ReactionComponent(p[1].name, p[0])
47
+ )
48
+ for p in products
49
+ ]
50
+ if products is not None
51
+ else self.products
52
+ )
53
+ self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase
54
+ self.other_properties = other_properties if other_properties is not None else self.other_properties
55
+
56
+
57
+ def serialize(self) -> Dict:
58
+ serialize_dict = {
59
+ "type": "EMISSION",
60
+ "name": self.name,
61
+ "scaling factor": self.scaling_factor,
62
+ "products": [r.serialize() for r in self.products],
63
+ "gas phase": self.gas_phase,
64
+ }
65
+ _add_other_properties(serialize_dict, self.other_properties)
66
+ return serialize_dict
67
+
68
+
69
+ Emission.__doc__ = """
70
+ A class representing an emission reaction rate constant.
71
+
72
+ Attributes:
73
+ name (str): The name of the emission reaction rate constant.
74
+ scaling_factor (float): The scaling factor for the emission rate constant.
75
+ products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction.
76
+ gas_phase (Phase): The gas phase in which the reaction occurs.
77
+ other_properties (Dict[str, Any]): A dictionary of other properties of the emission reaction rate constant.
78
+ """
79
+
80
+ Emission.__init__ = __init__
81
+ Emission.serialize = serialize
82
+ Emission.type = type
@@ -0,0 +1,90 @@
1
+ from .utils import _add_other_properties, _remove_empty_keys
2
+ from .species import Species
3
+ from .phase import Phase
4
+ from typing import Optional, Any, Dict, List, Union, Tuple
5
+ from .. import backend
6
+ from .reaction_component import ReactionComponent
7
+ from .ancillary import ReactionType
8
+
9
+ _backend = backend.get_backend()
10
+ FirstOrderLoss = _backend._mechanism_configuration._FirstOrderLoss
11
+
12
+ original_init = FirstOrderLoss.__init__
13
+
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
+ ):
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
+ 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.
62
+
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