// Cerebellum Granular Cell Model

xopen("$(NEURONHOME)/lib/hoc/noload.hoc") 


//DEFINITION OF CELL TEMPLATE

begintemplate grc

public soma
public x,y,z

//object variable will refer to a list that will hold an arbitrary number of NetCon objects.

public nclist
objectvar nclist  

//synapses         
public synAMPA,synNMDA,synGABAa1,synGABAa2 
objectvar synAMPA,synNMDA,synGABAa1,synGABAa2 

//counting spikes
public spiketimes,spikecount
objref spiketimes,spikecount

public voltagem
objref voltagem


tmax=1000   

create soma	//create compartment

public setv

proc setv() {
forall v=$1
}

proc init() {

x=$1
y=$2
z=$3

spiketimes=new Vector()
lastspikecount=0

voltagem=new Vector()

soma {

 pt3dclear()
 pt3dadd(x,y,z,10)	//set position of cell
 pt3dadd(x,y,z+10,10)
 
nseg=1
diam=11.8
L=11.8 
Ra=100
cm=1
celsius = 30

Area = PI*soma.diam*soma.L*1e-8

insert GRC_LKG1 
insert GRC_LKG2
insert GRC_NA 
insert GRC_KV
insert GRC_KA
insert GRC_KIR 
insert GRC_KCA 
insert GRC_CALC
//insert GrC_CaHVA
insert GRC_CA
insert GRC_KM 

gl_GRC_LKG1=5.68e-5	  //2009 model
ggaba_GRC_LKG2 = 3e-05 	  //2009 model
gkbar_GRC_KV= 0.003  	 //2009 model
gkbar_GRC_KA = 0.0032	  //2009 model
gkbar_GRC_KIR = 0.0009  //2009 model
gkbar_GRC_KM= 0.00025   //0.0001  //2009 model
gnabar_GRC_NA= 0.013     //2009 model  
gcabar_GRC_CA= 0.00046    //2009 model
gkbar_GRC_KCA = 0.04   //ajusted Version 3

beta_GRC_CALC = 1.5


usetable_GRC_NA 	= 0			      			
usetable_GRC_KV 	= 0
usetable_GRC_KA 	= 0
usetable_GRC_KIR 	= 0	  
usetable_GRC_KCA 	= 0
usetable_GRC_CA 	= 0
usetable_GRC_KM 	= 0

ena = 87.39
ek = -84.69
//eca = 129.33
ecl = -65

nclist=new List()

//Synapses
synAMPA=new Exp2Syn(0.5) //Adding synapse with rise and decay time
synAMPA.tau1=0.03  // ms rise time 
synAMPA.tau2=0.5  // ms decay time 
synAMPA.e=0     // mV reversal potential 

synNMDA=new Exp2Syn(0.5) //Adding synapse with rise and decay time
synNMDA.tau1=1  // ms rise time
synNMDA.tau2=13.3  // ms decay time 
synNMDA.e=0     // mV reversal potential 

synGABAa1=new Exp2Syn(0.5) //Adding synapse with rise and decay time
synGABAa1.tau1=0.31  // ms rise time 
synGABAa1.tau2=8.8  // ms decay time 
synGABAa1.e=-75     // mV reversal potential 

synGABAa2=new Exp2Syn(0.5) //Adding synapse with rise and decay time
synGABAa2.tau1=0.31  // ms rise time 
synGABAa2.tau2=300  // ms decay time 
synGABAa2.e=-75     // mV reversal potential 

//counting spikes
spikecount=new APCount(0.5)
spikecount.thresh=-20
spikecount.record(spiketimes)

//Saving Vm
voltagem.record(&v(0.5))
}
}

endtemplate grc


/*
 General settings
*/ 
v_init = -70

tstop = 1000 //for IClamp
dt = 0.025

secondorder=0  //method implicit backward euler

celsius = 30 
SogliaSpike=0