load_file("nrngui.hoc")
cvode_active(1)
load_file("geo5038804.hoc")
numbasal  = 52
numapical = 70
numuser5  = 49
objref stim0, stim1, stim2, stim3, stim4, stim5, ncstim, syn, syn2, nc0, nc1, nc2, nc3, nc4


load_file("biophysPLAST.hoc")
//load_file("synapses.hoc")
load_file("efheader.hoc")



tstop=10000

proc init() {

  t=0

  
  finitialize(Vrest)

	forall {
		v = Vrest
		if(ismembrane("nax") || ismembrane("na3")) {
			ena=55
		}
		if(ismembrane("kdr") || ismembrane("kap") || ismembrane("kad")) {
			ek=-90
		}
		if(ismembrane("hd")) {
			ehd_hd=-30
		}
	}

	finitialize(Vrest)
	fcurrent()

	forall {
		for(x) {
			if(ismembrane("na3") || ismembrane("nax")) {
				e_pas(x)=v(x)+(ina(x)+ik(x))/g_pas(x)
			}
			if(ismembrane("hd")) {
				e_pas(x)=e_pas(x)+i_hd(x)/g_pas(x)
			}
		}
	}

	/*for i = 0, nsyn-1 {
  		st[i].seed(114)
	}
*/
}

soma {

stim0= new NetStim(.5)
stim0.number=1
stim0.interval=10
stim0.start=10

stim1= new NetStim(.5)
stim1.number=50
stim1.interval=200
stim1.start=500

stim2 = new NetStim(.5)
stim2.number =4
stim2.interval =10
stim2.start =1000

ncstim = new NetCon(stim1, stim2, 0, 0, 0.001)

stim3= new NetStim(.5)
stim3.number =1
stim3.interval =10
stim3.start =1500
}

apical_dendrite[29] {

stim4= new NetStim(0.5)
stim4.number=1
stim4.interval=10
stim4.start=500

stim5= new NetStim(0.5)
stim5.number=1
stim5.interval=10
stim5.start=16000

}


apical_dendrite[27]{
syn= new giada2TBS(.5)
}

nc0= new NetCon(stim0, syn, 0, 0, 10e-3)
nc1 = new NetCon(stim2, syn, 0, 0, 10e-3)
nc2= new NetCon(stim3, syn, 0, 0, 10e-3)

apical_dendrite[29]{
syn2= new giada2TBS(0.5)
}


nc3= new NetCon(stim4, syn2, 0, 0, 1e-3)
nc4= new NetCon(stim5, syn2, 0, 0, 1e-3)

load_file("voltage.ses")
//load_file("heter.ses")
objref vp
vp = save_window_
vp.exec_menu("Keep Lines")
proc sim() {
  vp.erase_all()

	vp.label(0.949956, 0.931495, "no EF", 2, 1, 0, 0, 1)
	vp.label(0.950834, 0.878114, "EF", 2, 1, 0, 0, 2)
  vp.brush(2)
  vp.color(1)
  vp.addvar("", "v(0.5)")
  setstim(50, 6000, 50, 50, 0)
  changefield(100, 90, 90)
  run()

  vp.color(2)
  vp.addexpr("", "v(0.5)")
  setstim(50, 6000, 50, 50, 40)
  changefield(100, 90, 90)
  run()

}


xpanel("electric field sim")
xbutton("Run sims", "sim()")
xpanel(255,672)