Location: Blood HbO2 and HbCO2 Dissociation Curves @ f725b6864f22 / Figure06.py

Author:
nima <nafs080@aucklanduni.ac.nz>
Date:
2020-10-29 09:32:37+13:00
Desc:
All the Cellml files, Sedml files and python scripts for figures are added
Permanent Source URI:
https://models.fieldml.org/workspace/607/rawfile/f725b6864f22a00138a2c2455308142c8baba373/Figure06.py

# To reproduce the data needed for Figure 4 in associated Physiome paper,
# execute this script in the Python console in OpenCOR. This can be done
# with the following commands at the prompt in the OpenCOR Python console:
#
#     In [1]: cd path/to/folder_this_file_is_in
#     In [2]: %run Figure03.py
#

import opencor as opencor
# import numpy as np
Temp_list = [27, 32, 37, 42, 47]
DPG_rbc = [0.003, 0.0045, 0.006, 0.0075, 0.009]
pH_rbc = [6.92, 7.08, 7.24, 7.40, 7.56]
PO2_list = [10, 40, 70, 100, 500]
Hct_list = [0.1, 0.2, 0.3, 0.4, 0.5]
#######
#po2 and DPG are variables

CO2 = {}

simulation = opencor.open_simulation("Figure06.sedml")
data = simulation.data()
data.set_ending_point(99.5)
data.set_point_interval(1)


for i, pO2 in enumerate(PO2_list):
    # reset everything in case we are running interactively and have existing results
    simulation.reset(True)
    simulation.clear_results()

    data.constants()["main/pO2"] = pO2
    data.constants()["main/pH"] = 7.24
    simulation.run()
    ds = simulation.results().data_store()
    CO2[pO2] = ds.voi_and_variables()["main/CO2content"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("CO2(pO2).csv", 'w')
cols = []
for key, item in CO2.items():
     outfile.write(str(key) + ",")
     cols.append(item)
outfile.write("\n")

for i in range(0, len(cols[0])):
    for j in range(0, len(cols)):
        outfile.write(str(cols[j][i]) + ",")
    outfile.write("\n")
outfile.close()

CO2 = {}
for i, DPG in enumerate(DPG_rbc):
    # reset everything in case we are running interactively and have existing results
    simulation.reset(True)
    simulation.clear_results()

    data.constants()["main/DPG"] = DPG
    data.constants()["main/pH"] = 7.24
    simulation.run()
    ds = simulation.results().data_store()
    CO2[DPG] = ds.voi_and_variables()["main/CO2content"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("CO2(DPG).csv", 'w')
cols = []
for key, item in CO2.items():
     outfile.write(str(key) + ",")
     cols.append(item)
outfile.write("\n")

for i in range(0, len(cols[0])):
    for j in range(0, len(cols)):
        outfile.write(str(cols[j][i]) + ",")
    outfile.write("\n")
outfile.close()

#####
#pH is a variable
CO2 = {}

for i, pH in enumerate(pH_rbc):
    # reset everything in case we are running interactively and have existing results
    simulation.reset(True)
    simulation.clear_results()

    data.constants()["main/pH"] = pH
    simulation.run()
    ds = simulation.results().data_store()
    CO2[pH] = ds.voi_and_variables()["main/CO2content"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("CO2(pH).csv", 'w')
cols = []
for key, item in CO2.items():
     outfile.write(str(key) + ",")
     cols.append(item)
outfile.write("\n")

for i in range(0, len(cols[0])):
    for j in range(0, len(cols)):
        outfile.write(str(cols[j][i]) + ",")
    outfile.write("\n")
outfile.close()
#######
#Temp is a variable
CO2 = {}

for i, Temp in enumerate(Temp_list):
    # reset everything in case we are running interactively and have existing results
    simulation.reset(True)
    simulation.clear_results()

    data.constants()["main/pH"] = 7.24
    data.constants()["main/Temp"] = Temp
    simulation.run()
    ds = simulation.results().data_store()
    CO2[Temp] = ds.voi_and_variables()["main/CO2content"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("CO2(Temp).csv", 'w')
cols = []
for key, item in CO2.items():
     outfile.write(str(key) + ",")
     cols.append(item)
outfile.write("\n")

for i in range(0, len(cols[0])):
    for j in range(0, len(cols)):
        outfile.write(str(cols[j][i]) + ",")
    outfile.write("\n")
outfile.close()
#######
#Hct is a variable
CO2 = {}

for i, Hct in enumerate(Hct_list):
    # reset everything in case we are running interactively and have existing results
    simulation.reset(True)
    simulation.clear_results()

    data.constants()["main/pH"] = 7.24
    data.constants()["main/Hct"] = Hct
    simulation.run()
    ds = simulation.results().data_store()
    CO2[Hct] = ds.voi_and_variables()["main/CO2content"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("CO2(Hct).csv", 'w')
cols = []
for key, item in CO2.items():
     outfile.write(str(key) + ",")
     cols.append(item)
outfile.write("\n")

for i in range(0, len(cols[0])):
    for j in range(0, len(cols)):
        outfile.write(str(cols[j][i]) + ",")
    outfile.write("\n")
outfile.close()