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

celsius=22
tstop=100
vlow=-120
vhigh=40
dt=0.01

mtfac=1
htfac=10
drfac=20

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,"Figs.8B: steady-states")
gk.addexpr("minf_kamot",3,2, 2*tstop,0,2)
gk.addexpr("minf_kdrmot",1,2, 2*tstop,0,2)
gk.addexpr("hinf_kamot",2,2, 2*tstop,0,2)

gt = new Graph(0)
gt.view(vlow,0,vhigh-vlow,8,0,0,100,200)
gt.exec_menu("New Axis")
gt.exec_menu("10% Zoom out")
gt.label(0.1,0.9,"time constants (scale in ms)")
gt.addexpr("mtau_kamot/mtfac",3,2, 2*tstop,0,2)
gt.addexpr("mtau_kdrmot/drfac",1,2, 2*tstop,0,2)
gt.addexpr("htau_kamot/htfac",2,2, 2*tstop,0,2)

xpanel("")
xbutton("run ", "run()")
xpanel()
b.intercept(0)
b.map("K+ kinetics for rat motoneuron",100,0,200,400)

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

gf = new Graph(0)
gf.view(0,0,tstop,5,0,0,100,200)
gf.exec_menu("New Axis")
gf.exec_menu("10% Zoom out")
gf.label(0.1,0.9,"K-DR activation (pA), Fig.6B (middle)")
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()
for (v=vlow; v<vhigh; v=v+1) {
    trates_kamot(v)
    trates_kdrmot(v)
    gk.plot(v)
}
gk.flush()
doNotify()

gt.begin()
gt.mark(-110,1.5/mtfac,"o",6,3,2)
gt.mark(-60,6.3/mtfac,"o",6,3,2)
gt.mark(-70,6.5/mtfac,"o",6,3,2)
gt.mark(-80,4.9/mtfac,"o",6,3,2)
gt.mark(-90,4/mtfac,"o",6,3,2)
gt.mark(-100,2.9/mtfac,"o",6,3,2)
gt.mark(-110,5.9/drfac,"o",6,1,2)
gt.mark(-60,60.3/drfac,"o",6,1,2)
gt.mark(-70,32/drfac,"o",6,1,2)
gt.mark(-80,22/drfac,"o",6,1,2)
gt.mark(-90,18/drfac,"o",6,1,2)
gt.mark(-100,13/drfac,"o",6,1,2)
gt.color(2)
gt.label(0.1,0.8,"A_inact./10")
gt.color(3)
gt.label(0.72,0.3,"A_act.")
gt.color(1)
gt.label(0.33,0.18,"DR_act./20")
for (v=vlow; v<vhigh; v=v+1) {
    trates_kamot(v)
    trates_kdrmot(v)
    gt.plot(v)
}
gt.flush()
doNotify()

gbar_kamot=0.0001
gbar_kdrmot=0.0
gs.color(1)
gs.label(0.4,0.5,"-20")
gs.color(2)
gs.label(0.4,0.55,"+10")

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

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

gbar_kamot=0.0
gbar_kdrmot=0.00005
gf.color(1)
gf.label(0.6,0.53,"-20")
gf.color(2)
gf.label(0.6,0.75,"+10")

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