From 18ef172987cca5e9a12bb12e9541b168f92b54da Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Thu, 8 May 2025 12:39:09 -0500 Subject: [PATCH 1/3] removing python build --- .github/workflows/python.yml | 37 - CMakeLists.txt | 9 +- README.md | 1 - cmake/dependencies.cmake | 20 +- mechanism_configuration/CMakeLists.txt | 34 - mechanism_configuration/__init__.py | 2 - mechanism_configuration/tests/test_parser.py | 693 ---------- mechanism_configuration/types.py | 1290 ------------------ mechanism_configuration/wrapper.cpp | 522 ------- pyproject.toml | 50 - src/CMakeLists.txt | 4 +- 11 files changed, 3 insertions(+), 2659 deletions(-) delete mode 100644 .github/workflows/python.yml delete mode 100644 mechanism_configuration/CMakeLists.txt delete mode 100644 mechanism_configuration/__init__.py delete mode 100644 mechanism_configuration/tests/test_parser.py delete mode 100644 mechanism_configuration/types.py delete mode 100644 mechanism_configuration/wrapper.cpp delete mode 100644 pyproject.toml diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml deleted file mode 100644 index 35532452..00000000 --- a/.github/workflows/python.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Test python - -on: - push: - branches: - - main - pull_request: - workflow_dispatch: - -jobs: - build: - strategy: - fail-fast: false - matrix: - platform: [windows-latest, macos-latest, ubuntu-latest] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - # python versions: https://devguide.python.org/versions/ - - runs-on: ${{ matrix.platform }} - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Add requirements - run: python -m pip install --upgrade wheel setuptools - - - name: Build and install - run: pip install --verbose .[test] - - - name: Test - run: pytest \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c16602e..6508aad0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${PROJECT_SOURCE_DIR}/cmake") option(MECH_CONFIG_ENABLE_TESTS "Build the tests" ON) -option(MECH_CONFIG_ENABLE_PYTHON_LIBRARY "Build the python library" ON) option(MECH_CONFIG_ENABLE_PIC "Build the library with position independent code" ON) option(MECH_CONFIG_ENABLE_COVERAGE "Enable code coverage output" OFF) @@ -39,12 +38,6 @@ include(cmake/dependencies.cmake) add_subdirectory(src) -################################################################################ -# python -if(MECH_CONFIG_ENABLE_PYTHON_LIBRARY) - add_subdirectory(mechanism_configuration) -endif() - ################################################################################ # Tests @@ -74,6 +67,6 @@ endif() # Packaging # only include packaging if we are the top level project being built -if(PROJECT_IS_TOP_LEVEL AND NOT MECH_CONFIG_ENABLE_PYTHON_LIBRARY) +if(PROJECT_IS_TOP_LEVEL) add_subdirectory(packaging) endif() \ No newline at end of file diff --git a/README.md b/README.md index ba59d8bb..01b03b8c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ An attempt at defining a model-independent configuration schema for atmospheric [![Windows](https://github.com/ncar/MechanismConfiguration/actions/workflows/windows.yml/badge.svg)](https://github.com/ncar/MechanismConfiguration/actions/workflows/windows.yml) [![Mac](https://github.com/ncar/MechanismConfiguration/actions/workflows/mac.yml/badge.svg)](https://github.com/ncar/MechanismConfiguration/actions/workflows/mac.yml) [![Ubuntu](https://github.com/ncar/MechanismConfiguration/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/ncar/MechanismConfiguration/actions/workflows/ubuntu.yml) -[![PyPI version](https://badge.fury.io/py/mechanism_configuration.svg)](https://pypi.org/p/mechanism_configuration) [![codecov](https://codecov.io/gh/NCAR/MechanismConfiguration/branch/main/graph/badge.svg)](https://codecov.io/gh/NCAR/MechanismConfiguration) [![DOI](https://zenodo.org/badge/668458983.svg)](https://doi.org/10.5281/zenodo.15116380) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index c98bc705..19951ed7 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -39,22 +39,4 @@ FetchContent_Declare(yaml-cpp set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(yaml-cpp) - -################################################################################ -# pybind11 - -if(MECH_CONFIG_ENABLE_PYTHON_LIBRARY) - set(PYBIND11_NEWPYTHON ON) - - set_git_default(PYBIND11_GIT_REPOSITORY https://github.com/pybind/pybind11) - set_git_default(PYBIND11_GIT_TAG v2.12.0) - - FetchContent_Declare(pybind11 - GIT_REPOSITORY ${PYBIND11_GIT_REPOSITORY} - GIT_TAG ${PYBIND11_GIT_TAG} - GIT_PROGRESS NOT ${FETCHCONTENT_QUIET} - ) - - FetchContent_MakeAvailable(pybind11) -endif() +FetchContent_MakeAvailable(yaml-cpp) \ No newline at end of file diff --git a/mechanism_configuration/CMakeLists.txt b/mechanism_configuration/CMakeLists.txt deleted file mode 100644 index bd49865d..00000000 --- a/mechanism_configuration/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -pybind11_add_module(_mechanism_configuration - wrapper.cpp -) - -target_link_libraries(_mechanism_configuration PRIVATE mechanism_configuration) - -# Set the rpath for the shared library -if(APPLE) - message(STATUS "Building for MacOS") - set_target_properties(_mechanism_configuration PROPERTIES - INSTALL_RPATH "@loader_path" - BUILD_WITH_INSTALL_RPATH TRUE - ) -elseif(UNIX) - message(STATUS "Building for Linux") - set_target_properties(_mechanism_configuration PROPERTIES - INSTALL_RPATH "$ORIGIN" - BUILD_WITH_INSTALL_RPATH TRUE - ) -endif() - -if(WIN32) - # makefiles on windows don't need the config directory - if (${CMAKE_GENERATOR} MATCHES "MinGW Makefiles") - set(PYTHON_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}") - else() - # but visual studio does - set(PYTHON_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/$") - endif() -else() - set(PYTHON_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}") -endif() - -install(TARGETS _mechanism_configuration mechanism_configuration LIBRARY DESTINATION .) diff --git a/mechanism_configuration/__init__.py b/mechanism_configuration/__init__.py deleted file mode 100644 index 3950c21b..00000000 --- a/mechanism_configuration/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from _mechanism_configuration import * -from .types import * \ No newline at end of file diff --git a/mechanism_configuration/tests/test_parser.py b/mechanism_configuration/tests/test_parser.py deleted file mode 100644 index cb0e87b4..00000000 --- a/mechanism_configuration/tests/test_parser.py +++ /dev/null @@ -1,693 +0,0 @@ -import pytest -from mechanism_configuration import * -from _mechanism_configuration import _core - - -def validate_species(species): - # Define the expected species and their required attributes - expected_species = { - "A": { "other_properties": {"__absolute tolerance": "1e-30"} }, - "B": {"tracer_type": "AEROSOL"}, - "C": {"tracer_type": "THIRD_BODY"}, - "M": {}, - "H2O2": { - "HLC_298K_mol_m3_Pa": 1.011596348, - "HLC_exponential_factor_K": 6340, - "diffusion_coefficient_m2_s": 1.46e-05, - "N_star": 1.74, - "molecular_weight_kg_mol": 0.0340147, - "density_kg_m3": 1000.0, - "other_properties": {"__absolute tolerance": "1e-10"}, - }, - "ethanol": { - "diffusion_coefficient_m2_s": 0.95e-05, - "N_star": 2.55, - "molecular_weight_kg_mol": 0.04607, - "other_properties": {"__absolute tolerance": "1e-20"}, - }, - "ethanol_aq": { - "molecular_weight_kg_mol": 0.04607, - "density_kg_m3": 1000.0, - "other_properties": {"__absolute tolerance": "1e-20"}, - }, - "H2O2_aq": { - "molecular_weight_kg_mol": 0.0340147, - "density_kg_m3": 1000.0, - "other_properties": {"__absolute tolerance": "1e-10"}, - }, - "H2O_aq": { - "density_kg_m3": 1000.0, - "molecular_weight_kg_mol": 0.01801, - }, - "aerosol stuff": { - "molecular_weight_kg_mol": 0.5, - "density_kg_m3": 1000.0, - "other_properties": {"__absolute tolerance": "1e-20"}, - }, - "more aerosol stuff": { - "molecular_weight_kg_mol": 0.2, - "density_kg_m3": 1000.0, - "other_properties": {"__absolute tolerance": "1e-20"}, - }, - } - - # Create a dictionary for quick lookup of species by name - species_dict = {sp.name: sp for sp in species} - - # Validate each expected species - for name, attributes in expected_species.items(): - assert name in species_dict, f"Species '{name}' is missing." - for attr, expected_value in attributes.items(): - assert hasattr( - species_dict[name], attr - ), f"Attribute '{attr}' is missing for species '{name}'." - got_value = getattr(species_dict[name], attr) - # Handle special cases for floating-point representation - if isinstance(got_value, str) and ".0e" in got_value: - got_value = got_value.replace(".0e", "e") - elif isinstance(got_value, dict): - def replace_in_dict(d): - for key, value in d.items(): - if isinstance(value, str) and ".0e" in value: - d[key] = value.replace(".0e", "e") - elif isinstance(value, dict): - replace_in_dict(value) - replace_in_dict(got_value) - assert got_value == expected_value, ( - f"Attribute '{attr}' for species '{name}' has value " - f"{got_value}, expected {expected_value}." - ) - - -def validate_phases(phases): - # Define the expected phases and their associated species - expected_phases = { - "gas": ["A", "B", "C", "ethanol"], - "aqueous aerosol": ["H2O2_aq", "H2O_aq", "ethanol_aq", "A", "B", "C"], - "surface reacting phase": ["aerosol stuff", "more aerosol stuff"], - "cloud": ["B", "C"], - } - - # Create a dictionary for quick lookup of phases by name - phases_dict = {phase.name: phase for phase in phases} - - # Validate each expected phase - for name, expected_species in expected_phases.items(): - assert name in phases_dict, f"Phase '{name}' is missing." - assert hasattr( - phases_dict[name], "species" - ), f"Phase '{name}' does not have a 'species' attribute." - phase_species = getattr(phases_dict[name], "species") - assert set(phase_species) == set(expected_species), ( - f"Phase '{name}' has species {phase_species}, " - f"expected {expected_species}." - ) - - -def extract_components(components): - return [ - {"species name": component.species_name, "coefficient": component.coefficient} - for component in components - ] - - -def validate_arrhenius(reactions): - assert reactions[0].type == ReactionType.Arrhenius - assert extract_components(reactions[0].reactants) == [ - {"species name": "B", "coefficient": 1} - ] - assert extract_components(reactions[0].products) == [ - {"species name": "C", "coefficient": 1} - ] - assert reactions[0].A == 32.1 - assert reactions[0].B == -2.3 - assert reactions[0].C == 102.3 - assert reactions[0].D == 63.4 - assert reactions[0].E == -1.3 - assert reactions[0].name == "my arrhenius" - assert reactions[0].other_properties == {} - assert reactions[1].type == ReactionType.Arrhenius - assert extract_components(reactions[1].reactants) == [ - {"species name": "A", "coefficient": 1} - ] - assert extract_components(reactions[1].products) == [ - {"species name": "B", "coefficient": 1.2} - ] - assert reactions[1].A == 29.3 - assert reactions[1].B == -1.5 - assert reactions[1].C == -101.2 / 1.380649e-23 - assert reactions[1].D == 82.6 - assert reactions[1].E == -0.98 - assert reactions[1].name == "my other arrhenius" - assert reactions[1].other_properties == {} - - -def validate_henrys_law(reactions): - assert reactions[0].type == ReactionType.HenrysLaw - assert reactions[0].gas_phase == "gas" - assert extract_components([reactions[0].gas_phase_species]) == [ - {"species name": "H2O2", "coefficient": 1} - ] - assert reactions[0].aerosol_phase == "aqueous aerosol" - assert extract_components([reactions[0].aerosol_phase_species]) == [ - {"species name": "H2O2_aq", "coefficient": 1} - ] - assert reactions[0].aerosol_phase_water == "H2O_aq" - assert reactions[0].name == "my henry's law" - - -def validate_simpol_phase_transfer(reactions): - assert reactions[0].type == ReactionType.SimpolPhaseTransfer - assert reactions[0].gas_phase == "gas" - assert extract_components([reactions[0].gas_phase_species]) == [ - {"species name": "ethanol", "coefficient": 1} - ] - assert reactions[0].aerosol_phase == "aqueous aerosol" - assert extract_components([reactions[0].aerosol_phase_species]) == [ - {"species name": "ethanol_aq", "coefficient": 1} - ] - assert reactions[0].B == [-1.97e03, 2.91e00, 1.96e-03, -4.96e-01] - assert reactions[0].name == "my simpol" - - -def validate_aqueous_equilibrium(reactions): - assert reactions[0].type == ReactionType.AqueousEquilibrium - assert reactions[0].aerosol_phase == "aqueous aerosol" - assert reactions[0].aerosol_phase_water == "H2O_aq" - assert reactions[0].A == 1.14e-2 - assert reactions[0].C == 2300.0 - assert reactions[0].k_reverse == 0.32 - assert extract_components(reactions[0].reactants) == [ - {"species name": "A", "coefficient": 2} - ] - assert extract_components(reactions[0].products) == [ - {"species name": "B", "coefficient": 1}, - {"species name": "C", "coefficient": 1}, - ] - assert reactions[0].name == "my aqueous eq" - - -def validate_condensed_phase_arrhenius(reactions): - for reaction in reactions: - assert reaction.type == ReactionType.CondensedPhaseArrhenius - assert reaction.aerosol_phase == "aqueous aerosol" - assert reaction.aerosol_phase_water == "H2O_aq" - assert reaction.A == 123.45 - assert reaction.B == 1.3 - assert reaction.D == 300.0 - assert reaction.E == 0.6e-5 - assert extract_components(reaction.reactants) == [ - {"species name": "H2O2_aq", "coefficient": 1}, - {"species name": "H2O_aq", "coefficient": 1}, - ] - assert extract_components(reaction.products) == [ - {"species name": "ethanol_aq", "coefficient": 1} - ] - assert reactions[0].name == "my condensed arrhenius" - assert reactions[0].C == -123.45 / 1.380649e-23 - assert reactions[1].name == "my other condensed arrhenius" - assert reactions[1].C == 123.45 - - -def validate_condensed_phase_photolysis(reactions): - assert reactions[0].type == ReactionType.CondensedPhasePhotolysis - assert reactions[0].aerosol_phase == "aqueous aerosol" - assert reactions[0].aerosol_phase_water == "H2O_aq" - assert extract_components(reactions[0].reactants) == [ - {"species name": "H2O2_aq", "coefficient": 1} - ] - assert extract_components(reactions[0].products) == [ - {"species name": "ethanol_aq", "coefficient": 1} - ] - assert reactions[0].scaling_factor == 12.3 - assert reactions[0].name == "condensed photo B" - - -def validate_emission(reactions): - assert reactions[0].type == ReactionType.Emission - assert reactions[0].gas_phase == "gas" - assert extract_components(reactions[0].products) == [ - {"species name": "B", "coefficient": 1} - ] - assert reactions[0].scaling_factor == 12.3 - assert reactions[0].name == "my emission" - - -def validate_first_order_loss(reactions): - assert reactions[0].type == ReactionType.FirstOrderLoss - assert reactions[0].gas_phase == "gas" - assert extract_components(reactions[0].reactants) == [ - {"species name": "C", "coefficient": 1} - ] - assert reactions[0].scaling_factor == 12.3 - assert reactions[0].name == "my first order loss" - - -def validate_photolysis(reactions): - assert reactions[0].type == ReactionType.Photolysis - assert reactions[0].gas_phase == "gas" - assert extract_components(reactions[0].reactants) == [ - {"species name": "B", "coefficient": 1} - ] - assert extract_components(reactions[0].products) == [ - {"species name": "C", "coefficient": 1} - ] - assert reactions[0].scaling_factor == 12.3 - assert reactions[0].name == "photo B" - - -def validate_surface(reactions): - assert reactions[0].type == ReactionType.Surface - assert reactions[0].gas_phase == "gas" - assert extract_components([reactions[0].gas_phase_species]) == [ - {"species name": "A", "coefficient": 1} - ] - assert reactions[0].reaction_probability == 2.0e-2 - assert extract_components(reactions[0].gas_phase_products) == [ - {"species name": "B", "coefficient": 1}, - {"species name": "C", "coefficient": 1}, - ] - assert reactions[0].aerosol_phase == "surface reacting phase" - assert reactions[0].name == "my surface" - - -def validate_troe(reactions): - assert reactions[0].type == ReactionType.Troe - assert reactions[0].gas_phase == "gas" - assert extract_components(reactions[0].reactants) == [ - {"species name": "B", "coefficient": 1}, - {"species name": "M", "coefficient": 1}, - ] - assert extract_components(reactions[0].products) == [ - {"species name": "C", "coefficient": 1} - ] - assert reactions[0].k0_A == 1.2e-12 - assert reactions[0].k0_B == 167 - assert reactions[0].k0_C == 3 - assert reactions[0].kinf_A == 136 - assert reactions[0].kinf_B == 5 - assert reactions[0].kinf_C == 24 - assert reactions[0].Fc == 0.9 - assert reactions[0].N == 0.8 - assert reactions[0].name == "my troe" - - -def validate_branched_no_ro2(reactions): - assert reactions[0].type == ReactionType.Branched - assert reactions[0].gas_phase == "gas" - assert extract_components(reactions[0].reactants) == [ - {"species name": "A", "coefficient": 1} - ] - assert extract_components(reactions[0].alkoxy_products) == [ - {"species name": "B", "coefficient": 1} - ] - assert extract_components(reactions[0].nitrate_products) == [ - {"species name": "C", "coefficient": 1} - ] - assert reactions[0].X == 1.2e-4 - assert reactions[0].Y == 167 - assert reactions[0].a0 == 0.15 - assert reactions[0].n == 9 - assert reactions[0].name == "my branched" - - -def validate_tunneling(reactions): - assert reactions[0].type == ReactionType.Tunneling - assert reactions[0].gas_phase == "gas" - assert extract_components(reactions[0].reactants) == [ - {"species name": "B", "coefficient": 1} - ] - assert extract_components(reactions[0].products) == [ - {"species name": "C", "coefficient": 1} - ] - assert reactions[0].A == 123.45 - assert reactions[0].B == 1200.0 - assert reactions[0].C == 1.0e8 - assert reactions[0].name == "my tunneling" - - -def validate_wet_deposition(reactions): - assert reactions[0].type == ReactionType.WetDeposition - assert reactions[0].name == "rxn cloud" - assert reactions[0].aerosol_phase == "cloud" - assert reactions[0].scaling_factor == 12.3 - -def validate_user_defined(reactions): - assert reactions[0].type == ReactionType.UserDefined - assert reactions[0].gas_phase == "gas" - assert extract_components(reactions[0].reactants) == [ - {"species name": "A", "coefficient": 1}, - {"species name": "B", "coefficient": 1}, - ] - assert extract_components(reactions[0].products) == [ - {"species name": "C", "coefficient": 1.3} - ] - assert reactions[0].scaling_factor == 12.3 - assert reactions[0].name == "my user defined" - assert reactions[0].other_properties == {} - - -def validate_full_v1_mechanism(mechanism): - assert mechanism is not None - assert mechanism.name == "Full Configuration" - assert len(mechanism.species) == 11 - validate_species(mechanism.species) - assert len(mechanism.phases) == 4 - validate_phases(mechanism.phases) - assert len(mechanism.reactions.aqueous_equilibrium) == 1 - validate_aqueous_equilibrium(mechanism.reactions.aqueous_equilibrium) - assert len(mechanism.reactions.arrhenius) == 2 - validate_arrhenius(mechanism.reactions.arrhenius) - assert len(mechanism.reactions.branched) == 1 - validate_branched_no_ro2(mechanism.reactions.branched) - assert len(mechanism.reactions.condensed_phase_arrhenius) == 2 - validate_condensed_phase_arrhenius(mechanism.reactions.condensed_phase_arrhenius) - assert len(mechanism.reactions.condensed_phase_photolysis) == 1 - validate_condensed_phase_photolysis( - mechanism.reactions.condensed_phase_photolysis - ) - assert len(mechanism.reactions.emission) == 1 - validate_emission(mechanism.reactions.emission) - assert len(mechanism.reactions.first_order_loss) == 1 - validate_first_order_loss(mechanism.reactions.first_order_loss) - assert len(mechanism.reactions.henrys_law) == 1 - validate_henrys_law(mechanism.reactions.henrys_law) - assert len(mechanism.reactions.photolysis) == 1 - validate_photolysis(mechanism.reactions.photolysis) - assert len(mechanism.reactions.simpol_phase_transfer) == 1 - validate_simpol_phase_transfer(mechanism.reactions.simpol_phase_transfer) - assert len(mechanism.reactions.surface) == 1 - validate_surface(mechanism.reactions.surface) - assert len(mechanism.reactions.troe) == 1 - validate_troe(mechanism.reactions.troe) - assert len(mechanism.reactions.tunneling) == 1 - validate_tunneling(mechanism.reactions.tunneling) - assert len(mechanism.reactions.wet_deposition) == 1 - validate_wet_deposition(mechanism.reactions.wet_deposition) - assert len(mechanism.reactions.user_defined) == 1 - validate_user_defined(mechanism.reactions.user_defined) - assert mechanism.version.major == 1 - assert mechanism.version.minor == 0 - assert mechanism.version.patch == 0 - assert len(mechanism.reactions) == 17 - for reaction in mechanism.reactions: - assert reaction is not None - assert isinstance(reaction.type, _core._ReactionType) - - -def test_parsed_full_v1_configuration(): - parser = Parser() - extensions = [".yaml", ".json"] - for extension in extensions: - path = f"examples/v1/full_configuration{extension}" - mechanism = parser.parse(path) - validate_full_v1_mechanism(mechanism) - - -def test_parser_reports_bad_files(): - parser = Parser() - extensions = [".yaml", ".json"] - for extension in extensions: - path = f"examples/_missing_configuration{extension}" - with pytest.raises(Exception): - parser.parse(path) - - -def test_hard_coded_full_v1_configuration(): - - #Chemical species - A = Species(name = "A", other_properties = {"__absolute tolerance": "1.0e-30"}) - B = Species(name = "B", tracer_type = "AEROSOL") - C = Species(name = "C", tracer_type = "THIRD_BODY") - M = Species(name = "M") - H2O2 = Species( - name = "H2O2", - HLC_298K_mol_m3_Pa = 1.011596348, - HLC_exponential_factor_K = 6340, - diffusion_coefficient_m2_s = 1.46e-05, - N_star = 1.74, - molecular_weight_kg_mol = 0.0340147, - density_kg_m3 = 1000.0, - other_properties = {"__absolute tolerance": "1.0e-10"}, - ) - ethanol = Species( - name = "ethanol", - diffusion_coefficient_m2_s = 0.95e-05, - N_star = 2.55, - molecular_weight_kg_mol = 0.04607, - other_properties = {"__absolute tolerance": "1.0e-20"}, - ) - ethanol_aq = Species( - name = "ethanol_aq", - molecular_weight_kg_mol = 0.04607, - density_kg_m3 = 1000.0, - other_properties = {"__absolute tolerance": "1.0e-20"}, - ) - H2O2_aq = Species( - name = "H2O2_aq", - molecular_weight_kg_mol = 0.0340147, - density_kg_m3 = 1000.0, - other_properties = {"__absolute tolerance": "1.0e-10"}, - ) - H2O_aq = Species( - name = "H2O_aq", - density_kg_m3 = 1000.0, - molecular_weight_kg_mol = 0.01801, - ) - aerosol_stuff = Species( - name = "aerosol stuff", - molecular_weight_kg_mol = 0.5, - density_kg_m3 = 1000.0, - other_properties = {"__absolute tolerance": "1.0e-20"}, - ) - more_aerosol_stuff = Species( - name = "more aerosol stuff", - molecular_weight_kg_mol = 0.2, - density_kg_m3 = 1000.0, - other_properties = {"__absolute tolerance": "1.0e-20"}, - ) - - # Chemical phases - gas = Phase(name = "gas", species = [A, B, C, ethanol]) - aqueous_aerosol = Phase( - name = "aqueous aerosol", - species = [H2O2_aq, H2O_aq, ethanol_aq, A, B, C] - ) - surface_reacting_phase = Phase( - name = "surface reacting phase", - species = [aerosol_stuff, more_aerosol_stuff] - ) - cloud = Phase(name = "cloud", species = [B, C]) - - # Reactions - my_arrhenius = Arrhenius( - name = "my arrhenius", - A = 32.1, B = -2.3, C = 102.3, D = 63.4, E = -1.3, - gas_phase = gas, - reactants = [B], - products = [C] - ) - - my_other_arrhenius = Arrhenius( - name = "my other arrhenius", - A = 29.3, B = -1.5, Ea = 101.2, D = 82.6, E = -0.98, - gas_phase = gas, - reactants = [A], - products = [(1.2, B)] - ) - - my_condensed_arrhenius = CondensedPhaseArrhenius( - name = "my condensed arrhenius", - aerosol_phase = aqueous_aerosol, - aerosol_phase_water = H2O_aq, - A = 123.45, - B = 1.3, - Ea = 123.45, - D = 300.0, - E = 0.6e-5, - reactants = [H2O2_aq, H2O_aq], - products = [ethanol_aq] - ) - - my_other_condensed_arrhenius = CondensedPhaseArrhenius( - name = "my other condensed arrhenius", - aerosol_phase = aqueous_aerosol, - aerosol_phase_water = H2O_aq, - A = 123.45, - B = 1.3, - C = 123.45, - D = 300.0, - E = 0.6e-5, - reactants = [H2O2_aq, H2O_aq], - products = [ethanol_aq] - ) - - my_troe = Troe( - name = "my troe", - gas_phase = gas, - k0_A = 1.2e-12, - k0_B = 167, - k0_C = 3, - kinf_A = 136, - kinf_B = 5, - kinf_C = 24, - Fc = 0.9, - N = 0.8, - reactants = [B, M], - products = [C] - ) - - my_branched = Branched( - name = "my branched", - gas_phase = gas, - reactants = [A], - alkoxy_products = [B], - nitrate_products = [C], - X = 1.2e-4, - Y = 167, - a0 = 0.15, - n = 9, - ) - - my_tunneling = Tunneling( - name = "my tunneling", - gas_phase = gas, - reactants = [B], - products = [C], - A = 123.45, - B = 1200.0, - C = 1.0e8, - ) - - my_surface = Surface( - name = "my surface", - gas_phase = gas, - gas_phase_species = A, - reaction_probability = 2.0e-2, - gas_phase_products = [B, C], - aerosol_phase = surface_reacting_phase, - ) - - photo_B = Photolysis( - name = "photo B", - gas_phase = gas, - reactants = [B], - products = [C], - scaling_factor = 12.3, - ) - - condensed_photo_B = CondensedPhasePhotolysis( - name = "condensed photo B", - aerosol_phase = aqueous_aerosol, - aerosol_phase_water = H2O_aq, - reactants = [H2O2_aq], - products = [ethanol_aq], - scaling_factor = 12.3, - ) - - my_emission = Emission( - name = "my emission", - gas_phase = gas, - products = [B], - scaling_factor = 12.3, - ) - - my_first_order_loss = FirstOrderLoss( - name = "my first order loss", - gas_phase = gas, - reactants = [C], - scaling_factor = 12.3, - ) - - my_aqueous_equilibrium = AqueousEquilibrium( - name = "my aqueous eq", - gas_phase= gas, - aerosol_phase = aqueous_aerosol, - aerosol_phase_water = H2O_aq, - A = 1.14e-2, - C = 2300.0, - k_reverse = 0.32, - reactants = [(2, A)], - products = [B, C], - ) - - my_wet_deposition = WetDeposition( - name = "rxn cloud", - aerosol_phase = cloud, - scaling_factor = 12.3, - ) - - my_henrys_law = HenrysLaw( - name = "my henry's law", - gas_phase = gas, - gas_phase_species = H2O2, - aerosol_phase = aqueous_aerosol, - aerosol_phase_species = H2O2_aq, - aerosol_phase_water = H2O_aq, - ) - - my_simpol_phase_transfer = SimpolPhaseTransfer( - name = "my simpol", - gas_phase = gas, - gas_phase_species = ethanol, - aerosol_phase = aqueous_aerosol, - aerosol_phase_species = ethanol_aq, - B = [-1.97e03, 2.91e00, 1.96e-03, -4.96e-01], - ) - - user_defined = UserDefined( - name = "my user defined", - gas_phase = gas, - reactants = [A, B], - products = [(1.3, C)], - scaling_factor = 12.3, - ) - - #Mechanism - mechanism = Mechanism( - name = "Full Configuration", - species = [A, B, C, M, H2O2, ethanol, ethanol_aq, H2O2_aq, H2O_aq, - aerosol_stuff, more_aerosol_stuff], - phases = [gas, aqueous_aerosol, surface_reacting_phase, cloud], - reactions = [my_arrhenius, my_other_arrhenius, my_condensed_arrhenius, - my_other_condensed_arrhenius, my_troe, my_branched, - my_tunneling, my_surface, photo_B, condensed_photo_B, - my_emission, my_first_order_loss, my_aqueous_equilibrium, - my_wet_deposition, my_henrys_law, my_simpol_phase_transfer, - user_defined], - version = Version(1, 0, 0), - ) - - validate_full_v1_mechanism(mechanism) - -def test_hard_coded_default_constructed_types(): - arrhenius = Arrhenius() - assert arrhenius.type == ReactionType.Arrhenius - condensed_phase_arrhenius = CondensedPhaseArrhenius() - assert condensed_phase_arrhenius.type == ReactionType.CondensedPhaseArrhenius - condensed_phase_photolysis = CondensedPhasePhotolysis() - assert condensed_phase_photolysis.type == ReactionType.CondensedPhasePhotolysis - emission = Emission() - assert emission.type == ReactionType.Emission - first_order_loss = FirstOrderLoss() - assert first_order_loss.type == ReactionType.FirstOrderLoss - henrys_law = HenrysLaw() - assert henrys_law.type == ReactionType.HenrysLaw - photolysis = Photolysis() - assert photolysis.type == ReactionType.Photolysis - simpol_phase_transfer = SimpolPhaseTransfer() - assert simpol_phase_transfer.type == ReactionType.SimpolPhaseTransfer - surface = Surface() - assert surface.type == ReactionType.Surface - troe = Troe() - assert troe.type == ReactionType.Troe - tunneling = Tunneling() - assert tunneling.type == ReactionType.Tunneling - wet_deposition = WetDeposition() - assert wet_deposition.type == ReactionType.WetDeposition - branched = Branched() - assert branched.type == ReactionType.Branched - user_defined = UserDefined() - assert user_defined.type == ReactionType.UserDefined - - \ No newline at end of file diff --git a/mechanism_configuration/types.py b/mechanism_configuration/types.py deleted file mode 100644 index a0113735..00000000 --- a/mechanism_configuration/types.py +++ /dev/null @@ -1,1290 +0,0 @@ -# Copyright (C) 2025 University Corporation for Atmospheric Research -# SPDX-License-Identifier: Apache-2.0 -# -# This file is part of the musica Python package. -# For more information, see the LICENSE file in the top-level directory of this distribution. -from typing import Optional, Any, Dict, List, Union, Tuple -from _mechanism_configuration._core import ( - _ReactionType, - _Species, - _Phase, - _ReactionComponent, - _Arrhenius, - _CondensedPhaseArrhenius, - _Troe, - _Branched, - _Tunneling, - _Surface, - _Photolysis, - _CondensedPhasePhotolysis, - _Emission, - _FirstOrderLoss, - _AqueousEquilibrium, - _WetDeposition, - _HenrysLaw, - _SimpolPhaseTransfer, - _UserDefined, - _Reactions, - _ReactionsIterator, - _Mechanism, - _Version, - _Parser, -) - -BOLTZMANN_CONSTANT_J_K = 1.380649e-23 # J K-1 - - -class ReactionType(_ReactionType): - """ - A enum class representing a reaction type in a chemical mechanism. - """ - - -class Species(_Species): - """ - A class representing a species in a chemical mechanism. - - Attributes: - name (str): The name of the species. - HLC_298K_mol_m3_Pa (float): Henry's Law Constant at 298K [mol m-3 Pa-1] - HLC_exponential_factor_K: Henry's Law Constant exponential factor [K] - diffusion_coefficient_m2_s (float): Diffusion coefficient [m2 s-1] - N_star (float): A parameter used to calculate the mass accomodation factor (Ervens et al., 2003) - molecular_weight_kg_mol (float): Molecular weight [kg mol-1] - density_kg_m3 (float): Density [kg m-3] - tracer_type (str): The type of tracer ("AEROSOL", "THIRD_BODY", "CONSTANT"). - other_properties (Dict[str, Any]): A dictionary of other properties of the species. - """ - - def __init__( - self, - name: Optional[str] = None, - HLC_298K_mol_m3_Pa: Optional[float] = None, - HLC_exponential_factor_K: Optional[float] = None, - diffusion_coefficient_m2_s: Optional[float] = None, - N_star: Optional[float] = None, - molecular_weight_kg_mol: Optional[float] = None, - density_kg_m3: Optional[float] = None, - tracer_type: Optional[str] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Species object with the given parameters. - - Args: - name (str): The name of the species. - HLC_298K_mol_m3_Pa (float): Henry's Law Constant at 298K [mol m-3 Pa-1] - HLC_exponential_factor_K: Henry's Law Constant exponential factor [K] - diffusion_coefficient_m2_s (float): Diffusion coefficient [m2 s-1] - N_star (float): A parameter used to calculate the mass accomodation factor (Ervens et al., 2003) - molecular_weight_kg_mol (float): Molecular weight [kg mol-1] - density_kg_m3 (float): Density [kg m-3] - tracer_type (str): The type of tracer ("AEROSOL", "THIRD_BODY", "CONSTANT"). - other_properties (Dict[str, Any]): A dictionary of other properties of the species. - """ - super().__init__() - self.name = name if name is not None else self.name - self.HLC_298K_mol_m3_Pa = HLC_298K_mol_m3_Pa if HLC_298K_mol_m3_Pa is not None else self.HLC_298K_mol_m3_Pa - self.HLC_exponential_factor_K = HLC_exponential_factor_K if HLC_exponential_factor_K is not None else self.HLC_exponential_factor_K - self.diffusion_coefficient_m2_s = diffusion_coefficient_m2_s if diffusion_coefficient_m2_s is not None else self.diffusion_coefficient_m2_s - self.N_star = N_star if N_star is not None else self.N_star - self.molecular_weight_kg_mol = molecular_weight_kg_mol if molecular_weight_kg_mol is not None else self.molecular_weight_kg_mol - self.density_kg_m3 = density_kg_m3 if density_kg_m3 is not None else self.density_kg_m3 - self.tracer_type = tracer_type if tracer_type is not None else self.tracer_type - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Phase(_Phase): - """ - A class representing a phase in a chemical mechanism. - - Attributes: - name (str): The name of the phase. - species (List[Species]): A list of species in the phase. - other_properties (Dict[str, Any]): A dictionary of other properties of the phase. - """ - - def __init__( - self, - name: Optional[str] = None, - species: Optional[List[Species]] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Phase object with the given parameters. - - Args: - name (str): The name of the phase. - species (List[Species]): A list of species in the phase. - other_properties (Dict[str, Any]): A dictionary of other properties of the phase. - """ - super().__init__() - self.name = name - self.species = [s.name for s in species] if species is not None else self.species - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Arrhenius(_Arrhenius): - """ - A class representing an Arrhenius rate constant. - - k = A * exp( C / T ) * ( T / D )^B * exp( 1 - E * P ) - - where: - k = rate constant - A = pre-exponential factor [(mol m-3)^(n-1)s-1] - B = temperature exponent [unitless] - C = exponential term [K-1] - D = reference temperature [K] - E = pressure scaling term [Pa-1] - T = temperature [K] - P = pressure [Pa] - n = number of reactants - - Attributes: - name (str): The name of the Arrhenius rate constant. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1] where n is the number of reactants. - B (float): Temperature exponent [unitless]. - C (float): Exponential term [K-1]. - D (float): Reference Temperature [K]. - E (float): Pressure scaling term [Pa-1]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the Arrhenius rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - A: Optional[float] = None, - B: Optional[float] = None, - C: Optional[float] = None, - Ea: Optional[float] = None, - D: Optional[float] = None, - E: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Arrhenius object with the given parameters. - - Args: - name (str): The name of the Arrhenius rate constant. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1] where n is the number of reactants. - B (float): Temperature exponent [unitless]. - C (float): Exponential term [K-1]. - Ea (float): Activation energy [J molecule-1]. - D (float): Reference Temperature [K]. - E (float): Pressure scaling term [Pa-1]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the Arrhenius rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.A = A if A is not None else self.A - self.B = B if B is not None else self.B - if C is not None and Ea is not None: - raise ValueError("Cannot specify both C and Ea.") - self.C = -Ea / BOLTZMANN_CONSTANT_J_K if Ea is not None else C if C is not None else self.C - self.D = D if D is not None else self.D - self.E = E if E is not None else self.E - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class CondensedPhaseArrhenius(_CondensedPhaseArrhenius): - """ - A class representing a condensed phase Arrhenius rate constant. - - Attributes: - name (str): The name of the condensed phase Arrhenius rate constant. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1]. - B (float): Temperature exponent [unitless]. - C (float): Exponential term [K-1]. - Ea (float): Activation energy [J molecule-1]. - D (float): Reference Temperature [K]. - E (float): Pressure scaling term [Pa-1]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (Species): The water species in the aerosol phase. - other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase Arrhenius rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - A: Optional[float] = None, - B: Optional[float] = None, - C: Optional[float] = None, - Ea: Optional[float] = None, - D: Optional[float] = None, - E: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - aerosol_phase: Optional[Phase] = None, - aerosol_phase_water: Optional[Species] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the CondensedPhaseArrhenius object with the given parameters. - - Args: - name (str): The name of the condensed phase Arrhenius rate constant. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1]. - B (float): Temperature exponent [unitless]. - C (float): Exponential term [K-1]. - Ea (float): Activation energy [J molecule-1]. - D (float): Reference Temperature [K]. - E (float): Pressure scaling term [Pa-1]. - reactants (List[Union[Species, Tuple[float, Species]]]]: A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]]: A list of products formed in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (Species): The water species in the aerosol phase. - other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase Arrhenius rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.A = A if A is not None else self.A - self.B = B if B is not None else self.B - if C is not None and Ea is not None: - raise ValueError("Cannot specify both C and Ea.") - self.C = -Ea / BOLTZMANN_CONSTANT_J_K if Ea is not None else C if C is not None else self.C - self.D = D if D is not None else self.D - self.E = E if E is not None else self.E - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase - self.aerosol_phase_water = ( - aerosol_phase_water.name if aerosol_phase_water is not None else self.aerosol_phase_water - ) - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Troe(_Troe): - """ - A class representing a Troe rate constant. - - Attributes: - name (str): The name of the Troe rate constant. - k0_A (float): Pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1]. - k0_B (float): Temperature exponent for the low-pressure limit [unitless]. - k0_C (float): Exponential term for the low-pressure limit [K-1]. - kinf_A (float): Pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1]. - kinf_B (float): Temperature exponent for the high-pressure limit [unitless]. - kinf_C (float): Exponential term for the high-pressure limit [K-1]. - Fc (float): Troe parameter [unitless]. - N (float): Troe parameter [unitless]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the Troe rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - k0_A: Optional[float] = None, - k0_B: Optional[float] = None, - k0_C: Optional[float] = None, - kinf_A: Optional[float] = None, - kinf_B: Optional[float] = None, - kinf_C: Optional[float] = None, - Fc: Optional[float] = None, - N: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Troe object with the given parameters. - - k0 = k0_A * exp( k0_C / T ) * ( T / 300.0 )^k0_B - kinf = kinf_A * exp( kinf_C / T ) * ( T / 300.0 )^kinf_B - k = k0[M] / ( 1 + k0[M] / kinf ) * Fc^(1 + 1/N*(log10(k0[M]/kinf))^2)^-1 - - where: - k = rate constant - k0 = low-pressure limit rate constant - kinf = high-pressure limit rate constant - k0_A = pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1] - k0_B = temperature exponent for the low-pressure limit [unitless] - k0_C = exponential term for the low-pressure limit [K-1] - kinf_A = pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1] - kinf_B = temperature exponent for the high-pressure limit [unitless] - kinf_C = exponential term for the high-pressure limit [K-1] - Fc = Troe parameter [unitless] - N = Troe parameter [unitless] - T = temperature [K] - M = concentration of the third body [mol m-3] - - Args: - name (str): The name of the Troe rate constant. - k0_A (float): Pre-exponential factor for the low-pressure limit [(mol m-3)^(n-1)s-1]. - k0_B (float): Temperature exponent for the low-pressure limit [unitless]. - k0_C (float): Exponential term for the low-pressure limit [K-1]. - kinf_A (float): Pre-exponential factor for the high-pressure limit [(mol m-3)^(n-1)s-1]. - kinf_B (float): Temperature exponent for the high-pressure limit [unitless]. - kinf_C (float): Exponential term for the high-pressure limit [K-1]. - Fc (float): Troe parameter [unitless]. - N (float): Troe parameter [unitless]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the Troe rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.k0_A = k0_A if k0_A is not None else self.k0_A - self.k0_B = k0_B if k0_B is not None else self.k0_B - self.k0_C = k0_C if k0_C is not None else self.k0_C - self.kinf_A = kinf_A if kinf_A is not None else self.kinf_A - self.kinf_B = kinf_B if kinf_B is not None else self.kinf_B - self.kinf_C = kinf_C if kinf_C is not None else self.kinf_C - self.Fc = Fc if Fc is not None else self.Fc - self.N = N if N is not None else self.N - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Branched(_Branched): - """ - A class representing a branched reaction rate constant. - - (TODO: get details from MusicBox) - - Attributes: - name (str): The name of the branched reaction rate constant. - X (float): Pre-exponential branching factor [(mol m-3)^-(n-1)s-1]. - Y (float): Exponential branching factor [K-1]. - a0 (float): Z parameter [unitless]. - n (float): A parameter [unitless]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - nitrate_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the nitrate branch. - alkoxy_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the alkoxy branch. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the branched reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - X: Optional[float] = None, - Y: Optional[float] = None, - a0: Optional[float] = None, - n: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - nitrate_products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - alkoxy_products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Branched object with the given parameters. - - Args: - name (str): The name of the branched reaction rate constant. - X (float): Pre-exponential branching factor [(mol m-3)^-(n-1)s-1]. - Y (float): Exponential branching factor [K-1]. - a0 (float): Z parameter [unitless]. - n (float): A parameter [unitless]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - nitrate_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the nitrate branch. - alkoxy_products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the alkoxy branch. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the branched reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.X = X if X is not None else self.X - self.Y = Y if Y is not None else self.Y - self.a0 = a0 if a0 is not None else self.a0 - self.n = n if n is not None else self.n - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.nitrate_products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in nitrate_products - ] - if nitrate_products is not None - else self.nitrate_products - ) - self.alkoxy_products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in alkoxy_products - ] - if alkoxy_products is not None - else self.alkoxy_products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Tunneling(_Tunneling): - """ - A class representing a quantum tunneling reaction rate constant. - - k = A * exp( -B / T ) * exp( C / T^3 ) - - where: - k = rate constant - A = pre-exponential factor [(mol m-3)^(n-1)s-1] - B = tunneling parameter [K^-1] - C = tunneling parameter [K^-3] - T = temperature [K] - n = number of reactants - - Attributes: - name (str): The name of the tunneling reaction rate constant. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1]. - B (float): Tunneling parameter [K^-1]. - C (float): Tunneling parameter [K^-3]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the tunneling reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - A: Optional[float] = None, - B: Optional[float] = None, - C: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Tunneling object with the given parameters. - - Args: - name (str): The name of the tunneling reaction rate constant. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1]. - B (float): Tunneling parameter [K^-1]. - C (float): Tunneling parameter [K^-3]. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the tunneling reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.A = A if A is not None else self.A - self.B = B if B is not None else self.B - self.C = C if C is not None else self.C - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Surface(_Surface): - """ - A class representing a surface in a chemical mechanism. - - (TODO: get details from MusicBox) - - Attributes: - name (str): The name of the surface. - reaction_probability (float): The probability of a reaction occurring on the surface. - gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction. - gas_phase_products (List[Union[Species, Tuple[float, Species]]]): The gas phase products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the surface. - """ - - def __init__( - self, - name: Optional[str] = None, - reaction_probability: Optional[float] = None, - gas_phase_species: Optional[Union[Species, Tuple[float, Species]]] = None, - gas_phase_products: Optional[ - List[Union[Species, Tuple[float, Species]]] - ] = None, - gas_phase: Optional[Phase] = None, - aerosol_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Surface object with the given parameters. - - Args: - name (str): The name of the surface. - reaction_probability (float): The probability of a reaction occurring on the surface. - gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction. - gas_phase_products (List[Union[Species, Tuple[float, Species]]]): The gas phase products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the surface. - """ - super().__init__() - self.name = name if name is not None else self.name - self.reaction_probability = reaction_probability if reaction_probability is not None else self.reaction_probability - self.gas_phase_species = ( - ( - _ReactionComponent(gas_phase_species.name) - if isinstance(gas_phase_species, Species) - else _ReactionComponent(gas_phase_species[1].name, gas_phase_species[0]) - ) - if gas_phase_species is not None - else self.gas_phase_species - ) - self.gas_phase_products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in gas_phase_products - ] - if gas_phase_products is not None - else self.gas_phase_products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Photolysis(_Photolysis): - """ - A class representing a photolysis reaction rate constant. - - Attributes: - name (str): The name of the photolysis reaction rate constant. - scaling_factor (float): The scaling factor for the photolysis rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - scaling_factor: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Photolysis object with the given parameters. - - Args: - name (str): The name of the photolysis reaction rate constant. - scaling_factor (float): The scaling factor for the photolysis rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant. - """ - super().__init__() - self.name = name = name if name is not None else self.name - self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class CondensedPhasePhotolysis(_CondensedPhasePhotolysis): - """ - A class representing a condensed phase photolysis reaction rate constant. - - Attributes: - name (str): The name of the condensed phase photolysis reaction rate constant. - scaling_factor (float): The scaling factor for the photolysis rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (float): The water species in the aerosol phase [unitless]. - other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase photolysis reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - scaling_factor: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - aerosol_phase: Optional[Phase] = None, - aerosol_phase_water: Optional[Species] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the CondensedPhasePhotolysis object with the given parameters. - - Args: - name (str): The name of the condensed phase photolysis reaction rate constant. - scaling_factor (float): The scaling factor for the photolysis rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (Species): The water species in the aerosol phase [unitless]. - other_properties (Dict[str, Any]): A dictionary of other properties of the condensed phase photolysis reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase - self.aerosol_phase_water = ( - aerosol_phase_water.name if aerosol_phase_water is not None else self.aerosol_phase_water - ) - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Emission(_Emission): - """ - A class representing an emission reaction rate constant. - - Attributes: - name (str): The name of the emission reaction rate constant. - scaling_factor (float): The scaling factor for the emission rate constant. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the emission reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - scaling_factor: Optional[float] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the Emission object with the given parameters. - - Args: - name (str): The name of the emission reaction rate constant. - scaling_factor (float): The scaling factor for the emission rate constant. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the emission reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class FirstOrderLoss(_FirstOrderLoss): - """ - A class representing a first-order loss reaction rate constant. - - Attributes: - name (str): The name of the first-order loss reaction rate constant. - scaling_factor (float): The scaling factor for the first-order loss rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the first-order loss reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - scaling_factor: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the FirstOrderLoss object with the given parameters. - - Args: - name (str): The name of the first-order loss reaction rate constant. - scaling_factor (float): The scaling factor for the first-order loss rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the first-order loss reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class AqueousEquilibrium(_AqueousEquilibrium): - """ - A class representing an aqueous equilibrium reaction rate constant. - - Attributes: - name (str): The name of the aqueous equilibrium reaction rate constant. - gas_phase (Phase): The gas phase in which the reaction occurs. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (Species): The water species in the aerosol phase. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1]. - C (float): Exponential term [K-1]. - k_reverse (float): Reverse rate constant [(mol m-3)^(n-1)s-1]. - other_properties (Dict[str, Any]): A dictionary of other properties of the aqueous equilibrium reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - gas_phase: Optional[Phase] = None, - aerosol_phase: Optional[Phase] = None, - aerosol_phase_water: Optional[Species] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - A: Optional[float] = None, - C: Optional[float] = None, - k_reverse: Optional[float] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the AqueousEquilibrium object with the given parameters. - - Args: - name (str): The name of the aqueous equilibrium reaction rate constant. - gas_phase (Phase): The gas phase in which the reaction occurs. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (Species): The water species in the aerosol phase. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - A (float): Pre-exponential factor [(mol m-3)^(n-1)s-1]. - C (float): Exponential term [K-1]. - k_reverse (float): Reverse rate constant [(mol m-3)^(n-1)s-1]. - other_properties (Dict[str, Any]): A dictionary of other properties of the aqueous equilibrium reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase - self.aerosol_phase_water = ( - aerosol_phase_water.name if aerosol_phase_water is not None else self.aerosol_phase_water - ) - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.A = A if A is not None else self.A - self.C = C if C is not None else self.C - self.k_reverse = k_reverse if k_reverse is not None else self.k_reverse - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class WetDeposition(_WetDeposition): - """ - A class representing a wet deposition reaction rate constant. - - Attributes: - name (str): The name of the wet deposition reaction rate constant. - scaling_factor (float): The scaling factor for the wet deposition rate constant. - aerosol_phase (Phase): The aerosol phase which undergoes wet deposition. - unknown_properties (Dict[str, Any]): A dictionary of other properties of the wet deposition reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - scaling_factor: Optional[float] = None, - aerosol_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the WetDeposition object with the given parameters. - - Args: - name (str): The name of the wet deposition reaction rate constant. - scaling_factor (float): The scaling factor for the wet deposition rate constant. - aerosol_phase (Phase): The aerosol phase which undergoes wet deposition. - other_properties (Dict[str, Any]): A dictionary of other properties of the wet deposition reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor - self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class HenrysLaw(_HenrysLaw): - """ - A class representing a Henry's law reaction rate constant. - - Attributes: - name (str): The name of the Henry's law reaction rate constant. - gas_phase (Phase): The gas phase in which the reaction occurs. - gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (Species): The water species in the aerosol phase. - aerosol_phase_species (Union[Species, Tuple[float, Species]]): The aerosol phase species involved in the reaction. - other_properties (Dict[str, Any]): A dictionary of other properties of the Henry's law reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - gas_phase: Optional[Phase] = None, - gas_phase_species: Optional[Union[Species, Tuple[float, Species]]] = None, - aerosol_phase: Optional[Phase] = None, - aerosol_phase_water: Optional[Species] = None, - aerosol_phase_species: Optional[Union[Species, Tuple[float, Species]]] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the HenrysLaw object with the given parameters. - - Args: - name (str): The name of the Henry's law reaction rate constant. - gas_phase (Phase): The gas phase in which the reaction occurs. - gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_water (Species): The water species in the aerosol phase. - aerosol_phase_species (Union[Species, Tuple[float, Species]]): The aerosol phase species involved in the reaction. - other_properties (Dict[str, Any]): A dictionary of other properties of the Henry's law reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.gas_phase_species = ( - ( - _ReactionComponent(gas_phase_species.name) - if isinstance(gas_phase_species, Species) - else _ReactionComponent(gas_phase_species[1].name, gas_phase_species[0]) - ) - if gas_phase_species is not None - else self.gas_phase_species - ) - self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase - self.aerosol_phase_water = ( - aerosol_phase_water.name if aerosol_phase_water is not None else self.aerosol_phase_water - ) - self.aerosol_phase_species = ( - ( - _ReactionComponent(aerosol_phase_species.name) - if isinstance(aerosol_phase_species, Species) - else _ReactionComponent( - aerosol_phase_species[1].name, aerosol_phase_species[0] - ) - ) - if aerosol_phase_species is not None - else self.aerosol_phase_species - ) - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class SimpolPhaseTransfer(_SimpolPhaseTransfer): - """ - A class representing a simplified phase transfer reaction rate constant. - - Attributes: - name (str): The name of the simplified phase transfer reaction rate constant. - gas_phase (Phase): The gas phase in which the reaction occurs. - gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_species (Union[Species, Tuple[float, Species]]): The aerosol phase species involved in the reaction. - B (List[float]): The B parameters [unitless]. - unknown_properties (Dict[str, Any]): A dictionary of other properties of the simplified phase transfer reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - gas_phase: Optional[Phase] = None, - gas_phase_species: Optional[Union[Species, Tuple[float, Species]]] = None, - aerosol_phase: Optional[Phase] = None, - aerosol_phase_species: Optional[Union[Species, Tuple[float, Species]]] = None, - B: Optional[List[float]] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the SimpolPhaseTransfer object with the given parameters. - - Args: - name (str): The name of the simplified phase transfer reaction rate constant. - gas_phase (Phase): The gas phase in which the reaction occurs. - gas_phase_species (Union[Species, Tuple[float, Species]]): The gas phase species involved in the reaction. - aerosol_phase (Phase): The aerosol phase in which the reaction occurs. - aerosol_phase_species (Union[Species, Tuple[float, Species]]): The aerosol phase species involved in the reaction. - B (List[float]): The B parameters [unitless]. - other_properties (Dict[str, Any]): A dictionary of other properties of the simplified phase transfer reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.gas_phase_species = ( - ( - _ReactionComponent(gas_phase_species.name) - if isinstance(gas_phase_species, Species) - else _ReactionComponent(gas_phase_species[1].name, gas_phase_species[0]) - ) - if gas_phase_species is not None - else self.gas_phase_species - ) - self.aerosol_phase = aerosol_phase.name if aerosol_phase is not None else self.aerosol_phase - self.aerosol_phase_species = ( - ( - _ReactionComponent(aerosol_phase_species.name) - if isinstance(aerosol_phase_species, Species) - else _ReactionComponent( - aerosol_phase_species[1].name, aerosol_phase_species[0] - ) - ) - if aerosol_phase_species is not None - else self.aerosol_phase_species - ) - if B is not None: - if len(B) != 4: - raise ValueError("B must be a list of 4 elements.") - self.B = B - else: - self.B = [0, 0, 0, 0] - self.other_properties = other_properties if other_properties is not None else self.other_properties - -class UserDefined(_UserDefined): - """ - A class representing a user-defined reaction rate constant. - - Attributes: - name (str): The name of the photolysis reaction rate constant. - scaling_factor (float): The scaling factor for the photolysis rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant. - """ - - def __init__( - self, - name: Optional[str] = None, - scaling_factor: Optional[float] = None, - reactants: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - products: Optional[List[Union[Species, Tuple[float, Species]]]] = None, - gas_phase: Optional[Phase] = None, - other_properties: Optional[Dict[str, Any]] = None, - ): - """ - Initializes the UserDefined object with the given parameters. - - Args: - name (str): The name of the photolysis reaction rate constant. - scaling_factor (float): The scaling factor for the photolysis rate constant. - reactants (List[Union[Species, Tuple[float, Species]]]): A list of reactants involved in the reaction. - products (List[Union[Species, Tuple[float, Species]]]): A list of products formed in the reaction. - gas_phase (Phase): The gas phase in which the reaction occurs. - other_properties (Dict[str, Any]): A dictionary of other properties of the photolysis reaction rate constant. - """ - super().__init__() - self.name = name if name is not None else self.name - self.scaling_factor = scaling_factor if scaling_factor is not None else self.scaling_factor - self.reactants = ( - [ - ( - _ReactionComponent(r.name) - if isinstance(r, Species) - else _ReactionComponent(r[1].name, r[0]) - ) - for r in reactants - ] - if reactants is not None - else self.reactants - ) - self.products = ( - [ - ( - _ReactionComponent(p.name) - if isinstance(p, Species) - else _ReactionComponent(p[1].name, p[0]) - ) - for p in products - ] - if products is not None - else self.products - ) - self.gas_phase = gas_phase.name if gas_phase is not None else self.gas_phase - self.other_properties = other_properties if other_properties is not None else self.other_properties - - -class Reactions(_Reactions): - """ - A class representing a collection of reactions in a chemical mechanism. - - Attributes: - reactions (List[Any]): A list of reactions in the mechanism. - """ - - def __init__( - self, - reactions: Optional[List[Any]] = None, - ): - """ - Initializes the Reactions object with the given parameters. - - Args: - reactions (List[]): A list of reactions in the mechanism. - """ - super().__init__(reactions) - - -class ReactionsIterator(_ReactionsIterator): - """ - An iterator for the Reactions class. - """ - - -class Version(_Version): - """ - A class representing the version of the mechanism. - """ - - -class Mechanism(_Mechanism): - """ - A class representing a chemical mechanism. - - Attributes: - name (str): The name of the mechanism. - reactions (List[Reaction]): A list of reactions in the mechanism. - species (List[Species]): A list of species in the mechanism. - phases (List[Phase]): A list of phases in the mechanism. - version (Version): The version of the mechanism. - """ - - def __init__( - self, - name: Optional[str] = None, - reactions: Optional[List[Any]] = None, - species: Optional[List[Species]] = None, - phases: Optional[List[Phase]] = None, - version: Optional[Version] = None, - ): - """ - Initializes the Mechanism object with the given parameters. - - Args: - name (str): The name of the mechanism. - reactions (List[]): A list of reactions in the mechanism. - species (List[Species]): A list of species in the mechanism. - phases (List[Phase]): A list of phases in the mechanism. - version (Version): The version of the mechanism. - """ - super().__init__() - self.name = name - self.species = species if species is not None else [] - self.phases = phases if phases is not None else [] - self.reactions = Reactions(reactions=reactions) - self.version = version if version is not None else Version() - - -class Parser(_Parser): - """ - A class for parsing a chemical mechanism. - """ diff --git a/mechanism_configuration/wrapper.cpp b/mechanism_configuration/wrapper.cpp deleted file mode 100644 index ead2e012..00000000 --- a/mechanism_configuration/wrapper.cpp +++ /dev/null @@ -1,522 +0,0 @@ -// Copyright (C) 2025 University Corporation for Atmospheric Research -// SPDX-License-Identifier: Apache-2.0 -#include -#include - -#include -#include -#include -#include -#include - -namespace py = pybind11; -namespace constants = mechanism_configuration::constants; -namespace validation = mechanism_configuration::v1::validation; -using namespace mechanism_configuration::v1::types; - -enum class ReactionType -{ - Arrhenius, - Branched, - CondensedPhaseArrhenius, - CondensedPhasePhotolysis, - Emission, - FirstOrderLoss, - SimpolPhaseTransfer, - AqueousEquilibrium, - WetDeposition, - HenrysLaw, - Photolysis, - Surface, - Troe, - Tunneling, - UserDefined -}; - -struct ReactionsIterator -{ - using VariantType = std::variant< - Arrhenius, - Branched, - CondensedPhaseArrhenius, - CondensedPhasePhotolysis, - Emission, - FirstOrderLoss, - SimpolPhaseTransfer, - AqueousEquilibrium, - WetDeposition, - HenrysLaw, - Photolysis, - Surface, - Troe, - Tunneling, - UserDefined>; - - std::vector> reaction_lists; - size_t outer_index = 0; - size_t inner_index = 0; - - ReactionsIterator(Reactions &reactions) - : reaction_lists{ std::vector(reactions.arrhenius.begin(), reactions.arrhenius.end()), - std::vector(reactions.branched.begin(), reactions.branched.end()), - std::vector(reactions.condensed_phase_arrhenius.begin(), reactions.condensed_phase_arrhenius.end()), - std::vector(reactions.condensed_phase_photolysis.begin(), reactions.condensed_phase_photolysis.end()), - std::vector(reactions.emission.begin(), reactions.emission.end()), - std::vector(reactions.first_order_loss.begin(), reactions.first_order_loss.end()), - std::vector(reactions.simpol_phase_transfer.begin(), reactions.simpol_phase_transfer.end()), - std::vector(reactions.aqueous_equilibrium.begin(), reactions.aqueous_equilibrium.end()), - std::vector(reactions.wet_deposition.begin(), reactions.wet_deposition.end()), - std::vector(reactions.henrys_law.begin(), reactions.henrys_law.end()), - std::vector(reactions.photolysis.begin(), reactions.photolysis.end()), - std::vector(reactions.surface.begin(), reactions.surface.end()), - std::vector(reactions.troe.begin(), reactions.troe.end()), - std::vector(reactions.tunneling.begin(), reactions.tunneling.end()), - std::vector(reactions.user_defined.begin(), reactions.user_defined.end()) } - { - } - - py::object next() - { - while (outer_index < reaction_lists.size()) - { - const auto &vec = reaction_lists[outer_index]; - if (inner_index < vec.size()) - { - return std::visit([](auto &&arg) { return py::cast(arg); }, vec[inner_index++]); - } - ++outer_index; - inner_index = 0; - } - throw py::stop_iteration(); - } -}; - -std::vector get_reaction_components(const py::list& components) -{ - std::vector reaction_components; - for (const auto &item : components) { - if (py::isinstance(item)) { - ReactionComponent component; - component.species_name = item.cast().name; - reaction_components.push_back(component); - } else if (py::isinstance(item) && py::len(item.cast()) == 2) { - auto item_tuple = item.cast(); - if (py::isinstance(item_tuple[0]) && py::isinstance(item_tuple[1])) { - ReactionComponent component; - component.species_name = item_tuple[1].cast().name; - component.coefficient = item_tuple[0].cast(); - reaction_components.push_back(component); - } else if (py::isinstance(item_tuple[0]) && py::isinstance(item_tuple[1])) { - ReactionComponent component; - component.species_name = item_tuple[1].cast().name; - component.coefficient = item_tuple[0].cast(); - reaction_components.push_back(component); - } else { - throw py::value_error("Invalid tuple format. Expected (float, Species)."); - } - } else { - throw py::value_error("Invalid type for reactant. Expected a Species or a tuple of (float, Species)."); - } - } - std::unordered_set component_names; - for (const auto &component : reaction_components) { - if (!component_names.insert(component.species_name).second) { - throw py::value_error("Duplicate reaction component name found: " + component.species_name); - } - } - return reaction_components; -} - -Reactions create_reactions(const py::list& reactions) -{ - Reactions reaction_obj; - for (const auto &item : reactions) { - if (py::isinstance(item)) { - reaction_obj.arrhenius.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.branched.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.condensed_phase_arrhenius.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.condensed_phase_photolysis.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.emission.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.first_order_loss.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.simpol_phase_transfer.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.aqueous_equilibrium.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.wet_deposition.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.henrys_law.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.photolysis.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.surface.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.troe.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.tunneling.push_back(item.cast()); - } else if (py::isinstance(item)) { - reaction_obj.user_defined.push_back(item.cast()); - } else { - throw py::value_error("Invalid reaction type."); - } - } - return reaction_obj; -} - -PYBIND11_MODULE(_mechanism_configuration, m) -{ - - py::module_ core = m.def_submodule("_core"); - - py::enum_(core, "_ReactionType") - .value("Arrhenius", ReactionType::Arrhenius) - .value("Branched", ReactionType::Branched) - .value("CondensedPhaseArrhenius", ReactionType::CondensedPhaseArrhenius) - .value("CondensedPhasePhotolysis", ReactionType::CondensedPhasePhotolysis) - .value("Emission", ReactionType::Emission) - .value("FirstOrderLoss", ReactionType::FirstOrderLoss) - .value("SimpolPhaseTransfer", ReactionType::SimpolPhaseTransfer) - .value("AqueousEquilibrium", ReactionType::AqueousEquilibrium) - .value("WetDeposition", ReactionType::WetDeposition) - .value("HenrysLaw", ReactionType::HenrysLaw) - .value("Photolysis", ReactionType::Photolysis) - .value("Surface", ReactionType::Surface) - .value("Troe", ReactionType::Troe) - .value("Tunneling", ReactionType::Tunneling) - .value("UserDefined", ReactionType::UserDefined); - - py::class_(core, "_Species") - .def(py::init<>()) - .def_readwrite("name", &Species::name) - .def_readwrite("absolute_tolerance", &Species::absolute_tolerance) - .def_readwrite("diffusion_coefficient_m2_s", &Species::diffusion_coefficient) - .def_readwrite("molecular_weight_kg_mol", &Species::molecular_weight) - .def_readwrite("HLC_298K_mol_m3_Pa", &Species::henrys_law_constant_298) - .def_readwrite("HLC_exponential_factor_K", &Species::henrys_law_constant_exponential_factor) - .def_readwrite("N_star", &Species::n_star) - .def_readwrite("density_kg_m3", &Species::density) - .def_readwrite("tracer_type", &Species::tracer_type) - .def_readwrite("other_properties", &Species::unknown_properties) - .def("__str__", [](const Species &s) { return s.name; }) - .def("__repr__", [](const Species &s) { return ""; }); - - py::class_(core, "_Phase") - .def(py::init<>()) - .def_readwrite("name", &Phase::name) - .def_readwrite("species", &Phase::species) - .def_readwrite("other_properties", &Phase::unknown_properties) - .def("__str__", [](const Phase &p) { return p.name; }) - .def("__repr__", [](const Phase &p) { return ""; }); - - py::class_(core, "_ReactionComponent") - .def(py::init<>()) - .def(py::init([](const std::string &species_name) { - ReactionComponent rc; - rc.species_name = species_name; - return rc; - })) - .def(py::init([](const std::string &species_name, double coefficient) { - ReactionComponent rc; - rc.species_name = species_name; - rc.coefficient = coefficient; - return rc; - })) - .def_readwrite("species_name", &ReactionComponent::species_name) - .def_readwrite("coefficient", &ReactionComponent::coefficient) - .def_readwrite("other_properties", &ReactionComponent::unknown_properties) - .def("__str__", [](const ReactionComponent &rc) { return rc.species_name; }) - .def("__repr__", [](const ReactionComponent &rc) { return ""; }); - - py::class_(core, "_Arrhenius") - .def(py::init<>()) - .def_readwrite("A", &Arrhenius::A) - .def_readwrite("B", &Arrhenius::B) - .def_readwrite("C", &Arrhenius::C) - .def_readwrite("D", &Arrhenius::D) - .def_readwrite("E", &Arrhenius::E) - .def_readwrite("reactants", &Arrhenius::reactants) - .def_readwrite("products", &Arrhenius::products) - .def_readwrite("name", &Arrhenius::name) - .def_readwrite("gas_phase", &Arrhenius::gas_phase) - .def_readwrite("other_properties", &Arrhenius::unknown_properties) - .def("__str__", [](const Arrhenius &a) { return a.name; }) - .def("__repr__", [](const Arrhenius &a) { return ""; }) - .def_property_readonly("type", [](const Arrhenius &) { return ReactionType::Arrhenius; }); - - py::class_(core, "_CondensedPhaseArrhenius") - .def(py::init<>()) - .def_readwrite("A", &CondensedPhaseArrhenius::A) - .def_readwrite("B", &CondensedPhaseArrhenius::B) - .def_readwrite("C", &CondensedPhaseArrhenius::C) - .def_readwrite("D", &CondensedPhaseArrhenius::D) - .def_readwrite("E", &CondensedPhaseArrhenius::E) - .def_readwrite("reactants", &CondensedPhaseArrhenius::reactants) - .def_readwrite("products", &CondensedPhaseArrhenius::products) - .def_readwrite("name", &CondensedPhaseArrhenius::name) - .def_readwrite("aerosol_phase", &CondensedPhaseArrhenius::aerosol_phase) - .def_readwrite("aerosol_phase_water", &CondensedPhaseArrhenius::aerosol_phase_water) - .def_readwrite("other_properties", &CondensedPhaseArrhenius::unknown_properties) - .def("__str__", [](const CondensedPhaseArrhenius &cpa) { return cpa.name; }) - .def("__repr__", [](const CondensedPhaseArrhenius &cpa) { return ""; }) - .def_property_readonly("type", [](const CondensedPhaseArrhenius &) { return ReactionType::CondensedPhaseArrhenius; }); - - py::class_(core, "_Troe") - .def(py::init<>()) - .def_readwrite("k0_A", &Troe::k0_A) - .def_readwrite("k0_B", &Troe::k0_B) - .def_readwrite("k0_C", &Troe::k0_C) - .def_readwrite("kinf_A", &Troe::kinf_A) - .def_readwrite("kinf_B", &Troe::kinf_B) - .def_readwrite("kinf_C", &Troe::kinf_C) - .def_readwrite("Fc", &Troe::Fc) - .def_readwrite("N", &Troe::N) - .def_readwrite("reactants", &Troe::reactants) - .def_readwrite("products", &Troe::products) - .def_readwrite("name", &Troe::name) - .def_readwrite("gas_phase", &Troe::gas_phase) - .def_readwrite("other_properties", &Troe::unknown_properties) - .def("__str__", [](const Troe &t) { return t.name; }) - .def("__repr__", [](const Troe &t) { return ""; }) - .def_property_readonly("type", [](const Troe &) { return ReactionType::Troe; }); - - py::class_(core, "_Branched") - .def(py::init<>()) - .def_readwrite("X", &Branched::X) - .def_readwrite("Y", &Branched::Y) - .def_readwrite("a0", &Branched::a0) - .def_readwrite("n", &Branched::n) - .def_readwrite("reactants", &Branched::reactants) - .def_readwrite("nitrate_products", &Branched::nitrate_products) - .def_readwrite("alkoxy_products", &Branched::alkoxy_products) - .def_readwrite("name", &Branched::name) - .def_readwrite("gas_phase", &Branched::gas_phase) - .def_readwrite("other_properties", &Branched::unknown_properties) - .def("__str__", [](const Branched &b) { return b.name; }) - .def("__repr__", [](const Branched &b) { return ""; }) - .def_property_readonly("type", [](const Branched &) { return ReactionType::Branched; }); - - py::class_(core, "_Tunneling") - .def(py::init<>()) - .def_readwrite("A", &Tunneling::A) - .def_readwrite("B", &Tunneling::B) - .def_readwrite("C", &Tunneling::C) - .def_readwrite("reactants", &Tunneling::reactants) - .def_readwrite("products", &Tunneling::products) - .def_readwrite("name", &Tunneling::name) - .def_readwrite("gas_phase", &Tunneling::gas_phase) - .def_readwrite("other_properties", &Tunneling::unknown_properties) - .def("__str__", [](const Tunneling &t) { return t.name; }) - .def("__repr__", [](const Tunneling &t) { return ""; }) - .def_property_readonly("type", [](const Tunneling &) { return ReactionType::Tunneling; }); - - py::class_(core, "_Surface") - .def(py::init<>()) - .def_readwrite("reaction_probability", &Surface::reaction_probability) - .def_readwrite("gas_phase_species", &Surface::gas_phase_species) - .def_readwrite("gas_phase_products", &Surface::gas_phase_products) - .def_readwrite("name", &Surface::name) - .def_readwrite("gas_phase", &Surface::gas_phase) - .def_readwrite("aerosol_phase", &Surface::aerosol_phase) - .def_readwrite("other_properties", &Surface::unknown_properties) - .def("__str__", [](const Surface &s) { return s.name; }) - .def("__repr__", [](const Surface &s) { return ""; }) - .def_property_readonly("type", [](const Surface &) { return ReactionType::Surface; }); - - py::class_(core, "_Photolysis") - .def(py::init<>()) - .def_readwrite("scaling_factor", &Photolysis::scaling_factor) - .def_readwrite("reactants", &Photolysis::reactants) - .def_readwrite("products", &Photolysis::products) - .def_readwrite("name", &Photolysis::name) - .def_readwrite("gas_phase", &Photolysis::gas_phase) - .def_readwrite("other_properties", &Photolysis::unknown_properties) - .def("__str__", [](const Photolysis &p) { return p.name; }) - .def("__repr__", [](const Photolysis &p) { return ""; }) - .def_property_readonly("type", [](const Photolysis &) { return ReactionType::Photolysis; }); - - py::class_(core, "_CondensedPhasePhotolysis") - .def(py::init<>()) - .def_readwrite("scaling_factor", &CondensedPhasePhotolysis::scaling_factor) - .def_readwrite("reactants", &CondensedPhasePhotolysis::reactants) - .def_readwrite("products", &CondensedPhasePhotolysis::products) - .def_readwrite("name", &CondensedPhasePhotolysis::name) - .def_readwrite("aerosol_phase", &CondensedPhasePhotolysis::aerosol_phase) - .def_readwrite("aerosol_phase_water", &CondensedPhasePhotolysis::aerosol_phase_water) - .def_readwrite("other_properties", &CondensedPhasePhotolysis::unknown_properties) - .def("__str__", [](const CondensedPhasePhotolysis &cpp) { return cpp.name; }) - .def("__repr__", [](const CondensedPhasePhotolysis &cpp) { return ""; }) - .def_property_readonly("type", [](const CondensedPhasePhotolysis &) { return ReactionType::CondensedPhasePhotolysis; }); - - py::class_(core, "_Emission") - .def(py::init<>()) - .def_readwrite("scaling_factor", &Emission::scaling_factor) - .def_readwrite("products", &Emission::products) - .def_readwrite("name", &Emission::name) - .def_readwrite("gas_phase", &Emission::gas_phase) - .def_readwrite("other_properties", &Emission::unknown_properties) - .def("__str__", [](const Emission &e) { return e.name; }) - .def("__repr__", [](const Emission &e) { return ""; }) - .def_property_readonly("type", [](const Emission &) { return ReactionType::Emission; }); - - py::class_(core, "_FirstOrderLoss") - .def(py::init<>()) - .def_readwrite("scaling_factor", &FirstOrderLoss::scaling_factor) - .def_readwrite("reactants", &FirstOrderLoss::reactants) - .def_readwrite("name", &FirstOrderLoss::name) - .def_readwrite("gas_phase", &FirstOrderLoss::gas_phase) - .def_readwrite("other_properties", &FirstOrderLoss::unknown_properties) - .def("__str__", [](const FirstOrderLoss &fol) { return fol.name; }) - .def("__repr__", [](const FirstOrderLoss &fol) { return ""; }) - .def_property_readonly("type", [](const FirstOrderLoss &) { return ReactionType::FirstOrderLoss; }); - - py::class_(core, "_AqueousEquilibrium") - .def(py::init<>()) - .def_readwrite("name", &AqueousEquilibrium::name) - .def_readwrite("gas_phase", &AqueousEquilibrium::gas_phase) - .def_readwrite("aerosol_phase", &AqueousEquilibrium::aerosol_phase) - .def_readwrite("aerosol_phase_water", &AqueousEquilibrium::aerosol_phase_water) - .def_readwrite("reactants", &AqueousEquilibrium::reactants) - .def_readwrite("products", &AqueousEquilibrium::products) - .def_readwrite("A", &AqueousEquilibrium::A) - .def_readwrite("C", &AqueousEquilibrium::C) - .def_readwrite("k_reverse", &AqueousEquilibrium::k_reverse) - .def_readwrite("other_properties", &AqueousEquilibrium::unknown_properties) - .def("__str__", [](const AqueousEquilibrium &ae) { return ae.name; }) - .def("__repr__", [](const AqueousEquilibrium &ae) { return ""; }) - .def_property_readonly("type", [](const AqueousEquilibrium &) { return ReactionType::AqueousEquilibrium; }); - - py::class_(core, "_WetDeposition") - .def(py::init<>()) - .def_readwrite("scaling_factor", &WetDeposition::scaling_factor) - .def_readwrite("name", &WetDeposition::name) - .def_readwrite("aerosol_phase", &WetDeposition::aerosol_phase) - .def_readwrite("other_properties", &WetDeposition::unknown_properties) - .def("__str__", [](const WetDeposition &wd) { return wd.name; }) - .def("__repr__", [](const WetDeposition &wd) { return ""; }) - .def_property_readonly("type", [](const WetDeposition &) { return ReactionType::WetDeposition; }); - - py::class_(core, "_HenrysLaw") - .def(py::init<>()) - .def_readwrite("name", &HenrysLaw::name) - .def_readwrite("gas_phase", &HenrysLaw::gas_phase) - .def_readwrite("gas_phase_species", &HenrysLaw::gas_phase_species) - .def_readwrite("aerosol_phase", &HenrysLaw::aerosol_phase) - .def_readwrite("aerosol_phase_water", &HenrysLaw::aerosol_phase_water) - .def_readwrite("aerosol_phase_species", &HenrysLaw::aerosol_phase_species) - .def_readwrite("other_properties", &HenrysLaw::unknown_properties) - .def("__str__", [](const HenrysLaw &hl) { return hl.name; }) - .def("__repr__", [](const HenrysLaw &hl) { return ""; }) - .def_property_readonly("type", [](const HenrysLaw &) { return ReactionType::HenrysLaw; }); - - py::class_(core, "_SimpolPhaseTransfer") - .def(py::init<>()) - .def_readwrite("gas_phase", &SimpolPhaseTransfer::gas_phase) - .def_readwrite("gas_phase_species", &SimpolPhaseTransfer::gas_phase_species) - .def_readwrite("aerosol_phase", &SimpolPhaseTransfer::aerosol_phase) - .def_readwrite("aerosol_phase_species", &SimpolPhaseTransfer::aerosol_phase_species) - .def_readwrite("name", &SimpolPhaseTransfer::name) - .def_readwrite("B", &SimpolPhaseTransfer::B) - .def_readwrite("other_properties", &SimpolPhaseTransfer::unknown_properties) - .def("__str__", [](const SimpolPhaseTransfer &spt) { return spt.name; }) - .def("__repr__", [](const SimpolPhaseTransfer &spt) { return ""; }) - .def_property_readonly("type", [](const SimpolPhaseTransfer &) { return ReactionType::SimpolPhaseTransfer; }); - - py::class_(core, "_UserDefined") - .def(py::init<>()) - .def_readwrite("scaling_factor", &UserDefined::scaling_factor) - .def_readwrite("reactants", &UserDefined::reactants) - .def_readwrite("products", &UserDefined::products) - .def_readwrite("name", &UserDefined::name) - .def_readwrite("gas_phase", &UserDefined::gas_phase) - .def_readwrite("other_properties", &UserDefined::unknown_properties) - .def("__str__", [](const UserDefined &p) { return p.name; }) - .def("__repr__", [](const UserDefined &p) { return ""; }) - .def_property_readonly("type", [](const UserDefined &) { return ReactionType::UserDefined; }); - - py::class_(core, "_Reactions") - .def(py::init<>()) - .def(py::init([](const py::list &reactions) { - return create_reactions(reactions); - })) - .def_readwrite("arrhenius", &Reactions::arrhenius) - .def_readwrite("branched", &Reactions::branched) - .def_readwrite("condensed_phase_arrhenius", &Reactions::condensed_phase_arrhenius) - .def_readwrite("condensed_phase_photolysis", &Reactions::condensed_phase_photolysis) - .def_readwrite("emission", &Reactions::emission) - .def_readwrite("first_order_loss", &Reactions::first_order_loss) - .def_readwrite("simpol_phase_transfer", &Reactions::simpol_phase_transfer) - .def_readwrite("aqueous_equilibrium", &Reactions::aqueous_equilibrium) - .def_readwrite("wet_deposition", &Reactions::wet_deposition) - .def_readwrite("henrys_law", &Reactions::henrys_law) - .def_readwrite("photolysis", &Reactions::photolysis) - .def_readwrite("surface", &Reactions::surface) - .def_readwrite("troe", &Reactions::troe) - .def_readwrite("tunneling", &Reactions::tunneling) - .def_readwrite("user_defined", &Reactions::user_defined) - .def( - "__len__", - [](const Reactions &r) - { - return r.arrhenius.size() + r.branched.size() + r.condensed_phase_arrhenius.size() + r.condensed_phase_photolysis.size() + - r.emission.size() + r.first_order_loss.size() + r.simpol_phase_transfer.size() + r.aqueous_equilibrium.size() + - r.wet_deposition.size() + r.henrys_law.size() + r.photolysis.size() + r.surface.size() + r.troe.size() + r.tunneling.size() + - r.user_defined.size(); - }) - .def("__str__", [](const Reactions &r) { return "Reactions"; }) - .def("__repr__", [](const Reactions &r) { return ""; }) - .def("__iter__", [](Reactions &r) { return ReactionsIterator(r); }); - - py::class_(core, "_ReactionsIterator") - .def("__iter__", [](ReactionsIterator &it) -> ReactionsIterator & { return it; }) - .def("__next__", &ReactionsIterator::next); - - py::class_(core, "_Mechanism") - .def(py::init<>()) - .def_readwrite("name", &Mechanism::name) - .def_readwrite("species", &Mechanism::species) - .def_readwrite("phases", &Mechanism::phases) - .def_readwrite("reactions", &Mechanism::reactions) - .def_readwrite("version", &Mechanism::version) - .def("__str__", [](const Mechanism &m) { return m.name; }) - .def("__repr__", [](const Mechanism &m) { return ""; }); - - py::class_(core, "_Version") - .def(py::init<>()) - .def(py::init()) - .def(py::init()) - .def_readwrite("major", &mechanism_configuration::Version::major) - .def_readwrite("minor", &mechanism_configuration::Version::minor) - .def_readwrite("patch", &mechanism_configuration::Version::patch) - .def("to_string", &mechanism_configuration::Version::to_string) - .def("__str__", &mechanism_configuration::Version::to_string) - .def("__repr__", [](const mechanism_configuration::Version &v) { return ""; }); - - using V1Parser = mechanism_configuration::v1::Parser; - - py::class_(core, "_Parser") - .def(py::init<>()) - .def( - "parse", - [](V1Parser &self, const std::string &path) - { - auto parsed = self.Parse(std::filesystem::path(path)); - if (parsed) - { - return *parsed; - } - else - { - std::string error = "Error parsing file: " + path + "\n"; - for (auto &e : parsed.errors) - { - error += e.second + "\n"; - } - throw std::runtime_error(error); - } - }); -} diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 886f2399..00000000 --- a/pyproject.toml +++ /dev/null @@ -1,50 +0,0 @@ -[build-system] -requires = ["scikit-build-core", "pybind11"] -build-backend = "scikit_build_core.build" - -[project] -name = "mechanism_configuration" -dynamic = ["version"] -readme = "README.md" -description = "Mechanism Configuration is a library for managing chemical mechanisms in atmospheric models." -authors = [ - { name = "Matthew Dawsom", email = "mattdawson@ucar.edu" }, - { name = "Kyle Shores", email = "kshores@ucar.edu" }, -] -maintainers = [ - { name = "ACOM MUSICA Developers", email = "musica-support@ucar.edu" }, -] -license = { file = "LICENSE" } - -dependencies = [] - -[project.optional-dependencies] -test = [ - 'pytest' -] - -[tool.scikit-build] -cmake.args = [ - "-DMECH_CONFIG_ENABLE_PYTHON_LIBRARY=ON", - "-DMECH_CONFIG_ENABLE_TESTS=OFF", - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_POLICY_VERSION_MINIMUM=3.5", -] - -[project.urls] -homepage = "https://ncar.github.io/MechanismConfiguration/" - -# dynamically read the version: https://scikit-build-core.readthedocs.io/en/latest/configuration.html#dynamic-metadata -[tool.scikit-build.metadata.version] -provider = "scikit_build_core.metadata.regex" -input = "CMakeLists.txt" -regex = 'mechanism_configuration VERSION\s+(?P[0-9.]+)' - -[[tool.scikit-build.generate]] -path = "mechanism_configuration/_version.py" -template = ''' -version = "${version}" -''' - -[tool.cibuildwheel.macos.environment] -MACOSX_DEPLOYMENT_TARGET = "10.15" \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82d5dd94..62071bd7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,9 +7,7 @@ add_library(musica::mechanism_configuration ALIAS mechanism_configuration) target_compile_features(mechanism_configuration PUBLIC cxx_std_20) -if(MECH_CONFIG_ENABLE_PYTHON_LIBRARY OR MECH_CONFIG_ENABLE_PIC) - # Add the -fPIC flag for position-independent code if we are building shared libraries - # or the python library so that it links correctly on linux +if(MECH_CONFIG_ENABLE_PIC) set_target_properties(mechanism_configuration PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() From a1aaafd878fe6f0c6fd4035d0ccbcc8a327b3dc3 Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Thu, 8 May 2025 12:40:28 -0500 Subject: [PATCH 2/3] removing python wheel builds --- .github/workflows/release.yml | 90 ----------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index fc7cb6f4..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,90 +0,0 @@ -name: Publish Python Package - -on: - push: - branches: - - main - pull_request: - workflow_dispatch: - release: - types: - - published - -jobs: - build_sdist: - name: Build SDist - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Build SDist - run: pipx run build --sdist - - - name: Check metadata - run: pipx run twine check dist/* - - - uses: actions/upload-artifact@v4 - with: - name: cibw-sdist - path: dist/*.tar.gz - - build_wheels: - name: Build wheels on ${{ matrix.os }} with Python ${{ matrix.python-version }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.12"] - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - uses: pypa/cibuildwheel@v2.17 - env: - CIBW_ARCHS_MACOS: arm64 x86_64 - CIBW_SKIP: cp27-* cp34-* cp35-* cp36-* - CIBW_BUILD: cp37-* cp38-* cp39-* cp310-* cp311-* cp312-* - - - name: Verify clean directory - run: git diff --exit-code - shell: bash - - - name: Upload wheels - uses: actions/upload-artifact@v4 - with: - name: cibw-wheels-${{ matrix.os }}-py${{ matrix.python-version }} - path: wheelhouse/*.whl - - upload_all: - name: Upload release - needs: [build_wheels, build_sdist] - if: github.event_name == 'release' && github.event.action == 'published' - runs-on: ubuntu-latest - environment: - name: pypi - url: https://pypi.org/p/musica - permissions: - id-token: write - - steps: - - uses: actions/setup-python@v5 - with: - python-version: "3.x" - - - uses: actions/download-artifact@v4 - with: - pattern: cibw-* - path: dist - merge-multiple: true - - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 From 2de0f5645be28b992b4a4da5a07afb00620cf5b8 Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Thu, 8 May 2025 12:42:47 -0500 Subject: [PATCH 3/3] removing python builds from docker --- docker/Dockerfile | 8 -------- docker/Dockerfile.coverage | 1 - 2 files changed, 9 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 6c719771..8ec0ce3b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,10 +7,6 @@ RUN dnf -y update \ gdb \ git \ make \ - python3 \ - python3-devel \ - python3-pip \ - python3-setuptools \ && dnf clean all COPY . /mechanism_configuration/ @@ -18,10 +14,6 @@ COPY . /mechanism_configuration/ ENV CXX=g++ ENV CC=gcc -RUN cd /mechanism_configuration \ - && python3 -m pip install --upgrade wheel setuptools \ - && pip3 install --verbose .[test] - RUN mkdir /build \ && cd /build \ && cmake \ diff --git a/docker/Dockerfile.coverage b/docker/Dockerfile.coverage index 019ae8e7..922993d7 100644 --- a/docker/Dockerfile.coverage +++ b/docker/Dockerfile.coverage @@ -7,7 +7,6 @@ RUN dnf -y update \ git \ lcov \ make \ - python-devel \ && dnf clean all COPY . /mechanism_configuration/