# Examples

Complete, runnable scripts from
[`py-bridge/python/examples`](https://molfoundry.de/). Each is a standalone
program — run it with the project's Python interpreter:

```{code-block} bash
python examples/multiphase_serial_passage.py
```

Each script's module docstring explains the chemistry and the modeling choices;
read it alongside the code.

## Serial passage of a self-replicating species

Multi-phase stochastic simulation with {class}`~molfoundry.MultiPhaseStochsim`:
a species replicates in a `flask` phase and is periodically diluted into a
`waste` phase, producing the characteristic passage "sawtooth". Shows discrete,
operator-scheduled `transfer` moves between `simulate` segments and the exact
mass-balance invariants they satisfy.

```{literalinclude} ../examples/multiphase_serial_passage.py
:language: python
:linenos:
```

## Enzyme mechanism → electron-flow rules

Translating a curated M-CSA enzyme mechanism into molfoundry electron-graph
rules ({class}`~molfoundry.Rule` over `GraphType.Electron`). Each curly arrow of
the mechanism becomes one graph rewrite that relocates electron ownership; the
example parses the ChemAxon `MEFlow` arrows and emits composable per-step rules.

```{literalinclude} ../examples/mcsa_electron_rules.py
:language: python
:linenos:
```
