- Author:
- WeiweiAi <wai484@aucklanduni.ac.nz>
- Date:
- 2022-01-20 12:46:30+13:00
- Desc:
- revert the scaling in the currents
- Permanent Source URI:
- https://models.physiomeproject.org/workspace/701/rawfile/1451a14f3fbe8fd7aacd0d0a73d87cec591b26de/Simulation/src/VrampExp.py
# To reproduce the data needed for clamping experiments in associated original paper,
def VrampExp(simFign,Vinit, paraKeys,paras,outKeys):
import opencor as oc
import numpy as np
# The prefix of the saved output file name: simFign
# Load the simulation file
simfile='../Voltage_ramp_experiment.sedml'
simulation = oc.open_simulation(simfile)
# The data object houses all the relevant information
# and pointers to the OpenCOR internal data representations
data = simulation.data()
# Define the interval of interest for this simulation experiment
start, duration,pointInterval = 0, 280, 0.1
data.set_starting_point(start)
data.set_point_interval(pointInterval)
data.set_ending_point(duration)
# Data to save
varName = np.array(['V']+outKeys)
vars = np.reshape(varName, (1, len(varName)))
# start to save
rows=int((duration)/pointInterval+1)
r = np.zeros((rows,len(varName)))
for i, V in enumerate(Vinit):
# Reset states and parameters
simulation.reset(True)
# Set constant parameter values
data.states()['outputs/V'] = Vinit[i]
for j, para in enumerate(paras):
data.constants()[paraKeys[j]] = para
simulation.run()
# Access simulation results
results = simulation.results()
# Grab a specific algebraic variable results
r[:,0]=results.states()['outputs/V'].values()[-rows:]
for j, outKey in enumerate(outKeys):
r[:,j+1] = results.algebraic()[outKey].values()[-rows:]
# clear the results except the last run
simulation.clear_results()
# Save the simulation result of the last run
filename='../simulatedData/sim%s.csv' % (simFign)
np.savetxt(filename, vars, fmt='%s',delimiter=",")
with open(filename, "ab") as f:
np.savetxt(f, r, delimiter=",")
f.close