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…

                "passes_15mmHg_slab_po2_gate": fo_36_00944["passes_15mmHg_slab_po2_gate"],
            },
        },
        "prior_repository_corner_tests_and_zero_vessel_bound_context": {
            "novelty_boundary_statement": (
                "The zero-vessel case (k_p = 0, v_perf(t) == 0) is presented as an analytical/numerical lower bound "
                f"({zv_fo_exact['min_slab_po2_unrounded_mmhg']:.6f} mmHg [{zv_fo_exact['min_slab_po2_mmhg']:.3f} mmHg] minimum slab pO2 at "
                f"{zv_fo_exact['time_of_min_slab_po2_hours']:.0f} h under first-order release, "
                f"{zv_sc_exact['min_slab_po2_unrounded_mmhg']:.6f} mmHg [{zv_sc_exact['min_slab_po2_mmhg']:.3f} mmHg] at "
                f"{zv_sc_exact['time_of_min_slab_po2_hours']:.0f} h under shrinking-core release after finite-time CaO2 depletion at 329.62 h, "
                f"with gel-only cluster cores {zv_sc_exact['gel_only_120um_core_po2_unrounded_mmhg']:.6f}-{zv_fo_exact['gel_only_120um_core_po2_unrounded_mmhg']:.6f} mmHg "
                f"[0.000 mmHg] and uniform cores {zv_sc_exact['uniform_120um_core_po2_unrounded_mmhg']:.6f}-{zv_fo_exact['uniform_120um_core_po2_unrounded_mmhg']:.6f} mmHg), "
                "not as a newly introduced control. Earlier partial corner tests already existed in the repository; the specific addition of "
                "IIP-0002 is the systematic early transient timing-by-exchange crossing on the lead reference slab across both release laws."
            ),
            "existing_repository_partial_coverage_cited": [
                {
                    "location": "part_a_336h_spatial_reaction_diffusion_pouch_pde.design_x_100um_lamina_transport_qualification_v80_018.chronic_zero_source_and_mineralization_extension_muse_r3.physical_outer_annulus_masked_chronic_zero_source_audit_argon_r4.joint_chronic_source_free_areal_loading_capsule_ocr_envelope_sol61_r4.avascular_capsule_vascular_dropout_kperf_0_at_d_cap_50um",
                    "description": "Chronic post-CaO2 zero-source Design X capsule-dropout corner at k_perf = 0 s^-1 and d_cap = 50 um (delta_z_eq = 150 um), yielding min_slab_po2 = 0.0783 mmHg and 100-um/80-um cluster cores of 8.65e-6 / 7.50e-5 mmHg.",
                },
                {
                    "location": "part_a_336h_spatial_reaction_diffusion_pouch_pde.design_x_100um_lamina_transport_qualification_v80_018.vascular_inosculation_target_t50_hours",
                    "description": "Design Z pre-vascularized ribbon target midpoint t50 = 24.0 h (and Stage-0 Gate Z-04 microfluidic anastomosis target t50 <= 24-36 h).",
                },
                {
                    "location": "part_a_336h_spatial_reaction_diffusion_pouch_pde.lead_regime_4_scenario_sensitivity_table_sol_v80_12 & vascular_perfusion_conductance_sensitivity_v80_014",
                    "description": "Separate one-at-a-time lead-slab sensitivity sweeps for delayed inosculation (t50 = 60 h at k_p = 0.14 s^-1) and reduced k_p (0.0944-0.1800 s^-1 at t50 = 36 h).",
                },
            ],
            "exact_zero_vessel_bound_controls": zero_vessel_controls,
        },
        "parameter_source_and_provenance_table": [
            {
                "parameter": "target_curve_midpoint_t50_h",
                "values_tested": "36, 40, 44, 48, 52, 56, 60 h (plus hypothetical 96, 168 h)",
                "role_in_model": "Logistic target-curve inflection time t50 in v_target(t) = v_max / (1 + exp(-(t - t50)/8.0)); realized half-plateau v_perf(t) = 0.485 occurs 2.9426 h later due to the 3.0 h first-order lag ODE.",
                "source_and_provenance": (
                    "Exploratory engineering sensitivity grid brackets. Shepherd et al. 2004 (Arterioscler Thromb Vasc Biol 24(5):898-904, PMID:14988090) "
                    "demonstrates that microvessel-fragment constructs implanted in SCID mice can form perfused host connections "
                    "early in engraftment, and Altalhi et al. 2019 (Cell Mol Bioeng 12(5):443-454, PMID:31719926 / PMC6816716 Fig. 6) "
                    "shows reduced and delayed perfused vessel density in microvessel-fragment constructs in collagen hydrogels implanted subcutaneously "
                    "in streptozotocin-diabetic donor+recipient mice relative to non-diabetic controls "
                    "(confounded by simultaneous donor and recipient diabetic status). Neither cited paper calibrates the chosen timing values, "
                    "oxygen-transfer coefficients, or their joint distribution."
                ),
            },
            {
                "parameter": "coupled_internal_vascular_exchange_kp_s_inv",
                "values_tested": "0.0944, 0.1100, 0.1400, 0.1800 s^-1 (plus 0.0 s^-1 zero-vessel bound)",
                "role_in_model": "Maximum internal vascular exchange rate constant multiplying v_perf(t) across O2 exchange, H2O2 washout, and OH- clearance.",
                "source_and_provenance": (
                    "Layer 4 continuum Krogh-type internal capillary exchange prior (nominal 0.14 s^-1, chronic capsule-attenuated 0.1358 s^-1, "
                    "lower sensitivity brackets 0.1100 and 0.0944 s^-1, upper bracket 0.1800 s^-1; DEC-002 / AUDIT-REF). "
                    "Neither cited paper calibrates the chosen timing values, oxygen-transfer coefficients, or their joint distribution."
                ),
            },
            {
                "parameter": "release_kinetics_law",
                "values_tested": "first_order vs shrinking_core ((m/m0)^(2/3))",
                "role_in_model": "Governs solid CaO2 hydrolysis rate at fixed initial inventory (10.981 mmol / 791.5 mg CaO2 in 7.00 cm^3) and matched t_1/2 = 68.0 h.",
                "source_and_provenance": "Layer 4 Stage-0 Gate P05 (DIFF-0) dual kinetic-law qualification bracket (DEC-002 / DEC-078).",
            },
            {
                "parameter": "vmax_islet_pure_mol_cm3_s & cell_intrinsic_ocr_multiplier",
                "values_tested": "3.4e-8 mol/(cm^3*s) * 1.0x intrinsic OCR * 1.15x vascular/stromal overhead",
                "role_in_model": "Michaelis-Menten cellular O2 demand in the 350 um slab and 120 um spherical Wigner-Seitz cluster BVP.",
                "source_and_provenance": "Canonical human islet OCR prior with GY-004 consistency (RNLS-WT 1.0x baseline OCR retained across all lead-design rows).",
            },
        ],
        "near_threshold_grid_refinement_audit_nz_51_101_201": near_threshold_refinement_rows,
        "joint_grid_rows": joint_grid_rows,
    }


def solve_336h_spatial_pouch_pde() -> Dict[str, Any]:
    """
    Solve the coupled 1D spatial reaction-diffusion PDE system across z in [-175 um, +175 um]
    (51 spatial grid points) and t in [0, 336 hours (14 days)] plus the 4-scenario physiological
    sensitivity table under both first-order and shrinking-core (m/m0)^(2/3) release laws
    (closing AUDIT-REF, AUDIT-REF, AUDIT-REF, and AUDIT-REF).
    """
    regimes_spec = [
        ("PASSIVE_NO_CAO2_CONTROL", 0.0, "none", 68.0, True, 0.97),
        ("UNDERDOSED_CENTRAL_CAO2_F020_V70_12_TEST", 0.20, "central", 68.0, True, 0.97),
        ("LEAD_CENTRAL_LAMINA_PDMS_CAO2_F045_PLUS_CATALASE", 0.45, "central", 68.0, True, 0.97),
        ("PDMS_CAO2_F045_NO_CATALASE_ISOLATED_PEROXIDE_CONTROL", 0.45, "central", 68.0, False, 0.97),
        ("RAW_UNCOATED_CAO2_NO_CATALASE_CHEMICAL_TOXICITY", 0.45, "uniform", 4.0, False, 0.97),
        ("FULL_LENGTH_CD47_WT_IEC_ANGIOGENESIS_IMPAIRED", 0.45, "central", 68.0, True, 0.28),
    ]
    results = [_run_single_pouch_pde_regime(*spec) for spec in regimes_spec]

    # 4-Scenario Sensitivity Analysis on the Lead Pouch Architecture under BOTH first-order and
    # coupled shrinking-core (m/m0)^(2/3) hydrolysis laws (AUDIT-REF & AUDIT-REF):
    sensitivity_scenarios = [
        ("nominal_40mmHg_t50_36h", 40.0, 36.0, 1.0),
        ("boundary_po2_30mmHg_lower_vascularized_bed", 30.0, 36.0, 1.0),
        ("delayed_inosculation_midpoint_t50_60h", 40.0, 60.0, 1.0),
        ("elevated_metabolic_demand_plus_25pct", 40.0, 36.0, 1.25),
    ]
    sensitivity_table = []
    shrinking_core_coupled_regimes = []
    for s_name, p_bound, t50_h, dem_mult in sensitivity_scenarios:
        r_sens_fo = _run_single_pouch_pde_regime(
            regime_id=f"SENSITIVITY_{s_name.upper()}_FIRST_ORDER",
            f_chem_initial=0.45,
            spatial_mode="central",
            cao2_half_life_h=68.0,
            catalase_present=True,
            iec_max_perfusion_fraction=0.97,
            boundary_po2_mmhg=p_bound,
            inosculation_t50_h=t50_h,
            demand_multiplier_extra=dem_mult,
            release_kinetics_law="first_order",
        )
        r_sens_sc = _run_single_pouch_pde_regime(
            regime_id=f"SENSITIVITY_{s_name.upper()}_SHRINKING_CORE",
            f_chem_initial=0.45,
            spatial_mode="central",
            cao2_half_life_h=68.0,
            catalase_present=True,
            iec_max_perfusion_fraction=0.97,
            boundary_po2_mmhg=p_bound,
            inosculation_t50_h=t50_h,
            demand_multiplier_extra=dem_mult,
            release_kinetics_law="shrinking_core",
        )
        shrinking_core_coupled_regimes.append(r_sens_sc)
        sensitivity_table.append(
            {
                "scenario_id": s_name,
                "boundary_po2_mmhg": p_bound,
                "inosculation_t50_hours": t50_h,
                "demand_multiplier": dem_mult,
                "time_of_min_slab_po2_hours": r_sens_fo["time_of_min_slab_po2_hours"],
                "min_slab_po2_mmhg": r_sens_fo["min_slab_po2_across_14_days_mmhg"],
                "min_120um_cluster_core_po2_mmhg": r_sens_fo["min_120um_cluster_core_po2_mmhg"],
                "two_zone_fv_uniform_supply_core_po2_mmhg": r_sens_fo["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"][
                    "two_zone_fv_uniform_supply_120um_core_po2_mmhg"
                ],
                "two_zone_fv_uniform_supply_core_po2_unrounded_mmhg": r_sens_fo["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"][
                    "two_zone_fv_uniform_supply_120um_core_po2_unrounded_mmhg"
                ],
                "two_zone_fv_gel_only_supply_core_po2_mmhg": r_sens_fo["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"][
                    "two_zone_fv_gel_only_supply_120um_core_po2_mmhg"
                ],
                "two_zone_fv_gel_only_supply_core_po2_unrounded_mmhg": r_sens_fo["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"][
                    "two_zone_fv_gel_only_supply_120um_core_po2_unrounded_mmhg"
                ],
                "passes_15mmHg_gsis_gate_at_2500_ieq_cm2": bool(r_sens_fo["required_120um_oxygen_solvers_converged"] and r_sens_fo["min_slab_po2_unrounded_mmhg"] >= 15.0),
                "passes_0p5mmHg_anoxic_necrosis_gate": bool(r_sens_fo["required_120um_oxygen_solvers_converged"] and r_sens_fo["min_120um_cluster_core_po2_unrounded_mmhg"] >= 0.5),
                "passes_2p0mmHg_combined_core_safety_gate": bool(r_sens_fo["required_120um_oxygen_solvers_converged"] and r_sens_fo["min_120um_cluster_core_po2_unrounded_mmhg"] >= 2.0),
                "passes_0p5mmHg_two_zone_uniform_core_gate": bool(
                    r_sens_fo["required_120um_oxygen_solvers_converged"]
                    and r_sens_fo["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_uniform_supply_120um_core_po2_unrounded_mmhg"] >= 0.5
                ),
                "passes_2p0mmHg_two_zone_uniform_core_gate": bool(
                    r_sens_fo["required_120um_oxygen_solvers_converged"]
                    and r_sens_fo["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_uniform_supply_120um_core_po2_unrounded_mmhg"] >= 2.0
                ),
                "passes_0p5mmHg_two_zone_fv_gel_only_gate": bool(
                    r_sens_fo["required_120um_oxygen_solvers_converged"]
                    and r_sens_fo["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_unrounded_mmhg"] >= 0.5
                ),
                "passes_2p0mmHg_two_zone_fv_gel_only_gate": r_sens_fo["passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate"],
                "core_gate_basis_note": (
                    "passes_0p5mmHg_anoxic_necrosis_gate and passes_2p0mmHg_combined_core_safety_gate evaluate the optimistic Dirichlet boundary screen "
                    "(min_120um_cluster_core_po2_mmhg, p(R) = p_slab without pericellular shell depletion), whereas passes_2p0mmHg_two_zone_fv_gel_only_gate "
                    "and passes_0p5mmHg_two_zone_fv_gel_only_gate evaluate the operative conservative unrounded Wigner-Seitz two-zone gel-only pericellular-shell core pO2 (DEC-078; IIP-0025; DEC-104)."
                ),
                "shrinking_core_coupled_bvp_ultracode_v80_09": {
                    "time_of_min_slab_po2_hours": r_sens_sc["time_of_min_slab_po2_hours"],
                    "min_slab_po2_mmhg": r_sens_sc["min_slab_po2_across_14_days_mmhg"],
                    "min_120um_cluster_core_po2_mmhg": r_sens_sc["min_120um_cluster_core_po2_mmhg"],
                    "two_zone_fv_uniform_supply_core_po2_mmhg": r_sens_sc[
                        "wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"
                    ]["two_zone_fv_uniform_supply_120um_core_po2_mmhg"],
                    "two_zone_fv_uniform_supply_core_po2_unrounded_mmhg": r_sens_sc[
                        "wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"
                    ]["two_zone_fv_uniform_supply_120um_core_po2_unrounded_mmhg"],
                    "two_zone_fv_gel_only_supply_core_po2_mmhg": r_sens_sc[
                        "wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"
                    ]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"],
                    "two_zone_fv_gel_only_supply_core_po2_unrounded_mmhg": r_sens_sc[
                        "wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"
                    ]["two_zone_fv_gel_only_supply_120um_core_po2_unrounded_mmhg"],
                    "max_interstitial_h2o2_uM": r_sens_sc["max_interstitial_h2o2_uM"],
                    "max_interstitial_ph": r_sens_sc["max_interstitial_ph"],
                    "passes_15mmHg_gsis_gate_at_2500_ieq_cm2": bool(r_sens_sc["required_120um_oxygen_solvers_converged"] and r_sens_sc["min_slab_po2_unrounded_mmhg"] >= 15.0),
                    "passes_0p5mmHg_anoxic_necrosis_gate": bool(r_sens_sc["required_120um_oxygen_solvers_converged"] and r_sens_sc["min_120um_cluster_core_po2_unrounded_mmhg"] >= 0.5),
                    "passes_all_oxygen_peroxide_and_ph_gates": r_sens_sc["passes_all_oxygen_peroxide_and_ph_gates"],
                    "passes_0p5mmHg_two_zone_uniform_core_gate": bool(
                        r_sens_sc["required_120um_oxygen_solvers_converged"]
                        and r_sens_sc["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_uniform_supply_120um_core_po2_unrounded_mmhg"] >= 0.5
                    ),
                    "passes_2p0mmHg_two_zone_uniform_core_gate": bool(
                        r_sens_sc["required_120um_oxygen_solvers_converged"]
                        and r_sens_sc["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_uniform_supply_120um_core_po2_unrounded_mmhg"] >= 2.0
                    ),
                    "passes_0p5mmHg_two_zone_fv_gel_only_gate": bool(
                        r_sens_sc["required_120um_oxygen_solvers_converged"]
                        and r_sens_sc["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_unrounded_mmhg"] >= 0.5
                    ),
                    "passes_2p0mmHg_two_zone_fv_gel_only_gate": r_sens_sc["passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate"],
                },
            }
        )

    bvp_r60_ref = solve_spherical_cluster_po2_bvp(16.8, 0.0060)
    bvp_r150_ref = solve_spherical_cluster_po2_bvp(16.8, 0.0150)

    # Actual PDE execution for Bruggeman central-lamina diffusivity torture-test under outer-annular CAD Layout B (AUDIT-REF & AUDIT-REF):
    r_annular_nom = _run_single_pouch_pde_regime(
        "LAYOUT_B_ANNULAR_ISLET_DEMAND_NOMINAL", 0.45, "central", 68.0, True, 0.97, demand_spatial_mode="outer_annulus"
    )
    r_brug_042 = _run_single_pouch_pde_regime(
        "BRUGGEMAN_EPS_0P42_MACROPOROUS",
        0.45,
        "central",
        68.0,
        True,
        0.97,
        demand_spatial_mode="outer_annulus",
        lamina_d_o2_scale=0.42 ** 1.5,
    )
    r_brug_01754 = _run_single_pouch_pde_regime(
        "BRUGGEMAN_EPS_0P1754_DENSE",
        0.45,
        "central",
        68.0,
        True,
        0.97,
        demand_spatial_mode="outer_annulus",
        lamina_d_o2_scale=0.1754 ** 1.5,
    )
    cad = verify_exact_slab_source_distribution_algebra()["non_overlapping_phase_volume_and_cad_ledger_7cm3_ultracode_v80_18"]["layout_option_b_31wt_pct_cao2_confined_central_lamina_microbeads"]
    retained_inventory = cad["eps_0p42_inventory_retention_at_same_formulation_and_lamina"]
    r_brug_042_mass_conserving = _run_single_pouch_pde_regime(
        "BRUGGEMAN_EPS_0P42_REDUCED_INVENTORY_SAME_FORMULATION", 0.45 * retained_inventory,
        "central", 68.0, True, 0.97, demand_spatial_mode="outer_annulus", lamina_d_o2_scale=0.42 ** 1.5,
    )

    def packing_screen(regime: Dict[str, Any], *, inventory_fits: bool) -> Dict[str, Any]:
        return {
            "inventory_fits_declared_porosity_at_fixed_formulation": inventory_fits,
            "computed_gel_only_core_po2_mmhg": regime["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_unrounded_mmhg"],
            "spatial_control_volume_ledger": regime["spatial_control_volume_ledger"],
            "qualified_exact_product": False,
            "scope": "TRANSPORT_SENSITIVITY_ONLY; 120um clusters exceed each 115.5um outer band, and material/diffusivity/enzymatic release remain unmeasured",
        }
    bruggeman_torture_test = {