Skip to content
Projects

opencr.core.network

A reaction network: the states, the reactions between them and what is assumed.

ReactionNetwork holds plain Python objects and no arrays; the numerical layer compiles it (opencr.kinetics.system). Building one checks it (ReactionNetwork.problems): unique names, every state of every reaction in the network, the forward reaction of every detailed balance, the energy ordering of excitations and emissions. The manifest lists the states, the reactions, their sources and the assumptions in machine-readable form.

Classes

NameDescription
NetworkErrorA reaction network is inconsistent; problems lists every problem found.
ReactionNetworkStates and reactions, with the model's assumptions.

NetworkErrorclass#

class NetworkError(problems: Sequence[str])

Bases: ValueError

A reaction network is inconsistent; problems lists every problem found.

problemsattributeinstance attribute#

problems = list(problems)

ReactionNetworkclass#

class ReactionNetwork(states: Iterable[State], reactions: Iterable[Reaction], name: str = '', assumptions: Iterable[str] = (), check: bool = True)

States and reactions, with the model’s assumptions.

Parameters

NameTypeDefaultDescription
statesIterable[State]requiredThe states (the electron is implicit and must not be listed).
reactionsIterable[Reaction]requiredThe reactions; every state they use must be in states.
namestr''The name of the network, e.g. "hydrogen/atomic/basic".
assumptionsIterable[str]()The model’s assumptions and omissions, one sentence each.
checkboolTrueRaise NetworkError if problems finds any.

assumptionsattributeinstance attribute#

assumptions: tuple[str, ...] = tuple(assumptions)

nameattributeinstance attribute#

name = name

reactionsattributeinstance attribute#

reactions: tuple[Reaction, ...] = tuple(reactions)

statesattributeinstance attribute#

states: tuple[State, ...] = tuple(states)

speciesproperty#

species: tuple[Species, ...]

The species of the states, each once, in order of appearance.

state_namesproperty#

state_names: tuple[str, ...]

The names of the states, in order.

conservationmethod#

def conservation() -> _Conservation

Return the conserved quantities over the states: the elements and the charge.

The matrix has one row per quantity and one column per state: the number of atoms of the element in the state, or its charge. Electrons are not states, so charge is conserved only together with them.

manifestmethod#

def manifest() -> dict[str, Any]

Return the states, reactions, sources and assumptions as plain data.

mergemethod#

def merge(other: ReactionNetwork, name: str = '') -> ReactionNetwork

Return the union of two networks; shared states must be identical.

problemsmethod#

def problems() -> list[str]

Return every inconsistency found, as sentences; empty if none.

reactionmethod#

def reaction(name: str) -> Reaction

Return the reaction called name.

reactions_ofmethod#

def reactions_of(state: str) -> tuple[Reaction, ...]

Return the reactions that change the population of state.

statemethod#

def state(name: str) -> State

Return the state called name.

state_indexmethod#

def state_index(name: str) -> int

Return the position of the state called name.

subsetmethod#

def subset(keep: Iterable[str], name: str | None = None) -> ReactionNetwork

Return the network of the states keep and the reactions among them only.