uclchem.advanced.advanced_network#
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#
Runtime interface to UCLCHEM's compiled chemical network. |
|
Wrapper for a reaction in the compiled network. |
|
Wrapper for a species in the compiled network. |
- class uclchem.advanced.advanced_network.NetworkState[source]#
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.
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.
- reset_network_from_csv() None[source]#
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
Examples
>>> network = NetworkState() >>> # Modify some reaction... >>> network._network.alpha[0] = 999.0 >>> # Reset back to initial values >>> network.reset_state()
- reset_state() None[source]#
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)
Examples
>>> network = NetworkState() >>> # Modify some reaction parameters >>> network._network.alpha[0] = 999.0 >>> # Restore to initial state >>> network.reset_state()
- class uclchem.advanced.advanced_network.RuntimeReaction(index: int, network_ref: types.ModuleType)[source]#
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.
- Parameters:
index (int) – 1-based reaction index in Fortran arrays
network_ref (ModuleType) – Reference to the network module
- get_alpha() float[source]#
Get the alpha parameter (pre-exponential factor).
- Returns:
Alpha parameter
- Return type:
- get_beta() float[source]#
Get the beta parameter (temperature exponent).
- Returns:
Beta parameter
- Return type:
- get_exothermicity() float[source]#
Get the reaction exothermicity.
- Returns:
Exothermicity in erg
- Return type:
- get_gamma() float[source]#
Get the gamma parameter (activation energy).
- Returns:
Gamma parameter in Kelvin
- Return type:
- get_rate() float | None[source]#
Get the computed reaction rate from the last model run.
- Returns:
Computed rate (only meaningful after running a model)
- Return type:
float | None
- get_reduced_mass() float | None[source]#
Get the reduced mass for tunneling reactions.
- Returns:
Reduced mass in AMU (or None if not available)
- Return type:
float | None
- get_temphigh() float[source]#
Get the maximum valid temperature.
- Returns:
Maximum temperature in Kelvin
- Return type:
- get_templow() float[source]#
Get the minimum valid temperature.
- Returns:
Minimum temperature in Kelvin
- Return type:
- set_alpha(value: float) None[source]#
Set the alpha parameter.
- Parameters:
value (float) – New alpha value
- class uclchem.advanced.advanced_network.RuntimeSpecies(index: int, network_ref: types.ModuleType)[source]#
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.
- Parameters:
index (int) – 1-based species index in Fortran arrays
network_ref (ModuleType) – Reference to the network module
- get_binding_energy() float | None[source]#
Get the binding energy.
- Returns:
Binding energy in Kelvin (or None if not available)
- Return type:
float | None
- get_charge() int[source]#
Get the charge of the species.
- Returns:
Charge (+1, -1, or 0)
- Return type:
- get_enthalpy() float | None[source]#
Get the formation enthalpy.
- Returns:
Formation enthalpy in kJ/mol (or None if not available)
- Return type:
float | None