- Author:
- Leyla <lnor300>
- Date:
- 2022-11-02 15:33:57+13:00
- Desc:
- ..
- Permanent Source URI:
- https://models.cellml.org/workspace/763/rawfile/81e638b3f094d00aade965d9e2ca7bd101f33371/Simulation/Figure8/Fig8_sim.py
# Author : Leyla Noroozbabaee
# Date: 12/09/2021
# To reproduce the data needed for Figure 8 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 Fig8_sim.py
import opencor as oc
import matplotlib.pyplot as plt
import numpy as np
# The prefix of the saved output file name
prefilename = 'Fig8'
# Load the simulation file
simfile = 'Fig8_IP3_Imtiaz_2002.sedml'
simulation = oc.open_simulation(simfile)
data = simulation.data()
# Reset states variables and parameters
simulation.reset(True)
# Set constant values
start = 0
end = 35
pointInterval = 0.01
data.set_starting_point(start)
data.set_ending_point(end)
data.set_point_interval(pointInterval)
# Parameters to Genarate the Current (Stimulus)
t_d_init = [5.36, 2.36]
t_d_end = [6, 3]
for j in range(2):
# Reset states variables and parameters
simulation.reset(True)
data.constants()['vm/vm_init'] = -65.4
data.constants()['vm/t_1'] = t_d_init[j]
data.constants()['vm/t_2'] = t_d_end[j]
simulation.run()
# Access simulation results
results = simulation.results()
# Data to save
varName = np.array(["Time", "vm", "I_inj"])
vars = np.reshape(varName, (1, 3))
rows = end * 100 + 1
r = np.zeros((rows, len(varName)))
r[:, 0] = results.voi().values()
# print(varName, vars, rows)
r = np.zeros((rows, len(varName)))
simulation.run()
# Access simulation results
results = simulation.results()
# Grab a specific algebraic variable results
r[:, 0] = results.voi().values()
r[:, 1] = results.states()['vm/vm'].values()
r[:, 2] = results.algebraic()['vm/I_inj'].values()
# Save the Simulation Results
filename = '%s_%s.csv' % (prefilename, j)
np.savetxt(filename, vars, fmt='%s', delimiter=",")
with open(filename, "ab") as f:
np.savetxt(f, r, delimiter=",")
f.close