// mit_memb.hoc
// Membrane properties for mitral cell model
// Andrew Davison
// 24-11-98, 25-01-98

//********************************************************************************
// Reading function tables for tabchannels
//********************************************************************************

// kfasttab
objref tabkinfvec, tabninfvec, tabktauvec, tabntauvec, vvec
clipboard_retrieve("kfast_k.inf")
tabkinfvec = hoc_obj_[0]
vvec = hoc_obj_[1]
clipboard_retrieve("kfast_n.inf")
tabninfvec = hoc_obj_[0]
clipboard_retrieve("kfast_k.tau")
tabktauvec = hoc_obj_[0]
clipboard_retrieve("kfast_n.tau")
tabntauvec = hoc_obj_[0]
table_tabkinf_kfasttab(&tabkinfvec.x[0], vvec.size, &vvec.x[0])
table_tabninf_kfasttab(&tabninfvec.x[0], vvec.size, &vvec.x[0])
table_tabktau_kfasttab(&tabktauvec.x[0], vvec.size, &vvec.x[0])
table_tabntau_kfasttab(&tabntauvec.x[0], vvec.size, &vvec.x[0])

//kslowtab
objref tabkinfvecs, tabninfvecs, tabktauvecs, tabntauvecs
clipboard_retrieve("kslow_k.inf")
tabkinfvecs = hoc_obj_[0]
clipboard_retrieve("kslow_n.inf")
tabninfvecs = hoc_obj_[0]
clipboard_retrieve("kslow_k.tau")
tabktauvecs = hoc_obj_[0]
clipboard_retrieve("kslow_n.tau")
tabntauvecs = hoc_obj_[0]
table_tabkinf_kslowtab(&tabkinfvecs.x[0], vvec.size, &vvec.x[0])
table_tabninf_kslowtab(&tabninfvecs.x[0], vvec.size, &vvec.x[0])
table_tabktau_kslowtab(&tabktauvecs.x[0], vvec.size, &vvec.x[0])
table_tabntau_kslowtab(&tabntauvecs.x[0], vvec.size, &vvec.x[0])


//********************************************************************************
// Inserting channels and setting membrane properties
//********************************************************************************

print "<< Setting membrane properties and inserting channels >>"

// Global membrane properties

forall {
	insert pas
	e_pas = Erest	// reversal potential mV
	g_pas = 1/Rmemb // membrane conductance siemen-cm^-2 ( = 100000 ohm-cm^2 )	
	Ra = Raxial	// axial resistivity ohm-cm
}

// soma

soma {
	insert nafast
	insert kfasttab
	insert kA
	insert kslowtab
	insert lcafixed
	insert kca3
	insert cad
	depth_cad = diam/4
	gnabar_nafast = 0.1532
	gkbar_kfasttab = 0.1956
	gkbar_kA = 0.00587
	gkbar_kslowtab = 0.0028
	gcabar_lcafixed = 0.0040
	gkbar_kca3 = 0.0142
}


// insert electrode leak at soma
proc electrode_leak() {
  ElectrodeLeak = 120	// megaohms
  print "<< Electrode leak 120 megohms at soma >>"
  soma g_pas = 100/(ElectrodeLeak*area(0.5))
}

// axon

for i = 0,4 {
   axon[i] {
	insert nafast
	insert kfasttab
	insert kslowtab
	insert cad
	depth_cad = diam/4
	insert kca3
	insert lcafixed
	insert kA
	gnabar_nafast = 0.4681
	gkbar_kfasttab = 0.1156
	gkbar_kslowtab = 0.00155
	gkbar_kA = 0.00515
	gkbar_kca3 = 0.00887
	gcabar_lcafixed = 0.0020
   }
}

axon[0] gkbar_kfasttab = 0.1541
axon[1] gkbar_kfasttab = 0.1541

for i = 5,12 {
   axon[i] {
	insert nafast
	insert kfasttab
   }
}

axon[5] {
   gnabar_nafast = 0.3511
   gkbar_kfasttab = 0.0771
}
axon[6] {
   gnabar_nafast = 0.3511
   gkbar_kfasttab = 0.0771
}
axon[7] {
   gnabar_nafast = 0.2340
   gkbar_kfasttab = 0.0771
}
axon[8] {
   gnabar_nafast = 0.1170
   gkbar_kfasttab = 0.0771
}
axon[9] {
   gnabar_nafast = 0.0586
   gkbar_kfasttab = 0.0385
}
axon[10] {
   gnabar_nafast = 0.0234
   gkbar_kfasttab = 0.0077
}
axon[11] {
   gnabar_nafast = 0.0117
   gkbar_kfasttab = 0.0077
}
axon[12] {
   gnabar_nafast = 0.0117
   gkbar_kfasttab = 0.0077
}

// primary dendrite

forsec "prim_dend*" {
	insert nafast
	insert kfasttab
	insert kslowtab
	insert lcafixed
	insert cad
	depth_cad = diam/4
	gnabar_nafast = 0.00134
	gkbar_kfasttab = 0.00123
	gkbar_kslowtab = 0.00174
	gcabar_lcafixed = 0.0022
}

// for all secondary dendrites

forsec "sec_dend*" {
	insert nafast
	insert kfasttab
	gnabar_nafast = 0.0122		// set values in all dendritic sections
	gkbar_kfasttab = 0.0128		// later proximal sections will be changed
}

// for proximal secondary dendrites only

objref prox_sec_dend_list
prox_sec_dend_list = new SectionList()

forsec "sec_dendp.*" {
   prox_sec_dend_list.append()
}
forsec "sec_dendd.[0].*" {
   prox_sec_dend_list.append()
}
forsec "sec_dendd1[7]*" {
   prox_sec_dend_list.append()
}
forsec "sec_dendd2[7]*" {
   prox_sec_dend_list.append()
}
forsec "sec_dendd3[9]*" {
   prox_sec_dend_list.append()
}
forsec "sec_dendd4[5]*" {
   prox_sec_dend_list.append()
}

//print "Prox sec dends"
//prox_sec_dend_list.printnames()

forsec prox_sec_dend_list { 
	insert lcafixed
	insert kslowtab
	insert cad
	depth_cad = diam/4
	gnabar_nafast = 0.0330
	gkbar_kfasttab = 0.0226
	gcabar_lcafixed = 0.0004
	gkbar_kslowtab = 0.00085
}

// glomerulus

forsec "glom*" {
	insert lcafixed
	insert kslowtab
	insert cad
	depth_cad = diam/4
	gkbar_kslowtab = 0.0028
	gcabar_lcafixed = 0.0095
}

// set reversal potentials, etc.

forall if (ismembrane("ca_ion")) {
        eca = ErevCa	// 
	cai = CaConcInt	// mM 
	cao = CaConcExt	// mM
	ion_style("ca_ion",3,2,0,0,1)
}

forall if (ismembrane("na_ion")) {
	ena = ErevNa	// mV
}

forall if (ismembrane("k_ion")) {
	ek  = ErevK	//  mV
}