# opencr.core

*module*

Model definitions independent of any array backend.

Species, states, rate models, reactions, reaction networks and plasma
conditions, as plain Python objects.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/__init__.py#L1-L1)

## opencr.core.ELECTRON

*attribute* · *module attribute*

```python
ELECTRON = Species('e', -1, ELECTRON_MASS, {})
```

Re-exported from: `opencr.core.species`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L109-L109)

## opencr.core.ELECTRON_STATE

*attribute* · *module attribute*

```python
ELECTRON_STATE = State(ELECTRON, weight=2.0)
```

Re-exported from: `opencr.core.species`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L212-L212)

## opencr.core.RADIATIVE_KINDS

*attribute* · *module attribute*

```python
RADIATIVE_KINDS = ('spontaneous_emission', 'radiative_recombination')
```

Re-exported from: `opencr.core.reactions`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L54-L54)

## opencr.core.REACTION_KINDS

*attribute* · *module attribute*

```python
REACTION_KINDS = ('excitation', 'deexcitation', 'ionization', 'three_body_recombination', 'radiative_recombination', 'dielectronic_recombination', 'spontaneous_emission', 'dissociation', 'dissociative_excitation', 'dissociative_ionization', 'dissociative_recombination', 'attachment', 'dissociative_attachment', 'detachment', 'charge_exchange', 'mutual_neutralization', 'associative_detachment', 'penning_ionization', 'quenching', 'vibrational_transfer', 'proton_transfer', 'wall_loss', 'pumping', 'other')
```

Re-exported from: `opencr.core.reactions`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L27-L52)

## opencr.core.Arrhenius

*class* · *dataclass*

```python
class Arrhenius(RateModel)
```

Bases: `opencr.core.rates.RateModel`

Re-exported from: `opencr.core.rates`

``k = a T^b exp(-c / T)`` with ``T`` in eV and ``k`` in SI.

**Attributes**

- `a` (`float`) — The prefactor in the SI unit of the reaction's order.
- `b` (`float`) — The temperature exponent.
- `c` (`float`) — The activation energy in eV.

**Numerics**

*arrhenius*

$$
k = a\,T^b\,e^{-c/T}
$$

Assumptions:

- $T$ in eV, $k$ in the SI unit of the reaction's order; $c$ is the threshold taken out before evaluation

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L207-L245)

### opencr.core.Arrhenius.a

*attribute* · *class attribute* · *instance attribute*

```python
a: float = 0.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L227-L227)

### opencr.core.Arrhenius.b

*attribute* · *class attribute* · *instance attribute*

```python
b: float = 0.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L228-L228)

### opencr.core.Arrhenius.c

*attribute* · *class attribute* · *instance attribute*

```python
c: float = unit_field('eV', 0.0)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L229-L229)

### opencr.core.Arrhenius.kind

*attribute* · *class attribute*

```python
kind: str = 'arrhenius'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L226-L226)

### opencr.core.Arrhenius.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.Arrhenius.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the three parameters.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L237-L245)

## opencr.core.Conditions

*class* · *dataclass*

```python
class Conditions
```

Re-exported from: `opencr.core.conditions`

Plasma conditions, SI with temperatures in eV.

The temperatures and densities take quantities (see the module
docstring): ``Conditions("300 K", 1e12 * u.cm**-3)``.

**Attributes**

- `electron_temperature` (`float`) — ``kT_e`` in eV. With a non-Maxwellian ``eedf`` it is the temperature of the rates that are not cross sections and of detailed balance; `from_eedf` sets it to ``2/3 <eps>``.
- `electron_density` (`float | None`) — ``n_e`` in m^-3, or ``None`` for quasi-neutrality, ``n_e = sum z_i n_i`` over every charged state (evolving and prescribed).
- `eedf` (`Any`) — The electron energy distribution (an `opencr.kinetics.eedf.EEDF`), or ``None`` for a Maxwellian at ``electron_temperature``.
- `densities` (`Mapping[str, float]`) — Densities in m^-3 of the prescribed states, by name: the drivers of a quasi-static solve (e.g. ``H(n=1)`` and ``H+``) and fixed backgrounds (e.g. ``H2`` in an atomic model).
- `totals` (`Mapping[str, float]`) — For a closed steady state, the total density of each element in m^-3 over the evolving states, e.g. ``{"H": 1e19}``.
- `ion_temperature` (`float | None`) — ``kT_i`` in eV; the gas temperature if ``None``.
- `gas_temperature` (`float`) — ``kT`` of the neutral gas in eV (0.026 eV is 300 K).
- `escape` (`Mapping[str, float]`) — Escape factors in [0, 1] by reaction name, overriding the reactions' own and anything ``trapping`` computes.
- `trapping` (`RadiationTrapping | None`) — Compute the escape factors of the lines self-consistently from the populations (`opencr.kinetics.radiation`); ``None`` for an optically thin plasma (apart from ``escape``).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L76-L186)

### opencr.core.Conditions.densities

*attribute* · *class attribute* · *instance attribute*

```python
densities: Mapping[str, float] = unit_field('m-3', default_factory=dict)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L110-L110)

### opencr.core.Conditions.eedf

*attribute* · *class attribute* · *instance attribute*

```python
eedf: Any = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L109-L109)

### opencr.core.Conditions.electron_density

*attribute* · *class attribute* · *instance attribute*

```python
electron_density: float | None = unit_field('m-3', None)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L108-L108)

### opencr.core.Conditions.electron_temperature

*attribute* · *class attribute* · *instance attribute*

```python
electron_temperature: float = unit_field('eV')
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L107-L107)

### opencr.core.Conditions.escape

*attribute* · *class attribute* · *instance attribute*

```python
escape: Mapping[str, float] = field(default_factory=dict)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L114-L114)

### opencr.core.Conditions.gas_temperature

*attribute* · *class attribute* · *instance attribute*

```python
gas_temperature: float = unit_field('eV', 0.026)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L113-L113)

### opencr.core.Conditions.ion_temperature

*attribute* · *class attribute* · *instance attribute*

```python
ion_temperature: float | None = unit_field('eV', None)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L112-L112)

### opencr.core.Conditions.totals

*attribute* · *class attribute* · *instance attribute*

```python
totals: Mapping[str, float] = unit_field('m-3', default_factory=dict)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L111-L111)

### opencr.core.Conditions.trapping

*attribute* · *class attribute* · *instance attribute*

```python
trapping: RadiationTrapping | None = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L115-L115)

### opencr.core.Conditions.heavy_temperature

*property*

```python
heavy_temperature: dict[str, float]
```

The temperature of each kind of rate dependence (see `opencr.core.rates`).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L156-L168)

### opencr.core.Conditions.quasi_neutral

*property*

```python
quasi_neutral: bool
```

Whether ``n_e`` follows from quasi-neutrality.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L151-L153)

### opencr.core.Conditions.from_eedf

*method* · *classmethod*

```python
def from_eedf(eedf: Any, **kwargs: Any) -> Conditions
```

Return conditions with ``eedf`` and its effective temperature ``2/3 <eps>``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L145-L148)

### opencr.core.Conditions.replace

*method*

```python
def replace(**changes: Any) -> Conditions
```

Return a copy with ``changes`` applied.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L170-L172)

### opencr.core.Conditions.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the conditions as plain data (the EEDF by its description).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L174-L186)

## opencr.core.Constant

*class* · *dataclass*

```python
class Constant(RateModel)
```

Bases: `opencr.core.rates.RateModel`

Re-exported from: `opencr.core.rates`

A rate coefficient independent of temperature, e.g. an Einstein A in s^-1.

**Attributes**

- `value` (`float`) — ``k`` in the SI unit of the reaction's order.

**Numerics**

*constant*

$$
k = \mathrm{const}, \qquad \text{e.g. } k = g\,A_{ul} \text{ for a line with escape factor } g
$$

Assumptions:

- no temperature (`depends_on` is `none`): Einstein coefficients, wall losses, pumping

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L306-L334)

### opencr.core.Constant.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'none'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L323-L323)

### opencr.core.Constant.kind

*attribute* · *class attribute*

```python
kind: str = 'constant'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L322-L322)

### opencr.core.Constant.value

*attribute* · *class attribute* · *instance attribute*

```python
value: float = 0.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L324-L324)

### opencr.core.Constant.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the value.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L332-L334)

## opencr.core.CrossSectionRate

*class* · *dataclass*

```python
class CrossSectionRate(RateModel)
```

Bases: `opencr.core.rates.RateModel`

Re-exported from: `opencr.core.rates`

A rate from a cross section averaged over a velocity distribution.

For electrons (``depends_on="electron"``) the average is over the electron
energy distribution of the conditions (Maxwellian by default); otherwise over
a Maxwellian of relative velocities at the ion or gas temperature.

**Attributes**

- `cross_section` (`CrossSection | None`) — The cross section (m^2) against energy (eV).
- `mass` (`float`) — The reduced mass in kg of the colliding pair.
- `incident_mass` (`float | None`) — For a table against the incident particle's energy with the target at rest (the lab frame), the incident mass in kg; the table is looked up at ``E incident_mass / mass``. ``None`` for a table in the centre-of-mass frame. For electrons both agree.

**Numerics**

*maxwellian*

$$
k(T) = \sqrt{\frac{8}{\pi\mu}}\,(kT)^{-3/2} \int_{E_{\mathrm{th}}}^\infty \sigma(E)\,E\,e^{-E/kT}\,dE
$$

*lab frame*

$$
E_{\mathrm{lab}} = E\,\frac{m_{\mathrm{inc}}}{\mu}
$$

*eedf*

$$
k = \sqrt{\frac{2e}{m_e}} \int_0^\infty \varepsilon\,\sigma(\varepsilon)\,F_0(\varepsilon)\,d\varepsilon
$$

Assumptions:

- $\sigma$ a plasmacoll `CrossSection`: linear between the table points, held at the last value above, zero below the threshold
- a Maxwellian of the reduced mass $\mu$ at $T_e$, $T_i$ or $T_{\mathrm{gas}}$ (`depends_on`); for electrons the conditions' EEDF when it is not Maxwellian
- a lab-frame table (target at rest) is read at $E_{\mathrm{lab}}$; a centre-of-mass table at $E$

References:

- [Hagelaar and Pitchford, Plasma Sources Sci. Technol. 14, 722 (2005)](https://doi.org/10.1088/0963-0252/14/4/011)

Built from:

- `opencr.kinetics.rates.MaxwellianIntegral`
- `opencr.kinetics.eedf.EEDF`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L127-L204)

### opencr.core.CrossSectionRate.cross_section

*attribute* · *class attribute* · *instance attribute*

```python
cross_section: CrossSection | None = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L164-L164)

### opencr.core.CrossSectionRate.incident_mass

*attribute* · *class attribute* · *instance attribute*

```python
incident_mass: float | None = unit_field('kg', None)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L166-L166)

### opencr.core.CrossSectionRate.kind

*attribute* · *class attribute*

```python
kind: str = 'cross_section'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L163-L163)

### opencr.core.CrossSectionRate.mass

*attribute* · *class attribute* · *instance attribute*

```python
mass: float = unit_field('kg', ELECTRON_MASS)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L165-L165)

### opencr.core.CrossSectionRate.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.CrossSectionRate.table

*property*

```python
table: CrossSection
```

The cross section (never ``None`` after construction).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L181-L184)

### opencr.core.CrossSectionRate.threshold

*property*

```python
threshold: float
```

The threshold of the cross section in eV (in its own frame).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L187-L189)

### opencr.core.CrossSectionRate.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the table, threshold and masses.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L191-L204)

## opencr.core.DetailedBalance

*class* · *dataclass*

```python
class DetailedBalance(RateModel)
```

Bases: `opencr.core.rates.RateModel`

Re-exported from: `opencr.core.rates`

The inverse of another reaction of the network, by detailed balance.

De-excitation from excitation, three-body recombination from ionization,
and any other inverse whose forward reaction has the products as
reactants and an electron on both sides or one more on the forward
product side. The evaluation (`opencr.kinetics.rates`) uses the
state energies and weights: the Klein-Rosseland inverse cross section for
an electron-impact excitation (valid for any energy distribution), and
the Maxwellian relation (Boltzmann, Saha) otherwise.

**Attributes**

- `forward` (`str`) — The name of the forward reaction.

**Numerics**

*inverse*

$$
k_{\mathrm{inv}}(T) = k_{\mathrm{fwd}}(T)\,\frac{g_{\mathrm{in}}}{g_{\mathrm{out}}}\, e^{\Delta E/T}\,\big(\Lambda^3\big)^{\Delta e}, \qquad \Lambda^3 = \left(\frac{h^2}{2\pi m_e kT}\right)^{3/2}
$$

*klein rosseland*

$$
\sigma_{ul}(\varepsilon) = \frac{g_l}{g_u}\,\frac{\varepsilon + \Delta E}{\varepsilon}\,\sigma_{lu}(\varepsilon + \Delta E)
$$

Assumptions:

- $g_{\mathrm{in}}, g_{\mathrm{out}}$ the products of the weights of the forward reactants and products ($g_e = 2$), $\Delta E$ the forward energy change from the state energies
- the same number of heavy particles on both sides of the forward reaction and $\Delta e \ge 0$ extra electrons among its products: Boltzmann ($\Delta e = 0$) or Saha ($\Delta e = 1$)
- with a non-Maxwellian EEDF an electron-impact excitation is inverted by its Klein-Rosseland cross section; a Saha inverse uses the Maxwellian forward rate at $T_{\mathrm{eff}}$

References:

- [Klein and Rosseland, Z. Phys. 4, 46 (1921)](https://doi.org/10.1007/BF01328041)

Built from:

- `opencr.kinetics.rates.RateEvaluator.coefficients`
- `opencr.kinetics.rates.inverse_cross_section`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L394-L443)

### opencr.core.DetailedBalance.forward

*attribute* · *class attribute* · *instance attribute*

```python
forward: str = ''
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L429-L429)

### opencr.core.DetailedBalance.kind

*attribute* · *class attribute*

```python
kind: str = 'detailed_balance'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L428-L428)

### opencr.core.DetailedBalance.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.DetailedBalance.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the forward reaction's name.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L437-L443)

## opencr.core.Function

*class* · *dataclass*

```python
class Function(RateModel)
```

Bases: `opencr.core.rates.RateModel`

Re-exported from: `opencr.core.rates`

``k(T)`` from a Python function of the temperature in eV (array in, array out).

Written to files as a table on `file_temperatures`.

**Attributes**

- `function` (`Callable[[np.ndarray], np.ndarray] | None`) — ``k`` in SI as a function of ``T`` in eV.
- `label` (`str`) — What the function is, e.g. ``"Kramers radiative recombination"``.
- `threshold` (`float`) — As for `Tabulated`, used when the function is tabulated.
- `file_temperatures` (`tuple[float, ...]`) — The temperatures (eV) of the table written to files.

**Numerics**

*function*

$$
k = f(T)
$$

*tabulation*

$$
T_i = 10^{-2 + 6 i / 240}\ \mathrm{eV}, \quad i = 0, \dots, 240, \qquad \text{then as } \texttt{Tabulated}
$$

Assumptions:

- $f$ is host Python code; files and the JAX backend use its table
- $k$ itself is returned, so the threshold scaling does not protect it: $k$ underflows to zero once $E_{\mathrm{th}}/T \gtrsim 708$, and so does an inverse of it

Built from:

- `opencr.core.rates.Tabulated`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L337-L391)

### opencr.core.Function.file_temperatures

*attribute* · *class attribute* · *instance attribute*

```python
file_temperatures: tuple[float, ...] = unit_field('eV', default_factory=lambda : tuple(np.geomspace(0.01, 10000.0, 241).tolist()))
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L365-L367)

### opencr.core.Function.function

*attribute* · *class attribute* · *instance attribute*

```python
function: Callable[[np.ndarray], np.ndarray] | None = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L362-L362)

### opencr.core.Function.kind

*attribute* · *class attribute*

```python
kind: str = 'function'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L361-L361)

### opencr.core.Function.label

*attribute* · *class attribute* · *instance attribute*

```python
label: str = ''
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L363-L363)

### opencr.core.Function.threshold

*attribute* · *class attribute* · *instance attribute*

```python
threshold: float = unit_field('eV', 0.0)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L364-L364)

### opencr.core.Function.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.Function.tabulate

*method*

```python
def tabulate() -> Tabulated
```

Return the function as a `Tabulated` model on `file_temperatures`.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L375-L385)

### opencr.core.Function.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the function tabulated (see `tabulate`).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L387-L391)

## opencr.core.NetworkError

*class*

```python
class NetworkError(ValueError)
```

Bases: `ValueError`

Re-exported from: `opencr.core.network`

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L28-L34)

### opencr.core.NetworkError.problems

*attribute* · *instance attribute*

```python
problems = list(problems)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L33-L33)

## opencr.core.RadiationTrapping

*class* · *dataclass*

```python
class RadiationTrapping
```

Re-exported from: `opencr.core.conditions`

The escape-factor configuration of a solve (see `opencr.kinetics.radiation`).

The length takes a quantity (see the module docstring).

**Attributes**

- `length` (`float`) — The absorption length ``L`` in m (the distance to the wall).
- `model` (`str`) — One of `ESCAPE_MODELS`.
- `lines` (`tuple[str, ...] | None`) — The names of the ``spontaneous_emission`` reactions to trap, or ``None`` for all of them.
- `tolerance` (`float`) — The self-consistent iteration stops when no escape factor changes by more than this.
- `max_iterations` (`int`) — The limit of that iteration.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L35-L73)

### opencr.core.RadiationTrapping.length

*attribute* · *class attribute* · *instance attribute*

```python
length: float = unit_field('m')
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L51-L51)

### opencr.core.RadiationTrapping.lines

*attribute* · *class attribute* · *instance attribute*

```python
lines: tuple[str, ...] | None = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L53-L53)

### opencr.core.RadiationTrapping.max_iterations

*attribute* · *class attribute* · *instance attribute*

```python
max_iterations: int = 100
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L55-L55)

### opencr.core.RadiationTrapping.model

*attribute* · *class attribute* · *instance attribute*

```python
model: str = 'mewe'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L52-L52)

### opencr.core.RadiationTrapping.tolerance

*attribute* · *class attribute* · *instance attribute*

```python
tolerance: float = 1e-06
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L54-L54)

### opencr.core.RadiationTrapping.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the configuration as plain data.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/conditions.py#L67-L73)

## opencr.core.RateModel

*class* · *dataclass*

```python
class RateModel
```

Re-exported from: `opencr.core.rates`

Base class of the rate models; ``kind`` names the model in files.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L48-L63)

### opencr.core.RateModel.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.RateModel.kind

*attribute* · *class attribute*

```python
kind: str = ''
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L52-L52)

### opencr.core.RateModel.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the model as plain data (see `opencr.data.native`).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L61-L63)

## opencr.core.Reaction

*class* · *dataclass*

```python
class Reaction
```

Re-exported from: `opencr.core.reactions`

One reaction.

**Attributes**

- `name` (`str`) — A unique name in its network, e.g. ``"exc:H(n=1)->H(n=2)"``.
- `reactants` (`tuple[State, ...]`) — The reactant states; the electron is `ELECTRON_STATE`.
- `products` (`tuple[State, ...]`) — The product states.
- `kind` (`str`) — One of `REACTION_KINDS`.
- `rate` (`RateModel`) — The rate model.
- `provenance` (`Provenance | None`) — The origin of the rate data.
- `escape` (`float`) — For a spontaneous emission, the default escape factor of the line (1 for an optically thin plasma); conditions may override it.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L64-L179)

### opencr.core.Reaction.escape

*attribute* · *class attribute* · *instance attribute*

```python
escape: float = 1.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L86-L86)

### opencr.core.Reaction.kind

*attribute* · *instance attribute*

```python
kind: str
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L83-L83)

### opencr.core.Reaction.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L80-L80)

### opencr.core.Reaction.products

*attribute* · *instance attribute*

```python
products: tuple[State, ...]
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L82-L82)

### opencr.core.Reaction.provenance

*attribute* · *class attribute* · *instance attribute*

```python
provenance: Provenance | None = None
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L85-L85)

### opencr.core.Reaction.rate

*attribute* · *instance attribute*

```python
rate: RateModel
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L84-L84)

### opencr.core.Reaction.reactants

*attribute* · *instance attribute*

```python
reactants: tuple[State, ...]
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L81-L81)

### opencr.core.Reaction.energy_change

*property*

```python
energy_change: float
```

The internal energy of the products minus the reactants' in eV.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L157-L161)

### opencr.core.Reaction.equation

*property*

```python
equation: str
```

The reaction as text, e.g. ``"e + H(n=1) -> e + H(n=2)"``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L148-L154)

### opencr.core.Reaction.is_inverse

*property*

```python
is_inverse: bool
```

Whether the rate is the detailed balance of another reaction.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L171-L173)

### opencr.core.Reaction.net

*property*

```python
net: dict[str, int]
```

The net change of each state per reaction (products minus reactants).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L141-L145)

### opencr.core.Reaction.order

*property*

```python
order: int
```

The number of reactant particles.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L126-L128)

### opencr.core.Reaction.photon_energy

*property*

```python
photon_energy: float | None
```

For a spontaneous emission, the photon energy in eV; otherwise ``None``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L164-L168)

### opencr.core.Reaction.product_counts

*property*

```python
product_counts: dict[str, int]
```

How often each state is a product, by name.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L136-L138)

### opencr.core.Reaction.reactant_counts

*property*

```python
reactant_counts: dict[str, int]
```

How often each state is a reactant, by name.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L131-L133)

### opencr.core.Reaction.inverse_of

*method*

```python
def inverse_of(forward: Reaction) -> bool
```

Return whether this reaction is ``forward`` run backwards.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/reactions.py#L175-L179)

## opencr.core.ReactionNetwork

*class*

```python
class ReactionNetwork
```

Re-exported from: `opencr.core.network`

States and reactions, with the model's assumptions.

**Parameters**

- `states` (`Iterable[State]`) — The states (the electron is implicit and must not be listed).
- `reactions` (`Iterable[Reaction]`) — The reactions; every state they use must be in ``states``.
- `name` (`str`) (default: `''`) — The name of the network, e.g. ``"hydrogen/atomic/basic"``.
- `assumptions` (`Iterable[str]`) (default: `()`) — The model's assumptions and omissions, one sentence each.
- `check` (`bool`) (default: `True`) — Raise `NetworkError` if `problems` finds any.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L43-L275)

### opencr.core.ReactionNetwork.assumptions

*attribute* · *instance attribute*

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L66-L66)

### opencr.core.ReactionNetwork.name

*attribute* · *instance attribute*

```python
name = name
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L65-L65)

### opencr.core.ReactionNetwork.reactions

*attribute* · *instance attribute*

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L64-L64)

### opencr.core.ReactionNetwork.states

*attribute* · *instance attribute*

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L63-L63)

### opencr.core.ReactionNetwork.species

*property*

```python
species: tuple[Species, ...]
```

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L80-L85)

### opencr.core.ReactionNetwork.state_names

*property*

```python
state_names: tuple[str, ...]
```

The names of the states, in order.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L75-L77)

### opencr.core.ReactionNetwork.conservation

*method*

```python
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.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L182-L195)

### opencr.core.ReactionNetwork.manifest

*method*

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

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L237-L268)

### opencr.core.ReactionNetwork.merge

*method*

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

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L220-L235)

### opencr.core.ReactionNetwork.problems

*method*

```python
def problems() -> list[str]
```

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L146-L180)

### opencr.core.ReactionNetwork.reaction

*method*

```python
def reaction(name: str) -> Reaction
```

Return the reaction called ``name``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L102-L109)

### opencr.core.ReactionNetwork.reactions_of

*method*

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

Return the reactions that change the population of ``state``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L111-L113)

### opencr.core.ReactionNetwork.state

*method*

```python
def state(name: str) -> State
```

Return the state called ``name``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L87-L94)

### opencr.core.ReactionNetwork.state_index

*method*

```python
def state_index(name: str) -> int
```

Return the position of the state called ``name``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L96-L100)

### opencr.core.ReactionNetwork.subset

*method*

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

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

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/network.py#L197-L218)

## opencr.core.Species

*class* · *dataclass*

```python
class Species
```

Re-exported from: `opencr.core.species`

A particle kind.

**Attributes**

- `name` (`str`) — The formula, e.g. ``"H2+"``.
- `charge` (`int`) — The charge in units of e.
- `mass` (`float`) — The mass in kg.
- `composition` (`Mapping[str, int]`) — The number of atoms of each element, e.g. ``{"H": 2}``; empty for the electron.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L46-L105)

### opencr.core.Species.charge

*attribute* · *instance attribute*

```python
charge: int
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L59-L59)

### opencr.core.Species.composition

*attribute* · *class attribute* · *instance attribute*

```python
composition: Mapping[str, int] = field(default_factory=dict)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L61-L61)

### opencr.core.Species.mass

*attribute* · *class attribute* · *instance attribute*

```python
mass: float = unit_field('kg')
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L60-L60)

### opencr.core.Species.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L58-L58)

### opencr.core.Species.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the species as plain data.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L83-L90)

## opencr.core.State

*class* · *dataclass*

```python
class State
```

Re-exported from: `opencr.core.species`

One resolved state of a species.

**Attributes**

- `species` (`Species`) — The species.
- `label` (`str`) — The quantum label, e.g. ``"n=2"`` or ``"X,v=3"``; empty when the species is not resolved further.
- `energy` (`float`) — The energy in eV on the common scale of the element (see the module docstring).
- `weight` (`float`) — The statistical weight ``g``.
- `quantum_numbers` (`Mapping[str, Any]`) — The quantum numbers by name, e.g. ``{"n": 2}``, ``{"n": 2, "l": 1}`` or ``{"electronic": "X", "v": 3}``.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L144-L208)

### opencr.core.State.energy

*attribute* · *class attribute* · *instance attribute*

```python
energy: float = unit_field('eV', 0.0)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L161-L161)

### opencr.core.State.label

*attribute* · *class attribute* · *instance attribute*

```python
label: str = ''
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L160-L160)

### opencr.core.State.quantum_numbers

*attribute* · *class attribute* · *instance attribute*

```python
quantum_numbers: Mapping[str, Any] = field(default_factory=dict)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L163-L163)

### opencr.core.State.species

*attribute* · *instance attribute*

```python
species: Species
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L159-L159)

### opencr.core.State.weight

*attribute* · *class attribute* · *instance attribute*

```python
weight: float = 1.0
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L162-L162)

### opencr.core.State.charge

*property*

```python
charge: int
```

The charge in units of e.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L180-L182)

### opencr.core.State.name

*property*

```python
name: str
```

The state's name, ``"H(n=2)"``, or the species' name when unresolved.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L175-L177)

### opencr.core.State.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the state as plain data (the species by name).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L184-L192)

## opencr.core.Tabulated

*class* · *dataclass*

```python
class Tabulated(RateModel)
```

Bases: `opencr.core.rates.RateModel`

Re-exported from: `opencr.core.rates`

``k(T)`` from a table, interpolated linearly in ``log k`` against ``log T``.

A ``threshold`` (eV) removes the Boltzmann factor before interpolating,
``log(k exp(threshold / T))``, which keeps the interpolation accurate at
temperatures far below a threshold. Outside the table this scaled
quantity holds its end value, so ``k = k_end exp(threshold / T_end -
threshold / T)`` there.

**Attributes**

- `temperatures` (`tuple[float, ...]`) — The table temperatures in eV, increasing.
- `values` (`tuple[float, ...]`) — ``k`` in SI at ``temperatures``, non-negative.
- `threshold` (`float`) — The energy in eV of the Boltzmann factor to remove.

**Numerics**

*interpolation*

$$
\ln\!\big(k\, e^{E_{\mathrm{th}}/T}\big) \text{ linear in } \ln T \text{ between the table points}
$$

*extrapolation*

$$
k(T) = k_{\mathrm{end}}\, e^{E_{\mathrm{th}}/T_{\mathrm{end}} - E_{\mathrm{th}}/T} \quad \text{outside the table } (\ln T \text{ clipped})
$$

Order of accuracy: 2.

Assumptions:

- the order is in the table spacing in $\ln T$, for a smooth $\ln(k\,e^{E_{\mathrm{th}}/T})$
- outside the table the scaled quantity $k\,e^{E_{\mathrm{th}}/T}$ holds its end value, not $k$ itself

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L248-L303)

### opencr.core.Tabulated.kind

*attribute* · *class attribute*

```python
kind: str = 'tabulated'
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L276-L276)

### opencr.core.Tabulated.temperatures

*attribute* · *class attribute* · *instance attribute*

```python
temperatures: tuple[float, ...] = unit_field('eV', ())
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L277-L277)

### opencr.core.Tabulated.threshold

*attribute* · *class attribute* · *instance attribute*

```python
threshold: float = unit_field('eV', 0.0)
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L279-L279)

### opencr.core.Tabulated.values

*attribute* · *class attribute* · *instance attribute*

```python
values: tuple[float, ...] = ()
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L278-L278)

### opencr.core.Tabulated.depends_on

*attribute* · *class attribute* · *instance attribute*

```python
depends_on: str = 'electron'
```

Inherited from: `opencr.core.rates.RateModel`

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L53-L53)

### opencr.core.Tabulated.to_dict

*method*

```python
def to_dict() -> dict[str, Any]
```

Return the table.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/rates.py#L295-L303)

## opencr.core.species_from_formula

*function*

```python
def species_from_formula(formula: str) -> Species
```

Re-exported from: `opencr.core.species`

Return the species of a simple formula such as ``"H"``, ``"H2+"``, ``"Ar"`` or ``"H-"``.

The formula is one element symbol, an optional atom count and the charge
as repeated signs (``"H2+"``, ``"H-"``, ``"Ar++"``). The mass is the sum of
the atomic masses minus the missing electrons (plus the extra ones of a
negative ion).

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/core/species.py#L112-L141)

**Modules**

- `opencr.core.conditions`
- `opencr.core.network`
- `opencr.core.rates`
- `opencr.core.reactions`
- `opencr.core.species`
