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…

        },
        "hepatic_first_pass_extraction_sensitivity_sweep": {
            "ownership_note": (
                "First-pass hepatic extraction f_hepatic is owned solely by exploratory Mode B v2 to debit total pre-hepatic secretion "
                "from intracellular stores while delivering (1 - f_hepatic) systemically; it is strictly distinct from Layer 4's 13-state "
                "f_sys_ins insulin-action scaling and is never double-counted. Direct human hepatic-vein pulsatile extraction "
                "(Meier et al. 2005 PMID:15919785) and canine portal-vs-peripheral studies (Edgerton et al. 2019 PMID:30830873) provide "
                "route context only and do not validate a 40-60% extraction range for this graft."
            ),
            "f_hepatic_0p00_systemic_iu_day": round(sim_f00["cumulative_24h_systemic_appearance_iu"], 2),
            "f_hepatic_0p40_prehepatic_iu_day": round(sim_f40["cumulative_24h_prehepatic_secreted_iu"], 2),
            "f_hepatic_0p50_prehepatic_iu_day": round(sim_p["cumulative_24h_prehepatic_secreted_iu"], 2),
            "f_hepatic_0p50_systemic_iu_day": round(sim_p["cumulative_24h_systemic_appearance_iu"], 2),
            "f_hepatic_0p60_prehepatic_iu_day": round(sim_f60["cumulative_24h_prehepatic_secreted_iu"], 2),
        },
        "ceteris_paribus_isolated_tau_refill_meal_sensitivity": {
            "c0_fixed_iu": round(c0_w6, 2),
            "f_rrp_fixed": 0.0045,
            "gamma_amp_fixed": 0.08,
            "f_hepatic_fixed": 0.50,
            "canonical_5h_7h_250g_tir_tau16p5_pct": round(s_fast_57["tir_3p9_to_10_elapsed_pct"], 2),
            "canonical_5h_7h_250g_tir_tau45p0_pct": round(s_slow_57["tir_3p9_to_10_elapsed_pct"], 2),
            "realistic_4h_4h_250g_tir_tau16p5_pct": round(s_fast_44["tir_3p9_to_10_elapsed_pct"], 2),
            "realistic_4h_4h_250g_tir_tau45p0_pct": round(s_slow_44["tir_3p9_to_10_elapsed_pct"], 2),
        },
        "beta_fraction_stored_insulin_scaling_note": {
            "modeled_60_30_10_500k_ieq_range_iu": [41.5, 138.3],
            "unadjusted_70_20_10_500k_ieq_equal_per_beta_content_range_iu": [round(41.5 * 7.0 / 6.0, 2), round(138.3 * 7.0 / 6.0, 2)],
            "gate0s_escalation_trigger_iu": 138.3,
            "caveat": (
                "Arithmetic scaling assumes identical total IEQ and identical mature insulin content per beta-equivalent "
                "(Perez-Frances et al. 2024 PMID:39169271 did not measure this recipe). Stage-0 therefore measures intact mature "
                "insulin directly at the actual final dose and escalates to full scope-matched Gate 0S atomic-ledger review "
                "whenever U95_t(stored_insulin_iu) > 138.3 IU or max_lot > 138.3 IU."
            ),
        },
        "local_4schedule_jacobian_and_fim_conditioning": {
            "log_parameter_jacobian_condition_number": round(jac_cond, 2),
            "log_parameter_fim_condition_number": round(jac_cond ** 2, 1),
            "identifiability_caveat": (
                "Local 4-summary FIM ill-conditioning (which depends on parameter scaling) and cross-protocol validation "
                "confirm that uncalibrated ODE parameter inversion cannot replace empirical Stage-0 two-pulse Readout 2, "
                "direct inert-tracer tau_chamber verification, and mature-insulin inventory measurement."
            ),
        },
        "primary_citations": [
            "PMID:30661993",
            "PMID:35241836",
            "PMID:36136756",
            "PMID:31068696",
            "PMID:30710150",
            "PMID:27163171",
            "PMID:30931946",
            "PMID:25303535",
            "PMID:12879249",
            "PMID:33737253",
            "PMID:31177185",
            "PMID:39169271",
            "PMID:15919785",
            "PMID:30830873",
        ],
    }
# === END_IIP_0029_EXPLORATORY_MODE_B_V2_GRANULE_STORE_SENSITIVITY ===


def main() -> None:
    part_a_algebra = verify_exact_slab_source_distribution_algebra()
    part_a_pde = solve_336h_spatial_pouch_pde()
    live_series_film_table_r6 = part_a_pde["design_x_100um_lamina_transport_qualification_v80_018"].pop("live_series_film_table_r6")
    dx_coupled_regimes = part_a_pde["design_x_100um_lamina_transport_qualification_v80_018"].pop("coupled_pde_regimes_for_metabolic_ode")
    part_a_pde["regimes_simulated"].extend(dx_coupled_regimes)
    part_a_pde["bed_level_convective_o2_budget_and_periimplant_fluid_film_audit_sonnet55_r5"] = {
        "finding_ids": ["AUDIT-REF", "AUDIT-REF", "AUDIT-REF", "AUDIT-REF", "AUDIT-REF", "AUDIT-REF", "AUDIT-REF"],
        "primary_citations": ["PMID:17497731", "PMID:29695723", "PMID:22371586"],
        "citation_provenance_reconciliation_r6": (
            "Replaces prior misattributed Round-5 PMIDs "
            "with verified islet oxygen transport and macroencapsulation biotransport studies: Papas et al. 2007 PMID:17497731, "
            "Evron et al. 2018 Sci Rep PMID:29695723, and Pedraza et al. 2012 PNAS PMID:22371586 (AUDIT-REF [DEC-050/DEC-078])."
        ),
        # Oxygen-demand basis reconciliation (three distinct, non-interchangeable bases in this file):
        # (i) Pure-islet Vmax basis: 500,000 IEQ x 1.7671e-6 cm^3/IEQ x 34 nmol/cm^3/s = 1.802 umol/min.
        # (ii) Local-film peak basis (periimplant_stagnant_fluid_film_transport_limit below):
        #      q_face = 1.125e-10 mol/cm^2/s at 2,500 IEQ/cm^2 over two faces of 200 cm^2 = 2.70 umol/min
        #      (equivalently 6.75e-11 at 1,500 IEQ/cm^2 over two faces of 333.33 cm^2).
        # (iii) Whole-bed macro-flow peak basis (this dict): 0.153 mL STP/min = 6.83 umol/min, matched by
        #      6.21 mL/min x 1.10 mM arteriovenous extraction = 6.831 umol/min (2.53x basis (ii)).
        # Bases (ii) and (iii) are different assumed demand states (local film peak vs safety-scaled whole-bed
        # peak); map both to the same measured lot/state before combining them in one capacity claim.
        "macroscopic_bed_convective_o2_budget_500k_ieq": {
            "total_graft_o2_consumption_mol_min_range": [1.65e-6, 2.75e-6],
            "total_graft_o2_consumption_ml_stp_min_range": [0.037, 0.062],
            "nominal_500k_ieq_o2_consumption_ml_stp_min": 0.049,
            "peak_500k_ieq_o2_consumption_ml_stp_min": 0.153,
            "arteriovenous_o2_extraction_delta_c_av_mM": 1.10,
            "required_local_microvascular_blood_flow_ml_min_range": [1.50, 2.50],
            "peak_required_omental_blood_flow_ml_min_at_1p10mM_extraction": 6.21,
            "peak_required_omental_blood_flow_ml_min_at_1p42mM_extraction": 4.80,
            "peak_required_omental_blood_flow_ml_min_at_1p42mM_hyperemic_extraction": 4.80,
            "resting_subcutaneous_adipose_blood_flow_ml_min_per_10g": 0.30,
            "subcutaneous_full_dose_convective_feasibility": False,
            "omental_portal_venous_fold_blood_flow_ml_min_across_333cm2": 12.5,
            "omental_modular_cassette_array_3_to_4_x_100cm2_feasible": True,
        },
        "periimplant_stagnant_fluid_film_transport_limit": {
            "d_o2_water_37C_cm2_s": 2.8e-5,
            "d_o2_proteinaceous_seroma_37C_cm2_s": 1.584e-5,
            "alpha_o2_water_mol_cm3_mmhg": 1.35e-9,
            "alpha_o2_seroma_mol_cm3_mmhg": 1.35e-9,
            "basal_o2_flux_1500_ieq_cm2_mol_cm2_s": 3.90e-11,
            "basal_o2_flux_2500_ieq_cm2_mol_cm2_s": 6.50e-11,
            "o2_flux_1500_ieq_cm2_mol_cm2_s": 6.75e-11,
            "o2_flux_2500_ieq_cm2_mol_cm2_s": 1.125e-10,
            "unvascularized_100pct_surface_flux_seroma_50um_film_drop_basal_mmhg": round((3.90e-11 * 50.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "unvascularized_100pct_surface_flux_seroma_50um_film_drop_peak_mmhg": round((6.75e-11 * 50.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "unvascularized_100pct_surface_flux_seroma_80um_film_drop_peak_mmhg": round((6.75e-11 * 80.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "vascularized_outer_band_kperf_0p1358_external_surface_flux_fraction": 0.32,
            "vascularized_32pct_external_flux_seroma_50um_film_drop_basal_mmhg": round(0.32 * (3.90e-11 * 50.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "vascularized_32pct_external_flux_seroma_50um_film_drop_peak_mmhg": round(0.32 * (6.75e-11 * 50.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "vascularized_32pct_external_flux_seroma_80um_film_drop_peak_mmhg": round(0.32 * (6.75e-11 * 80.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "seroma_adjusted_50um_film_drop_basal_mmhg": round((3.90e-11 * 50.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "seroma_adjusted_50um_film_drop_peak_mmhg": round((6.75e-11 * 50.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "seroma_adjusted_80um_film_drop_peak_mmhg": round((6.75e-11 * 80.0e-4) / (1.584e-5 * 1.35e-9), 2),
            "water_permeability_50um_film_drop_at_3p90e11_basal_mmhg": round((3.90e-11 * 50.0e-4) / (2.8e-5 * 1.35e-9), 2),
            "water_permeability_50um_film_drop_at_6p75e11_peak_mmhg": round((6.75e-11 * 50.0e-4) / (2.8e-5 * 1.35e-9), 2),
            "water_permeability_80um_film_drop_at_6p75e11_peak_mmhg": round((6.75e-11 * 80.0e-4) / (2.8e-5 * 1.35e-9), 2),
            "critical_stagnant_fluid_film_thickness_seroma_100pct_flux_for_15mmhg_drop_um_at_1500_ieq_cm2": round(
                (1.584e-5 * 1.35e-9 * 15.0 / 6.75e-11) * 1e4, 1
            ),
            "critical_stagnant_fluid_film_thickness_seroma_100pct_flux_for_15mmhg_drop_um_at_2500_ieq_cm2": round(
                (1.584e-5 * 1.35e-9 * 15.0 / 1.125e-10) * 1e4, 1
            ),
            "critical_stagnant_fluid_film_thickness_for_15mmhg_drop_um_at_1500_ieq_cm2": round(
                (2.8e-5 * 1.35e-9 * 15.0 / 6.75e-11) * 1e4, 1
            ),
            "critical_stagnant_fluid_film_thickness_for_15mmhg_drop_um_at_2500_ieq_cm2": round(
                (2.8e-5 * 1.35e-9 * 15.0 / 1.125e-10) * 1e4, 1
            ),
            "coupled_bvp_and_series_fluid_film_core_po2_table_r6": {
                "day0_to_3_pre_anastomosis_with_ca_o2_f045_and_50um_film_min_slab_po2_mmhg": 18.42,
                "day90_vascularized_kperf_0p1358_1500_ieq_cm2_with_35um_film_core_po2_mmhg": round(28.34 - 0.32 * (6.75e-11 * 35.0e-4) / (1.584e-5 * 1.35e-9), 2),
                "day90_vascularized_kperf_0p1358_1500_ieq_cm2_with_50um_film_core_po2_mmhg": round(28.34 - 0.32 * (6.75e-11 * 50.0e-4) / (1.584e-5 * 1.35e-9), 2),
                "day90_vascularized_kperf_0p1358_1500_ieq_cm2_with_80um_film_core_po2_mmhg": round(28.34 - 0.32 * (6.75e-11 * 80.0e-4) / (1.584e-5 * 1.35e-9), 2),
                "day90_unvascularized_kperf_0_1500_ieq_cm2_with_50um_film_core_po2_mmhg": 0.08,
                "explanation": (
                    "Exact 1D Fick's law in proteinaceous seroma (D_seroma = 1.584e-5 cm^2/s, alpha = 1.35e-9 mol/cm^3/mmHg) gives "
                    "Delta_P = 9.12 mmHg (basal J = 3.90e-11) and 15.78 mmHg (peak J = 6.75e-11) at 50 um (25.25 mmHg at 80 um, with a 47.5 um critical thickness for a 15.0 mmHg drop) "
                    "if 100% of graft O2 demand crosses the external fluid film; once the outer vascularized hydrogel band anastomoses (k_perf = 0.1358 s^-1 >= 0.10 s^-1), "
                    "68% of O2 is supplied by intra-band microvessels and 32% crosses the outer boundary, reducing the effective external-film drop to 2.92 mmHg (basal) / 5.05 mmHg (peak) at 50 um "
                    "and 8.08 mmHg (peak) at 80 um, maintaining coupled Day-90 slab/outer-band pO2 at 24.80 mmHg (35 um), 23.29 mmHg (50 um), and 20.26 mmHg (80 um; AUDIT-REF & AUDIT-REF [DEC-050]). "
                    "When coupled in series with the live chronic zero-source Nz=201 BVP (capsule = 15 um, k_perf = 0.1358 s^-1, 1,500 IEQ/cm^2) and internal spherical cluster diffusion, "
                    "a 100-um cluster drops from core 7.96 mmHg [7.9650 mmHg 4-dec / 7.97 mmHg direct 2-dec] (0 um film) to 6.23 mmHg (35 um), 5.65 mmHg (50 um), and 4.71 mmHg (< 5.0 mmHg at 80 um film, surface 13.09 mmHg), whereas the DX-b 80-um cluster cap "
                    "maintains core pO2 = 12.35 mmHg (0 um), 10.55 mmHg (35 um), 9.95 mmHg (50 um, surface 15.45 mmHg >= 15.0 mmHg), and 8.95 mmHg (80 um, surface 14.43 mmHg; AUDIT-REF & MW-R6-S2-R4 [DEC-052/053/054/059])."
                ),
                "live_chronic_bvp_and_spherical_cluster_series_film_table_astra6_r6": live_series_film_table_r6,
                "cao2_hydroxide_peroxide_inventory_and_peak_ocr_seroma_fick_audit_muse_r6": {
                    "finding_ids": ["MW-R6-S1-12", "MW-R6-S1-14", "MW-R6-S1-15", "MW-R6-S2-F01", "MW-R6-S2-F02", "MW-R6-S2-R4", "L4A-F01", "L4A-F02"],
                    "cao2_total_alkaline_and_peroxide_stoichiometric_inventory_7cm3_pouch": {
                        "active_cao2_mass_mg": 100.78,
                        "active_cao2_mmol": 1.3982,
                        "total_caoh2_produced_mmol": 1.3982,
                        "total_hydroxide_equivalents_mmol": 2.7964,
                        "total_h2o2_intermediate_generated_mmol": 1.3982,
                        "effective_14d_first_order_release_rate_s_inv": 1.24e-6,
                        "effective_14d_release_half_life_h": round(math.log(2.0) / (1.24e-6 * 3600.0), 2),
                        "peak_day0_oh_generation_flux_mol_cm3_s": round((2.7964e-3 / 7.0) * 1.24e-6, 10),
                        "bicarbonate_co2_vascular_washout_clearance_ratio_vs_oh_flux": 48.5,
                        "sentinel_patch_volume_cm3_at_12cm2_350um": 0.42,
                        "sentinel_patch_volume_range_cm3_10_to_14cm2_350um": [0.35, 0.49],
                        "sentinel_local_peak_day0_oh_generation_flux_at_100p78mg_in_0p42cm3_mol_cm3_s": round((2.7964e-3 / 0.42) * 1.24e-6, 10),
                        "sentinel_local_peak_day0_oh_generation_flux_range_0p35_to_0p49cm3_mol_cm3_s": [
                            round((2.7964e-3 / 0.49) * 1.24e-6, 10),
                            round((2.7964e-3 / 0.35) * 1.24e-6, 10),
                        ],
                        "sentinel_local_bicarbonate_washout_clearance_ratio_at_100p78mg_in_0p42cm3": round(2.40e-8 / ((2.7964e-3 / 0.42) * 1.24e-6), 2),
                        "sentinel_local_bicarbonate_washout_clearance_ratio_range_0p35_to_0p49cm3": [
                            round(2.40e-8 / ((2.7964e-3 / 0.35) * 1.24e-6), 2),
                            round(2.40e-8 / ((2.7964e-3 / 0.49) * 1.24e-6), 2),
                        ],
                        "canonical_68h_sentinel_30000ieq_cao2_mass_mg": round(791.4990 * (30000.0 / 500000.0), 2),
                        "canonical_68h_sentinel_25000_to_35000ieq_cao2_mass_range_mg": [
                            round(791.4990 * (25000.0 / 500000.0), 2),
                            round(791.4990 * (35000.0 / 500000.0), 2),
                        ],
                        "canonical_68h_local_peak_day0_oh_generation_flux_mol_cm3_s": round((21.962290e-3 / 7.0) * 2.831484e-6, 10),
                        "canonical_68h_local_bicarbonate_washout_clearance_ratio": round(2.40e-8 / ((21.962290e-3 / 7.0) * 2.831484e-6), 2),
                        "coimmobilized_catalase_k1_s_inv": 18.0,
                        "catalase_peroxide_scavenging_half_life_ms": round(1000.0 * 0.693147 / 18.0, 2),
                        "two_regime_cao2_inventory_reconciliation_note": (
                            "Reconciles both the mass/kinetics basis and the volume-normalization denominator (AUDIT-REF, AUDIT-REF & L4A-F01 [DEC-054/059/077]): "
                            "(1) Mass & kinetic basis: 100.78 mg (1.3982 mmol CaO2, 2.7964 mmol OH-) at slow 14-day release k_14d = 1.24e-6 s^-1 (t_1/2 = 155.27 h = 6.47 d) supplies Hour-0 O2 demand for 27,881 IEQ at f_chem,0 = 0.45 (r_O2,0 = 0.5 * 1.3982e-3 * 1.24e-6 = 8.6689e-10 mol/s at 6.9095e-14 mol/s/IEQ incl. +15% iEC), "
                            "whereas on the canonical 68.0-h half-life basis (k_ref = 2.8315e-6 s^-1), a 30,000 IEQ (6.0% dose, 12.0 cm^2) sentinel patch requires 47.49 mg CaO2 (0.6589 mmol CaO2, 1.3177 mmol OH-; 44.17 mg at 27,881 IEQ; 39.57-55.40 mg across 25,000-35,000 IEQ), and the full 500,000 IEQ (2,500 IEQ/cm^2, 7.00 cm^3) pouch requires 791.49 mg [791.50 mg / 791.4990 mg exact] (10.9811 mmol CaO2, 21.9623 mmol total OH-, 11.4199 mmol OH- over 72 h); "
                            "(2) Volume-normalization denominator: peak_day0_oh_generation_flux_mol_cm3_s = 4.9536e-10 mol/(cm^3*s) (clearance ratio 48.5x against 2.40e-8 mol/(cm^3*s) bicarbonate washout) dilutes the 100.78 mg sentinel inventory across the full 7.00 cm^3 pouch volume, "
                            "whereas normalizing by the physical sentinel patch volume V_sentinel = 12.0 cm^2 * 0.035 cm = 0.420 cm^3 (0.350-0.490 cm^3 across 10-14 cm^2) yields a true local sentinel OH- generation flux of 8.2561e-9 mol/(cm^3*s) (7.0766e-9 to 9.9072e-9 mol/(cm^3*s), local clearance ratio 2.91x [2.42-3.39x]) at k_14d = 1.24e-6 s^-1, and 8.8837e-9 mol/(cm^3*s) (local clearance ratio 2.70x) on the canonical 68.0-h basis (47.49 mg in 0.420 cm^3 or 791.49 mg in 7.00 cm^3)."
                        ),
                        "mandatory_stage0_gate_0d_0f_qualification": (
                            "Closed-loop 14-day coupon dissolution test must verify interstitial pH <= 7.45 (no local CaCO3 mineralization crust or > 7.60 alkaline boundary layer) "
                            "and interstitial H2O2 <= 2.0 uM across the 72-h post-implant seroma window before pre-anastomosis microvascular sink establishment."
                        ),
                    },
                    "peak_stimulated_vs_reference_ocr_seroma_fick_reconciliation": {
                        "reference_areal_o2_flux_1500_ieq_cm2_mol_cm2_s": 6.75e-11,
                        "max_theoretical_pure_islet_vmax_flux_1500_ieq_cm2_mol_cm2_s": 8.89e-11,
                        "pde_two_sided_total_pure_islet_vmax_flux_1500_ieq_cm2_mol_cm2_s": round(1500.0 * (4.0 / 3.0 * math.pi * (0.0075 ** 3)) * 3.40e-8, 14),
                        "pde_per_face_pure_islet_vmax_flux_1500_ieq_cm2_mol_cm2_s": round(0.5 * 1500.0 * (4.0 / 3.0 * math.pi * (0.0075 ** 3)) * 3.40e-8, 14),
                        "pde_two_sided_total_with_15pct_iec_vmax_flux_1500_ieq_cm2_mol_cm2_s": round(1.15 * 1500.0 * (4.0 / 3.0 * math.pi * (0.0075 ** 3)) * 3.40e-8, 14),