OpenIslet

scripts/run_layer4_tissue_and_metabolic_twin.py

Layer 4: Multi-Scale Tissue, Vascular & Metabolic Digital Twin Plane (v0.8.0)

script Release v0.8.0 gen-eb955f8266035aba 713 KB · 47 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/run_layer4_tissue_and_metabolic_twin.py · SHA-256: 624a491d5e418a7d…

        regime_id="AUDIT_TWO_SCALE_ENDO1P50_VASC1P00",
        areal_loading_ieq_cm2=2500.0,
        endocrine_intrinsic_ocr_multiplier=1.50,
        vascular_intrinsic_ocr_multiplier=1.00,
    )

    # 2. Corrected slab washout eigenmodes (two-sink vs one-sink, D = 2.8e-6 vs 4.5e-6 cm^2/s)
    washout_eigenmodes = [
        compute_slab_drug_washout_eigenmodes_s(h_um, d_val)
        for d_val in (2.8e-6, 4.5e-6)
        for h_um in (140.0, 300.0, 350.0)
    ]

    # 3. Parameterized Design Z acute vs chronic vs adverse mixed vs passive 5% PFC matrix
    design_z_matrix = {
        "Acute_25mmHg_1p0xOCR_AcuteGel": compute_design_z_140um_parameterized_case(
            bed_po2_mmhg=25.0, ocr_multiplier=1.0, d_gel_cm2_s=9.40254e-6, k_perf_s_inv=0.097
        ),
        "Acute_25mmHg_0p70xOCR_AcuteGel": compute_design_z_140um_parameterized_case(
            bed_po2_mmhg=25.0, ocr_multiplier=0.70, d_gel_cm2_s=9.40254e-6, k_perf_s_inv=0.097
        ),
        "Acute_40mmHg_1p0xOCR_AcuteGel": compute_design_z_140um_parameterized_case(
            bed_po2_mmhg=40.0, ocr_multiplier=1.0, d_gel_cm2_s=9.40254e-6, k_perf_s_inv=0.097
        ),
        "Chronic_25mmHg_1p097xOCR_ChronicGel": compute_design_z_140um_parameterized_case(
            bed_po2_mmhg=25.0, ocr_multiplier=1.097, d_gel_cm2_s=1.5e-5, k_perf_s_inv=0.1358
        ),
        "Chronic_40mmHg_1p097xOCR_ChronicGel": compute_design_z_140um_parameterized_case(
            bed_po2_mmhg=40.0, ocr_multiplier=1.097, d_gel_cm2_s=1.5e-5, k_perf_s_inv=0.1358
        ),
        "Chronic_25mmHg_1p097xOCR_5volPctPFC_ChronicGel": compute_design_z_140um_parameterized_case(
            bed_po2_mmhg=25.0, ocr_multiplier=1.097, d_gel_cm2_s=1.5e-5, k_perf_s_inv=0.1358, pfc_vol_fraction=0.05
        ),
        "Adverse_40mmHg_1p097xOCR_UnremodeledAcuteGel_kperf0p097": compute_design_z_140um_parameterized_case(
            bed_po2_mmhg=40.0, ocr_multiplier=1.097, d_gel_cm2_s=9.40254e-6, k_perf_s_inv=0.097
        ),
    }

    # 4. M101 standalone closed-slab reservoir bounds across 100->15 mmHg and 40->15 mmHg (n_H = 2.5 and 3.0)
    m101_bounds = {
        "AirSaturated_100_to_15mmHg_n2p5": compute_m101_hill_reservoir_bound(p_start_mmhg=100.0, hill_n=2.5),
        "AirSaturated_100_to_15mmHg_n3p0": compute_m101_hill_reservoir_bound(p_start_mmhg=100.0, hill_n=3.0),
        "HostBed_40_to_15mmHg_n2p5": compute_m101_hill_reservoir_bound(p_start_mmhg=40.0, hill_n=2.5),
        "HostBed_40_to_15mmHg_n3p0": compute_m101_hill_reservoir_bound(p_start_mmhg=40.0, hill_n=3.0),
    }

    washout_and_cat = compute_early_washout_and_catalase_derating_checks()

    return {
        "contribution_id": "IIP-0021",
        "decision_id": "DEC-100",
        "baseline_cao2_mass_mg_preserved": 791.5,
        "hurdle1_computational_judgement_preserved_pct": 88,
        "inosculation_t50_bounds_preserved_h": [36.0, 60.0],
        "primary_citations": [
            "PMID:23935835",
            "PMID:17130499",
            "PMID:17503968",
            "PMID:42547502",
            "PMID:37318185",
            "PMID:16897713",
            "PMID:41951603",
            "PMID:23190609",
            "PMID:34572979",
            "PMID:29789532",
            "PMID:32893325",
            "PMID:34252539",
        ],
        "two_scale_lineage_ocr_verification": {
            "legacy_dec064_loading_alias_at_0p70": {
                "areal_loading_ieq_cm2": legacy_alias_070["areal_loading_ieq_cm2"],
                "min_slab_po2_mmhg": round(float(legacy_alias_070["min_slab_po2_unrounded_mmhg"]), 5),
                "gel_only_120um_core_po2_mmhg": round(
                    float(legacy_alias_070["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"]), 5
                ),
            },
            "uniform_cell_intrinsic_0p70_at_2500ieq": {
                "areal_loading_ieq_cm2": uniform_ocr_070["areal_loading_ieq_cm2"],
                "min_slab_po2_mmhg": round(float(uniform_ocr_070["min_slab_po2_unrounded_mmhg"]), 5),
                "gel_only_120um_core_po2_mmhg": round(
                    float(uniform_ocr_070["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"]), 5
                ),
            },
            "two_scale_endo0p55_vasc1p00_at_2500ieq": {
                "slab_normalized_ocr_multiplier": two_scale_endo055_vasc100["slab_normalized_ocr_multiplier"],
                "cluster_endocrine_ocr_multiplier": two_scale_endo055_vasc100["cluster_endocrine_ocr_multiplier"],
                "min_slab_po2_mmhg": round(float(two_scale_endo055_vasc100["min_slab_po2_unrounded_mmhg"]), 5),
                "gel_only_120um_core_po2_mmhg": round(
                    float(two_scale_endo055_vasc100["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"]), 5
                ),
            },
            "two_scale_endo1p50_vasc1p00_at_2500ieq": {
                "slab_normalized_ocr_multiplier": two_scale_endo150_vasc100["slab_normalized_ocr_multiplier"],
                "cluster_endocrine_ocr_multiplier": two_scale_endo150_vasc100["cluster_endocrine_ocr_multiplier"],
                "min_slab_po2_mmhg": round(float(two_scale_endo150_vasc100["min_slab_po2_unrounded_mmhg"]), 5),
                "gel_only_120um_core_po2_mmhg": round(
                    float(two_scale_endo150_vasc100["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"]), 5
                ),
            },
            "biological_scope_qualification": (
                "14.30% vascular cell fraction (133.5M / 933.5M) and 13.04% modeled vascular OCR share (0.15 / 1.15) are distinct quantities; "
                "while Ma et al. 2013 (PMID:23935835) measured rat-islet OCR after washout/reoxygenation, Sweet & Gilbert 2006 (PMID:17130499) "
                "observed ~30% acute glucose-stimulated rat-islet OCR reduction under diazoxide/nimodipine and MacDonald et al. 2007 (PMID:17503968) "
                "showed human alpha-cell K_ATP sensitivity to diazoxide, making empirical 120-h assembled-organoid OCR + glucagon/GSIS measurement mandatory."
            ),
        },
        "slab_free_drug_washout_first_eigenmode_table": {
            "eigenmodes": washout_eigenmodes,
            "boundary_and_diffusivity_note": (
                "Two-sink tau_1 = H^2/(pi^2 * D) gives 7.09, 32.57, and 44.33 s at 140, 300, and 350 um for D = 2.8e-6 cm^2/s "
                "(4.41, 20.26, and 27.58 s correspond to faster aqueous D = 4.5e-6 cm^2/s), whereas one-sink/one-reflecting geometry "
                "is 4x longer (28.37, 130.26, and 177.30 s at D = 2.8e-6 cm^2/s); all remain <3 min e-folding times vs 120-h bridge duration."
            ),
        },
        "design_z_140um_parameterized_acute_chronic_and_pfc_matrix": {
            "operative_gate_definition": "fv_harmonic_face_min_unrounded_mmhg >= 15.0 AND min_core_po2_unrounded_mmhg >= 5.0 (coupled with Stage-2 loaded Readout 2 perifusion kinetics; IIP-0025; DEC-104)",
            "acute_vs_chronic_parameter_disclosure": (
                "Acute unremodeled gel uses d_gel_cm2_s = 9.40254e-6 cm^2/s and k_perf = 0.097 s^-1, whereas chronic vascularized gel assumes "
                "d_gel_cm2_s = 1.5e-5 cm^2/s (+59.5%) and k_perf = 0.1358 s^-1; adverse unremodeled chronic OCR (1.097x at acute d_gel/k_perf) "
                "is tabulated explicitly alongside nominal chronic cases."
            ),
            "cases": design_z_matrix,
        },
        "staged_portal_exercise_insulin_lag_bounds_and_qualifications": {
            "v0p18_150k_total_90k_beta_eq_Tins5p17_tau8p0_preserved_paracrine_min_G_mM": 4.6372,
            "v0p18_150k_total_90k_beta_eq_Tins5p17_tau8p0_scaled_paracrine_min_G_mM": 3.5296,
            "v0p36_300k_total_180k_beta_eq_Tins3p64_tau8p0_min_G_mM": 3.5005,
            "v0p60_500k_total_300k_beta_eq_Tins2p71_tau7p1429_min_G_mM": 3.5001,
            "v0p60_500k_total_300k_beta_eq_Tins1p96_tau8p0_min_G_mM": 3.5004,
            "qualification_note": (
                "Deterministic ODE margins at T_ins = 3.64 / 2.71 / 1.96 min sit 0.0001-0.0005 mM above 3.50 mM without exogenous rescue/controller "
                "modeling, v = 0.18 drops from 4.6372 to 3.5296 mM (<3.90 mM) if local paracrine drive scales down with v, and the 150,000-IEQ omental "
                "cassette is distinct from Roadmap Stage-5A's 25,000-35,000 IEQ forearm sentinel; full-dose v = 0.60 clearance remains non-waivable."
            ),
        },
        "m101_closed_slab_standalone_reservoir_bounds": {
            "scope_qualification": (
                "Conditional standalone finite-reservoir bound in a closed 10 mL slab (5 g/L = 50 mg carrier, vs 5,490.58 umol O2 from 791.5 mg CaO2; "
                "Rousselot et al. 2006 PMID:16897713 reports P50 = 7.05 +/- 0.93 mmHg, n50 = 2.54 +/- 0.23; distinct from air-exposed 1 g/L 24-h culture "
                "in Lemaire et al. 2023 PMID:37318185 and not a general facilitated-diffusion proof under open external oxygen resupply)."
            ),
            "bounds": m101_bounds,
        },
        **washout_and_cat,
    }
# === END_IIP_0021_LINEAGE_OCR_AND_M101_AUDIT ===


# === BEGIN_IIP_0025_HURDLE4_SPATIAL_OXYGEN_CATALASE_AND_CHALLENGERS ===
def build_hurdle4_spatial_oxygen_catalase_and_route_challengers_iip_0025() -> Dict[str, Any]:
    """
    Build reproducible Hurdle-4 unrounded multi-mesh dual-band worst-face oxygen, two-timepoint
    recombinant human catalase (UniProt P04040) sizing/peroxide/endotoxin reconciliation, Design Z
    standoff/cutoff sensitivity, and zero-primate Contrasts B1-B3 audit (IIP-0025; DEC-104).
    """
    p_krogh_ch = 1.50e-5 * ALPHA_BUNSEN_MOL_CM3_MMHG
    p_krogh_is = D_O2_ISLET_TISSUE_CM2_S * ALPHA_BUNSEN_MOL_CM3_MMHG
    p_ext_col = p_krogh_ch / 3.0
    curative_ieq = 500_000.0

    def _solve_uc_iip25(
        load_ieq: float,
        diam_um: float,
        slab_um: float = 350.0,
        lam_um: float = 100.0,
        buf_um: float = 0.0,
        p_bed_mmhg: float = 35.0,
        standoff_phys_um: float = 15.0,
        ocr_mult: float = 1.097,
        k_perf_val: float = 0.14 * 0.97,
        nx_c: int = 40,
        nz_c: int | None = None,
        shift_half_voxel: bool = False,
        eps_lam_cm: float = 0.0,
        gel_ref_load_ieq: float | None = None,
    ) -> Dict[str, Any]:
        if nz_c is None:
            nz_c = int(round((slab_um / 5.0) * (nx_c / 40.0)))
        rad_cm = 0.5 * diam_um * 1e-4
        vol_sph = (4.0 / 3.0) * math.pi * (rad_cm ** 3)
        n_face = 0.5 * ((load_ieq * VOL_1_IEQ_CM3) / vol_sph)
        side_cm = math.sqrt(1.0 / n_face)
        slab_cm = slab_um * 1e-4
        lam_half_cm = 0.5 * lam_um * 1e-4
        buf_cm = buf_um * 1e-4
        band_in = lam_half_cm + buf_cm
        band_out = 0.5 * slab_cm
        band_thick_um = (band_out - band_in) * 1e4
        if band_thick_um < diam_um:
            raise RuntimeError(f"Cell band {band_thick_um:.1f} um < cluster diameter {diam_um:.1f} um")
        dx_c, dz_c = side_cm / nx_c, slab_cm / nz_c
        xs = (np.arange(nx_c) + 0.5) * dx_c - 0.5 * side_cm
        zs = (np.arange(nz_c) + 0.5) * dz_c - 0.5 * slab_cm
        X, Y, Z = np.meshgrid(xs, xs, zs, indexing="ij")
        x0 = 0.5 * dx_c if shift_half_voxel else 0.0
        z_mid = 0.5 * (band_in + band_out)
        z_c = min(band_out - rad_cm - min(0.0002, 0.5 * (band_out - band_in - 2.0 * rad_cm)), z_mid)
        z_c = max(z_c, band_in + rad_cm)
        ddx = np.minimum(np.abs(X - x0), side_cm - np.abs(X - x0))
        ddy = np.minimum(np.abs(Y - x0), side_cm - np.abs(Y - x0))
        top_sph = (ddx ** 2 + ddy ** 2 + (Z - z_c) ** 2) <= (rad_cm ** 2)
        bot_sph = (ddx ** 2 + ddy ** 2 + (Z + z_c) ** 2) <= (rad_cm ** 2)
        in_sph = top_sph | bot_sph
        in_lam = np.abs(Z) <= (lam_half_cm + eps_lam_cm)
        in_buf = (np.abs(Z) > (lam_half_cm + eps_lam_cm)) & (np.abs(Z) <= (band_in + eps_lam_cm))
        sph_asym = int(np.sum(top_sph != bot_sph[:, :, ::-1]))
        lam_asym = int(np.sum(in_lam != in_lam[:, :, ::-1]))
        buf_asym = int(np.sum(in_buf != in_buf[:, :, ::-1]))
        perm = np.where(in_lam, p_krogh_ch * (0.42 ** 1.5), p_krogh_ch)
        perm[in_sph] = p_krogh_is
        in_gel = (~in_sph) & (~in_lam) & (~in_buf)
        t_phi = (load_ieq * VOL_1_IEQ_CM3) / slab_cm
        t_phi_gel = ((gel_ref_load_ieq if gel_ref_load_ieq is not None else load_ieq) * VOL_1_IEQ_CM3) / slab_cm
        vmax = np.zeros_like(X)
        vmax[in_sph] = (VMAX_ISLET_PURE_MOL_CM3_S * ocr_mult) * (t_phi / float(np.mean(in_sph)))
        vmax[in_gel] = (t_phi_gel * VMAX_ISLET_PURE_MOL_CM3_S * 0.15 * ocr_mult) / float(np.mean(in_gel))
        kp = np.where(in_gel, float(k_perf_val), 0.0)
        fvm_out = _solve_3d_oxygen_strict_iip_0019(
            perm, vmax, np.zeros_like(X), kp, dx_c, dx_c, dz_c, p_bed_mmhg,
            standoff_z_cm=standoff_phys_um * 1e-4, p_ext=p_ext_col,
        )
        p3 = fvm_out["p_3d"]
        st_t = _compute_exact_fv_interface_stats_iip_0019(p3, perm, top_sph)
        st_b = _compute_exact_fv_interface_stats_iip_0019(p3, perm, bot_sph)
        dual_min_raw = float(min(st_t["fv_harmonic_face_min_mmhg"], st_b["fv_harmonic_face_min_mmhg"]))
        dual_mean_raw = float(min(st_t["fv_harmonic_face_mean_mmhg"], st_b["fv_harmonic_face_mean_mmhg"]))
        core_min_raw = float(np.min(p3[in_sph]))
        return {
            "mesh": f"{nx_c}x{nx_c}x{nz_c}",
            "fv_harmonic_face_mean_mmhg": round(dual_mean_raw, 4),
            "fv_harmonic_face_min_unrounded_mmhg": dual_min_raw,
            "fv_harmonic_face_min_mmhg": round(dual_min_raw, 4),
            "top_band_face_min_mmhg": round(float(st_t["fv_harmonic_face_min_mmhg"]), 4),
            "bottom_band_face_min_mmhg": round(float(st_b["fv_harmonic_face_min_mmhg"]), 4),
            "min_core_po2_unrounded_mmhg": core_min_raw,
            "min_core_po2_mmhg": round(core_min_raw, 4),
            "sphere_mask_asymmetry_voxels": sph_asym,
            "lamina_mask_asymmetry_voxels": lam_asym,
            "film_mask_asymmetry_voxels": buf_asym,
            "passes_unrounded_dual_band": bool(dual_min_raw >= 15.0 and core_min_raw >= 5.0),
        }

    def _multimesh_pack(
        load_ieq: float,
        diam_um: float,
        slab_um: float = 350.0,
        buf_um: float = 0.0,
        standoff_phys_um: float = 15.0,
        ocr_mult: float = 1.097,
    ) -> Dict[str, Any]: