load_file("nrngui.hoc")
create a
a	{nseg=1 diam=5 L=5 
	insert cat cao=2 cai=0.00005 vrest_cat=0
	insert pas g_pas=1/10000 Ra=150 cm=1}
access a

tstop=100
vlow=-50
vhigh=125
dt=0.1
celsius=22

objref gk, b,gt,vc, gs,c, gf,ic
b = new VBox()
c = new VBox()
b.intercept(1)
gk = new Graph(0)
gk.view(vlow,0,vhigh-vlow,1,0,0,100,200)
gk.exec_menu("New Axis")
gk.exec_menu("10% Zoom out")
gk.label(0.1,0.9,"steady-states")
gk.addexpr("minf_cat^3",3,2, 2*tstop,0,2)
gk.addexpr("hinf_cat",2,2, 2*tstop,0,2)

gt = new Graph(0)
gt.view(vlow,0,vhigh-vlow,10,0,0,100,200)
gt.exec_menu("New Axis")
gt.exec_menu("10% Zoom out")
gt.label(0.1,0.9,"time constants")
gt.addexpr("mtau_cat",3,2, 2*tstop,0,2)
gt.addexpr("htau_cat/5",2,2, 2*tstop,0,2)

xpanel("")
xbutton("run ", "run()")
xpanel()
b.intercept(0)
b.map("Ca-T kinetics from Williams & Stuart (2000)",100,0,200,400)

c.intercept(1)
gs = new Graph(0)
gs.view(0,-15,tstop,15,0,0,100,200)
gs.exec_menu("New Axis")
gs.exec_menu("10% Zoom out")
gs.label(0.1,0.9,"activation (pA), Fig.8A")
gs.exec_menu("Keep Lines")

gf = new Graph(0)
gf.view(0,-10,tstop,10,0,0,100,200)
gf.exec_menu("New Axis")
gf.exec_menu("10% Zoom out")
gf.label(0.1,0.9,"inactivation (pA), Fig.8B")
gf.exec_menu("Keep Lines")

c.intercept(0)
c.map("activation and inactivation",390,0,500,370)

vc = new SEClamp(0.5)

proc run() {
gk.begin()
gk.color(3)
gk.label(0.5,0.5,"m^3")
for (v=vlow; v<vhigh; v=v+1) {
    trates_cat(v)
    gk.plot(v)
}
gk.flush()
doNotify()

gt.begin()
gt.color(2)
gt.label(0.65,0.7,"tau_inact./5")
gt.color(3)
gt.label(0.65,0.4,"tau_act.")
for (v=vlow; v<vhigh; v=v+1) {
    trates_cat(v)
    gt.plot(v)
}
gt.flush()
doNotify()

gbar_cat=0.007

gs.addexpr("ica*area(0.5)*10",1,1, 2*tstop,0,2) // *10=pA, *1e-2=nA
gf.addexpr("ica*area(0.5)*10",1,1, 2*tstop,0,2) // *10=pA, *1e-2=nA

gs.begin()
k=15
while (k<66) {
t=0
vc.amp1=vrest_cat
vc.dur1=2
vc.amp2=vrest_cat+k
vc.dur2=tstop
forall {finitialize(vc.amp1)}
while (t<tstop) {
    fadvance()
    gs.plot(t)
    }
gs.flush()
doNotify()
k=k+5
gs.begin()
}
vc.dur1=0
vc.dur2=0
vc.dur3=0

k=-40
while (k<31) {
t=0
vc.amp1=vrest_cat+k
vc.dur1=2
vc.amp2=vrest_cat+40
vc.dur2=tstop
forall {finitialize(k)}
while (t<tstop) {
    fadvance()
    gf.plot(t)
    }
gf.flush()
doNotify()
k=k+10
gf.begin()
}
vc.dur1=0
vc.dur2=0
vc.dur3=0
}