scripts/run_layer3_structural_binder_plane.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/run_layer3_structural_binder_plane.py · SHA-256: a070de200dfefd3d…
"Reconciles the literature SPR affinity scales by explicitly tagging construct, valency, temperature, assay format, and cached PMID: "
"1.2 uM (SIRPa V1) / 1.6 uM (SIRPa V2) are unverified secondary 25 C working model priors (Hatherley et al. 2008 PMID:18657508 text reports ~1-2 uM across alleles, "
"and Weiskopf et al. 2013 PMID:23722425 reports 0.3-0.5 uM WT CD47 affinity around Fig. 1C and ~1 uM general WT baseline), whereas Hatherley et al. 2014 (PMID:24550402 Table 2) "
"directly measured 0.74 +/- 0.07 uM (SIRPa V1), 0.64 +/- 0.06 uM (SIRPa V2), 0.78 +/- 0.09 uM (SIRPa v5), 0.65 +/- 0.05 uM (SIRPa v7), and 0.67 +/- 0.05 uM (SIRPa v10) at physiological 37 C using immobilized 3-domain human SIRPa (d1-d3)-rCD4(d3+4)-biotin "
"on streptavidin with soluble monomeric human CD47 IgV (d1) analyte (so the 2008/2013 vs 2014 figures also differ in 1-domain vs 3-domain SIRPa immobilization "
"architecture rather than forming an identical-construct temperature series; S55R2-D3-04, AUDIT-REF, AUDIT-REF & AUDIT-REF,PE-F2)."
),
"pmid_anchored_spr_measurement_ledger": [
{
"construct": "Soluble human CD47 IgV (C15G) : SIRPa V1 d1 monomer (unverified secondary model prior; Hatherley 2008 text reports ~1-2 uM range and Weiskopf 2013 reports 0.3-0.5 uM / ~1 uM WT baseline)",
"valency": "1:1 monomer",
"temperature_C": 25.0,
"assay_format": "Surface plasmon resonance (secondary model prior; ~1-2 uM range in Hatherley 2008)",
"kd_uM": 1.2,
"pmid": "18657508",
"citation": "Hatherley et al. 2008 Mol Cell 31:266-277 & Weiskopf et al. 2013 Science 341:88-91 (PMID:23722425)",
},
{
"construct": "Soluble human CD47 IgV (C15G) : SIRPa V2 d1 monomer (unverified secondary model prior; Hatherley 2008 text reports ~1-2 uM range and Weiskopf 2013 reports 0.3-0.5 uM / ~1 uM WT baseline)",
"valency": "1:1 monomer",
"temperature_C": 25.0,
"assay_format": "Surface plasmon resonance (secondary model prior; ~1-2 uM range in Hatherley 2008)",
"kd_uM": 1.6,
"pmid": "18657508",
"citation": "Hatherley et al. 2008 Mol Cell 31:266-277 & Weiskopf et al. 2013 Science 341:88-91 (PMID:23722425)",
},
{
"construct": "Immobilized 3-domain human SIRPa V1 (d1-d3)-rCD4(d3+4)-biotin on streptavidin vs soluble monomeric human CD47 IgV (d1)",
"valency": "1:1 monomeric CD47 IgV analyte over immobilized 3-domain SIRPa (d1-d3)",
"temperature_C": 37.0,
"assay_format": "Surface plasmon resonance at physiological 37 C (Table 2)",
"kd_uM": 0.74,
"kd_sd_uM": 0.07,
"pmid": "24550402",
"citation": "Hatherley et al. 2014 J Biol Chem 289:10024-10033",
},
{
"construct": "Immobilized 3-domain human SIRPa V2 (d1-d3)-rCD4(d3+4)-biotin on streptavidin vs soluble monomeric human CD47 IgV (d1)",
"valency": "1:1 monomeric CD47 IgV analyte over immobilized 3-domain SIRPa (d1-d3)",
"temperature_C": 37.0,
"assay_format": "Surface plasmon resonance at physiological 37 C (Table 2)",
"kd_uM": 0.64,
"kd_sd_uM": 0.06,
"pmid": "24550402",
"citation": "Hatherley et al. 2014 J Biol Chem 289:10024-10033",
},
],
},
"kd_sirpa_v8_uM_unmeasured_interpolation_prior": 1.35,
"exact_product_sirpa_v8_kd_uM": None,
"sirpa_v8_experimental_structure_analyzed": False,
"sirpa_v8_sequence_and_polymorphism_scope_note": (
"Only SIRPa V2 (PDB:2JJS) and SIRPa V1 (PDB:4CMM, where V1 Asp101 [2.79 A to CD47; paired with sequence-annotated insertion Asp100 at 4.65 A] resides directly inside the 4.5 A CD47 contact shell alongside position 66; AUDIT-REF & AUDIT-REF) co-crystal structures are analyzed in the local coordinate corpus; "
"SIRPa V8 (one of the 10 polymorphic human SIRPa IgV alleles identified in the 37-donor sequence panel of Takenaka et al. 2007 PMID:17982459 Supp. Table 3, where V1 and V2 are the two most frequent alleles in that panel and V8 is a lower-frequency polymorphic variant, and where Hatherley et al. 2014 PMID:24550402 Table 2 measured soluble 37 C SPR for 5 variants v1, v2, v5, v7, and v10 [K_D = 0.64-0.78 uM across the 5 measured variant means: v1 = 0.74 +/- 0.07, v2 = 0.64 +/- 0.06, v5 = 0.78 +/- 0.09, v7 = 0.65 +/- 0.05, v10 = 0.67 +/- 0.05 uM] rather than V8; AUDIT-REF, AUDIT-REF & AUDIT-REF) has no co-crystal "
"structure in the corpus, so exact_product_sirpa_v8_kd_uM is null (1.35 uM is an unmeasured working interpolation prior requiring Stage-0 SPR and primary donor macrophage validation)."
),
"pan_allelic_sirpa_protection_status": "UNRESOLVED_REQUIRES_V1_V2_V8_PRIMARY_HUMAN_MACROPHAGE_PHAGOCYTOSIS_ASSAY",
"bare_wlc_9aa_stalk_rms_nm_at_l0_3p5_and_3p8A": [1.483, 1.554],
"phagocytic_synapse_stalk_reach_and_spatial_exclusion_qualification_astra_r1": (
"CD47-IgV-GPI fuses the single CD47 IgV domain (~4.0 nm) to the 9-aa retained DAF (CD55) GPI stalk (PNKGSGTTS, "
"L_c = 3.15 nm [l_0 = 3.5 A] to 3.42 nm [l_0 = 3.8 A]; bare-WLC RMS = 1.483-1.554 nm at L_p = 4.0 A, and ~1.7-2.1 nm under O-glycosylated Ser/Thr mucin stiffening; AUDIT-REF). "
"Because CD47:SIRPa inhibition requires physical engagement across the intercellular phagocytic synapse (~11.5 nm FcR-IgG synapse gap and 6 / 9.5 / 16.5 / 21.5 nm synthetic Fibcon protein domain tethers with FKBP/FRB rapalog coupling in Morrissey et al. 2020 PMID:32768386 [Immunity; and 2023 Immunity Correction PMID:37703830 correcting recombinant mouse CD47 expression boundaries from 40-182 to 19-140], where CD47 ligation retains SIRPa in the synapse to suppress inside-out integrin activation whereas ~14 nm total gap / ~10-12 nm 3-domain SIRPa ectodomain reach are geometric model estimates; AUDIT-REF & AUDIT-REF), "
"Stage-0 bench validation must test cell-bound SIRPa-Fc avidity and primary V1/V2/V8 macrophage phagocytosis +/- neuraminidase "
"and +/- PI-PLC against a longer DAF-SCR4 stalk comparator if steric glycocalyx burial is observed (AUDIT-REF, AUDIT-REF & AUDIT-REF)."
),
"scope_and_limitations_note": (
"Crystal structures 2JJS and 4CMM capture the soluble C15G (C33G) extracellular IgV complex for SIRPa V2 and V1 "
"(no experimental structure is analyzed for SIRPa V8, whose 1.35 uM value is an unmeasured working prior) and do not "
"include the wild-type Cys33 thiol, lipid-bilayer GPI anchor, membrane tether orientation, or glycocalyx; "
"pan-allelic macrophage/NK phagocytic suppression requires empirical donor-panel flow-cytometry & PI-PLC verification."
),
},
}
def validate_alphafold_reference(atoms: List[Dict[str, Any]], metadata: Any,
accession: str, length: int) -> Dict[str, Any]:
"""Bind every modeled residue and confidence to its declared AF reference."""
if isinstance(metadata, list):
if len(metadata) != 1:
raise ValueError("Exactly one AlphaFold reference metadata entry is required")
metadata = metadata[0]
if not isinstance(metadata, dict) or metadata.get("uniprotAccession") != accession:
raise ValueError(f"AlphaFold metadata accession mismatch: {accession}")
model_id = f"AF-{accession}-F1"
if (metadata.get("modelEntityId") != model_id or metadata.get("entryId") != model_id
or type(metadata.get("latestVersion")) is not int or metadata["latestVersion"] != 6
or metadata.get("chainId") != "A"
or metadata.get("cifUrl") != f"https://alphafold.ebi.ac.uk/files/{model_id}-model_v6.cif"
or metadata.get("paeDocUrl") != f"https://alphafold.ebi.ac.uk/files/{model_id}-predicted_aligned_error_v6.json"):
raise ValueError(f"AlphaFold metadata model/version identity mismatch: {accession}")
sequence = metadata.get("uniprotSequence")
global_plddt = metadata.get("globalMetricValue")
if (not isinstance(sequence, str) or len(sequence) != length
or type(metadata.get("uniprotStart")) is not int or metadata.get("uniprotStart") != 1
or type(metadata.get("uniprotEnd")) is not int or metadata.get("uniprotEnd") != length
or isinstance(global_plddt, (bool, np.bool_)) or not isinstance(global_plddt, Real)
or not math.isfinite(global_plddt) or not 0 <= global_plddt <= 100):
raise ValueError(f"Incomplete AlphaFold sequence/range/confidence metadata: {accession}")
ca = get_ca_map(atoms, "A")
if set(ca) != set(range(1, length + 1)):
raise ValueError(f"AlphaFold model must contain every declared residue exactly once: {accession}")
three_to_one = dict(zip(
"ALA ARG ASN ASP CYS GLN GLU GLY HIS ILE LEU LYS MET PHE PRO SER THR TRP TYR VAL".split(),
"ARNDCQEGHILKMFPSTWYV"))
model_sequence = "".join(three_to_one.get(ca[i]["comp_id"], "?") for i in range(1, length + 1))
if model_sequence != sequence:
raise ValueError(f"AlphaFold coordinate residue identities differ from metadata: {accession}")
for atom in atoms:
value = atom["b_iso"]
if isinstance(value, (bool, np.bool_)) or not isinstance(value, Real) or not 0.0 <= value <= 100.0:
raise ValueError(f"AlphaFold pLDDT must be within [0,100]: {accession}")
residue = ca.get(atom["seq_id"])
if (atom["chain"] != "A" or residue is None or atom["ins_code"] != ""
or atom["comp_id"] != residue["comp_id"] or value != residue["b_iso"]):
raise ValueError(f"AlphaFold atom identity/confidence disagrees within its declared residue: {accession}")
# Give every residue one vote, irrespective of its number of sidechain
# atoms. Keep the supplied metadata value visible even when it is stale.
coordinate_mean = math.fsum(float(ca[i]["b_iso"]) for i in range(1, length + 1)) / length
result = dict(metadata)
result["coordinate_global_plddt"] = round(coordinate_mean, 2)
result["global_plddt_audit"] = {
"source": "unweighted_mean_of_one_CA_pLDDT_per_reference_residue",
"coordinate_residue_count": length,
"coordinate_mean_unrounded": coordinate_mean,
"metadata_supplied_global_plddt": float(global_plddt),
"metadata_minus_coordinate_mean": float(global_plddt) - coordinate_mean,
"agreement_at_two_decimal_places": round(float(global_plddt), 2) == round(coordinate_mean, 2),
"published_value_source": "validated_coordinate_residue_mean",
}
return result
def analyze_complex_3_serpinb9_gzmb(layer2_ledger: Dict[str, Any]) -> Dict[str, Any]:
"""
Analyze Complex 3: SERPINB9 (PI-9) : Granzyme B.
Closes V70-07 (local RCL pLDDT, 21/26/50-aa tail contour lengths, and unresolved status)
and V70-08 (insertion-code-safe 226/226 global alignment of AF-P10144 vs PDB:1IAU).
"""
snapshots = verify_structural_reference_inputs(
"AF-P50453-F1-model_v6.cif", "AF-P10144-F1-model_v6.cif", "pdb_00001iau.cif",
"AF-P50453-F1-predicted_aligned_error_v6.json", "AF-P10144-F1-predicted_aligned_error_v6.json")
atoms_sb9 = parse_mmcif_atoms(STRUCT_DIR / "AF-P50453-F1-model_v6.cif", source_bytes=snapshots["AF-P50453-F1-model_v6.cif"])
atoms_gzmb_af = parse_mmcif_atoms(STRUCT_DIR / "AF-P10144-F1-model_v6.cif", source_bytes=snapshots["AF-P10144-F1-model_v6.cif"])
# Retain insertion codes (e.g. 184A) for PDB:1IAU; evaluate both altloc A (occupancy 0.38) and dominant altloc B (occupancy 0.62)
atoms_1iau = parse_mmcif_atoms(STRUCT_DIR / "pdb_00001iau.cif", source_bytes=snapshots["pdb_00001iau.cif"], keep_insertion_codes=True, allowed_alt_ids=(".", "?", "A"))
atoms_1iau_altb = parse_mmcif_atoms(STRUCT_DIR / "pdb_00001iau.cif", source_bytes=snapshots["pdb_00001iau.cif"], keep_insertion_codes=True, allowed_alt_ids=(".", "?", "B"))
with (STRUCT_DIR / "AF-P50453-F1-metadata.json").open() as f:
meta_sb9 = json.load(f)
with (STRUCT_DIR / "AF-P10144-F1-metadata.json").open() as f:
meta_gzmb = json.load(f)
meta_sb9 = validate_alphafold_reference(atoms_sb9, meta_sb9, "P50453", 376)
meta_gzmb = validate_alphafold_reference(atoms_gzmb_af, meta_gzmb, "P10144", 247)
if layer2_ledger["SERPINB9_cytosolic_with_21aa_GSG_P2A_stub"]["sequence"][:376] != meta_sb9["uniprotSequence"]:
raise ValueError("Engineered SERPINB9 native domain differs from the analyzed reference sequence")
pae_sb9_raw = json.loads(snapshots["AF-P50453-F1-predicted_aligned_error_v6.json"])
pae_gzmb_raw = json.loads(snapshots["AF-P10144-F1-predicted_aligned_error_v6.json"])
sb9_pae_mat = validated_pae_matrix(pae_sb9_raw, 376, "SERPINB9")
gzmb_pae_mat = validated_pae_matrix(pae_gzmb_raw, 247, "Granzyme B")
sb9_core_pae_mean = round(_pae_mean(sb9_pae_mat[:322, :322]), 2)
# In official AlphaFold DB PAE v6 JSON (predicted_aligned_error[i][j]), row index i is the ALIGNED residue and column index j is the SCORED residue (AUDIT-REF):
sb9_rows_rcl_aligned_cols_core_scored_pae_mean = round(_pae_mean(sb9_pae_mat[334:345, :322]), 2) # 27.29 A
sb9_rows_core_aligned_cols_rcl_scored_pae_mean = round(_pae_mean(sb9_pae_mat[:322, 334:345]), 2) # 15.20 A
sb9_row_pro376_aligned_cols_rcl_335_345_scored_pae_mean = round(_pae_mean(sb9_pae_mat[375:376, 334:345]), 2) # 21.27 A
sb9_rows_rcl_335_345_aligned_col_pro376_scored_pae_mean = round(_pae_mean(sb9_pae_mat[334:345, 375:376]), 2) # 25.45 A
sb9_rows_cterm_372_376_aligned_cols_rcl_335_350_scored_pae_mean = round(_pae_mean(sb9_pae_mat[371:376, 334:350]), 2) # 13.24 A
sb9_rows_rcl_335_350_aligned_cols_cterm_372_376_scored_pae_mean = round(_pae_mean(sb9_pae_mat[334:350, 371:376]), 2) # 19.90 A
sb9_rcl_to_core_pae_mean = sb9_rows_rcl_aligned_cols_core_scored_pae_mean
sb9_core_to_rcl_pae_mean = sb9_rows_core_aligned_cols_rcl_scored_pae_mean
gzmb_mature_21_246_pae_mean = round(_pae_mean(gzmb_pae_mat[20:246, 20:246]), 2)
gzmb_mature_21_247_pae_mean = round(_pae_mean(gzmb_pae_mat[20:, 20:]), 2)
ca_sb9 = get_ca_map(atoms_sb9, "A")
core_plddts = [ca_sb9[r]["b_iso"] for r in range(1, 323) if r in ca_sb9]
rcl_hinge_to_p3p_plddts = [ca_sb9[r]["b_iso"] for r in range(322, 349) if r in ca_sb9]
rcl_recognition_335_345_plddts = [ca_sb9[r]["b_iso"] for r in range(335, 346) if r in ca_sb9]
rcl_mobile_loop_335_350_plddts = [ca_sb9[r]["b_iso"] for r in range(335, 351) if r in ca_sb9]
cterm_plddts = [ca_sb9[r]["b_iso"] for r in range(349, 377) if r in ca_sb9]
plddt_glu340 = float(ca_sb9[340]["b_iso"])
plddt_cys341 = float(ca_sb9[341]["b_iso"])
glu340_ca = get_atom_coord(atoms_sb9, "A", 340, "CA")
cys341_ca = get_atom_coord(atoms_sb9, "A", 341, "CA")
pro376_ca = get_atom_coord(atoms_sb9, "A", 376, "CA")
pro376_c_atom = get_atom_coord(atoms_sb9, "A", 376, "C")
val322_ca = get_atom_coord(atoms_sb9, "A", 322, "CA")
dist_pro376_to_glu340 = euclidean_distance(pro376_ca, glu340_ca)
dist_pro376_to_cys341 = euclidean_distance(pro376_ca, cys341_ca)
dist_pro376_to_val322 = euclidean_distance(pro376_ca, val322_ca)
cterm_atoms = filter_polymer_atoms(atoms_sb9, ["A"], (372, 376))
pro376_atoms = filter_polymer_atoms(atoms_sb9, ["A"], (376, 376))
rcl_recognition_atoms = filter_polymer_atoms(atoms_sb9, ["A"], (335, 345))
rcl_337_346_atoms = filter_polymer_atoms(atoms_sb9, ["A"], (337, 346))
rcl_mobile_335_350_atoms = filter_polymer_atoms(atoms_sb9, ["A"], (335, 350))
rcl_proximal_hinge_318_334_atoms = filter_polymer_atoms(atoms_sb9, ["A"], (318, 334))
c_cterm = np.array([[a["x"], a["y"], a["z"]] for a in cterm_atoms if a["element"] != "H"])
c_pro376 = np.array([[a["x"], a["y"], a["z"]] for a in pro376_atoms if a["element"] != "H"])
c_rcl = np.array([[a["x"], a["y"], a["z"]] for a in rcl_recognition_atoms if a["element"] != "H"])
c_rcl_337_346 = np.array([[a["x"], a["y"], a["z"]] for a in rcl_337_346_atoms if a["element"] != "H"])
c_rcl_335_350 = np.array([[a["x"], a["y"], a["z"]] for a in rcl_mobile_335_350_atoms if a["element"] != "H"])
c_hinge_318_334 = np.array([[a["x"], a["y"], a["z"]] for a in rcl_proximal_hinge_318_334_atoms if a["element"] != "H"])
min_heavy_dist_cterm_to_rcl = float(np.min(np.linalg.norm(c_cterm[:, None, :] - c_rcl[None, :, :], axis=-1)))
min_heavy_dist_pro376_only_to_rcl = float(np.min(np.linalg.norm(c_pro376[:, None, :] - c_rcl[None, :, :], axis=-1)))
min_heavy_dist_pro376_c_to_rcl_335_345 = float(np.min(np.linalg.norm(c_rcl - pro376_c_atom[None, :], axis=-1)))
min_heavy_dist_cterm_to_rcl_337_346 = float(np.min(np.linalg.norm(c_cterm[:, None, :] - c_rcl_337_346[None, :, :], axis=-1)))
min_heavy_dist_pro376_only_to_rcl_337_346 = float(np.min(np.linalg.norm(c_pro376[:, None, :] - c_rcl_337_346[None, :, :], axis=-1)))
min_heavy_dist_cterm_to_rcl_335_350 = float(np.min(np.linalg.norm(c_cterm[:, None, :] - c_rcl_335_350[None, :, :], axis=-1)))
min_heavy_dist_pro376_only_to_rcl_335_350 = float(np.min(np.linalg.norm(c_pro376[:, None, :] - c_rcl_335_350[None, :, :], axis=-1)))
min_heavy_dist_pro376_c_to_rcl_335_350 = float(np.min(np.linalg.norm(c_rcl_335_350 - pro376_c_atom[None, :], axis=-1)))
min_heavy_dist_cterm_to_hinge_318_334 = float(np.min(np.linalg.norm(c_cterm[:, None, :] - c_hinge_318_334[None, :, :], axis=-1)))