- 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/clampExp.py
# To reproduce the data needed for clamping experiments in associated original paper,
def clampExp(simFign, V_clamp,paraKeys,paras,outKeys):
import opencor as oc
import numpy as np
# The prefix of the saved output file name: simFign
# V_clamp=[Vholding,t_ss, t_act,Vtest0, Vtestn, Vstep,]
# Load the simulation file
simfile='../Patch_clamp_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()
# Set the experiments
Vtest = range (V_clamp[3], V_clamp[4], V_clamp[5])
# Define the interval of interest for this simulation experiment
pointInterval=0.01
data.set_starting_point(0)
data.set_ending_point(V_clamp[1]+V_clamp[2]+100)
data.set_point_interval(pointInterval)
# Data to save
varName = np.array(['V']+outKeys)
vars = np.reshape(varName, (1, len(varName)))
row_start=int(V_clamp[1]/pointInterval-50) # to get the peak
row_end=int((V_clamp[1]+V_clamp[2])/pointInterval) # to get the peak
r = np.zeros((len(Vtest),len(varName)))
for i, V in enumerate(Vtest):
# Reset states and parameters
simulation.reset(True)
# Set constant parameter values
data.constants()['Clamp_parameters/V_actHolding'] = V_clamp[0]
data.constants()['Clamp_parameters/t_ss'] = V_clamp[1]
data.constants()['Clamp_parameters/t_act'] = V_clamp[2]
data.constants()['Clamp_parameters/V_actTest'] = V
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[i,0] = V
for j, outKey in enumerate(outKeys):
temp = results.algebraic()[outKey].values()[row_start:row_end]
index_max = np.argmax(abs(temp))
r[i,j+1] = temp[index_max]
# 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