File size: 1,521 Bytes
bb6d2aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from __future__ import annotations
import json
from pathlib import Path
from typing import Iterable
from staplebridge.data.schemas import BuildingBlock
def default_catalog() -> list[BuildingBlock]:
"""Single CP-Composer-style stapled block: K ↔ D/E lactam at i,i+3 or i,i+4.
Motif and Cα window come straight from CP-Composer's success criterion
(`evaluate_utils/success_utils.ipynb`):
- peptide[i] == 'K' and peptide[i+3] in {'D','E'} or peptide[i+4] in {'D','E'}
- 4.0 ≤ Cα(i)-Cα(j) ≤ 6.5 Å
"""
return [
BuildingBlock(
block_id="STAPLE_LACTAM",
name="K-(D/E) lactam staple",
chemistry_class="stapled",
synthetic_accessibility_score=0.85,
cost_score=0.5,
spps_score=0.7,
motif={"i_aa": ["K"], "j_aa": ["D", "E"], "spacings": [3, 4]},
ca_window=(4.0, 6.5),
),
]
def save_catalog(blocks: Iterable[BuildingBlock], out_path: str | Path) -> None:
path = Path(out_path)
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("w", encoding="utf-8") as f:
json.dump([b.to_dict() for b in blocks], f, indent=2)
def load_catalog(path: str | Path) -> list[BuildingBlock]:
with Path(path).open("r", encoding="utf-8") as f:
data = json.load(f)
return [BuildingBlock.from_dict(x) for x in data]
def catalog_index(blocks: Iterable[BuildingBlock]) -> dict[str, BuildingBlock]:
return {b.block_id: b for b in blocks}
|