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

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

a0m_kasup=0.75
vhalfm_kasup=-60
zetam_kasup=0.03
gmm_kasup=0.5

a0h_kasup=0.033
vhalfh_kasup=40
zetah_kasup=0.01
gmh_kasup=0.8

a0m_kdrsup=0.018
vhalfm_kdrsup=-45
zetam_kdrsup=0.1
gmm_kdrsup=0.75

mtfac=1
htfac=15
drfac=25

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.5B-7C-10B: steady-states")
gk.addexpr("minf_kasup",3,2, 2*tstop,0,2)
gk.addexpr("hinf_kasup",2,2, 2*tstop,0,2)
gk.addexpr("minf_kdrsup",1,2, 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,"time constants (scale in ms)")
gt.addexpr("mtau_kasup/mtfac",3,2, 2*tstop,0,2)
gt.addexpr("htau_kasup/htfac",2,2, 2*tstop,0,2)
gt.addexpr("mtau_kdrsup/drfac",1,2, 2*tstop,0,2)

xpanel("")
xbutton("run ", "run()")
xpanel()
b.intercept(0)
b.map("K-A and K-DR for superficial neocortical neurons",100,0,200,400)

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

gf = new Graph(0)
gf.view(0,0,100,15,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), protocol as in Fig.10A")
gf.exec_menu("Keep Lines")

c.intercept(0)
c.map("currents",390,0,500,370)

vc = new SEClamp(0.5)

proc run() {
gk.begin()
gk.color(1)
gk.label(0.6,0.2,"K-DR act.")
for (v=vlow; v<vhigh; v=v+1) {
    trates_kasup(v)
    trates_kdrsup(v)
    gk.plot(v)
}
gk.flush()
doNotify()

gt.begin()
gt.mark(-30,0.6/mtfac,"+",12,5,2)
gt.mark(-20,0.51/mtfac,"+",12,5,2)
gt.mark(-10,0.5/mtfac,"+",12,5,2)
gt.mark(0,0.42/mtfac,"+",12,5,2)
gt.mark(10,0.42/mtfac,"+",12,5,2)
gt.mark(20,0.35/mtfac,"+",12,5,2)
gt.mark(30,0.31/mtfac,"+",12,5,2)
gt.mark(-30,12/htfac,"+",12,6,2)
gt.mark(-20,12.5/htfac,"+",12,6,2)
gt.mark(-10,13/htfac,"+",12,6,2)
gt.mark(0,13/htfac,"+",12,6,2)
gt.mark(10,13.3/htfac,"+",12,6,2)
gt.mark(20,14/htfac,"+",12,6,2)
gt.mark(30,15/htfac,"+",12,6,2)
gt.mark(0,17.5/drfac,"+",12,7,2)
gt.mark(10,15/drfac,"+",12,7,2)
gt.mark(20,11/drfac,"+",12,7,2)
gt.mark(30,8/drfac,"+",12,7,2)
gt.color(1)
gt.label(0.55,0.2,"DR act./25")
gt.color(2)
gt.label(0.25,0.2,"A inact./15")
for (v=vlow; v<vhigh; v=v+1) {
    trates_kasup(v)
    trates_kdrsup(v)
    gt.plot(v)
}
gt.flush()
doNotify()

gbar_kasup=0.0002
gbar_kdrsup=0.0

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

gbar_kasup=0.0
gbar_kdrsup=0.0002

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