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#

NetworkState

Runtime interface to UCLCHEM's compiled chemical network.

RuntimeReaction

Wrapper for a reaction in the compiled network.

RuntimeSpecies

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()
validate() None[source]#

Re-run validation to check on-disk matches in-memory.

Useful after modifications to verify consistency.

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:

float

get_beta() float[source]#

Get the beta parameter (temperature exponent).

Returns:

Beta parameter

Return type:

float

get_exothermicity() float[source]#

Get the reaction exothermicity.

Returns:

Exothermicity in erg

Return type:

float

get_gamma() float[source]#

Get the gamma parameter (activation energy).

Returns:

Gamma parameter in Kelvin

Return type:

float

get_product_names() list[str][source]#

Get the names of product species.

Returns:

List of product names (NAN for empty slots)

Return type:

list[str]

get_products() list[int][source]#

Get the product species indices.

Returns:

List of species indices (1-based, 0 for NAN)

Return type:

list[int]

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_reactant_names() list[str][source]#

Get the names of reactant species.

Returns:

List of reactant names (NAN for empty slots)

Return type:

list[str]

get_reactants() list[int][source]#

Get the reactant species indices.

Returns:

List of species indices (1-based, 0 for NAN)

Return type:

list[int]

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:

float

get_templow() float[source]#

Get the minimum valid temperature.

Returns:

Minimum temperature in Kelvin

Return type:

float

set_alpha(value: float) None[source]#

Set the alpha parameter.

Parameters:

value (float) – New alpha value

set_beta(value: float) None[source]#

Set the beta parameter.

Parameters:

value (float) – New beta value

set_gamma(value: float) None[source]#

Set the gamma parameter.

Parameters:

value (float) – New gamma 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:

int

get_enthalpy() float | None[source]#

Get the formation enthalpy.

Returns:

Formation enthalpy in kJ/mol (or None if not available)

Return type:

float | None

get_mass() float[source]#

Get the molecular mass.

Returns:

Mass in atomic mass units

Return type:

float

get_name() str[source]#

Get the species name.

Returns:

Species name

Return type:

str

is_ice_species() bool[source]#

Return whether the species is a species on the grain.

Returns:

True if it is an ice species.

Return type:

bool

is_ion() bool[source]#

Check if this is an ion.

Returns:

True if species name contains + or -

Return type:

bool