//Interneuron for PFC - fast spiking parvalbumin interneuron 
//Based on Durstewitz and Gabriel 2006
//"Irregular spiking in NMDA-driven prefrontal cortex neurons"


begintemplate FScell

public soma, axon, dend

create soma, axon, dend


proc init () {

create soma, axon, dend

soma_nafin=0.045 
soma_kdrin=0.018  
soma_Kslowin=0.000725*0.1
soma_hin=0.00001
soma_kapin=0.0032*15
soma_canin=0.0003
soma_kctin=0.0001

soma {
     nseg=1
     L=27
     diam=29

	insert pas
	cm=1.2            //microF/cm2
	g_pas =1/10000    //mho/cm2   
	e_pas = v_initin   //(Kawaguchi k Kubota, 1993 --> -73+-3.9)
	v_initin= -73
	Ra=150 

     insert Nafx
     gnafbar_Nafx= soma_nafin

     insert kdrin
     gkdrbar_kdrin= soma_kdrin

     insert IKsin	
     gKsbar_IKsin= soma_Kslowin

     insert hin
     gbar_hin=soma_hin

     insert kapin
     gkabar_kapin=soma_kapin

     insert canin
     gcalbar_canin=soma_canin

     insert kctin
     gkcbar_kctin=soma_kctin

     insert cadyn

}

axon {
	nseg=1
	L=115 
	diam=1.5
	
	insert pas
	cm=1.2            //microF/cm2
	g_pas =1/10000  //mho/cm2   
	e_pas = v_initin
	v_initin= -73
	Ra=150 

	insert Nafx
	gnafbar_Nafx=soma_nafin*10

	insert kdrin
	gkdrbar_kdrin=soma_kdrin*0.5
}


dend {
	nseg=1
	L=2*22 
	diam=7


	insert pas
	cm=1.2         //microF/cm2
	g_pas =1/10000    //mho/cm2   
	e_pas = v_initin//(Kawaguchi k Kubota, 1993 --> -73+-3.9)
	v_initin= -73
	Ra=150

	insert Nafx
	gnafbar_Nafx=0.018*5

	insert kdrin
	gkdrbar_kdrin=0.018*0.5

     	insert kapin
    	gkabar_kapin=soma_kapin*10

}

	ko0_k_ion = 3.82   //mM
 	ki0_k_ion = 140    //mM
	celsius   = 23
	connect axon(0), soma(0.5)
	connect dend(0), soma(0)  
}

init()

endtemplate FScell


//Creating new interneurons

objref FScell1

FScell1 = new FScell()

//Create list with segments
objref insoma_list, incell_list

insoma_list = new SectionList()
FScell1.soma insoma_list.append()

incell_list = new SectionList()
FScell1.soma incell_list.append()
FScell1.axon incell_list.append()
FScell1.dend incell_list.append()

proc current_balancein() {

  finitialize($1)
  fcurrent()

  printf("Balancing each compartment to %d mV\n", $1)

  forsec incell_list{
   for (x) {
    	if (ismembrane("na_ion")) {e_pas(x)=v(x)+ina(x)/g_pas(x)} 
   	if (ismembrane("k_ion")) {e_pas(x)=e_pas(x)+ik(x)/g_pas(x)} 

      	if (ismembrane("ca_ion")) {e_pas(x)=e_pas(x)+ica(x)/g_pas(x)}
//        if (ismembrane("Ca_ion")) {e_pas(x)=e_pas(x)+iCa(x)/g_pas(x)}
 //       if (ismembrane("in_ion")) {e_pas(x)=e_pas(x)+in(x)/g_pas(x)} //ican
       if (ismembrane("h")) {e_pas(x)=e_pas(x)+ihi(x)/g_pas(x)}

//        d = distance(1,x)
//	xdist = find_vector_distance_precise(secname(),x)    // calc. perpedicular distance      
  //	 printf("x = %e, xdist = %e, d = %e, e_pas = %e mV, rm = %e mA/(mVcm2)\n", x,  xdist, d, e_pas(x), 1./g_pas(x))
      //	fcurrent()
    }
  }

//finitialize(v_init)
fcurrent()
}



current_balancein(-73)