Location: Blood HbO2 and HbCO2 Dissociation Curves @ f725b6864f22 / Figure04.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.cellml.org/workspace/607/rawfile/f725b6864f22a00138a2c2455308142c8baba373/Figure04.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]
PCO2_list = [5, 20, 40, 65, 100]
#######
#pH(rbc) is a variable

SHbO2 = {}

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


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()
    SHbO2[pH] = ds.voi_and_variables()["main/SHbO2"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("SHbO2(pH).csv", 'w')
cols = []
for key, item in SHbO2.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()

######
#PCO2 is a variable
SHbO2 = {}

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

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

# cache results for plotting
outfile = open("SHbO2(PCO2).csv", 'w')
cols = []
for key, item in SHbO2.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()

SHbO2 = {}

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
    simulation.run()
    ds = simulation.results().data_store()
    SHbO2[DPG] = ds.voi_and_variables()["main/SHbO2"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("SHbO2(DPG).csv", 'w')
cols = []
for key, item in SHbO2.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()

SHbO2 = {}

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/Temp"] = Temp
    simulation.run()
    ds = simulation.results().data_store()
    SHbO2[Temp] = ds.voi_and_variables()["main/SHbO2"].values()
    # print((glucose_i))
    # for key, value in glucose_i.items():
    #     print(key, value)

# cache results for plotting
outfile = open("SHbO2(Temp).csv", 'w')
cols = []
for key, item in SHbO2.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()