# opencr.core.species

*module*

Species and their quantum states.

A `Species` is a particle kind named by its formula, as in plasmacoll
and carafe (``"e"``, ``"H"``, ``"H+"``, ``"H2"``, ``"H-"``), with its
charge, mass and elemental composition. A `State` is one state of a
species that the model resolves: an atomic level ``H(n=2)``, a fine-structure
level, a molecular electronic-vibrational state ``H2(X,v=3)``, or the species
as a whole (an empty label) when it is not resolved. The solver sees only
states, so the resolution of a model changes without changing the solver.

Energies of the states of one element share one scale: zero at the ground
state of the neutral, the ion's ground state at the ionization energy. Detailed
balance and the photon energies of radiative transitions are computed from
these energies.

The mass of a species and the energy of a state take an astropy Quantity or a
string such as ``"1.008 u"`` or ``"10.2 eV"`` as well as a number in kg or eV
(see `plasmacoll.units`).

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

## opencr.core.species.ELECTRON

*attribute* · *module attribute*

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

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

## opencr.core.species.ELECTRON_STATE

*attribute* · *module attribute*

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

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

## opencr.core.species.Species

*class* · *dataclass*

```python
class 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.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.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.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.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.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.species.State

*class* · *dataclass*

```python
class State
```

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.species.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.species.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.species.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.species.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.species.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.species.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.species.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.species.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.species.species_from_formula

*function*

```python
def species_from_formula(formula: str) -> 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)
