load_file("nrngui.hoc")
load_file("cell_seed_150218A2.hoc")
cvode_active(1)
objref testcell, stim, stim2, apc, v1
testcell = new CA1_pyr_mouse_epfl() 



testcell.init()

celsius=34 

proc distribute_distance(){local x localobj sl
  strdef stmp, distfunc, mech

  sl = $o1
  mech = $s2
  distfunc = $s3
  testcell.soma[0] distance(0, 0.5)
  sprint(distfunc, "%%s %s(%%f) = %s", mech, distfunc)
  forsec sl for(x, 0) {
  sprint(stmp, distfunc, secname(), x, distance(x))
  execute(stmp)
  }
}

proc value() {
	valuehd= 3.6167305226029524e-05
	valuekad= 0.0080020254556537225
	valuekdb= 4.1348020273088422e-06
}


value()

proc def(){ 
	
//******AXON************
gpasall=testcell.axon.g_pas
epasall=testcell.axon.e_pas
Raall=testcell.axon.Ra
kdr_ax=testcell.axon.gkdrbar_kdr
nax_ax=testcell.axon.gbar_nax    
kap_ax=testcell.axon.gkabar_kap
kmb_ax=testcell.axon.gbar_kmb   
	
//******DEND-BASAL************
gpasall=testcell.dend.g_pas
epasall=testcell.dend.e_pas
Raall=testcell.dend.Ra
kdr_allnoax=testcell.dend.gkdrbar_kdr
na3_dend=testcell.dend.gbar_na3
can_allnoax=testcell.dend.gcanbar_can
cal_allnoax=testcell.dend.gcalbar_cal
cat_allnoax=testcell.dend.gcatbar_cat
kca_allnoax=testcell.dend.gbar_kca  			
cagk_allnoax=testcell.dend.gbar_cagk
hd_allnoax=testcell.dend.ghdbar_hdpas

//******DEND-APICAL************
gpasall=testcell.apic.g_pas
epasall=testcell.apic.e_pas
Raall=testcell.apic.Ra
kdr_allnoax=testcell.apic.gkdrbar_kdr
na3_apic=testcell.apic.gbar_na3
can_allnoax=testcell.apic.gcanbar_can
cal_allnoax=testcell.apic.gcalbar_cal
cat_allnoax=testcell.apic.gcatbar_cat
kca_allnoax=testcell.apic.gbar_kca  			
cagk_allnoax=testcell.apic.gbar_cagk
hd_allnoax=testcell.apic.ghdbar_hdpas
	
//**********SOMA********
gpasall=testcell.soma.g_pas
epasall=testcell.soma.e_pas
Raall=testcell.soma.Ra
kdr_allnoax=testcell.soma.gkdrbar_kdr
na3_soma=testcell.soma.gbar_na3
kap_soma=testcell.soma.gkabar_kap 
kmb_soma=testcell.soma.gbar_kmb
kdb_soma=testcell.soma.gkdbar_kdbm
hd_soma=testcell.soma.ghdbar_hdpas
can_allnoax=testcell.soma.gcanbar_can
cal_allnoax=testcell.soma.gcalbar_cal
cat_allnoax=testcell.soma.gcatbar_cat
kca_allnoax=testcell.soma.gbar_kca  			
cagk_allnoax=testcell.soma.gbar_cagk

}
//********************************************

Vrest=-70
proc init() {

  t=0
  
  finitialize(Vrest)

	forall {
		v = Vrest
		if(ismembrane("nax") || ismembrane("na3")) {
			ena=50
		}
		if(ismembrane("kdr") || ismembrane("kap") || ismembrane("kad") || ismembrane("kmb") || ismembrane("kir") || ismembrane("kdbm")) {
			ek=-90
		}
	}

	finitialize(Vrest)
	fcurrent()
	cvode.re_init()

}



def()
init() 
proc biophysint() {

forsec testcell.axonal {  

	g_pas = gpasall
    e_pas = epasall
	Ra = Raall
	gkdrbar_kdr = kdr_ax
	gbar_nax = nax_ax
	gkabar_kap = kap_ax
	gbar_kmb=kmb_ax
}

forsec testcell.basal {
	
	g_pas = gpasall
	e_pas = epasall
    Ra = Raall
	gkdrbar_kdr = kdr_allnoax
	gbar_na3 = na3_dend
	gcanbar_can = can_allnoax 
	gcalbar_cal = cal_allnoax 	
	gcatbar_cat= cat_allnoax
	gbar_kca = kca_allnoax
	gbar_cagk = cagk_allnoax
}

forsec testcell.apical {
	
	g_pas = gpasall
	e_pas = epasall
    Ra = Raall
	gkdrbar_kdr = kdr_allnoax
	gbar_na3 = na3_apic
	gcanbar_can = can_allnoax 
	gcalbar_cal = cal_allnoax 	
	gcatbar_cat= cat_allnoax
	gbar_kca = kca_allnoax
	gbar_cagk = cagk_allnoax
}
  
forsec testcell.somatic {
	
	Ra = Raall
    g_pas = gpasall
	e_pas = epasall
	gkdrbar_kdr= kdr_allnoax
	gbar_na3=na3_soma
	gkabar_kap=kap_soma
	gbar_kmb=kmb_soma
	gkdbar_kdbm=kdb_soma
	ghdbar_hdpas=hd_soma
	gcanbar_can= can_allnoax
	gcalbar_cal= cal_allnoax
	gcatbar_cat= cat_allnoax
	ghdbar_kca=kca_allnoax
	gbar_cagk=cagk_allnoax
}
  
  distribute_distance(testcell.apical, "gkdbar_kdbm", "(15./(1. + exp((%.17g-50)/50)))*valuekdb")
  distribute_distance(testcell.apical, "ghdbar_hdpas", "(1. + 3./100. * %.17g)*valuehd")
  distribute_distance(testcell.apical, "gkabar_kad", "(15./(1. + exp((150-%.17g)/10)))*valuekad")
  distribute_distance(testcell.basal, "ghdbar_hdpas", "(1. + 3./100. * %.17g)*valuehd")
  distribute_distance(testcell.basal, "gkabar_kad", "(15./(1. + exp((150-%.17g)/10)))*valuekad")
  
}
  


proc rest() {
testcell.biophys()
def()
//biophysint()
print "reset"
}


access testcell.soma

	
testcell.soma {
stim = new IClamp(0.5)
stim.del=250
stim.dur=188
stim.amp=0.52
}
testcell.soma {
stim2 = new IClamp(0.5)
stim2.del=0
stim2.dur=600
stim2.amp=-0.10526400059461594
}
testcell.soma {
apc = new APCount(0.5)
apc.thresh = -20
v1 = new Vector()
apc.record(v1)
}

xpanel("values")
xvalue("gpasall")
xvalue("epasall")
xvalue("Raall")
xvalue("nax_ax")
xvalue("na3_soma")
xvalue("na3_apic")
xvalue("na3_dend")
xvalue("kdr_ax")
xvalue("kdr_allnoax")
xvalue("kap_ax")
xvalue("kap_soma")
xvalue("valuekad")
xvalue("kmb_soma")
xvalue("kmb_ax")
xvalue("kdb_soma")
xvalue("valuekdb")
xvalue("hd_soma")
xvalue("valuehd")
xvalue("cal_allnoax") 
xvalue("can_allnoax")
xvalue("cat_allnoax")
xvalue("kca_allnoax")
xvalue("cagk_allnoax")
xpanel()

xpanel("set")
xbutton("set cond", "biophysint()")
xbutton("reset", "rest()")
xpanel()

xpanel("protocols")
xbutton("0.52", "stim.amp=0.52")
xbutton("0.44", "stim.amp=0.44")
xbutton("0.36", "stim.amp=0.36")
xbutton("0.28", "stim.amp=0.28")
xbutton("0.20", "stim.amp=0.20")
xbutton("0.12", "stim.amp=0.12")
xbutton("-0.085", "stim.amp=-0.085")
xbutton("-0.160", "stim.amp=-0.160")
xbutton("-0.240", "stim.amp=-0.240")
xbutton("-0.320", "stim.amp=-0.320")
xpanel()

load_file("panel.ses")