load_file("nrngui.hoc")
load_file("cell_seed4_0_v4.hoc")
cvode_active(1) 

objref testcell, stim
testcell = new Stellate_ventEC() 

testcell.init()

celsius=32 //EG

proc def(){ 
	
//******AXON************
gpasax=testcell.axon.g_pas
epasax=testcell.axon.e_pas
RaAx=testcell.axon.Ra
kdr_ax=testcell.axon.gkdrbar_kdr //ok
nax_ax=testcell.axon.gbar_nax    //ok
kap_ax=testcell.axon.gkabar_kap //ok
napIn_ax=testcell.axon.gbar_napIn   //ok 
kmb_ax=testcell.axon.gbar_kmb   
//ih_ax=testcell.axon.gihbar_ih  
 	
//******DEND-BASAL************
gpasallnoax=testcell.dend.g_pas
epasallnoax=testcell.dend.e_pas
Raallnoax=testcell.dend.Ra
kdr_dend=testcell.dend.gkdrbar_kdr
nax_dend=testcell.dend.gbar_nax
kap_dend=testcell.dend.gkabar_kap //remove
//kad_dend=testcell.dend.gkabar_kad
//ih_fast_dend=testcell.dend.gfastbar_ih 
//ih_slow_dend=testcell.dend.gslowbar_ih  
hd_dend=testcell.dend.ghdbar_hd 
//can_dend=testcell.dend.gcanbar_can
//cal_dend=testcell.dend.gcalbar_cal
//catb_allnoax=testcell.dend.gcatbar_catb
catb_dend=testcell.dend.gcatbar_catb
//kca_allnoax=testcell.dend.gbar_kca  
kca_dend=testcell.dend.gbar_kca  			
//napIn_allnoax=testcell.dend.gbar_napIn   
napIn_dend=testcell.dend.gbar_napIn
cagk_dend=testcell.soma.gbar_cagk
	
//**********SOMA********
gpasallnoax=testcell.soma.g_pas
epasallnoax=testcell.soma.e_pas
Raallnoax=testcell.soma.Ra
kdr_soma=testcell.soma.gkdrbar_kdr
nax_soma=testcell.soma.gbar_nax
kap_soma=testcell.soma.gkabar_kap 
//ih_fast_soma=testcell.soma.gfastbar_ih 
//ih_slow_soma=testcell.soma.gslowbar_ih
hd_soma=testcell.soma.ghdbar_hd
//can_soma=testcell.soma.gcanbar_can
//cal_soma=testcell.soma.gcalbar_cal
//catb_allnoax=testcell.soma.gcatbar_catb
catb_soma=testcell.soma.gcatbar_catb
kca_soma=testcell.soma.gbar_kca
//napIn_allnoax=testcell.soma.gbar_napIn 
napIn_soma=testcell.soma.gbar_napIn 
cagk_soma=testcell.soma.gbar_cagk
kmb_soma=testcell.soma.gbar_kmb			                                                                                           //new pv
}
//********************************************

access testcell.soma

Vrest=-68.6                //EG
proc init() {

  t=0
  
  finitialize(Vrest)

	forall {
		v = Vrest
		if(ismembrane("nax") || ismembrane("napIn")) {
			ena=50
		}
		if(ismembrane("kdr") || ismembrane("kap") || ismembrane("kir") || ismembrane("kdb") || ismembrane("kmb") || ismembrane("kad")) {       //pv cos'รจ kap? dovevamo aggiungere kdb e krdb?
			ek=-90
		}
		if(ismembrane("ih")) {
			eih_ih=-30
		}
		if(ismembrane("cacum")) {tau_cacum=500}
	}

	finitialize(Vrest)
	fcurrent()
	if(ismembrane("cacum")) {irest_cacum=ica}
	print ica, irest_cacum
	cvode.re_init()
/*
	forall {
		for(x) {
			if(ismembrane("na3") || ismembrane("nax")) {
				e_pas(x)=v(x)+(ina(x)+ik(x))/g_pas(x)
			}
			if(ismembrane("ih")) {
				e_pas(x)=e_pas(x)+i_ih(x)/g_pas(x)
			}
		}
	}
*/
}
objref syn, ns, nc
access testcell.soma
syn = new Exp2Syn(.5)
syn.tau1=0.3
syn.tau2=3
syn.e=0
ns = new NetStim(.5)
ns.number=5
ns.interval=20
ns.start=4000
ns.noise=0
nc = new NetCon(ns, syn, 0, 0, 0e-3) //7e-3

def()
init() 
proc biophysint() {

forsec testcell.axonal {  

	g_pas = gpasax
    e_pas = epasax
	Ra = RaAx
	gkdrbar_kdr = kdr_ax
	gbar_nax = nax_ax
	gkabar_kap = kap_ax
	gbar_napIn =  napIn_ax
	gbar_kmb= kmb_ax
	//gihbar_ih = ih_ax
}

forsec testcell.basal {
	
	g_pas = gpasallnoax
	e_pas = epasallnoax
    Ra = Raallnoax
	gkdrbar_kdr = kdr_dend
	gbar_nax = nax_dend
	gkabar_kap = kap_dend //remove
	//gkabar_kad = kad_dend
	//gfastbar_ih =ih_fast_dend
	//gslowbar_ih =ih_slow_dend
	//gcanbar_can = can_dend 
	//gcalbar_cal = cal_dend 	
	//gcatbar_catb= catb_allnoax
	gcatbar_catb= catb_dend
	gbar_kca = kca_dend
	//gbar_napIn =  napIn_allnoax
	gbar_napIn =  napIn_dend
	ghdbar_hd= hd_dend
	gbar_cagk=cagk_dend
}
  
forsec testcell.somatic {
	
	g_pas = gpasallnoax
	e_pas = epasallnoax
    Ra = Raallnoax
	gkdrbar_kdr = kdr_soma
	gbar_nax = nax_soma
	gkabar_kap = kap_soma
	//gfastbar_ih =ih_fast_soma
	//gslowbar_ih =ih_slow_soma
	//gcanbar_can = can_soma 
	//gcalbar_cal = cal_soma
	//gcatbar_catb= catb_allnoax
	gcatbar_catb= catb_soma
	gbar_kca = kca_soma
	//gbar_napIn =  napIn_allnoax
	gbar_napIn =  napIn_soma
	ghdbar_hd= hd_soma
	gbar_cagk= cagk_soma
	gbar_kmb=kmb_soma
}
  
}

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


testcell.soma {
stim = new IClamp(0.5)
stim.del=2000
stim.dur=4000
stim.amp=0.2
}

xpanel("values")
xvalue("gpasax")
xvalue("gpasallnoax")
xvalue("epasax")
xvalue("epasallnoax")
xvalue("RaAx")
xvalue("Raallnoax")
xvalue("nax_ax")
xvalue("nax_soma")
xvalue("nax_dend")
xvalue("napIn_ax")
//xvalue("napIn_allnoax")
xvalue("napIn_soma")
xvalue("napIn_dend")
xvalue("kdr_ax")
xvalue("kdr_soma")
xvalue("kdr_dend")
xvalue("kap_ax")
xvalue("kap_soma")
xvalue("kap_dend") //remove
xvalue("kmb_ax")
xvalue("kmb_soma")
//xvalue("kad_dend")
//xvalue("ih_ax")                                                //pv
//xvalue("ih_fast_soma")
//xvalue("ih_slow_soma")
//xvalue("ih_fast_dend")
//xvalue("ih_slow_dend")
//xvalue("cal_soma")
//xvalue("cal_dend") 
//xvalue("can_soma")
//xvalue("can_dend")
//xvalue("catb_allnoax")
xvalue("hd_soma")
xvalue("hd_dend")
xvalue("catb_dend")
xvalue("catb_soma")
xvalue("kca_dend")
xvalue("kca_soma")
xvalue("cagk_soma")
xvalue("cagk_dend")
xpanel()



xpanel("cond")
xbutton("set cond", "biophysint()")
//xbutton("reset", "rest()")
xbutton("reset init kin", "set_kin_init()")
xbutton("change all kin", "change_kin()")
xbutton("change nax", "change_nax()")
xbutton("change kdr", "change_kdr()")
xbutton("change kap", "change_kap()")
xbutton("change kad", "change_kad()")
xbutton("change nap", "change_nap()")
xbutton("change catb", "change_catb()")

xpanel()

proc def_kin_init() {

forall{
		tha_nax_init=tha_nax
		qa_nax_init=qa_nax
		thinf_nax_init=thinf_nax
		qinf_nax_init=qinf_nax
		
		vhalfn_kdr_init=vhalfn_kdr
		zetan_kdr_init=zetan_kdr


		zetan_kap_init=zetan_kap
		zetal_kap_init=zetal_kap

		vhalfn_kap_init=vhalfn_kap
		vhalfl_kap_init=vhalfl_kap

	//ih
	//vhalfl_ih=-83.1
	//kl_ih=8.1

	//napIn

	sh0_napIn_init=sh0_napIn
	sh1_napIn_init=sh1_napIn

	km_napIn_init=km_napIn
	
	//catb
	
	vhm_catb_init=vhm_catb
	km_catb_init=km_catb

	vhh_catb_init=vhh_catb
	ki_catb_init=ki_catb


	vhalfm_catb_init=vhalfm_catb
	zetam_catb_init=zetam_catb
	gmm_catb_init=gmm_catb
	a0m_catb_init=a0m_catb


	zetah_catb_init=zetah_catb
	gmh_catb_init=gmh_catb
	vhalfh_catb_init=vhalfh_catb
	a0h_catb_init=a0h_catb
	
	}
}

def_kin_init()
proc set_kin_init() {
print "reset_all_kin"
forall{
		tha_nax=tha_nax_init
		qa_nax=qa_nax_init
		thinf_nax=thinf_nax_init
		qinf_nax=qinf_nax_init
		
		vhalfn_kdr=vhalfn_kdr_init
		zetan_kdr=zetan_kdr_init


		zetan_kap=zetan_kap_init
		zetal_kap=zetal_kap_init

		vhalfn_kap=vhalfn_kap_init
		vhalfl_kap=vhalfl_kap_init

	//ih
	//vhalfl_ih=-83.1
	//kl_ih=8.1

	//napIn

	sh0_napIn=sh0_napIn_init
	sh1_napIn=sh1_napIn_init

	km_napIn=km_napIn_init
	
	//catb
	
	vhm_catb=vhm_catb_init
	km_catb=km_catb_init

	vhh_catb=vhh_catb_init
	ki_catb=ki_catb_init


	vhalfm_catb=vhalfm_catb_init
	zetam_catb=zetam_catb_init
	gmm_catb=gmm_catb_init
	a0m_catb=a0m_catb_init


	zetah_catb=zetah_catb_init
	gmh_catb=gmh_catb_init
	vhalfh_catb=vhalfh_catb_init
	a0h_catb=a0h_catb_init
	
	}
}

proc change_kin(){
print "change_all_kin"
	forall{
	// Nax
	tha_nax=-31
	qa_nax=5.1
	thinf_nax=-58.2
	qinf_nax=5


	/*Kdr
	vhalfn_kdr=-3.8
	zetan_kdr=-2.4
	*/
	change_kdr()

	//kaprox

	zetan_kap=-2.2
	zetal_kap=2.2

	vhalfn_kap=-34.7
	vhalfl_kap=-80.3

	//ih
	//vhalfl_ih=-83.1
	//kl_ih=8.1

	//napIn

	sh0_napIn=-8
	sh1_napIn=0.8

	km_napIn=5.2
	
	//catb
	
	vhm_catb=-60.5
	km_catb=5.3

	vhh_catb=-80.6
	ki_catb=5.44


	vhalfm_catb=-48
	zetam_catb=6.8
	gmm_catb=0.4
	a0m_catb=0.028


	zetah_catb=11
	gmh_catb=0.8
	vhalfh_catb=-60
	a0h_catb=0.0032
	}

}

proc change_catb(){
print "change_catb"
	forall{
	vhm_catb=-60.5
	km_catb=5.3

	vhh_catb=-80.6
	ki_catb=5.44
	
	vhalfm_catb=-48
	zetam_catb=6.8
	gmm_catb=0.4
	a0m_catb=0.028


	zetah_catb=11
	gmh_catb=0.8
	vhalfh_catb=-60
	a0h_catb=0.0032
	}

}

proc change_nax(){
print "change_nax"
forall {
	tha_nax=-31
	qa_nax=5.1
	thinf_nax=-58.2
	qinf_nax=5
	}
}

proc change_kdr(){
//print "change kdr"
/*forall {
	//vhalfn_kdr=-3.8
	//zetan_kdr=-2.4
	}
*/
forall if(ismembrane("kdr")){
			a0n_kdr=0.002
			vhalfn_kdr=-30
			zetan_kdr=-2.4
			}
}

proc change_kap(){
print "change_kap"
forall {
	zetan_kap=-2.2
	zetal_kap=2.2

	vhalfn_kap=-34.7
	vhalfl_kap=-80.3
}
}

proc change_kad(){
print "change_kad"
forall {
	zetan_kad=-2.2
	zetal_kad=2.2

	vhalfn_kad=-34.7-12
	vhalfl_kad=-80.3
}
}

proc change_nap(){
print "change_nap"
forall {
	sh0_napIn=-8
	sh1_napIn=0.8

	km_napIn=5.2
	}
}

load_file("for_rev_traces.ses")
//load_file("epsps_rev.ses")