File size: 1,827 Bytes
98bde72 | 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 | """Export chemistry-preserving AlphaFold 3 jobs and parse confidence records."""
from __future__ import annotations
from .schema import Molecule, Target
def af3_input(name: str, proteins: list[Target], peptide: Molecule, seeds=(2027,2028,2029)):
if peptide.n_terminus!="free" or peptide.c_terminus!="free":
raise ValueError("terminal chemistry requires explicit CCD residues before AF3 export")
molecules=[t.molecule for t in proteins]+[peptide]
if len(molecules)>26:raise ValueError("too many chains")
sequences=[];bonds=[]
for index,mol in enumerate(molecules):
if mol.n_terminus!="free" or mol.c_terminus!="free":
raise ValueError("unencoded terminal chemistry")
chain=chr(65+index)
entry={"id":chain,"sequence":mol.sequence}
if mol.modifications:
entry["modifications"]=[{"ptmType":m.ccd,"ptmPosition":m.position} for m in mol.modifications]
sequences.append({"protein":entry})
for i,ai,j,aj in mol.bonds:bonds.append([[chain,i,ai],[chain,j,aj]])
result={"name":name,"modelSeeds":list(seeds),"sequences":sequences,"dialect":"alphafold3","version":3}
if bonds:result["bondedAtomPairs"]=bonds
return result
def ternary_interface_features(chain_pair_iptm, peptide_index=2):
"""Retain both peptide interfaces; the weaker interface is the bottleneck."""
import numpy as np
a=np.asarray(chain_pair_iptm,float)
if a.shape!=(3,3) or peptide_index not in range(3):raise ValueError("expected three-chain matrix")
others=[i for i in range(3) if i!=peptide_index]
vals=[float(a[peptide_index,i]) for i in others]
if not all(np.isfinite(vals)):raise ValueError("missing interface confidence")
return {"peptide_partner_1":vals[0],"peptide_partner_2":vals[1],"weakest_interface":min(vals)}
|