//**********************       HIPP CELL         ****************************************
// HIPP CELL template

// extracted from
// Dentate gyrus network model 
// Santhakumar V, Aradi I, Soltesz I (2005) J Neurophysiol 93:437-53 
// https://senselab.med.yale.edu/ModelDB/showModel.cshtml?model=51781&file=\dentategyrusnet2005\DG500_M7.hoc

// ModelDB file along with publication:
// Yim MY, Hanuschkin A, Wolfart J (2015) Hippocampus 25:297-308.
// http://onlinelibrary.wiley.com/doi/10.1002/hipo.22373/abstract

// modified by
// Abraham Nunes / 2022
// Man Yi Yim / 2015
// Alexander Hanuschkin / 2011


begintemplate HIPPCell

ndend1=3
ndend2=3
ndend3=3
ndend4=3
public  pre_list, connect_pre, subsets, is_art, is_connected
public vbc2gc, vmc2gc, vhc2gc, vgc2bc, vbc2bc, vmc2bc, vhc2bc, vgc2mc, vbc2mc, vmc2mc, vhc2mc, vgc2hc, vmc2hc
public soma, hcdend1, hcdend2, hcdend3, hcdend4
create soma, hcdend1[ndend1], hcdend2[ndend2], hcdend3[ndend3], hcdend4[ndend4]
public all, pdend, ddend
objref syn, pre_list


objref syn
proc init() {
	pre_list = new List()
	subsets()
	temp()
	synapse()
}

objref all, pdend, ddend

proc subsets() { local i
	objref all, pdend, ddend
	all = new SectionList()
		soma all.append()
		for i=0, 2 hcdend1 [i] all.append()
		for i=0, 2 hcdend2 [i] all.append()
		for i=0, 2 hcdend3 [i] all.append()
		for i=0, 2 hcdend4 [i] all.append()

	pdend  = new SectionList()
		hcdend1 [0] pdend.append()
		hcdend2 [0] pdend.append()
		hcdend3 [0] pdend.append()
		hcdend4 [0] pdend.append()

	ddend  = new SectionList()
		for i=1, 2 hcdend1 [i] ddend.append()
		for i=1, 2 hcdend2 [i] ddend.append()
		for i=1, 2 hcdend3 [i] ddend.append()
		for i=1, 2 hcdend4 [i] ddend.append()
}

proc temp() {

	soma {nseg=1 L=20 diam=10} 
		
	hcdend1 [0] {nseg=1 L=75 diam=3}
	hcdend1 [1] {nseg=1 L=75 diam=2}
	hcdend1 [2] {nseg=1 L=75 diam=1}

	hcdend2 [0] {nseg=1 L=75 diam=3}
	hcdend2 [1] {nseg=1 L=75 diam=2}
	hcdend2 [2] {nseg=1 L=75 diam=1}
 		 
	hcdend3 [0] {nseg=1 L=50 diam=3}
	hcdend3 [1] {nseg=1 L=50 diam=2}
	hcdend3 [2] {nseg=1 L=50 diam=1}
	
	hcdend4 [0] {nseg=1 L=50 diam=3}
	hcdend4 [1] {nseg=1 L=50 diam=2}
	hcdend4 [2] {nseg=1 L=50 diam=1}	

    
	forall {
		insert ccanl
            catau_ccanl = 10
            caiinf_ccanl = 5.e-6
		insert ka
            gkabar_ka=0.0008
		insert nca  
            gncabar_nca=0.0
		insert lca
            glcabar_lca=0.0015
		insert sk
            gskbar_sk=0.003
		insert bk
            gkbar_bk=0.003
		insert ih 
            ghyfbar_ih=0.000015
            ghysbar_ih=0.000015
	    insert ichan2
	        vshiftma_ichan2 = 55                          // Manually adjusted for excitability, 43 original value Yim et al. 2015
            vshiftmb_ichan2 = 15                           // value Yim et al. 2015
            vshiftha_ichan2 = 120                             // Manually adjusted for excitability, 65 original value Yim et al. 2015
            vshifthb_ichan2 = 12.5                          // value Yim et al. 2015
            vshiftnfa_ichan2 = 18                           // value Yim et al. 2015
            vshiftnfb_ichan2 = 43                           // value Yim et al. 2015
            vshiftnsa_ichan2 = 30                        // value Yim et al. 2015
            vshiftnsb_ichan2 = 55                         // value Yim et al. 2015
	}

	soma {
		// Parameters here from optimization algorithm: fit is not good, but all param choices here improve excitability relative to baseline
		insert bk
            gkbar_bk=0.003
		insert ichan2  
			gnatbar_ichan2=0.40286053528981347
			vshiftma_ichan2 = 40                          					// Manually adjusted for excitability, 43 original value Yim et al. 2015
            vshiftmb_ichan2 = 34.009920934895774                           // value Yim et al. 2015
            vshiftha_ichan2 = 135                           				// Manually adjusted for excitability, 65 original value Yim et al. 2015
            vshifthb_ichan2 = 17.88045072448461                         	// value Yim et al. 2015
            vshiftnfa_ichan2 = 25.980836892849453                           // value Yim et al. 2015
            vshiftnfb_ichan2 = 32.63622302191759                           // value Yim et al. 2015
            vshiftnsa_ichan2 = 31.539655883127935                       	// value Yim et al. 2015
            vshiftnsb_ichan2 = 62.85303255068065                         	// value Yim et al. 2015
			gkfbar_ichan2=0.015089593009058445
			gksbar_ichan2 = 0.0863032228319594
			gl_ichan2 = 3.473399315538747e-05
		insert ka
            gkabar_ka=0.0005003483721712866
		insert lca
            glcabar_lca=0.0007274383172642894
		insert nca  
            gncabar_nca=0.00011696067190574842
		insert sk
            gskbar_sk=0.0006968877311317309
		insert ih 
            ghyfbar_ih=1.944031922432364e-05
            ghysbar_ih=3.7500000000000003e-05

		
		cm=1.1
	} 

	forsec pdend {
		insert ichan2
			gnatbar_ichan2=0.2  
			gkfbar_ichan2=0.006
			gl_ichan2 = 0.000036
		cm=1.1
	}
		
	forsec ddend {
		insert ichan2
			gnatbar_ichan2=0.0
			gkfbar_ichan2=0.00
			gl_ichan2 = 0.000036
		cm=1.1
	}

	connect hcdend1[0](0), soma(1)
	connect hcdend2[0](0), soma(1)
	connect hcdend3[0](0), soma(0)
	connect hcdend4[0](0), soma(0)
	for i=1,2 {connect hcdend1[i](0), hcdend1[i-1](1)}
	for i=1,2 {connect hcdend2[i](0), hcdend2[i-1](1)}
	for i=1,2 {connect hcdend3[i](0), hcdend3[i-1](1)}
	for i=1,2 {connect hcdend4[i](0), hcdend4[i-1](1)}

	forall {Ra=100}
	forall {
        	ena 		= 	50        		// ena was unified from enat=55 (BC, HIPP, MC) and enat=45 (GC) in Santhakumar et al. (2005) <ah>
            ek			=	-90          	// simplified ekf=eks=ek=esk; note the eK was erroneously reported as -105mV in the Yim et al. 2015 <ah>
            el_ichan2 	=	-70.45
			ehyf		=	-40
			ehys		=	-40
            cao_ccanl	=	2 
			}
		}

// Defining synapses on to HIPP cells

	objref syn  
	proc synapse() {

	hcdend1 [0] syn = new Exp2Syn(0.5)	//GC(AMPA) syn to prox dend similar to GC>BC
	syn.tau1 = .3	syn.tau2 = .6	syn.e = 0
	pre_list.append(syn)

	hcdend2 [0] syn = new Exp2Syn(0.5)	//GC(AMPA) syn to prox dend similar to GC>BC
	syn.tau1 = .3	syn.tau2 = .6	syn.e = 0
	pre_list.append(syn)

	hcdend3 [0] syn = new Exp2Syn(0.5)	//GC(AMPA) syn to prox dend similar to GC>BC
	syn.tau1 = .3 syn.tau2 = .6	syn.e = 0
	pre_list.append(syn)

	hcdend4 [0] syn = new Exp2Syn(0.5)	//GC(AMPA) syn to prox dend similar to GC>BC
	syn.tau1 = .3	syn.tau2 = .6	syn.e = 0
	pre_list.append(syn)

	hcdend1 [1] syn = new Exp2Syn(0.5)	//MC(AMPA) syn to mid dend similar to CA3>int Aaron
	syn.tau1 = .9	syn.tau2 = 3.6	syn.e = 0 //*** Assumed data at physio temp
	pre_list.append(syn)

	hcdend2 [1] syn = new Exp2Syn(0.5)	//MC(AMPA) syn to mid dend similar to CA3>int Aaron
	syn.tau1 = 0.9	syn.tau2 = 3.6	syn.e = 0 //*** Assumed data at physio temp
	pre_list.append(syn)

	hcdend3 [1] syn = new Exp2Syn(0.5)	//MC(AMPA) syn to mid dend similar to CA3>int Aaron
	syn.tau1 = 0.9	syn.tau2 = 3.6	syn.e = 0  //*** Assumed data at physio temp
	pre_list.append(syn)

	hcdend4 [1] syn = new Exp2Syn(0.5)	//MC(AMPA) syn to mid dend similar to CA3>int Aaron
	syn.tau1 = 0.9		syn.tau2 = 3.6 	syn.e = 0  //*** Assumed data at physio temp
	pre_list.append(syn)

// Total of 12 synapses 	0-3 PP; 	4-7 GC; 	8-11 MC	
	}

	proc connect_pre() {  
	soma $o2 = new NetCon (&v(1), $o1)
	}

func is_art()  { return 0 }

endtemplate HIPPCell