uclchem.advanced.advanced_network ================================= .. py:module:: uclchem.advanced.advanced_network .. autoapi-nested-parse:: Runtime access to UCLCHEM's compiled chemical network state. This module provides a class-based interface for accessing and modifying the chemical network that is compiled into the Fortran code. Unlike the Network class in makerates (used for building networks), NetworkState provides access to the active, in-memory network during model execution. RuntimeSpecies and RuntimeReaction provide APIs similar to the Species and Reaction classes in makerates, but wrap the compiled Fortran data rather than generating new code. **Thread Safety Warning:** NetworkState modifies global Fortran module state and is **NOT thread-safe**. Do not use with multiprocessing, multithreading, or concurrent model runs. Note: Changes made through NetworkState affect the global Fortran state and persist across model runs in the same Python session. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: uclchem.advanced.advanced_network.NetworkState uclchem.advanced.advanced_network.RuntimeReaction uclchem.advanced.advanced_network.RuntimeSpecies .. py:class:: NetworkState Runtime interface to UCLCHEM's compiled chemical network. Loads the network from CSV files (on-disk version) and compares with the compiled Fortran network (in-memory version) to ensure consistency. **Thread Safety Warning:** This class modifies global Fortran module state and is **NOT thread-safe**. Do not use with multiprocessing, multithreading, or concurrent model runs. .. rubric:: Examples >>> from uclchem.advanced import NetworkState >>> network = NetworkState() >>> network.validate() # Check on-disk matches in-memory >>> print(f"Species: {len(network.species_list)}") Species: ... >>> print(f"Reactions: {len(network.reaction_list)}") Reactions: ... Initialize the NetworkState interface. Loads species and reactions from CSV files and compares with the compiled Fortran network data. Caches the initial state of all modifiable network parameters for fast resetting. .. py:method:: reset_network_from_csv() -> None Reset the Fortran network to match the cached initial state. This method now uses cached values for better performance and reliability. It's equivalent to reset_state() but kept for backward compatibility. Note: This uses the cached initial state from when NetworkState was created, not by re-reading CSV files. Use reset_state() for the same functionality with a clearer name. Modifiable arrays restored: - alpha, beta, gama: Reaction rate parameters - bindingenergy: Species binding energies .. rubric:: Examples >>> network = NetworkState() >>> # Modify some reaction... >>> network._network.alpha[0] = 999.0 >>> # Reset back to initial values >>> network.reset_state() .. py:method:: reset_state() -> None Reset the Fortran network to its initial cached state. Uses cached values instead of re-reading and parsing CSV files. Restores all modifiable network parameters to their initial values from when NetworkState was created. Modifiable arrays restored: - alpha, beta, gama: Reaction rate parameters - bindingenergy: Species binding energies - formationenthalpy: Formation enthalpies (if available) .. rubric:: Examples >>> network = NetworkState() >>> # Modify some reaction parameters >>> network._network.alpha[0] = 999.0 >>> # Restore to initial state >>> network.reset_state() .. py:method:: validate() -> None Re-run validation to check on-disk matches in-memory. Useful after modifications to verify consistency. .. py:class:: RuntimeReaction(index: int, network_ref: types.ModuleType) Wrapper for a reaction in the compiled network. Provides a similar API to makerates.Reaction but accesses the compiled Fortran data. Initialize a runtime reaction wrapper. :param index: 1-based reaction index in Fortran arrays :type index: int :param network_ref: Reference to the network module :type network_ref: ModuleType .. py:method:: get_alpha() -> float Get the alpha parameter (pre-exponential factor). :returns: Alpha parameter :rtype: float .. py:method:: get_beta() -> float Get the beta parameter (temperature exponent). :returns: Beta parameter :rtype: float .. py:method:: get_exothermicity() -> float Get the reaction exothermicity. :returns: Exothermicity in erg :rtype: float .. py:method:: get_gamma() -> float Get the gamma parameter (activation energy). :returns: Gamma parameter in Kelvin :rtype: float .. py:method:: get_product_names() -> list[str] Get the names of product species. :returns: List of product names (NAN for empty slots) :rtype: list[str] .. py:method:: get_products() -> list[int] Get the product species indices. :returns: List of species indices (1-based, 0 for NAN) :rtype: list[int] .. py:method:: get_rate() -> float | None Get the computed reaction rate from the last model run. :returns: Computed rate (only meaningful after running a model) :rtype: float | None .. py:method:: get_reactant_names() -> list[str] Get the names of reactant species. :returns: List of reactant names (NAN for empty slots) :rtype: list[str] .. py:method:: get_reactants() -> list[int] Get the reactant species indices. :returns: List of species indices (1-based, 0 for NAN) :rtype: list[int] .. py:method:: get_reduced_mass() -> float | None Get the reduced mass for tunneling reactions. :returns: Reduced mass in AMU (or None if not available) :rtype: float | None .. py:method:: get_temphigh() -> float Get the maximum valid temperature. :returns: Maximum temperature in Kelvin :rtype: float .. py:method:: get_templow() -> float Get the minimum valid temperature. :returns: Minimum temperature in Kelvin :rtype: float .. py:method:: set_alpha(value: float) -> None Set the alpha parameter. :param value: New alpha value :type value: float .. py:method:: set_beta(value: float) -> None Set the beta parameter. :param value: New beta value :type value: float .. py:method:: set_gamma(value: float) -> None Set the gamma parameter. :param value: New gamma value :type value: float .. py:class:: RuntimeSpecies(index: int, network_ref: types.ModuleType) Wrapper for a species in the compiled network. Provides a similar API to makerates.Species but accesses the compiled Fortran data. Initialize a runtime species wrapper. :param index: 1-based species index in Fortran arrays :type index: int :param network_ref: Reference to the network module :type network_ref: ModuleType .. py:method:: get_binding_energy() -> float | None Get the binding energy. :returns: Binding energy in Kelvin (or None if not available) :rtype: float | None .. py:method:: get_charge() -> int Get the charge of the species. :returns: Charge (+1, -1, or 0) :rtype: int .. py:method:: get_enthalpy() -> float | None Get the formation enthalpy. :returns: Formation enthalpy in kJ/mol (or None if not available) :rtype: float | None .. py:method:: get_mass() -> float Get the molecular mass. :returns: Mass in atomic mass units :rtype: float .. py:method:: get_name() -> str Get the species name. :returns: Species name :rtype: str .. py:method:: is_ice_species() -> bool Return whether the species is a species on the grain. :returns: True if it is an ice species. :rtype: bool .. py:method:: is_ion() -> bool Check if this is an ion. :returns: True if species name contains + or - :rtype: bool