// Artificial cells no longer need a default section.
//Network cell templates
//   VIPCell
// Simplified version (BPG 27-9-08)
//  - geometry and channels from Santhakumar et al 2005
//  - geometry modified to preserve VCUs different dendrites

global_lambda_f = 1
  func lambda_f() {return global_lambda_f}

begintemplate VIPCRCell_EDITED
public is_art
public init, topol, basic_shape, subsets, geom, biophys
public pre_list, connect2target

public soma
public rad1 	// public radProx1, radMed1, radDist1, lmM1, lmt1
public rad2 	// public radProx2, radMed2, radDist2, lmM2, lmt2
public ori1 	// public oriProx1, oriMed1, oriDist1
public ori2 	// public oriProx2, oriMed2, oriDist2
public all

objref pre_list

proc init() {
	topol()
	subsets()
	geom()
	biophys()
	geom_nseg()
	pre_list = new List()
	synapses()
}

create soma
create rad1 	// create radProx1, radMed1, radDist1, lmM1, lmt1
create rad2 	// create radProx2, radMed2, radDist2, lmM2, lmt2
create ori1 	// create oriProx1, oriMed1, oriDist1
create ori2 	// create oriProx2, oriMed2, oriDist2

proc topol() { local i
	connect rad1(0), soma(0) // connect radProx1(0), soma(0)
	// connect radMed1(0),  radProx1(1)
	// connect radDist1(0), radMed1(1)
	// connect lmM1(0),     radDist1(1)
	// connect lmt1(0),     lmM1(1)
	connect rad2(0), soma(1) // connect radProx2(0), soma(1)
	// connect radMed2(0),  radProx2(1)
	// connect radDist2(0), radMed2(1)
	// connect lmM2(0),     radDist2(1)
	// connect lmt2(0),     lmM2(1)	
	connect ori1(0), soma(0) // connect oriProx1(0), soma(0)
	// connect oriMed1(0),  oriProx1(1)
	// connect oriDist1(0), oriMed1(1)
	connect ori2(0), soma(1) // connect oriProx2(0), soma(1)
	// connect oriMed2(0),  oriProx2(1)
	// connect oriDist2(0), oriMed2(1)
	//basic_shape()
}

//proc basic_shape() {
	//soma     { pt3dclear() pt3dadd(0, 0, 0, 10)      pt3dadd(15, 0, 0, 10)        }
	//rad1     { pt3dclear() pt3dadd()  pt3dadd()	}
	//rad2     { pt3dclear() pt3dadd()  pt3dadd()	}
	//ori1     { pt3dclear() pt3dadd()  pt3dadd()	}
	//ori2     { pt3dclear() pt3dadd()  pt3dadd() }
	//radProx1 { pt3dclear() pt3dadd(0, 0, 0, 4)       pt3dadd(-7, 7.50, 0, 4)      }
	//radMed1  { pt3dclear() pt3dadd(-14, 15, 0, 3)    pt3dadd(-21.5, 22.5, 0, 3)   }
	//radDist1 { pt3dclear() pt3dadd(-29, 30, 0, 2)    pt3dadd(-36.5, 37.5, 0, 2)   }
	//lmM1     { pt3dclear() pt3dadd(-44, 45, 0, 1.5)  pt3dadd(-51.5, 52.5, 0, 1.5) }
	//lmt1     { pt3dclear() pt3dadd(-59, 60, 0, 1)    pt3dadd(-74, 75, 0, 1)       }
	//radProx2 { pt3dclear() pt3dadd(15, 0, 0, 4)      pt3dadd(30, 15, 0, 4)        }
	//radMed2  { pt3dclear() pt3dadd(45, 30, 0, 3)     pt3dadd(60, 45, 0, 3)        }
	//radDist2 { pt3dclear() pt3dadd(75, 60, 0, 2)     pt3dadd(82.5, 67.5, 0, 2)    }
	//lmM2     { pt3dclear() pt3dadd(90, 75, 0, 1.5)   pt3dadd(97.5, 82.5, 0, 1.5)  }
	//lmt2     { pt3dclear() pt3dadd(105, 90, 0, 1)    pt3dadd(112.50, 97.5, 0, 1)  }	
	//oriProx1 { pt3dclear() pt3dadd(0, 0, 0, 2)       pt3dadd(-14.5, -14.5, 0, 2)  }
	//oriMed1  { pt3dclear() pt3dadd(-29, -29, 0, 1.5) pt3dadd(-44, -44, 0, 1.5)    }
	//oriDist1 { pt3dclear() pt3dadd(-59, -59, 0, 1)   pt3dadd(-74, -74, 0, 1)      }
	//oriProx2 { pt3dclear() pt3dadd(15, 0, 0, 2)      pt3dadd(30, -14.5, 0, 2)     }
	//oriMed2  { pt3dclear() pt3dadd(45, -29, 0, 1.5)  pt3dadd(60, -44, 0, 1.5)     }
	//oriDist2 { pt3dclear() pt3dadd(75, -59, 0, 1)    pt3dadd(90, -74, 0, 1)       }
//}

objref all
proc subsets() { local i
	objref all
	all = new SectionList()
	soma     all.append()
	rad1     all.append()
	rad2     all.append()
	ori1     all.append()
	ori2     all.append()
	//radProx1 all.append()
	//radMed1  all.append()
	//radDist1 all.append()
	//lmM1     all.append()
	//lmt1     all.append()
	//radProx2 all.append()
	//radMed2  all.append()
	//radDist2 all.append()
	//lmM2     all.append()
	//lmt2     all.append()	
	//oriProx1 all.append()
	//oriMed1  all.append()
	//oriDist1 all.append()
	//oriProx2 all.append()
	//oriMed2  all.append()
	//oriDist2 all.append()
}

proc geom() {
	forsec all {  }
	soma     {  L = 20   diam = 10  }
	rad1     {  L = 300  diam = 3   }
	rad2     {  L = 300  diam = 3   }
	ori1     {  L = 150  diam = 1.5 }
	ori2     {  L = 150  diam = 1.5 }
	//radProx1 {  L = 50   diam = 4   }
	//radMed1  {  L = 50   diam = 3   }
	//radDist1 {  L = 100  diam = 2   }
	//lmM1     {  L = 50   diam = 1.5 }
	//lmt1     {  L = 50   diam = 1   }
	//radProx2 {  L = 50   diam = 4   }
	//radMed2  {  L = 50   diam = 3   }
	//radDist2 {  L = 100  diam = 2   }
	//lmM2     {  L = 50   diam = 1.5 }
	//lmt2     {  L = 50   diam = 1   }	
	//oriProx1 {  L = 50   diam = 2   }
	//oriMed1  {  L = 50   diam = 1.5 }
	//oriDist1 {  L = 50   diam = 1   }
	//oriProx2 {  L = 50   diam = 2   }
	//oriMed2  {  L = 50   diam = 1.5 }
	//oriDist2 {  L = 50   diam = 1   }
}

external lambda_f
proc geom_nseg() {
  forsec all { nseg = 1} //int((L/(0.1*lambda_f(100))+.9)/2)*2 + 1  }
}

proc biophys() {

	soma_nafcr   = 0.015
	soma_kdrcr   = 0.018 
	soma_Kslowcr = 0.000725
	soma_iCcr    = 0.00003
	soma_kadcr   = 0.003
	soma_cancr   = 0.001
	v_initcr     = -70
	
	soma {
		insert pas
		cm       = 1.2            //microF/cm2
		g_pas    = 1/20000
		e_pas    = v_initcr
		Ra       = 150

		insert Nafcr
		gnafbar_Nafcr= soma_nafcr

		insert kdrcr
		gkdrbar_kdrcr= soma_kdrcr

		insert IKscr
		gKsbar_IKscr= soma_Kslowcr

		insert iCcr
		gkcbar_iCcr= soma_iCcr

		//insert kadcr --> do not see this listed as a mod file 
		//gkabar_kadcr= soma_kadcr

		insert cancr
		gcabar_cancr=soma_cancr //gcabar_cancr not gcatbar_cancr

		insert cadyn
		// TO DO: cadyn_new, compile,insert, and verify the validation tests
	}
	
	rad1 {
		insert pas
		cm       = 1.2            //microF/cm2
		g_pas    = 1/20000
		e_pas    = v_initcr
		v_initcr = -70
		Ra       = 150 

		insert Nafcr
		gnafbar_Nafcr = 0.018*5

		insert kdrcr
		gkdrbar_kdrcr = 0.018*0.5
	}

	rad2 {
		insert pas
		cm       = 1.2            //microF/cm2
		g_pas    = 1/20000
		e_pas    = v_initcr
		v_initcr = -70
		Ra       = 150 

		insert Nafcr
		gnafbar_Nafcr = 0.018*5

		insert kdrcr
		gkdrbar_kdrcr = 0.018*0.5
	}	

	ori1 {
		insert pas
		cm       = 1.2            //microF/cm2
		g_pas    = 1/20000
		e_pas    = v_initcr
		v_initcr = -70
		Ra       = 150 

		insert Nafcr
		gnafbar_Nafcr = 0.018*5

		insert kdrcr
		gkdrbar_kdrcr = 0.018*0.5
	}			

	ori2 {
		insert pas
		cm       = 1.2            //microF/cm2
		g_pas    = 1/20000
		e_pas    = v_initcr
		v_initcr = -70
		Ra       = 150 

		insert Nafcr
		gnafbar_Nafcr = 0.018*5

		insert kdrcr
		gkdrbar_kdrcr = 0.018*0.5
	}			

	forsec all {
		ko0_k_ion = 3.82   //mM
	 	ki0_k_ion = 140    //mM
		celsius   = 23
	} 					

}

obfunc connect2target() { localobj nc //$o1 target point process, optional $o2 returned NetCon
	soma nc = new NetCon(&v(1), $o1)
	nc.threshold = -10
	if (numarg() == 2) { $o2 = nc } // for backward compatibility
	return nc
}

objref syn_


proc synapses_EC() {
	/* E0 */   rad1 syn_ = new MyExp2Syn(0.5)  pre_list.append(syn_)	// AMPA		EC  // was lmM1: 200-250 from soma(0) 
	syn_.tau1 = 2.0
	syn_.tau2 = 6.3
	syn_.e    = 0
	/* E1 */   rad2 syn_ = new MyExp2Syn(0.5)  pre_list.append(syn_)	// AMPA		EC  // was lmM2: 200-250 from soma(1)
	syn_.tau1 = 2.0
	syn_.tau2 = 6.3
	syn_.e    = 0
}

proc synapses_CA3() {
	/* E2 */   rad1 syn_ = new MyExp2Syn(0.5)  pre_list.append(syn_)	// AMPA		CA3 Shaffer collateral // was radProx1 & radMed1: 0-50 & 50-100 from soma(0)
	syn_.tau1 = 2.0
	syn_.tau2 = 6.3
	syn_.e    = 0
	/* E3 */   rad2 syn_ = new MyExp2Syn(0.5)  pre_list.append(syn_)	// AMPA		CA3 Shaffer collateral // was radProx2 & radMed2: 0-50 & 50-100 from soma(1) 
	syn_.tau1 = 2.0
	syn_.tau2 = 6.3
	syn_.e    = 0
}

proc synapses_PC() {
	/* E4 */   ori1 syn_ = new MyExp2Syn(0.5)  pre_list.append(syn_)	// AMPA		PC // was oriProx1: 0-50 from soma(0)
	syn_.tau1 = 0.5
	syn_.tau2 = 3.0
	syn_.e    = 0
	/* E5 */   ori2 syn_ = new MyExp2Syn(0.5)  pre_list.append(syn_)	// AMPA		PC // was oriProx2: 0-50 from soma(1) 
	syn_.tau1 = 0.5
	syn_.tau2 = 3.0
	syn_.e    = 0
}

proc synapses_SEP() {
	/* I8 */   ori1 syn_ = new MyExp2Syn(0.6)  pre_list.append(syn_)	// GABA-A	Septum // was oriProx1: 0-50 from soma(0)
	syn_.tau1 = 1
	syn_.tau2 = 8
	syn_.e    = -75
	/* I9 */   ori2 syn_ = new MyExp2Syn(0.6)  pre_list.append(syn_)	// GABA-A	Septum // was oriProx2: 0-50 from soma(1)
	syn_.tau1 = 1
	syn_.tau2 = 8
	syn_.e    = -75
	/* I10 */   ori1 syn_ = new MyExp2Syn(0.6)  pre_list.append(syn_)	// GABA-B	Septum // was oriProx1: 0-50 from soma(0)
	syn_.tau1 = 35
	syn_.tau2 = 100
	syn_.e    = -75
	/* I11 */   ori2 syn_ = new MyExp2Syn(0.6)  pre_list.append(syn_)	// GABA-B	Septum // was oriProx2: 0-50 from soma(1)
	syn_.tau1 = 35
	syn_.tau2 = 100
	syn_.e    = -75
}

proc synapses() {
  synapses_EC()
  synapses_CA3()
  synapses_PC()
  synapses_SEP()
}



func is_art() { return 0 }

endtemplate VIPCRCell_EDITED