load_file("nrngui.hoc")
cvode.active(1)
cvode.atol(1.e-4)
create a
a	{nseg=1 diam=5 L=5 
	insert kdrf ek=-90
	insert kdrs ek=-90
	insert ka   ek=-90
	insert pas g_pas=1/10000 Ra=150 cm=1}
access a

celsius=24
tstop=100
vlow=-120
vhigh=80
dt=0.1

a0h_ka=0.17
vhalfh_ka=-105

mfac=1
hfac=1
msfac=1

objref gk, b,gt,vc, gs,c, gf,ic, ga
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,"Figs.5B,6B,7B: steady-states")
gk.addexpr("minf_kdrf",1,2, 2*tstop,0,2)
gk.addexpr("hinf_kdrf",1,2, 2*tstop,0,2)
gk.addexpr("hinf_kdrs",2,2, 2*tstop,0,2)
gk.addexpr("minf_kdrs",2,2, 2*tstop,0,2)
gk.addexpr("hinf_ka",3,2, 2*tstop,0,2)
gk.addexpr("minf_ka",3,2, 2*tstop,0,2)

gt = new Graph(0)
gt.view(vlow,0,vhigh-vlow,30,0,0,100,200)
gt.exec_menu("New Axis")
gt.exec_menu("10% Zoom out")
gt.label(0.1,0.9,"time constants (ms)")
gt.addexpr("mtau_kdrf/mfac",1,2, 2*tstop,0,2)
gt.addexpr("mtau_kdrs/msfac",2,2, 2*tstop,0,2)
gt.addexpr("htau_ka",3,2, 2*tstop,0,2)

xpanel("")
xbutton("run ", "run()")
xpanel()
b.intercept(0)
b.map("K kinetics for hipp. interneurons",100,0,200,400)

c.intercept(1)
gs = new Graph(0)
gs.view(0,0,tstop,25,0,0,100,200)
gs.exec_menu("New Axis")
gs.exec_menu("10% Zoom out")
gs.label(0.35,0.95,"fast KDR (pA)")
gs.label(0.2,0.9,"(protocol as in Fig.5A)")
gs.exec_menu("Keep Lines")

gf = new Graph(0)
gf.view(0,0,tstop,25,0,0,100,200)
gf.exec_menu("New Axis")
gf.exec_menu("10% Zoom out")
gf.label(0.35,0.95,"slow KDR (pA)")
gf.label(0.2,0.9,"(protocol as in Fig.6A)")
gf.exec_menu("Keep Lines")

ga = new Graph(0)
ga.view(0,0,tstop,25,0,0,100,200)
ga.exec_menu("New Axis")
ga.exec_menu("10% Zoom out")
ga.label(0.35,0.95,"KA (pA)")
ga.label(0.2,0.9,"(protocol as in Fig.7A)")
ga.exec_menu("Keep Lines")

c.intercept(0)
c.map("activation",450,0,200,600)

vc = new SEClamp(0.5)

proc run() {
gk.begin()
gk.color(1)
gk.label(0.65,0.5,"fast KDR")
gk.color(2)
gk.label(0.65,0.45,"slow KDR")
gk.color(3)
gk.label(0.65,0.4,"KA")
for (v=vlow; v<vhigh; v=v+1) {
    trates_kdrf(v)
    trates_kdrs(v)
    trates_ka(v)
    gk.plot(v)
}
gk.flush()
doNotify()

gt.begin()
gt.mark(-10,18.7/msfac,"+",12,5,2)
gt.mark(70,6.7/msfac,"+",12,5,2)
gt.mark(-40,21/msfac,"+",12,5,2)
gt.mark(0,10/msfac,"+",12,5,2)
gt.mark(-40,11.1/mfac,"+",12,6,2)
gt.mark(-10,11.6/mfac,"+",12,6,2)
gt.mark(70,0.8/mfac,"+",12,6,2)
gt.mark(60,25,"O",9,7,2)
gt.mark(30,20,"O",9,7,2)
gt.mark(-20,14,"O",9,7,2)
gt.color(1)
gt.label(0.02,0.6,"fast KDR")
gt.color(2)
gt.label(0.02,0.55,"slow KDR")
gt.color(3)
gt.label(0.02,0.5,"KA inact.")
for (v=vlow; v<vhigh; v=v+1) {
    trates_kdrf(v)
    trates_kdrs(v)
    trates_ka(v)
    gt.plot(v)
}
gt.flush()
doNotify()

gbar_kdrs=0.0
gbar_kdrf=0.0002
gbar_ka=0.0

gs.begin()
k=-30
color=1
while (k<71) {
gs.addexpr("ik*area(0.5)*10",color,1, 2*tstop,0,2) // *10=pA, *1e-2=nA
t=0
vc.amp1=-90
vc.dur1=0.2
vc.amp2=k
vc.dur2=tstop
forall {finitialize(vc.amp1)}
while (t<tstop) {
    fadvance()
    gs.plot(t)
    }
gs.flush()
doNotify()
k=k+10
//color=color+1
gs.begin()
}

vc.dur1=0
vc.dur2=0
vc.dur3=0

gbar_kdrs=0.0002
gbar_kdrf=0.0
gbar_ka=0.0

gf.begin()
k=-30
color=1
while (k<71) {
gf.addexpr("ik*area(0.5)*10",color,1, 2*tstop,0,2) // *10=pA, *1e-2=nA
t=0
vc.amp1=-90
vc.dur1=0.2
vc.amp2=k
vc.dur2=tstop
forall {finitialize(vc.amp1)}
while (t<tstop) {
    fadvance()
    gf.plot(t)
    }
gf.flush()
doNotify()
k=k+10
//color=color+1
gf.begin()
}
vc.dur1=0
vc.dur2=0
vc.dur3=0

gbar_kdrs=0.0
gbar_kdrf=0.0
gbar_ka=0.0002

ga.begin()
k=-30
color=1
while (k<71) {
ga.addexpr("ik*area(0.5)*10",color,1, 2*tstop,0,2) // *10=pA, *1e-2=nA
t=0
vc.amp1=-90
vc.dur1=0.2
vc.amp2=k
vc.dur2=tstop
forall {finitialize(vc.amp1)}
while (t<tstop) {
    fadvance()
    ga.plot(t)
    }
ga.flush()
doNotify()
k=k+10
//color=color+1
ga.begin()
}
vc.dur1=0
vc.dur2=0
vc.dur3=0

}