"_struct_ref_seq_dif.details", "F 163 ASN SER 'engineered mutation'", "#", "loop_", "_atom_site.group_PDB", "_atom_site.id", "_atom_site.type_symbol", "_atom_site.label_atom_id", "_atom_site.label_comp_id", "_atom_site.label_asym_id", "_atom_site.label_seq_id", "_atom_site.Cartn_x", "_atom_site.Cartn_y", "_atom_site.Cartn_z", "_atom_site.auth_seq_id", "_atom_site.auth_comp_id", "_atom_site.auth_asym_id", "ATOM 1 O OG SER F 163 0.000 0.000 0.000 163 SER F", "ATOM 2 C CA ASN D 297 7.709 0.000 0.000 297 ASN D", ] aid = 3 for i_l in range(14): cif_lines.append( f"HETATM {aid} C C{i_l + 1} NAG L . {glyc_l_x + 0.1 * i_l:.3f} 0.000 0.000 1001 NAG D" ) aid += 1 for i_m in range(10): cif_lines.append( f"HETATM {aid} C C{i_m + 1} FUC M . {22.500 + 0.1 * i_m:.3f} 0.000 0.000 1002 FUC D" ) aid += 1 return "\n".join(cif_lines) + "\n" synth_cif_ok = tmp_dir_p / "synth_4x4m_asm2_ok.cif" synth_cif_ok.write_text(_build_synthetic_4x4m_asm2_cif(21.821), encoding="utf-8") res_m1_ok = parse_mmcif_interface_contacts( synth_cif_ok, receptor_chains={"F"}, partner_chains={"C", "D", "I", "J", "K", "L", "M"}, cutoff_angstrom=4.5, include_partner_hetatm=True, partner_protein_chains={"C", "D"}, ) synth_cif_hit = tmp_dir_p / "synth_4x4m_asm2_hit.cif" synth_cif_hit.write_text(_build_synthetic_4x4m_asm2_cif(3.500), encoding="utf-8") res_m1_hit = parse_mmcif_interface_contacts( synth_cif_hit, receptor_chains={"F"}, partner_chains={"C", "D", "I", "J", "K", "L", "M"}, cutoff_angstrom=4.5, include_partner_hetatm=True, partner_protein_chains={"C", "D"}, ) if not ( res_m1_ok["chain_id_namespace"] == "label_asym_id_preferred_with_auth_asym_id_fallback" and res_m1_ok["fc_linked_glycan_chains_from_struct_conn"] == ["L"] and res_m1_ok["partner_fc_hetatm_glycan_heavy_atoms_by_chain"] == {"L": 14, "M": 10} and res_m1_ok["partner_fc_hetatm_glycan_heavy_atoms_total"] == 24 and abs(res_m1_ok["min_engineered_mutation_dist_to_partner_protein_A"] - 7.709) < 1e-3 and abs(res_m1_ok["min_engineered_mutation_dist_to_partner_glycan_A"] - 21.821) < 1e-3 and res_m1_ok["engineered_mutations_in_protein_contacts_le_4p5A"] == [] and res_m1_ok["engineered_mutations_in_fc_glycan_contacts_le_4p5A"] == [] and res_m1_hit["engineered_mutations_in_fc_glycan_contacts_le_4p5A"] == ["N163S"] and abs(res_m1_hit["min_engineered_mutation_dist_to_partner_glycan_A"] - 3.500) < 1e-3 ): raise ValueError(f"R11 M1 label_asym_id glycan inventory/distance check failed: ok={res_m1_ok}, hit={res_m1_hit}") cases.append({"case": "m1_r11_mmcif_label_asym_id_glycan_inventory_and_distance_audit", "passed": True}) # 60. R11 M2: Early rejections (n == 0 all-missing-mcb_id, empty recipients=[], non-dict payload) MUST return # explicit False (never None or omitted!) for ALL 4 ancestry/ledger verification flags AND icc_sensitivity_report_attached=False! r11_no_mcb = [ {"recipient_id": f"NM-{i:02d}", "lot_id": "L00", "followup_months": 12, "met_c2b_criteria": True, "intercurrent_event": "NONE"} for i in range(5) ] p_early_nomcb = { "cohort_id": "COHORT-R11-M2-NOMCB", **GATE_28A_COMPATIBILITY_TARGET, "includes_reichman": False, "recipients": r11_no_mcb, } p_early_empty = { "cohort_id": "COHORT-R11-M2-EMPTY", **GATE_28A_COMPATIBILITY_TARGET, "includes_reichman": False, "recipients": [], } for lbl_m2, res_m2 in ( ("all_missing_mcb_n0", evaluate_gate28a_h1_promotion(p_early_nomcb, trusted_clinical_store=r11_store)), ("empty_recipients", evaluate_gate28a_h1_promotion(p_early_empty, trusted_clinical_store=r11_store)), ("non_dict_payload", evaluate_gate28a_h1_promotion("not-a-dict", trusted_clinical_store=r11_store)), # type: ignore[arg-type] ): if not ( res_m2["promotion_authorized"] is False and res_m2["status"] == "HOLD_H1_AT_88PCT" and res_m2["lot_bank_hierarchy_valid"] is False and res_m2["lot_to_mcb_manifest_verified"] is False and res_m2["lot_to_wcb_manifest_verified"] is False and res_m2["parallel_cmc_ledger_verified"] is False and res_m2["icc_sensitivity_report_attached"] is False and res_m2["icc_sensitivity_report"] is None and res_m2["deff"] is None and res_m2["n_eff"] is None and res_m2["k_eff"] is None ): raise ValueError(f"R11 M2 early rejection ({lbl_m2}) missing explicit False flags: {res_m2}") cases.append({"case": "m2_r11_gate28a_early_rejection_explicit_false_flags_and_no_sensitivity_report", "passed": True}) # 61. R11 M3: Semantic canonicalization of WCB ancestry aliases: # (a) working_cell_bank_id alone (without wcb_id) reconciles cleanly against manifest lot_to_wcb_manifest; # (b) adding identical top-level lot_to_wcb_manifest alongside matching nested WCB in lot_to_mcb_manifest # leaves cohort_canonical_sha256 invariant; semantic WCB mutation changes digest and fails closed! r11_wcb_alias_recs = copy.deepcopy(r10_plain60) for rec_wa in r11_wcb_alias_recs: if rec_wa["lot_id"] == "L00": rec_wa["working_cell_bank_id"] = "W0" r11_wcb_alias_cmc = copy.deepcopy(r10_plain_rows) r11_wcb_alias_cmc[0]["working_cell_bank_id"] = "W0" p_wcb_alias, _ = build_valid_gate28a_reference_bundle( r11_store, r11_wcb_alias_recs, cohort_id="COHORT-R11-M3-WCB-ALIAS", lot_to_mcb_manifest={lid: ({"mcb_id": mid, "wcb_id": "W0"} if lid == "L00" else mid) for lid, mid in r10_bank_map.items()}, lot_to_wcb_manifest=None, parallel_cmc_lot_ledger=r11_wcb_alias_cmc, ) sha_nested_only = compute_gate28a_cohort_canonical_sha256(p_wcb_alias) p_wcb_alias_plus_top = copy.deepcopy(p_wcb_alias) p_wcb_alias_plus_top["lot_to_wcb_manifest"] = {"L00": "W0"} sha_nested_plus_matching_top = compute_gate28a_cohort_canonical_sha256(p_wcb_alias_plus_top) p_wcb_alias_mut = copy.deepcopy(p_wcb_alias) p_wcb_alias_mut["lot_to_wcb_manifest"] = {"L00": "W9"} sha_mutated_wcb = compute_gate28a_cohort_canonical_sha256(p_wcb_alias_mut) r_m3_ok = evaluate_gate28a_h1_promotion(p_wcb_alias_plus_top, trusted_clinical_store=r11_store) r_m3_mut = evaluate_gate28a_h1_promotion(p_wcb_alias_mut, trusted_clinical_store=r11_store) if not ( sha_nested_only == sha_nested_plus_matching_top and sha_mutated_wcb != sha_nested_only and r_m3_ok["promotion_authorized"] is True and r_m3_ok["lot_to_wcb_manifest_verified"] is True and r_m3_mut["promotion_authorized"] is False and r_m3_mut["lot_to_wcb_manifest_verified"] is False ): raise ValueError( f"R11 M3 semantic canonicalization check failed: sha_same={sha_nested_only == sha_nested_plus_matching_top}, " f"sha_diff={sha_mutated_wcb != sha_nested_only}, ok={r_m3_ok}, mut={r_m3_mut}" ) cases.append({"case": "m3_r11_gate28a_semantic_canonicalization_wcb_aliases_and_mutation_rejection", "passed": True}) # --- R12 B1, B2, B3, M1: Final-Closure Self-Tests (Cases 62-65) --- r12_store = tmp_dir_p / "r12_gate28a_store.json" # 62. R12 B1: Decision-relevant top-level control flags (`primary_peer_reviewed_full_text_verified` and # `parallel_cmc_readiness_ledger_disclosed`) are injectively bound into `cohort_canonical_sha256` # (and reconciled against SOURCE_VERIFICATION_ATTESTATION): # On a 120-recipient / 30-lot / 10-MCB cohort with both flags False -> HOLD; deleting both flags, # deleting either single flag, toggling False->True post-attestation, mutating invalid non-bool values # (including literal "__ABSENT__"), or adding a False flag post-attestation ALL alter cohort_canonical_sha256, # invalidate stored attestations, and HOLD (NEVER PROMOTE)! r12_120 = [ { "recipient_id": f"R12-{lot:02d}-{rep}", "lot_id": f"L12-{lot:02d}", "mcb_id": f"M12-{lot // 3}", "followup_months": 12, "met_c2b_criteria": True, "intercurrent_event": "NONE", } for lot in range(30) for rep in range(4) ] p_b1_false, _ = build_valid_gate28a_reference_bundle( r12_store, r12_120, cohort_id="COHORT-R12-B1-BOTH-FALSE", primary_peer_reviewed_full_text_verified=False, parallel_cmc_readiness_ledger_disclosed=False, ) r_b1_false = evaluate_gate28a_h1_promotion(p_b1_false, trusted_clinical_store=r12_store) sha_b1_false = r_b1_false["cohort_canonical_sha256"] p_b1_del_both = copy.deepcopy(p_b1_false) p_b1_del_both.pop("primary_peer_reviewed_full_text_verified") p_b1_del_both.pop("parallel_cmc_readiness_ledger_disclosed") r_b1_del_both = evaluate_gate28a_h1_promotion(p_b1_del_both, trusted_clinical_store=r12_store) p_b1_del_pdf = copy.deepcopy(p_b1_false) p_b1_del_pdf.pop("primary_peer_reviewed_full_text_verified") r_b1_del_pdf = evaluate_gate28a_h1_promotion(p_b1_del_pdf, trusted_clinical_store=r12_store) p_b1_del_cmc = copy.deepcopy(p_b1_false) p_b1_del_cmc.pop("parallel_cmc_readiness_ledger_disclosed") r_b1_del_cmc = evaluate_gate28a_h1_promotion(p_b1_del_cmc, trusted_clinical_store=r12_store) p_b1_toggle_true = copy.deepcopy(p_b1_false) p_b1_toggle_true["primary_peer_reviewed_full_text_verified"] = True p_b1_toggle_true["parallel_cmc_readiness_ledger_disclosed"] = True r_b1_toggle_true = evaluate_gate28a_h1_promotion(p_b1_toggle_true, trusted_clinical_store=r12_store) p_b1_nonbool, _ = build_valid_gate28a_reference_bundle( r12_store, r12_120, cohort_id="COHORT-R12-B1-NONBOOL", primary_peer_reviewed_full_text_verified="__ABSENT__", parallel_cmc_readiness_ledger_disclosed=1, ) r_b1_nonbool = evaluate_gate28a_h1_promotion(p_b1_nonbool, trusted_clinical_store=r12_store) p_b1_nonbool_del = copy.deepcopy(p_b1_nonbool) p_b1_nonbool_del.pop("primary_peer_reviewed_full_text_verified") p_b1_nonbool_del.pop("parallel_cmc_readiness_ledger_disclosed") r_b1_nonbool_del = evaluate_gate28a_h1_promotion(p_b1_nonbool_del, trusted_clinical_store=r12_store) p_b1_ok, _ = build_valid_gate28a_reference_bundle( r12_store, r12_120, cohort_id="COHORT-R12-B1-VALID-TRUE", ) r_b1_ok = evaluate_gate28a_h1_promotion(p_b1_ok, trusted_clinical_store=r12_store) if not ( r_b1_ok["status"] == "PROMOTE_H1_88_TO_90" and r_b1_ok["promotion_authorized"] is True and r_b1_false["status"] == "HOLD_H1_AT_88PCT" and r_b1_false["promotion_authorized"] is False and r_b1_false["source_verification_attestation_verified"] is False and r_b1_del_both["status"] == "HOLD_H1_AT_88PCT" and r_b1_del_both["promotion_authorized"] is False and r_b1_del_both["cohort_canonical_sha256"] != sha_b1_false and r_b1_del_both["prespecification_attestation_verified"] is False and r_b1_del_both["source_verification_attestation_verified"] is False and r_b1_del_pdf["promotion_authorized"] is False and r_b1_del_pdf["cohort_canonical_sha256"] != sha_b1_false and r_b1_del_pdf["prespecification_attestation_verified"] is False and r_b1_del_cmc["promotion_authorized"] is False and r_b1_del_cmc["cohort_canonical_sha256"] != sha_b1_false and r_b1_del_cmc["prespecification_attestation_verified"] is False and r_b1_toggle_true["status"] == "HOLD_H1_AT_88PCT" and r_b1_toggle_true["promotion_authorized"] is False and r_b1_toggle_true["cohort_canonical_sha256"] != sha_b1_false and r_b1_toggle_true["prespecification_attestation_verified"] is False and r_b1_toggle_true["source_verification_attestation_verified"] is False and r_b1_nonbool["promotion_authorized"] is False and r_b1_nonbool_del["promotion_authorized"] is False and r_b1_nonbool_del["cohort_canonical_sha256"] != r_b1_nonbool["cohort_canonical_sha256"] and r_b1_nonbool_del["prespecification_attestation_verified"] is False ): raise ValueError( f"R12 B1 control-flag canonical digest binding failed: ok={r_b1_ok}, false={r_b1_false}, " f"del_both={r_b1_del_both}, toggle={r_b1_toggle_true}, nonbool={r_b1_nonbool}, nonbool_del={r_b1_nonbool_del}" ) cases.append({"case": "b1_r12_gate28a_control_flags_bound_in_canonical_digest_and_tamper_rejected", "passed": True}) # 63. R12 B2: Recipient WCB alias normalization (`working_cell_bank_id` <-> `wcb_id`) BEFORE hashing: