Location: Sneyd_2016 @ da1f78260d85 / Simulations / Fig1_sim.py

Author:
Leyla <noroozbabaee@gmail.com>
Date:
2021-11-11 23:09:06+13:00
Desc:
All the files are updated!
Permanent Source URI:
https://staging.physiomeproject.org/workspace/7b3/rawfile/da1f78260d851b46a4490c0cde5b78233b64a835/Simulations/Fig1_sim.py

# Author : Leyla Noroozbabaee
# Bioengineering Institute
# The University of Auckland
# Date: 26/10/2021

# To reproduce the data needed for Figure 1 in associated original 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 Fig1_sim.py

import opencor as oc
import numpy as np
# I_stim1, I_stim2, I_stim3 = [1, 0, 0]
# I_stim1, I_stim2, I_stim3 = [0, 1, 0]
I_stim1, I_stim2, I_stim3 = [0, 0, 1]

if I_stim1:
    prefilename = 'Fig1_A'
elif I_stim2:
    prefilename = 'Fig1_B'
else:
    prefilename = 'Fig1_C'
simfile = 'Sneyd_2016.sedml'
simulation = oc.open_simulation(simfile)
data = simulation.data()
# Reset states and parameters
simulation.reset(True)
print(data.constants())

if I_stim1:
    end = 150
    data.constants()['ca/p/time_init'] = 65
    data.constants()['ca/p/time_end'] = end
elif I_stim2:
    end = 150
    data.constants() ['ca/p/time_init'] = 59.9459
    data.constants() ['ca/p/time_end'] = end
else:
    end = 450
    data.constants() [ 'ca/p/time_init' ] = 43.7685
    data.constants()['ca/p/time_end'] = end

# Set constant parameter values
start = 0
pointInterval = 0.1
data.set_starting_point(start)
data.set_ending_point(end)
data.set_point_interval(pointInterval)
# Run simulation
simulation.run()
# Access simulation results
results = simulation.results()
# Grab the selected results
varName = np.array(["time", "ca_c", "ca_e", "p"])
vars = np.reshape(varName, (1, 4))
rows = end * 10 + 1
print(rows)
r = np.zeros((rows, len(varName)))

r[:,0] = results.voi().values()
r[:,1] = results.states()['ca/ca_c'].values()
r[:,2] = results.states()['ca/ca_e'].values()
r[:,3] = results.algebraic()['ca/p/p'].values()


# Save the data
filename = '%s.csv' % prefilename
np.savetxt(filename, vars, fmt='%s', delimiter=",")
with open(filename, "ab") as f:
    np.savetxt(f, r, delimiter=",")
f.close