create a
a {nseg=1 diam=5 L=10 
	insert kf ek=-21  // 65mM K+ in the bath
	insert ks ek=-21  // 65 mM K+ in the bath
	insert pas g_pas=1/12000 Ra=150 cm=1}
access a

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

objref gk, b,gt,vc, gs,c, gf
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,"fast K+ current: figs. 4A,4C,5D,5E")
gk.addvar("linf_kf",2,2, 2*tstop,0,2)
gk.addexpr("taul_kf/60",2,1, 2*tstop,0,2)
gk.addexpr("ninf_kf^4",3,2, 2*tstop,0,2)
gk.addexpr("taun_kf/1.5",3,1, 2*tstop,0,2)

gt = new Graph(0)
gt.view(vlow,0,vhigh-vlow,1,0,0,100,200)
gt.exec_menu("New Axis")
gt.exec_menu("10% Zoom out")
gt.label(0.1,0.9,"slow K+ current: figs. 7A,7C,8C,8D")
gt.addvar("linf_ks",2,2, 2*tstop,0,2)
gt.addexpr("taul_ks/1500",2,1, 2*tstop,0,2)
gt.addexpr("ninf_ks^2",3,2, 2*tstop,0,2)
gt.addexpr("taun_ks/50",3,1, 2*tstop,0,2)

xpanel("")
xbutton("run ", "run()")
xpanel()
b.intercept(0)
b.map("kinetics from Korngreen and Sakmann (2000)",100,0,200,400)

c.intercept(1)
gf = new Graph(0)
gf.view(50,-60,5,180,0,0,100,100)
gf.exec_menu("New Axis")
gf.exec_menu("10% Zoom out")
gf.label(0.2,0.95,"Fig.4B fast current (pA)")
gf.label(0.15,0.9,"activation and deactivation")

gs = new Graph(0)
gs.view(400,-150,50,300,0,0,100,100)
gs.exec_menu("New Axis")
gs.exec_menu("10% Zoom out")
gs.label(0.2,0.95,"Fig.7B slow current (pA)")
gs.label(0.15,0.9,"activation and deactivation")
c.intercept(0)
c.map("activation and deactivation",390,0,200,370)


vc = new SEClamp(0.5)

proc run() {
gk.begin()
gk.color(3)
gk.label(0.65,0.6,"n^4")
gk.label(0.7,0.35,"tau_n / 1.5")
gk.color(2)
gk.label(0.1,0.82,"l")
gk.label(0.12,0.3,"tau_l / 60")
for (v=vlow; v<vhigh; v=v+1) {
    rates_kf(v)
    gk.plot(v)
}
gk.flush()
doNotify()

gt.begin()
gt.color(3)
gt.label(0.7,0.75,"n^2")
gt.label(0.7,0.25,"tau_n / 50")
gt.color(2)
gt.label(0.1,0.82,"l")
gt.label(0.7,0.35,"tau_l / 1500")
for (v=vlow; v<vhigh; v=v+1) {
    rates_ks(v)
    gt.plot(v)
}
gt.flush()
doNotify()

gkbar_kf=0.001
gkbar_ks=0.0
vc.amp1=-110
vc.dur1=50
vc.amp2=80
vc.dur2=2
vc.amp3=-120
vc.dur3=tstop
finitialize(-110)
fcurrent()
gf.addexpr("10*ik*area(0.5)",2,1, 2*tstop,0,2) // *10=pA
gf.begin()
t=0
while (t<tstop) {
    fadvance()
    gf.plot(t)
    }
gf.flush()
doNotify()

gkbar_kf=0.0
gkbar_ks=0.001
tstop=450
vc.amp1=-110
vc.dur1=400
vc.amp2=80
vc.dur2=20
vc.amp3=-120
vc.dur3=tstop
finitialize(-110)
fcurrent()
gs.addexpr("10*ik*area(0.5)",2,1, 2*tstop,0,2) // *10=pA
gs.begin()
t=0
while (t<tstop) {
    fadvance()
    gs.plot(t)
    }
gs.flush()
doNotify()
}