load_file("nrngui.hoc")
cvode.active(1)
cvode.atol(1e-3)
// ************* NEURON A **********

FARADAY=96520
PI=3.14159
secondorder=2
dt=0.025
celsius=30
strdef title
flagl=0

xopen("ca3a.geo")

objref g, b,c
b = new VBox()
b.intercept(1)
g = new Graph()
c = new HBox()
c.intercept(1)
xpanel("",1)
xbutton("run burst", "runb()")
xbutton("run no-burst short", "runnbs()")
xbutton("run no-burst long", "runnbl()")
xpanel()
c.intercept(0)
c.map()
b.intercept(0)
b.map()


proc conductances() {
        forall {
                insert pas e_pas=-65 g_pas=1/60000 Ra=200
                insert cadifus
                insert cal  gcalbar_cal=0.0025
                insert can  gcanbar_can=0.0025
                insert cat  gcatbar_cat=0.00025
                insert kahp gkahpbar_kahp=0.0004
                insert cagk gkbar_cagk=0.00055
        }

        soma {
                insert nahh    gnabar_nahh=gna
                insert borgkdr gkdrbar_borgkdr=gkdr
                insert borgka  gkabar_borgka=gka
                insert borgkm  gkmbar_borgkm=gkm
        }
                
        for i=0,1 dend2[i] {
                insert nahh    gnabar_nahh=gna
                insert borgkdr gkdrbar_borgkdr=gkdr
                insert borgka  gkabar_borgka=gka
                insert borgkm  gkmbar_borgkm=gkm
        }
        for i=0,2 dend3[i] {
                insert nahh    gnabar_nahh=gna   
                insert borgkdr gkdrbar_borgkdr=gkdr
                insert borgka  gkabar_borgka=gka
                insert borgkm  gkmbar_borgkm=gkm
        }
                
        for i=37,38 dend3[i] {
                insert nahh    gnabar_nahh=gna   
                insert borgkdr gkdrbar_borgkdr=gkdr
                insert borgka  gkabar_borgka=gka
                insert borgkm  gkmbar_borgkm=gkm
        }

}

access soma
distance()
proc init() {

	t=0
        coord_cadifus()
        forall {
        cao=2
        cai=50.e-6
        ek=-91
        v=-65
        if (ismembrane("nahh")) {ena=50}
}

	finitialize(v)
        fcurrent()

        forall {
	if (ismembrane("nahh")) {e_pas=v+(ina+ik+ica)/g_pas} else {e_pas=v+(ik+ica)/g_pas}
		}
	cvode.re_init()
    }

proc step() {

	fadvance()
g.plot(t)
g.flush()
doNotify()

}


proc run() {

        nstim=1
        fstim(nstim)
        fstim(0, 0.5, 2, tstim, strength)
	init()
	while(t<tstop) { step() flushPlot()}

}

proc runb() {

	strength = 1.0	/*namps*/
	tstim = 3
	tstop=50
	gna=0.015
	gkdr=0.009
	gka=0.0001
	gkm=0.00002
	conductances()
g.erase_all()
g.size(0,tstop,-70,30)
g.addexpr("gkmbar_borgkm*m_borgkm(0.5)*5.e5",2,2,2*tstop,0,2)
g.addexpr("gkca_cagk(0.5)*5e5",7,2,2*tstop,0,2)
g.addexpr("(cai-50e-6)*2.e6",3,2,2*tstop,0,2)
g.addexpr("gka_borgka(0.5)*5e5",4,2,2*tstop,0,2)
g.addvar("soma.v(0.5)",1,1, 2*tstop,0,2)
// g.addvar("dend10[2].v(0.5)",5,1, 2*tstop,0,2)
g.color(1)
g.label(0.2,0.15,"somatic current injection 1nA, 3ms ")
g.color(2)
g.label(0.7,0.5,"gKM")
g.color(7)
g.label(0.7,0.35,"gKCa")
g.color(3)
g.label(0.7,0.3,"[Ca]i (nM*2)")
g.color(4)
g.label(0.7,0.45,"gKA")
// g.color(5)
// g.label(0.7,0.55,"dend10[2].v(0.5)")
g.xaxis(1)
g.begin()
run()
}

proc runnb() {
	gna=0.015
	gkdr=0.03
	gka=0.001
	gkm=0.0001
	conductances()
g.erase_all()
g.size(0,tstop,-70,30)
g.addexpr("gkmbar_borgkm*m_borgkm(0.5)*5.e5",2,2,2*tstop,0,2)
g.addexpr("gkca_cagk(0.5)*5e5",4,2,2*tstop,0,2)
g.addexpr("(cai-50e-6)*2.e6",3,2,2*tstop,0,2)
g.addexpr("gka_borgka(0.5)*5e5",7,2,2*tstop,0,2)
g.addvar("soma.v(0.5)",1,1, 2*tstop,0,2)
g.addvar("dend10[2].v(0.5)",5,1, 2*tstop,0,2)
g.color(1)
g.label(0.2,0.05,title)
g.color(2)
g.label(0.8,0.5,"gKM")
g.color(4)
g.label(0.8,0.45,"gKCa")
g.color(3)
g.label(0.8,0.3,"[Ca]i (nM*2)")
g.color(7)
g.label(0.8,0.4,"gKA")
// g.color(5)
// g.label(0.7,0.55,"dend10[2].v(0.5)")
g.xaxis(1)
g.begin()
run()
}

proc runnbs() {
title = "somatic current injection 1nA, 3ms"
strength = 1.0	/*namps*/
tstim = 3
tstop=50
runnb()
}
proc runnbl() {
title = "somatic current injection 0.15nA, 250ms"
strength = 0.15	/*namps*/
tstim = 250
tstop=250
runnb()
}