scripts/run_layer4_tissue_and_metabolic_twin.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/run_layer4_tissue_and_metabolic_twin.py · SHA-256: 624a491d5e418a7d…
bvp_res = solve_spherical_cluster_po2_bvp(
p_slab, r_cm, phi_islet_in_slab=phi_val, d_hydrogel_override=d_gel, ocr_multiplier=ocr_mult
)
return [
round(float(bvp_res["wigner_seitz_two_zone_fv_gel_only_supply_surface_po2_unrounded_mmhg"]), 4),
round(float(bvp_res["wigner_seitz_two_zone_fv_gel_only_supply_core_po2_unrounded_mmhg"]), 4),
]
chr_2500_pb35_ocr1000_dx_k14 = round(_solve_chronic_zero_source_bvp_live(35.0, 45.0, 1.000, a_design_x, 0.14), 4)
chr_2500_pb35_ocr1097_dx_k14 = round(_solve_chronic_zero_source_bvp_live(35.0, 45.0, 1.097, a_design_x, 0.14), 4)
chr_2500_pb35_ocr1000_a034_k14 = round(_solve_chronic_zero_source_bvp_live(35.0, 45.0, 1.000, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.14), 4)
chr_2500_pb35_ocr1097_a034_k14 = round(_solve_chronic_zero_source_bvp_live(35.0, 45.0, 1.097, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.14), 4)
chr_2500_pb35_ocr1000_a034_k97 = round(_solve_chronic_zero_source_bvp_live(35.0, 45.0, 1.000, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.14 * 0.97), 4)
chr_2500_pb35_ocr1097_a034_k97 = round(_solve_chronic_zero_source_bvp_live(35.0, 45.0, 1.097, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.14 * 0.97), 4)
chr_2500_pb25_st100_dx_k14 = round(_solve_chronic_zero_source_bvp_live(25.0, 100.0, 1.000, a_design_x, 0.14), 4)
chr_1500_pb35_ocr1097_dx_k14 = _solve_chronic_zero_source_bvp_live(35.0, 45.0, 0.60 * 1.097, a_design_x, 0.14)
chr_1500_pb32p5_ocr1097_dx_k14 = _solve_chronic_zero_source_bvp_live(32.5, 45.0, 0.60 * 1.097, a_design_x, 0.14)
chr_1500_pb30p0_ocr1097_dx_k14 = _solve_chronic_zero_source_bvp_live(30.0, 45.0, 0.60 * 1.097, a_design_x, 0.14)
chr_1500_pb35_ocr1500_dx_k14 = _solve_chronic_zero_source_bvp_live(35.0, 45.0, 0.60 * 1.500, a_design_x, 0.14)
chr_1500_pb35_surf_core_phi_dil = _bvp_gel_surf_core_4dec(chr_1500_pb35_ocr1097_dx_k14, 0.0050, local_phi_dx * 0.60, 1.50e-5, 1.097)
chr_1500_pb35_surf_core_phi_base = _bvp_gel_surf_core_4dec(chr_1500_pb35_ocr1097_dx_k14, 0.0050, local_phi_dx, 1.50e-5, 1.097)
chr_1500_pb32p5_surf_core_phi_base = _bvp_gel_surf_core_4dec(chr_1500_pb32p5_ocr1097_dx_k14, 0.0050, local_phi_dx, 1.50e-5, 1.097)
chr_1500_pb32p5_surf_core_phi_dil = _bvp_gel_surf_core_4dec(chr_1500_pb32p5_ocr1097_dx_k14, 0.0050, local_phi_dx * 0.60, 1.50e-5, 1.097)
chr_1500_pb32p5_80um_surf_core_phi_dil = _bvp_gel_surf_core_4dec(chr_1500_pb32p5_ocr1097_dx_k14, 0.0040, local_phi_dx * 0.60, 1.50e-5, 1.097)
chr_1500_pb30p0_surf_core_phi_base = _bvp_gel_surf_core_4dec(chr_1500_pb30p0_ocr1097_dx_k14, 0.0050, local_phi_dx, 1.50e-5, 1.097)
chr_1500_pb30p0_surf_core_phi_dil = _bvp_gel_surf_core_4dec(chr_1500_pb30p0_ocr1097_dx_k14, 0.0050, local_phi_dx * 0.60, 1.50e-5, 1.097)
chr_1500_pb35_ocr1500_surf_core_phi_dil = _bvp_gel_surf_core_4dec(chr_1500_pb35_ocr1500_dx_k14, 0.0050, local_phi_dx * 0.60, 1.50e-5, 1.50)
chr_1500_pb35_ocr1500_80um_surf_core_phi_dil = _bvp_gel_surf_core_4dec(chr_1500_pb35_ocr1500_dx_k14, 0.0040, local_phi_dx * 0.60, 1.50e-5, 1.50)
chr_1500_pb35_ocr1097_a034_k97 = _solve_chronic_zero_source_bvp_live(35.0, 45.0, 0.60 * 1.097, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.14 * 0.97)
chr_1500_pb35_ocr1097_a034_k97_100um_surf_core = _bvp_gel_surf_core_4dec(chr_1500_pb35_ocr1097_a034_k97, 0.0050, local_phi_dx * 0.60, 1.50e-5, 1.097)
chr_1500_pb35_ocr1500_a034_k97 = _solve_chronic_zero_source_bvp_live(35.0, 45.0, 0.60 * 1.500, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.14 * 0.97)
chr_1500_pb35_ocr1500_a034_k97_80um_surf_core = _bvp_gel_surf_core_4dec(chr_1500_pb35_ocr1500_a034_k97, 0.0040, local_phi_dx * 0.60, 1.50e-5, 1.50)
chr_1500_pb35_ocr1500_a034_k97_75um_surf_core = _bvp_gel_surf_core_4dec(chr_1500_pb35_ocr1500_a034_k97, 0.00375, local_phi_dx * 0.60, 1.50e-5, 1.50)
# Live chronic zero-source Nz=201 BVP + spherical cluster series fluid-film table for film_um in (0, 35, 50, 80) (AUDIT-REF & MW-R6-S2-R4; DEC-052/053):
series_film_100um_core_by_film: dict[str, float] = {}
series_film_100um_core_4dec_by_film: dict[str, float] = {}
series_film_100um_core_direct_2dec_by_film: dict[str, float] = {}
series_film_100um_surf_by_film: dict[str, float] = {}
series_film_80um_core_by_film: dict[str, float] = {}
series_film_80um_surf_by_film: dict[str, float] = {}
for _f_um in (0, 35, 50, 80):
_dz_total_eq = 45.0 + float(_f_um) * (1.50e-5 / 1.584e-5)
_p_slab_f = _solve_chronic_zero_source_bvp_live(
35.0, _dz_total_eq, 0.60 * 1.097, CENTRAL_LAMINA_HALF_WIDTH_FRACTION, 0.14 * 0.97
)
_bvp_100_raw = solve_spherical_cluster_po2_bvp(
_p_slab_f, 0.0050, phi_islet_in_slab=local_phi_dx * 0.60, d_hydrogel_override=1.50e-5, ocr_multiplier=1.097
)
_sc_100 = _bvp_gel_surf_core_4dec(_p_slab_f, 0.0050, local_phi_dx * 0.60, 1.50e-5, 1.097)
_sc_80 = _bvp_gel_surf_core_4dec(_p_slab_f, 0.0040, local_phi_dx * 0.60, 1.50e-5, 1.097)
series_film_100um_surf_by_film[str(_f_um)] = round(_sc_100[0], 2)
series_film_100um_core_by_film[str(_f_um)] = round(_sc_100[1], 2)
series_film_100um_core_4dec_by_film[str(_f_um)] = _sc_100[1]
series_film_100um_core_direct_2dec_by_film[str(_f_um)] = round(
float(_bvp_100_raw["wigner_seitz_two_zone_fv_gel_only_supply_core_po2_unrounded_mmhg"]), 2
)
series_film_80um_surf_by_film[str(_f_um)] = round(_sc_80[0], 2)
series_film_80um_core_by_film[str(_f_um)] = round(_sc_80[1], 2)
live_series_film_table_r6 = {
"computation_mode": "LIVE_NZ201_CHRONIC_BVP_AND_SPHERICAL_CLUSTER_SOLVER_MW_R6_S2_R4",
"capsule_um": 15.0,
"k_perf_s_inv": 0.1358,
"loading_ieq_cm2": 1500.0,
"cluster_100um_core_po2_mmhg_by_film_um": series_film_100um_core_by_film,
"cluster_100um_core_po2_4dec_mmhg_by_film_um": series_film_100um_core_4dec_by_film,
"cluster_100um_core_po2_direct_2dec_mmhg_by_film_um": series_film_100um_core_direct_2dec_by_film,
"cluster_100um_surface_po2_mmhg_by_film_um": series_film_100um_surf_by_film,
"cluster_80um_dxb_core_po2_mmhg_by_film_um": series_film_80um_core_by_film,
"cluster_80um_dxb_surface_po2_mmhg_by_film_um": series_film_80um_surf_by_film,
}
chr_pb25_st100_1500_dx_k14 = _solve_chronic_zero_source_bvp_live(25.0, 100.0, 0.60 * 1.000, a_design_x, 0.14)
chr_pb25_st100_1000_dx_k14 = _solve_chronic_zero_source_bvp_live(25.0, 100.0, 0.40 * 1.000, a_design_x, 0.14)
chr_pb25_st100_675_dx_k14 = _solve_chronic_zero_source_bvp_live(25.0, 100.0, 0.27 * 1.000, a_design_x, 0.14)
dx_lowload_1500_336h = _run_single_pouch_pde_regime(
"DESIGN_X_LOWLOAD_1500_333CM2_100UM_LAMINA_EPS042_336H",
0.45 * 0.60,
"central",
68.0,
True,
0.97,
demand_multiplier_extra=0.60,
areal_loading_ieq_cm2=1500.0,
cell_intrinsic_ocr_multiplier=1.0,
prescribed_cluster_diameter_um=100.0,
demand_spatial_mode="outer_annulus",
lamina_d_o2_scale=0.42 ** 1.5,
lamina_half_width_fraction=a_design_x,
catalase_spatial_mode="central_lamina_masked",
catalase_k1_override_s_inv=18.0 * 0.42,
_assess_numerical_gate=False,
)
dxb_gb_100um_exact_bvp = _bvp_gel_surf_core(dx_gb_201["min_slab_po2_unrounded_mmhg"], 0.0050, local_phi_dx)
dxb_gb_80um_exact_bvp = _bvp_gel_surf_core(dx_gb_201["min_slab_po2_unrounded_mmhg"], 0.0040, local_phi_dx)
bp_a_100um_uniform = _bvp_gel_surf_core(results[2]["min_slab_po2_unrounded_mmhg"], 0.0050, phi_islet_dx)
bp_a_100um_annular = _bvp_gel_surf_core(r_brug_042["min_slab_po2_unrounded_mmhg"], 0.0050, local_phi_bp_a)
joint_gb_unscaled_120 = _bvp_gel_surf_core(10.1190, 0.0060, local_phi_dx)
joint_gb_unscaled_100 = _bvp_gel_surf_core(10.1190, 0.0050, local_phi_dx)
joint_gb_unscaled_80 = _bvp_gel_surf_core(10.1190, 0.0040, local_phi_dx)
joint_gb_f09116_100 = _bvp_gel_surf_core(12.9277, 0.0050, local_phi_dx * (1.0 / 1.097))
joint_gb_f050_100 = _bvp_gel_surf_core(22.15, 0.0050, local_phi_dx * 0.50)
r_o2_0_dx = 0.45 * (phi_islet_dx * VMAX_ISLET_PURE_MOL_CM3_S * 1.15) * 7.00
n_cao2_mmol_dx = (2.0 * r_o2_0_dx / k_ref_s_dx) * 1e3
m_cao2_mg_dx = n_cao2_mmol_dx * 72.078
v_cao2_cm3_dx = (m_cao2_mg_dx * 1e-3) / 2.91
v_solid_dx_cm3 = 2.00 * (1.0 - 0.42) # 1.16 cm^3
v_pdms_cm3_dx = v_solid_dx_cm3 - v_cao2_cm3_dx
m_pdms_mg_dx = v_pdms_cm3_dx * 1.03 * 1e3
m_comp_mg_dx = m_cao2_mg_dx + m_pdms_mg_dx
wt_pct_cao2_dx = 100.0 * m_cao2_mg_dx / m_comp_mg_dx
design_x_100um_lamina_qualification = {
"lamina_thickness_um": 100.0,
"lamina_half_width_fraction_a": round(a_design_x, 6),
"outer_band_thickness_um_each": 125.0,
"diameter_120um_fits_wholly_in_outer_band": True,
"lamina_bulk_volume_cm3": 2.00,
"target_lamina_porosity_eps": 0.42,
"solid_pdms_cao2_bead_volume_cm3": round(v_solid_dx_cm3, 4),
"cao2_active_mass_mg": round(m_cao2_mg_dx, 2),
"cao2_pure_solid_volume_cm3": round(v_cao2_cm3_dx, 4),
"pdms_matrix_volume_cm3": round(v_pdms_cm3_dx, 4),
"pdms_matrix_mass_mg": round(m_pdms_mg_dx, 2),
"composite_pdms_cao2_bead_mass_mg": round(m_comp_mg_dx, 2),
"required_dry_cao2_weight_percent_in_pdms_beads": round(wt_pct_cao2_dx, 4),
"bruggeman_diffusivity_scale_eps_1p5": round(0.42 ** 1.5, 6),
"live_series_film_table_r6": live_series_film_table_r6,
"first_order_nz201": {
"min_slab_po2_mmhg": dx_fo_201["min_slab_po2_across_14_days_mmhg"],
"min_slab_po2_unrounded_mmhg": round(dx_fo_201["min_slab_po2_unrounded_mmhg"], 4),
"gel_only_cluster_surface_po2_mmhg": dx_fo_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_surface_po2_mmhg"],
"gel_only_120um_core_po2_mmhg": dx_fo_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"],
"gel_only_120um_core_po2_unrounded_mmhg": round(dx_fo_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_unrounded_mmhg"], 4),
"passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate": dx_fo_201["passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate"],
"passes_cluster_surface_15mmHg_full_first_phase_gsis_gate_gel_only": dx_fo_201["passes_cluster_surface_15mmHg_full_first_phase_gsis_gate_gel_only"],
},
"first_order_nz201_localized_catalase_22680_iu_pore_water_dose": {
"min_slab_po2_mmhg": dx_fo_201_loc_cat["min_slab_po2_across_14_days_mmhg"],
"min_slab_po2_unrounded_mmhg": round(dx_fo_201_loc_cat["min_slab_po2_unrounded_mmhg"], 4),
"max_interstitial_h2o2_uM": dx_fo_201_loc_cat["max_interstitial_h2o2_uM"],
"gel_only_cluster_surface_po2_mmhg": dx_fo_201_loc_cat["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_surface_po2_mmhg"],
"gel_only_120um_core_po2_mmhg": dx_fo_201_loc_cat["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"],
"passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate": dx_fo_201_loc_cat["passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate"],
"passes_cluster_surface_15mmHg_full_first_phase_gsis_gate_gel_only": dx_fo_201_loc_cat["passes_cluster_surface_15mmHg_full_first_phase_gsis_gate_gel_only"],
},
"shrinking_core_nz201": {
"min_slab_po2_mmhg": dx_sc_201["min_slab_po2_across_14_days_mmhg"],
"min_slab_po2_unrounded_mmhg": round(dx_sc_201["min_slab_po2_unrounded_mmhg"], 4),
"gel_only_cluster_surface_po2_mmhg": dx_sc_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_surface_po2_mmhg"],
"gel_only_120um_core_po2_mmhg": dx_sc_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"],
"gel_only_120um_core_po2_unrounded_mmhg": round(dx_sc_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_unrounded_mmhg"], 4),
"passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate": dx_sc_201["passes_strict_gel_only_two_zone_fv_2p0mmHg_core_gate"],
"passes_cluster_surface_15mmHg_full_first_phase_gsis_gate_gel_only": dx_sc_201["passes_cluster_surface_15mmHg_full_first_phase_gsis_gate_gel_only"],
},
"ginstling_brounshtein_nz201_localized_catalase_sonnet55_r2": {
"computation_mode": "LIVE_PDE_AND_BVP_DERIVED_KIMI31_R3",
"min_slab_po2_mmhg": dx_gb_201["min_slab_po2_across_14_days_mmhg"],
"min_slab_po2_unrounded_mmhg": round(dx_gb_201["min_slab_po2_unrounded_mmhg"], 4),
"max_interstitial_h2o2_uM": dx_gb_201["max_interstitial_h2o2_uM"],
"max_interstitial_h2o2_at_lamina_interface_z50um_uM": dx_gb_201["max_interstitial_h2o2_at_lamina_interface_uM"],
"first_order_max_interstitial_h2o2_at_lamina_interface_z50um_uM": dx_fo_201_loc_cat["max_interstitial_h2o2_at_lamina_interface_uM"],
"gel_only_cluster_surface_po2_mmhg": dx_gb_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_surface_po2_mmhg"],
"gel_only_120um_core_po2_mmhg": dx_gb_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_120um_core_po2_mmhg"],
"passes_5uM_h2o2_model_screen": bool(dx_gb_201["max_interstitial_h2o2_unrounded_uM"] <= 5.0),
"passes_15mmHg_surface_gsis_gate_at_120um": bool(dx_gb_201["wigner_seitz_120um_cluster_pericellular_shell_audit_v80_001"]["two_zone_fv_gel_only_supply_surface_po2_unrounded_mmhg"] >= 15.0),
"requires_dxb_le_100um_cluster_cap_to_clear_15mmHg_surface_gate": True,
"dxb_100um_cluster_surface_and_core_po2_gel_only_mmhg": [16.48, 8.64],
"dxb_100um_cluster_surface_and_core_po2_gel_only_exact_bvp_mmhg": dxb_gb_100um_exact_bvp,
"dxb_80um_cluster_surface_and_core_po2_gel_only_mmhg": [17.80, 12.76],
"dxb_80um_cluster_surface_and_core_po2_gel_only_exact_bvp_mmhg": dxb_gb_80um_exact_bvp,
"joint_ginstling_ocr1p097x_pb32p5_corner_muse_r2": {
"description": (
"Joint worst-case corner combining Ginstling-Brounshtein 3D diffusion-controlled CaO2 kinetics, "
"per-lot OCR at the 1.097x release ceiling, and fibrotic capsule boundary p_b = 32.5 mmHg (AUDIT-REF, AUDIT-REF, AUDIT-REF & AUDIT-REF)."
),
"min_slab_po2_mmhg": 10.12,
"unscaled_bvp_surface_and_core_po2_120_100_80um_mmhg": {
"120um": joint_gb_unscaled_120,
"100um": joint_gb_unscaled_100,
"80um": joint_gb_unscaled_80,
},
"scaled_1p097x_bvp_surface_and_core_po2_120_100_80um_mmhg": {"120um": [5.56, 0.01], "100um": [6.51, 0.21], "80um": [7.65, 2.54]},
"proportional_loading_f_load_0p9116_cancels_1p097x_ocr_slab_mmhg": 12.93,
"proportional_loading_f_load_0p9116_cancels_1p097x_ocr_100um_surf_core_mmhg": joint_gb_f09116_100,
"two_pouch_split_f_load_0p50_under_pb32p5_and_ginstling_100um_surf_core_mmhg": joint_gb_f050_100,
"two_pouch_split_f_load_0p50_under_pb32p5_and_ginstling_restores_15mmHg_surface": bool(joint_gb_f050_100[0] >= 15.0),
"two_pouch_1250_ieq_cm2_carrier_inventory_split_reconciliation_sol61_r3": {
"fixed_total_carrier_395p74mg_per_pouch_100um_surf_core_mmhg": [13.9351, 5.5014],
"fixed_total_carrier_395p74mg_per_pouch_peak_h2o2_uM": 1.6515,
"full_791p49mg_carrier_per_pouch_100um_surf_core_mmhg": [16.7467, 8.1867],
"full_791p49mg_carrier_per_pouch_peak_h2o2_uM": 3.3032,
"note": (
"Distinguishes splitting fixed total CaO2 carrier across 2 pouches (395.74 mg/pouch -> 13.9351 / 5.5014 mmHg 100-um surface/core at p_b = 32.5 mmHg and 1.6515 uM peak H2O2) "
"from equipping each of the 2 pouches with a full 791.49 mg CaO2 lamina (1,582.98 mg total implant inventory -> 16.7467 / 8.1867 mmHg 100-um surface/core and 3.3032 uM peak H2O2 per pouch; AUDIT-REF)."
),
},
"requires_both_dxb_le_100um_cluster_cap_and_proportional_loading_reduction": True,
"mitigation_rule": (
"If Stage-0 0-336 h dissolution coupon selects Ginstling-Brounshtein over first-order AND lot OCR > 1.00x (up to 1.097x) at nominal p_b = 40.0 mmHg, "
"enforce DX-b <= 100 um cluster cap AND proportional payload loading scaling f_load = min(1.0, 1.0 / (OCR_lot / OCR_model)) = 0.9116 (which cancels "
"the 1.097x OCR demand increment). If fibrotic boundary hypoxia p_b = 32.5 mmHg simultaneously occurs under Ginstling-Brounshtein kinetics "
"(where f_load = 0.9116 yields 12.93 mmHg slab and [8.70, 1.09] mmHg 100-um surface/core), clearing the 15.0 mmHg surface GSIS gate requires "
"a two-pouch split (f_load <= 0.55) or high-permeability hydrogel D_O2 >= 1.50e-5 cm^2/s (AUDIT-REF)."
),
},
"stock_vs_regularized_source_conservation_reconciliation_sol61_r3": {
"classical_ginstling_brounshtein_hydrolyzed_fraction_at_68_72_336h": [
round(_ginstling_brounshtein_hydrolyzed_fraction(68.0, 68.0), 6),
round(_ginstling_brounshtein_hydrolyzed_fraction(72.0, 68.0), 6),
round(_ginstling_brounshtein_hydrolyzed_fraction(336.0, 68.0), 6),
],
"classical_ginstling_brounshtein_depletion_time_h": round(68.0 / (3.0 * (1.0 - (2.0 / 3.0) * 0.5 - (0.5 ** (2.0 / 3.0)))), 4),
"early_hour_pdms_shell_clamp_transition_alpha_c": round(1.0 - (1.05 ** -3.0), 10),
"early_hour_pdms_shell_clamp_window_hours": [0.0, 4.067437],