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
| Name | Description |
|---|---|
NetworkError | A reaction network is inconsistent; problems lists every problem found. |
ReactionNetwork | States 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.
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
| Name | Type | Default | Description |
|---|---|---|---|
states | Iterable[State] | required | The states (the electron is implicit and must not be listed). |
reactions | Iterable[Reaction] | required | The reactions; every state they use must be in states. |
name | str | '' | The name of the network, e.g. "hydrogen/atomic/basic". |
assumptions | Iterable[str] | () | The model’s assumptions and omissions, one sentence each. |
check | bool | True | Raise NetworkError if problems finds any. |
assumptionsattributeinstance attribute#
assumptions: tuple[str, ...] = tuple(assumptions)nameattributeinstance attribute#
name = namereactionsattributeinstance 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() -> _ConservationReturn 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 = '') -> ReactionNetworkReturn 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) -> ReactionReturn 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) -> StateReturn the state called name.
state_indexmethod#
def state_index(name: str) -> intReturn the position of the state called name.
subsetmethod#
def subset(keep: Iterable[str], name: str | None = None) -> ReactionNetworkReturn the network of the states keep and the reactions among them only.