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…

                                )(_solve_chronic_zero_source_bvp_live(35.0, 150.0, 0.60 * 1.097, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.0)),
                                "surface_gsis_15mmhg_max_capsule_um_100um_cluster": 20.0,
                                "surface_gsis_15mmhg_max_capsule_um_80um_cluster": 30.0,
                                "core_viability_5mmhg_max_capsule_um_100um_cluster": 30.0,
                                "core_viability_5mmhg_max_capsule_um_80um_cluster": 100.0,
                                "reconciliation_note": (
                                    "Live BVP verification across physical fibrotic capsule thickness d_cap in {15, 20, 30, 50, 75, 100} um (delta_z_eq = 3*d_cap) "
                                    "at 1,500 IEQ/cm2, P_b = 35 mmHg, OCR = 1.097x, D_gel = 1.50e-5 cm2/s, slab lamina half-width fraction a_slab = 0.34 (with cluster packing fraction local_phi_dx * 0.60 = 0.1489 derived from Design-X 100-um central lamina; whereas pure uniform a = 0.34 packing phi = 0.1251 yields 12.4959 / 4.1680 mmHg at d_cap = 50 um), k_perf = 0.1358 s^-1: "
                                    "at d_cap = 15 um, 100-um clusters achieve 16.5172 / 7.9650 mmHg (PASS 15/5 mmHg); at d_cap = 50 um, 100-um clusters drop to "
                                    "12.2729 / 3.9653 mmHg (failing both 15 mmHg surface GSIS and 5 mmHg core viability) while 80-um clusters preserve core viability at "
                                    "13.6039 / 8.1437 mmHg (core >= 5.0 mmHg up to d_cap = 100 um [11.1594 / 5.7785 mmHg], though full surface GSIS >= 15.0 mmHg requires "
                                    "d_cap <= 20 um for 100-um clusters or d_cap <= 30 um for 80-um clusters); and if outer-band capillary perfusion drops out (k_perf = 0) "
                                    "under a 50 um capsule, min_slab_pO2 collapses to 0.0783 mmHg (100-um cluster core 8.65e-6 mmHg, 80-um cluster core 7.50e-5 mmHg; AUDIT-REF, AUDIT-REF & AUDIT-REF)."
                                ),
                            }
                        )(),
                    },
                    "phase_resolved_cao2_to_caco3_net_solid_expansion_audit_sol61_r4": (
                        lambda _n_cao2_mmol, _v_cao2_cm3, _m_caco3_g: {
                            "primary_citations": ["PMID:38343991", "PMID:22371586"],
                            "cao2_initial_mass_g": 0.7915,
                            "cao2_molar_mass_g_mol": 72.078,
                            "cao2_molar_amount_mmol": round(_n_cao2_mmol, 2),
                            "cao2_molar_amount_exact_mmol": round(_n_cao2_mmol, 6),
                            "cao2_crystal_density_g_cm3": 2.91,
                            "cao2_initial_solid_volume_cm3": round(_v_cao2_cm3, 4),
                            "caco3_molar_mass_g_mol": 100.0869,
                            "caco3_complete_carbonation_mass_g": round(_m_caco3_g, 3),
                            "caco3_complete_carbonation_mass_exact_g": round(_m_caco3_g, 6),
                            "caco3_calcite_density_g_cm3": 2.71,
                            "caco3_complete_carbonation_solid_volume_cm3": round(_m_caco3_g / 2.71, 4),
                            "net_solid_volume_expansion_cao2_to_caco3_cm3": round((_m_caco3_g / 2.71) - _v_cao2_cm3, 4),
                            "design_x_lamina_pore_water_volume_cm3": 0.8400,
                            "net_solid_expansion_fraction_of_pore_water_if_external_pore_nucleation": round(((_m_caco3_g / 2.71) - _v_cao2_cm3) / 0.8400, 4),
                            "amorphous_acc_and_porous_mineral_phase_branches_kimi31_r4": {
                                "calcite_2p71_g_cm3": {
                                    "solid_volume_cm3": round(_m_caco3_g / 2.71, 4),
                                    "net_expansion_vs_cao2_cm3": round((_m_caco3_g / 2.71) - _v_cao2_cm3, 4),
                                    "net_expansion_fraction_of_0p84cm3_pore_water": round(((_m_caco3_g / 2.71) - _v_cao2_cm3) / 0.8400, 4),
                                    "gross_volume_fraction_of_0p84cm3_pore_water_if_zero_pdms_intrusion": round((_m_caco3_g / 2.71) / 0.8400, 4),
                                },
                                "hydrated_amorphous_calcium_carbonate_acc_1p75_g_cm3_pmid_38343991": {
                                    "solid_volume_cm3": round(_m_caco3_g / 1.75, 4),
                                    "net_expansion_vs_cao2_cm3": round((_m_caco3_g / 1.75) - _v_cao2_cm3, 4),
                                    "net_expansion_fraction_of_0p84cm3_pore_water": round(((_m_caco3_g / 1.75) - _v_cao2_cm3) / 0.8400, 4),
                                    "gross_volume_fraction_of_0p84cm3_pore_water_if_zero_pdms_intrusion": round((_m_caco3_g / 1.75) / 0.8400, 4),
                                },
                                "low_density_porous_caco3_precipitate_1p50_g_cm3": {
                                    "solid_volume_cm3": round(_m_caco3_g / 1.50, 4),
                                    "net_expansion_vs_cao2_cm3": round((_m_caco3_g / 1.50) - _v_cao2_cm3, 4),
                                    "net_expansion_fraction_of_0p84cm3_pore_water": round(((_m_caco3_g / 1.50) - _v_cao2_cm3) / 0.8400, 4),
                                    "gross_volume_fraction_of_0p84cm3_pore_water_if_zero_pdms_intrusion": round((_m_caco3_g / 1.50) / 0.8400, 4),
                                },
                            },
                            "pdms_intrusion_vs_hydrogel_pore_precipitation_partition": (
                                f"Although 0.7915 g CaO2 ({_v_cao2_cm3:.4f} cm3 at 2.91 g/cm3) vacates intrabead volume as it reacts, complete conversion of {_n_cao2_mmol:.2f} mmol ({_n_cao2_mmol:.6f} mmol exact) Ca2+ to {_m_caco3_g:.3f} g ({_m_caco3_g:.6f} g exact) CaCO3 "
                                f"produces {(_m_caco3_g / 2.71):.4f} cm3 of crystalline calcite (2.71 g/cm3; net expansion +{( _m_caco3_g / 2.71 - _v_cao2_cm3):.4f} cm3 = +49.1% relative to initial CaO2 volume, or 15.90% of the 0.8400 cm3 hydrogel pore water if nucleated in situ vs 48.28% if Ca2+ leaches into the hydrogel without water intrusion into hydrophobic PDMS voids) "
                                f"or {(_m_caco3_g / 1.75):.4f}-{(_m_caco3_g / 1.50):.4f} cm3 if precipitated as hydrated amorphous calcium carbonate (ACC, 1.50-1.75 g/cm3; net expansion +{( _m_caco3_g / 1.75 - _v_cao2_cm3):.4f} to +{( _m_caco3_g / 1.50 - _v_cao2_cm3):.4f} cm3 = 42.39-54.85% net / 74.77-87.23% gross of pore water; Tomioka et al. 2024 PMID:38343991). "
                                "Gate 0D-alkali therefore measures day-14 micro-CT mineral volume fraction, Raman/FTIR polymorph phase (ACC vs vaterite vs calcite), ICP-MS residual Ca, and 10-70 kDa FITC-dextran effective diffusivity across spent composite coupons (requiring <= 15% permeability loss; AUDIT-REF & AUDIT-REF)."
                            ),
                        }
                    )(0.7915 / 72.078 * 1000.0, 0.7915 / 2.91, (0.7915 / 72.078) * 100.0869),
                },
            },
        },
        "design_z_radical_zero_cao2_microvascular_pfc_ribbon_wildcard_spec_dec020": {
            "tournament_slot": "Z (Tier-2 Radical Biophysical/Vascular Wildcard competing to dethrone X; DEC-020)",
            "cao2_mass_mg": 0.0,
            "chemical_h2o2_generation_uM": 0.0,
            "calcium_hydroxide_alkali_generation_mmol": 0.0,
            "ribbon_half_thickness_um": 60.0,
            "total_pleated_ribbon_thickness_um": 120.0,
            "cluster_diameter_cap_um": 80.0,
            "passive_oxygen_shuttle": "10% v/v perfluorooctyl bromide (PFOB) phospholipid-stabilized nanoemulsion (phi_PFC = 0.10, K_p = alpha_PFC/alpha_aq = 20.0, zero chemical reaction)",
            "effective_medium_transport_parameterization_muse_r1": {
                "pfc_volume_fraction_phi": 0.10,
                "partition_coefficient_kp_pfc_to_aq": 20.0,
                "effective_bunsen_solubility_ratio_alpha_eff_over_alpha_aq": round(1.0 + 0.10 * (20.0 - 1.0), 4),
                "effective_oxygen_permeability_multiplier_p_eff_over_p_aq": 2.50,
                "legacy_parallel_rule_of_mixtures_upper_bound_p_eff_over_p_aq": 2.50,
                "steady_state_fickian_permeability_multiplier_p_eff_over_p_aq_at_r20": round((20.0 + 2.0 + 2.0 * 0.10 * 19.0) / (20.0 + 2.0 - 0.10 * 19.0), 4),
                "maxwell_garnett_impermeable_sphere_limit_p_eff_over_p_aq_6_over_7": round(6.0 / 7.0, 6),
                "maxwell_garnett_equal_diffusivity_r20_p_eff_over_p_aq": round((20.0 + 2.0 + 2.0 * 0.10 * 19.0) / (20.0 + 2.0 - 0.10 * 19.0), 6),
                "maxwell_garnett_infinite_droplet_permeability_upper_bound_p_eff_over_p_aq_4_over_3": round((1.0 + 2.0 * 0.10) / (1.0 - 0.10), 6),
                "apparent_concentration_diffusivity_ratio_d_app_over_d_aq_at_r20": round(
                    ((20.0 + 2.0 + 2.0 * 0.10 * 19.0) / (20.0 + 2.0 - 0.10 * 19.0)) / 2.90, 6
                ),
                "zero_supply_equilibrium_o2_storage_buffer_time_seconds_at_25_and_40_mmhg": [6.75, 10.80],
                "governing_partial_pressure_pde": "alpha_eff * dp/dt = div(P_eff * grad(p)) - q_cells(p) + s_vascular(p)",
                "governing_robin_boundary_condition": "-P_eff * (dp/dz)|_{z=+/-60um} = h_host * (p(L_half, t) - p_host(t))",
                "axial_microvascular_advection_graetz_verification_argon_r2": {
                    "assumed_vessel_length_cm": 1.0,
                    "assumed_lumen_diameter_um": 25.0,
                    "assumed_mean_axial_velocity_cm_s": 0.25,
                    "assumed_radial_o2_diffusivity_in_blood_cm2_s": 2.0e-5,
                    "axial_peclet_number_pe_axial": 12500.0,
                    "graetz_number_gz": 51.3,
                    "single_pass_driving_head_extraction_pct": 11.24,
                    "single_pass_total_inlet_40mmhg_extraction_pct": 7.15,
                    "arteriolar_inlet_po2_mmhg": 40.00,
                    "venular_outlet_po2_mmhg": 37.14,
                },
                "stage0_kill_coupons_z01_to_z04": [
                    "Z-01: Permeation time-lag and equilibrium solubility coupon verifying steady-state partial-pressure permeability P_eff / P_aq in [1.20x, 1.33x] (1.2836x at D_PFC = D_aq, bounded above by (1+2*phi)/(1-phi) = 1.3333x for disconnected spheres at phi = 0.10; AUDIT-REF), equilibrium storage alpha_eff / alpha_aq = 2.90x (apparent t_lag ~ 2.26x blank gel via D_app / D_aq = 0.4426), and dynamic droplet stability (DLS Z-average <= 220 nm, <10% Ostwald ripening over 14 days at 37 C)",
                    "Z-02: 72-h hypoxic microfluidic chamber challenge (pO2_ext = 25 mmHg, 0 mg CaO2) requiring 80 um micro-islet core pO2 >= 5.0 mmHg, viability >= 90%, and SI >= 2.5",
                    "Z-03: THP-1 / primary human macrophage + complement (C3a/C5a) innate reactogenicity screen on PFOB-hydrogel coupons requiring IL-1beta/TNF-alpha <= 1.5x blank hydrogel",
                    "Z-04: Microfluidic fibrin/hydrogel angiogenesis chip verifying iEC + pericyte cord lumenization and perfusable anastomosis within t_50 <= 24-36 h",
                ],
            },
            "vascular_inosculation_target_t50_hours": 24.0,
            "scientific_rationale": (
                "Radical zero-CaO2 biophysical wildcard (Design Z) that eliminates solid peroxide hydrolysis, catalase washout/inactivation "
                "dependence, and 5.71 mmol Ca(OH)2 mineral/alkali export by combining a pleated <=120 um pre-vascularized microvascular "
                "ribbon (L_half = 60 um <= passive Krogh limit) with 80 um micro-islet spheroids, 10% v/v PFOB passive oxygen-shuttle "
                "nanoemulsion (in partial-pressure coordinates with continuous p, equilibrium storage is alpha_eff/alpha_aq = 1 + phi*(K_p - 1) = 2.90x, "
                "while steady-state Maxwell-Garnett partial-pressure permeability is P_eff/P_aq = [r+2+2*phi*(r-1)]/[r+2-phi*(r-1)] with r = K_p*D_PFC/D_aq, "
                "yielding 6/7 = 0.8571x for impermeable spheres r->0, 1.2836x at D_PFC = D_aq [r = 20], and bounded above by (1+2*phi)/(1-phi) = 4/3 = 1.3333x as r->inf, "
                "with apparent concentration diffusivity D_app/D_aq = (P_eff/P_aq)/(alpha_eff/alpha_aq) = 0.4426 and ~6.75-10.80 s zero-supply storage buffer; AUDIT-REF), "
                "and pre-inosculated iEC/iPericyte cords (L = 1.0 cm, d = 25 um, u = 0.25 cm/s -> Pe_axial = 12,500, Gz = 51.3, "
                "11.24% single-pass driving-head extraction, 37.14 mmHg outlet pO2; DEC-020, AUDIT-REF, AUDIT-REF, & AUDIT-REF)."
            ),
        },
        "coupled_pde_regimes_for_metabolic_ode": [dx_fo_201, dx_sc_201, dx_fo_201_loc_cat, dx_gb_201],
    }
    bruggeman_torture_test["design_x_100um_lamina_eps_0p42_46p39wtpct_cao2"] = design_x_100um_lamina_qualification

    # Dynamically compute Hour-0 Newton BVP spatial and dose Catalase controls via _solve_peroxide_slab_bvp on both nz=51 and nz=201 (AUDIT-REF, AUDIT-REF, & AUDIT-REF):
    geom_ctrl_51 = _slab_control_volume_profiles(51, 0.0175, lamina_half_width_fraction=CENTRAL_LAMINA_HALF_WIDTH_FRACTION)
    dz_ctrl_51 = float(geom_ctrl_51["z"][1] - geom_ctrl_51["z"][0])
    s_h2o2_0_ctrl = (2.0 * (r_o2_0_dx / 7.00) * 1e9 * geom_ctrl_51["central_source"])[1:-1]
    mask_int_51 = geom_ctrl_51["central_mask"][1:-1]
    k_perf_0_ctrl = 0.14 * 0.01
    h0_uniform_18 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl, dz_ctrl_51, 18.0, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_masked_18 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl, dz_ctrl_51, 18.0 * mask_int_51, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    k1_lamina_pore_dose = 18.0 * (0.41745 / 2.3800)
    h0_masked_pore_dose = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl, dz_ctrl_51, k1_lamina_pore_dose * mask_int_51, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    k1_uniform_7cm3_dose = 18.0 * (0.41745 / 7.0000)
    h0_uniform_7cm3_dose = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl, dz_ctrl_51, k1_uniform_7cm3_dose, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_uncatalyzed = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl, dz_ctrl_51, 0.008, k_perf_0_ctrl, km_uM=None)["concentration_uM"]))

    geom_ctrl_201_std = _slab_control_volume_profiles(201, 0.0175, lamina_half_width_fraction=CENTRAL_LAMINA_HALF_WIDTH_FRACTION)
    dz_ctrl_201_std = float(geom_ctrl_201_std["z"][1] - geom_ctrl_201_std["z"][0])
    s_h2o2_0_ctrl_201 = (2.0 * (r_o2_0_dx / 7.00) * 1e9 * geom_ctrl_201_std["central_source"])[1:-1]
    mask_int_201_std = geom_ctrl_201_std["central_mask"][1:-1]
    h0_uniform_18_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl_201, dz_ctrl_201_std, 18.0, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_masked_18_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl_201, dz_ctrl_201_std, 18.0 * mask_int_201_std, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_masked_pore_dose_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl_201, dz_ctrl_201_std, k1_lamina_pore_dose * mask_int_201_std, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_uniform_7cm3_dose_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl_201, dz_ctrl_201_std, k1_uniform_7cm3_dose, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_uncatalyzed_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl_201, dz_ctrl_201_std, 0.008, k_perf_0_ctrl, km_uM=None)["concentration_uM"]))

    geom_ctrl_dx_51 = _slab_control_volume_profiles(51, 0.0175, lamina_half_width_fraction=a_design_x)
    s_h2o2_0_dx_ctrl_51 = (2.0 * (r_o2_0_dx / 7.00) * 1e9 * geom_ctrl_dx_51["central_source"])[1:-1]
    mask_int_dx_51 = geom_ctrl_dx_51["central_mask"][1:-1]
    k1_dx_lamina_pore_dose = 18.0 * 0.42
    h0_dx_masked_22680_iu_51 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_dx_ctrl_51, dz_ctrl_51, k1_dx_lamina_pore_dose * mask_int_dx_51, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))

    geom_ctrl_dx_201 = _slab_control_volume_profiles(201, 0.0175, lamina_half_width_fraction=a_design_x)
    dz_ctrl_201 = float(geom_ctrl_dx_201["z"][1] - geom_ctrl_dx_201["z"][0])
    s_h2o2_0_dx_ctrl = (2.0 * (r_o2_0_dx / 7.00) * 1e9 * geom_ctrl_dx_201["central_source"])[1:-1]
    mask_int_dx_201 = geom_ctrl_dx_201["central_mask"][1:-1]
    h0_dx_masked_22680_iu = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_dx_ctrl, dz_ctrl_201, k1_dx_lamina_pore_dose * mask_int_dx_201, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    k1_dx_22680_diluted_in_2p38cm3 = 18.0 * (0.8400 / 2.3800)
    h0_dx_22680_diluted_119um_mask_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_dx_ctrl, dz_ctrl_201, k1_dx_22680_diluted_in_2p38cm3 * mask_int_201_std, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_dx_k6p3529_100um_mask_19059_iu_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_dx_ctrl, dz_ctrl_201, k1_dx_22680_diluted_in_2p38cm3 * mask_int_dx_201, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))
    h0_layout_b_source_and_119um_mask_22680_iu_201 = float(np.max(_solve_peroxide_slab_bvp(s_h2o2_0_ctrl_201, dz_ctrl_201_std, k1_dx_22680_diluted_in_2p38cm3 * mask_int_201_std, k_perf_0_ctrl, km_uM=25000.0)["concentration_uM"]))

    catalase_multi_denominator_iu_ledger = {
        "local_aqueous_target_k1_s_inv": 18.0,
        "michaelis_constant_km_uM": 25000.0,
        "local_aqueous_vmax_M_s_inv": 0.45,
        "local_aqueous_activity_iu_per_ml_pore_water": 27000.0,
        "active_cao2_mass_mg": round(m_cao2_mg_dx, 2),
        "composite_pdms_cao2_bead_mass_layout_b_31p25wtpct_mg": 2532.77,
        "composite_pdms_cao2_bead_mass_layout_a_25p00wtpct_mg": 3165.96,
        "composite_pdms_cao2_bead_mass_design_x_46p39wtpct_mg": round(m_comp_mg_dx, 2),
        "denominators": {
            "lamina_aqueous_pore_volume_layout_b_0p41745_cm3": {
                "volume_cm3": 0.41745,
                "total_pouch_catalase_iu": 11271.2,
                "iu_per_mg_active_cao2": 14.24,
                "iu_per_mg_composite_bead_layout_b": 4.45,
                "iu_per_mg_composite_bead_layout_a": 3.56,
            },
            "lamina_aqueous_pore_volume_design_x_0p8400_cm3": {
                "volume_cm3": 0.8400,
                "total_pouch_catalase_iu": 22680.0,
                "iu_per_mg_active_cao2": 28.65,