load_file("nrngui.hoc")
create a
a	{nseg=1 diam=20 L=20 
	insert htc eh_htc=-47 
	insert pas g_pas=1/10000 Ra=150 cm=1}
access a

tstop=500
vlow=-110
vhigh=-40
dt=0.1
celsius=36
color=1

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-state, Fig.2A")
gk.addexpr("linf_htc",1,2, 2*tstop,0,2)

gt = new Graph(0)
gt.view(vlow,0,vhigh-vlow,1000,0,0,100,200)
gt.exec_menu("New Axis")
gt.exec_menu("10% Zoom out")
gt.label(0.1,0.9,"Time constant, Fig.3A")
gt.addexpr("taul_htc",2,2, 2*tstop,0,2)

gs = new Graph(0)
gs.view(0,-120,tstop,50,0,0,100,200)
gs.exec_menu("New Axis")
gs.exec_menu("10% Zoom out")
gs.label(0.1,0.9,"Example of current injection")
gs.exec_menu("Keep Lines")

xpanel("")
xbutton("run ", "run()")
xpanel()
b.intercept(0)
b.map("kinetics from McCormick and Pape (1990)",100,0,200,600)

c.intercept(1)
gf = new Graph(0)
gf.view(0,-200,3000,210,0,0,100,100)
gf.exec_menu("New Axis")
gf.exec_menu("10% Zoom out")
gf.label(0.3,0.95,"Voltage-clamp; steps from -59mV (Fig.2B)")
gf.exec_menu("Keep Lines")
c.intercept(0)
c.map("activation and deactivation",435,0,500,360)

vc = new SEClamp(0.5)
ic= new IClamp(0.5)

proc run() {
gk.begin()
for (v=vlow; v<vhigh; v=v+1) {
    rate_htc(v)
    gk.plot(v)
}
gk.flush()
doNotify()

gt.begin()
for (v=vlow; v<vhigh; v=v+1) {
    rate_htc(v)
    gt.plot(v)
}
gt.flush()
doNotify()

gs.addexpr("a.v(0.5)",3,1, 2*tstop,0,2)

gs.begin()
tstop=500
ic.del=2
ic.dur=tstop
ic.amp=-0.05
t=0
v=-70
finitialize(v)
fcurrent()
e_pas=v+(i_htc)/g_pas
while (t<tstop) {
    fadvance()
    gs.plot(t)
    }
gs.flush()
doNotify()
ic.amp=0


gf.addexpr("i_htc*area(0.5)*10",2 ,1, 2*tstop,0,2) // *10=pA, *1e-2=nA
ghbar_htc=0.0004
tstop=3100
k=-49
while (k>=-91) {
t=0
vc.amp1=-59
vc.dur1=100
vc.amp2=k
vc.dur2=2000
vc.amp3=-59
vc.dur3=1000
forall {finitialize(-59)}
fcurrent()
while (t<tstop) {
    fadvance()
    gf.plot(t)
    }
gf.flush()
doNotify()
k=k-5
gf.begin()
}
vc.dur1=0
vc.dur2=0
vc.dur3=0
}