# Selective intervention, target support and closed RAFs

Runnable source-specific example for **Certified selective interventions and closed-RAF structure in a pooled prokaryotic network**, manuscript entry 27, SHA-256 `d271244c721f70339c8e26094d51d691ef1915e556e742e3dc0648a64c0aa50c`.

The paper distinguishes three questions: which small sets sustain catalytic organization, which sets produce a chosen target from food, and which sets are closed under every supported reaction in a stated ambient network. These questions have different answers. The example reconstructs the actual parent source and reproduces the selective valine intervention, restoration witnesses, ten-reaction subsystem, pooling extension and meeting parent RAF bounds.

## Run

Python 3.11 or newer. Core structural calculations use the standard library; NumPy and Matplotlib generate the figures.

```sh
python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
python -m pip install -r requirements.txt
python -m unittest -v test_example.py
python example.py --output outputs
```

The default calculation takes seconds. It writes two figure pairs, four CSV tables, explicit parent/postcut activation and maximum sets, structured results, a console summary and file hashes. It does not attempt the complete parent irreducible catalogue. Small exhaustive enumeration has an explicit subset budget and reports unresolved if the budget is insufficient.

## Literal input and provenance

`prokaryotic-network.txt` contains the unchanged bytes of the paper's archived `prokaryotic-network.crs`; only its filename extension differs for packaging. SHA-256:

`f6834863b2d272d074af5befcb6149c11edf5a64b1aa0ba716ebeb8f10b3700b`.

The pinned source is [CatReNet, commit fcb11fb1027f3378075f3a9ef6fc84fae776ff88](https://github.com/husonlab/catrenet/blob/fcb11fb1027f3378075f3a9ef6fc84fae776ff88/examples/prokaryotic-network.crs). Its original header attributes the network to Xavier, Hordijk, Kauffman, Steel and Martin (2020), *Autocatalytic chemical networks at the origin of metabolism*, Proceedings of the Royal Society B 287:20192377. The source is a pooled prokaryotic reaction collection, not an organism-specific reconstruction. The original attribution is retained.

All 6,039 source actions are parsed; splitting 3,192 reversible rows yields 9,231 directed reactions. Both directions retain the **same action identifier and catalyst formula**. The source food declaration has exactly 68 species or formal markers. In particular, C00003 and Pooling are supplied, whereas NADs, valine C00183, methionine C00073 and precursor C00141 are not.

`certificate_inputs.json` contains the paper supplement's 18-species siphon and three restoration supports, translated from source indices into stable direction identifiers. Their validity is recomputed against the pinned source. The parser retains stoichiometric coefficients, but the structural presence/absence calculation uses only species membership. It is not a stoichiometric flux model. Source pinning, parsing and finite checks are not a replay of the paper's Lean proofs.

## Reusable components and editable inputs

- `CatalystFormula` parses positive formulas: commas or `|` mean OR, `&` or `*` mean AND, parentheses preserve grouping. AND has precedence over OR. Empty formulas mean true. A formula such as `(Flavins,Hemes)&NADs` needs NADs **and** at least one of the other catalysts; flattening it would change the model.
- `Reaction` holds reactants, products, catalyst, direction/action identifiers and original line number. `ReactionSystem.read(path)` loads another file in the same syntax. Pass an expected hash to pin it; the default main run pins the paper source. `subset`, `delete_actions` and `add_food` return modified systems. Deleting an action removes all its directions.
- `RAFAnalysis.closure` ignores catalysts and computes reactant reachability from food. `is_raf` then checks every catalyst in the **final** closure. `maximum` repeatedly prunes unsupported directions, retaining its count trace. `capability` requires a nonempty RAF and target membership in its closure—even a supplied target does not make an empty reaction system capable under this definition.
- `constructive` checks catalysts in each prefix pool, giving a potentially smaller set A. `closed_uniqueness_certificate` compares A and maxRAF M as actual direction sets. A=M nonempty certifies the unique closed RAF. A strict gap is unresolved by this criterion, not proof of multiple closed RAFs. An empty M means no RAF.
- `closed_extension` grows a supplied RAF to its least closed extension in the current ambient system. `catalogue` exhausts all small subsets, separately reporting irreducible RAFs, closed RAFs and target RAFs. `necessary_producers` traces sound unique-producer obligations, including mandatory catalyst atoms. It leaves ambiguous alternatives unresolved.
- `SiphonCertificate` checks every surviving producer, independently of catalyst annotations. `InterventionStudy` combines this negative obstruction with ranked positive restoration witnesses. It certifies inclusion-minimality, not global minimum cost.

For another target or medium, edit the constants at the top. The included restoration witnesses and barrier remain **candidates**: changing the cut or source can invalidate them, and the result will say so. For unrelated data, call the reusable classes with your own identifiers and certificates rather than expecting the paper's small-subsystem IDs to exist.

```python
from example import ReactionSystem, RAFAnalysis
system = ReactionSystem.read('prokaryotic-network.txt')
after_cut = system.delete_actions(('R01209','R01210','R04441'))
analysis = RAFAnalysis(after_cut)
assert not analysis.capability('C00183')
assert analysis.capability('C00073')
rescued = RAFAnalysis(after_cut.add_food(('C00141',)))
assert rescued.capability('C00183')
```

## What the default run establishes

The three deleted actions remove four directions; none directly produces valine. All 58 surviving directions producing a member of the 18-species siphon also require a member as a reactant. Since the food is disjoint from it, no member can enter the reactant closure. This prevents valine even if catalyst requirements are weakened or replaced. It also persists after further deletions and food additions outside the siphon. It does not prove depletion of species already present.

Restoring R01209, R01210 or R04441 admits valine-producing RAF witnesses of 9, 13 or 13 directions, respectively. Reactant ranks use earlier products; catalyst formulas are checked against final closure, not those ranks. These witnesses prove inclusion-minimality by monotonicity. Methionine is retained through singleton R09639 forward, whose reactants and catalyst are supplied. Food enlargement outside the siphon together with catalyst weakening preserves the positive witnesses; arbitrary strengthening need not. Supplying C00141 crosses the environmental boundary: a four-direction RAF restores valine after the cut. This does not mean every siphon species would do so.

Inside H, the ten specified directions have exactly 22 RAFs. The complete irreducible catalogue is the two singletons {0} and {7}, while the sole valine-producing RAF is all of H. Unique-producer and mandatory-catalyst propagation forces every direction. The two closed RAFs relative to H are L={0,1,4,7,8} and H. L has the same irreducible catalogue but cannot produce valine.

Adding q=R_NADs_1 forward, C00003 [Pooling] -> NADs, changes the ambient system. Both its reactant and catalyst are food, and now all eleven directions form the **only** closed RAF. This pooling row represents catalyst availability in the source abstraction; it is not a newly proposed physical reaction. Closedness must always name its ambient set.

For the full source and cut source, constructive activation reaches exactly the respective maxRAF sets in 23 synchronous layers. The pruning traces are:

    Parent: 9231 -> 2823 -> 2148 -> 2148
    Cut:    9227 -> 2584 -> 2085 -> 2085

The equality is checked by identifiers, not counts. Each nonempty common set is the unique parent closed RAF in its ambient source. The least parent closed extensions of L and H both equal the original parent maximum. This conclusion needs no complete parent irreducible catalogue.

## Scientific checks and limits

Seven test groups cover catalyst truth tables and parser failures; reversed action semantics and nonunit coefficient preservation; a RAF that cannot constructively activate; exhaustive small catalogues and target obligations; all eight subcuts and restoration ranks; annotation-independent obstruction, weakening and precursor rescue; parent set equality and activation ranks; and independent exhaustive maxRAF checks on small networks.

These are source-dependent structural results. RAF support does not establish positive net flux, stoichiometric self-amplification, growth, persistence or a concentration equilibrium. A unique closed RAF does not exclude kinetic multistability. The siphon argument gives no startup from an initially absent barrier under reactant-respecting firings and no barrier supply, not disappearance of a pre-existing population. The parent irrRAF catalogue and globally cheapest intervention remain uncomputed here, as in the paper.

Manuscript map: source and action semantics, Section 2; selective intervention and robustness, Section 3; subsystem and pooling, Section 4; meeting bounds, Section 5; firing/kinetic interpretation, Section 6. The paper's supplementary raw source, barrier and restoration certificates supplied the literal inputs.

Licensing: MIT is proposed for the original example code, pending the owner's decision; no license grant is made here. This proposal does not relicense the attributed third-party reaction source or manuscript.
