# opencr.data.native

*module*

OpenCR's native, versioned file format for reaction networks.

A network is written as one JSON document::

    {"format": "opencr-network", "version": 1, "name": ..., "assumptions": [...],
     "species": [...], "states": [...], "reactions": [...]}

Each reaction lists its reactants and products by state name (``"e"`` for the
electron), its kind, its rate model (`opencr.core.rates.RateModel.to_dict`;
a `Function` is written as its table) and its
provenance. Reading checks the format name and version, then builds and
checks the network. Files of a newer major version are refused.

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

## opencr.data.native.FORMAT_NAME

*attribute* · *module attribute*

```python
FORMAT_NAME = 'opencr-network'
```

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

## opencr.data.native.FORMAT_VERSION

*attribute* · *module attribute*

```python
FORMAT_VERSION = 1
```

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/native.py#L49-L49)

## opencr.data.native.load_network

*function*

```python
def load_network(path: str | Path) -> ReactionNetwork
```

Read a network written by `save_network`.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/native.py#L181-L187)

## opencr.data.native.network_from_dict

*function*

```python
def network_from_dict(data: Mapping[str, Any]) -> ReactionNetwork
```

Return the network of `network_to_dict`'s output, checked.

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

## opencr.data.native.network_to_dict

*function*

```python
def network_to_dict(network: ReactionNetwork) -> dict[str, Any]
```

Return the network in the native format as plain data.

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

## opencr.data.native.rate_from_dict

*function*

```python
def rate_from_dict(data: Mapping[str, Any]) -> RateModel
```

Return the rate model of `to_dict`'s output.

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

## opencr.data.native.save_network

*function*

```python
def save_network(network: ReactionNetwork, path: str | Path) -> Path
```

Write the network to ``path`` as native JSON and return the path.

[View source](https://github.com/max-models/OpenCR/blob/devel/src/opencr/data/native.py#L174-L178)
