load_file("nrngui.hoc")
load_file("mitral-lss.hoc")
load_file("gc-ka.hoc")
cvode.active(0)

Vrest = -65
dt = 1
celsius=35
tstop=2000

objref nconp[3], net, netp[3], g, b, nil, stim, stim2
objref mt[3], gc[3] 
objref nc[27]

for i=0, 1 {
mt[i] = new Mitral()
gc[i] = new GC()
}

weight=.1
amp=.03
rel=0.2
inh=0.4
synstr=3
nmdafactor=0.0035
frac=1

mt[0].soma {
stim = new IClamp(.5)
stim.amp=0.15
stim.dur=tstop
stim.del=2
}
mt[1].soma {
stim2 = new IClamp(.5)
stim2.amp=0.15
stim2.dur=tstop
stim2.del=30
}

temp=100
flag=0
b = new VBox()
b.intercept(1)
g = new Graph()
g.size(0,tstop,-70,0)
g.xaxis(1)
g.addvar("mt[0].soma.v(0.5)",1,1,0.7,1,2)
g.addvar("mt[1].soma.v(0.5)",2,1,0.7,0.98,2)
g.exec_menu("10% Zoom out")
xpanel("",1)
xbutton("run", "run()")
xstatebutton("with GCs",&flag, "runm()")
xpanel()
b.intercept(0)
b.map()


////////////////// circuit definition  

///// gc <-> mt

mt[0].secden[1]	nc[16]= new NetCon(&v(0.8),gc[1].synmt[2],-40,1,synstr*nmdafactor) 
mt[0].secden[1]	nc[17]= new NetCon(&v(0.8),gc[1].sampa[2],-40,1,synstr*1e-3) 

mt[1].secden[0]	nc[7]= new NetCon(&v(0.8),gc[0].synmt[2],-40,1,synstr*nmdafactor) 
mt[1].secden[0]	nc[8]= new NetCon(&v(0.8),gc[0].sampa[2],-40,1,synstr*1e-3) 

gc[0].dend[0]	nc[0]= new NetCon(&v(1),mt[0].igp[1][0],-40,1,inh*1e-3) 
gc[1].dend[0]	nc[9]= new NetCon(&v(1),mt[1].igp[1][0],-40,1,inh*1e-3) 

////////////////// end circuit definition

proc init() {
	t=0
	finitialize(Vrest)
        fcurrent()
        forall {
		v=Vrest
		if (ismembrane("nax")) {e_pas=v+(ina+ik)/g_pas
		} else {
		e_pas=v+ik/g_pas
		}
	}
	nc[0].weight=flag*inh*1e-3
	nc[9].weight=flag*inh*1e-3
	cvode.re_init()
	cvode.event(500, "act()")
	g.begin()
	g.plot(t)
}

proc advance() {
	fadvance()
	g.plot(t)
	g.flush()
	doNotify()
}

proc runm() {
	nc[0].weight=flag*inh*1e-3
	nc[9].weight=flag*inh*1e-3
}

proc act() {
flag=1
nc[0].weight=flag*inh*1e-3
nc[9].weight=flag*inh*1e-3
}