// New version of Granule cell with Calcium in dendrites
// Multicompartmental model - cell template 
// Shyam Diwakar M. 
// Last modified 5-Feb-2007 
 
begintemplate GrC 

	      ndend = 4 
              nsg = 5
	      naxon = 56
	      npf=500  		
	 
              public soma,synA,synNS,synG,Area,CC,dend_1,dend_2,dend_3,dend_4,hillock,axon,pf
              public connect_pre,rescale,Us 
              public list_go_grc,list_con_inhib 
	      public branch0,branch1,branch2,branch3,br0,br1,br2,br3
              public SpikeTrain 
              create soma,hillock[1],axon[1],dend_1[1],dend_2[1],dend_3[1],dend_4[1],pf[1]//,branch0,branch1,branch2,branch3,br0,br1,br2,br3
              objref synNS[4],synA[4],synG[4] 
              objref list_go_grc,list_con_inhib 
              objref Inhib[4],CC
	    
	    	//objref gol_rec
              objref SpikeTrain,nil,netcon 
		 
              proc init() {  
			list_go_grc=new List() 
			list_con_inhib=new List() 
			//gol_rec=new Vector() 
			if(numarg()==5){ndend=$1 nsg =$2 nbut=$3 naxon=$4 npf=$5} else {ndend=4 nsg=5 nbut=20 naxon=56 npf=500} 
			create soma, hillock[nsg],axon[naxon],dend_1[ndend],dend_2[ndend],dend_3[ndend],dend_4[ndend],pf[npf]//,branch0,branch1,branch2,branch3,br0,br1,br2,br3  
			
					 
                        soma {
			     access soma 
                             nseg = 1 
                             diam = 5.8//6.06 
                             L = 5.8//6.16 
                             cm = 1 
                             Ra = 100
			     celsius=30
			     //for membrane current
			     //insert extracellular    
			     
			     
			     // Soma Channels 
                             insert GRC_LKG1 
                             insert GRC_LKG2
			     ggaba_GRC_LKG2 = 3e-05
 	 
                             insert GRC_KIR 
                             insert GRC_KA 
                             insert GRC_KM 
                              
 	 		     usetable_GRC_KA 	= 0	// 1 
                             usetable_GRC_KIR 	= 0	// 1 
                             usetable_GRC_KM 	= 0	// 1
			     
			     insert GRC_NA 
	                     insert GRC_KV 
		
	 		     usetable_GRC_NA 	= 0	// 1
			     usetable_GRC_KV 	= 0	// 1     

                             insert GRC_KCA 
                             usetable_GRC_KCA 	= 0	// 1 
                             gkbar_GRC_KCA = 0//0.010041491     // 1 
 
                             insert GRC_CA 
                             usetable_GRC_CA 	= 0	// 1 
                             gcabar_GRC_CA        = 0//0.001154771    // 1 
 
                             insert GRC_CALC 
			     beta_GRC_CALC = 1.5

			     ena = 87.39	
			     ek = -84.69 
                             eca = 129.33 
                             ecl = -65
			     
			     //CC =new VClamp(0.5)
	   
			     Area = L*diam*PI*1e-8	 
                        } 
                      // Hillock definition 
 
                      for(w1=0;w1<nsg;w1=w1+1) {
			hillock[w1] {
				    access hillock[w1]
                                    nseg = 1 
	                            diam = 2.3-0.5*w1 
	                            L = 0.5 
	                            cm = 1 
	                            Ra = 100
				    
 
	                            // Hillock Channels 
	                            insert GRC_LKG1 
	                            // insert GRC_Lkg2
				    //insert extracellular    
				    insert GRC_NA 
	                     	    insert GRC_KV 
		
	 		     	    usetable_GRC_NA 	= 0	// 1 
	                     	    usetable_GRC_KV 	= 0	// 1
				    				     	
				    ena = 87.39
				    ek = -84.69 
				    //Area = PI*L*diam*1e-8		  
	                         }
		      }
 
		      
		      for(w3=0;w3<naxon;w3=w3+1) { 
                      	axon[w3] {   // Axon definition
				 access axon[w3] 
	                         nseg = 1 
	                         diam = 0.15 
	                         L = 2.3367 
	                         cm = 1 
	                         Ra = 100
				 
				  
	                         // Axon Channels 
	                         insert GRC_LKG3
				 insert GRC_NA 
	                     	 insert GRC_KV 
		
	 		     	 usetable_GRC_NA 	= 0	// 1 
	                     	 usetable_GRC_KV 	= 0	// 1
  

   		  	  	 //insert extracellular    					
				 ena = 87.39 
				 ek = -84.69  
			} 
				  
                    }
	
			for(w2=0;w2<ndend;w2=w2+1) { 
                            dend_1[w2] {
				   access dend_1[w2]  
	                           nseg = 1 
	                           diam = 0.75 
	                           L = 5 
	                           cm = 1 
	                           Ra = 100
				    
 
	                           // Dendritic Channels 
	                           insert GRC_LKG1 
				   insert GRC_LKG2
			      	   ggaba_GRC_LKG2 = 3e-05	 
 
	                           insert GRC_KIR 
	                           usetable_GRC_KIR 	= 0	// 1 
	                           gkbar_GRC_KIR=0 

				   //insert extracellular     
	                           insert GRC_KA 
	                           usetable_GRC_KA 	= 0	// 1 
	                           gkbar_GRC_KA=0 
 
                                   insert GRC_KCA 
                                   usetable_GRC_KCA 	= 0	// 1 
                                   gkbar_GRC_KCA = 0//0.010041491     // 1 
 
                                   insert GRC_CA 
                                   usetable_GRC_CA 	= 0	// 1 
                                   gcabar_GRC_CA        = 0//0.001154771    // 1 
 
                                   insert GRC_CALC 
				   beta_GRC_CALC = 1.5
 
                                   eca = 129.33 
                                   ek = -84.69 
				    
                             }
			} 
                      	 
                        // Dendrite definition: second compartment 
                        for(w2=0;w2<ndend;w2=w2+1) { 
                            dend_2[w2] { 
				   access dend_2[w2]
                                   nseg = 1 
                                   diam = 0.75 
                                   L = 5 
                                   cm = 1 
                                   Ra = 100
				  
				    //insert extracellular    				    
	                           // Dendritic Channels 
	                           insert GRC_LKG1
				   insert GRC_LKG2
			      	   ggaba_GRC_LKG2 = 3e-05	 
                                   
				   insert GRC_KIR 
	                           usetable_GRC_KIR 	= 0	// 1 
	                           gkbar_GRC_KIR=0 
 
	                           insert GRC_KA 
	                           usetable_GRC_KA 	= 0	// 1 
                                   gkbar_GRC_KA=0 
 
                                   insert GRC_KCA 
                                   usetable_GRC_KCA 	= 0	// 1 
                                   gkbar_GRC_KCa = 0//.010041491     // 1 
 
                                   insert GRC_CA 
                                   usetable_GRC_CA 	= 0	// 1 
                                   gcabar_GRC_CA        = 0//.001154771     // 1 
 
                                   insert GRC_CALC 
				   beta_GRC_CALC = 1.5
 
                                   eca = 129.33 
                                   ek = -84.69
				    
                               } 
                        }
			  
                        // Dendrite definition: third compartment 
                        // 
			  for(w2=0;w2<ndend;w2=w2+1) {	 
                            dend_3[w2] {
				   access dend_3[w2] 
                                   nseg = 1 
	                           diam = 0.75 
	                           L = 2.5 
	                           cm = 1 
	                           Ra = 100
                                   
 
	                           // Dendritic Channels 
 
	                           insert GRC_LKG1
				   insert GRC_LKG2
			      	   ggaba_GRC_LKG2 = 3e-05	 
 
	                           insert GRC_KIR 
	                           usetable_GRC_KIR 	= 0	// 1 
	                           gkbar_GRC_KIR=0 
 				   //insert extracellular    
	                           insert GRC_KA 
	                           usetable_GRC_KA 	= 0	// 1 
	                           gkbar_GRC_KA=0 
 
                                   insert GRC_KCA 
                                   usetable_GRC_KCA 	= 0	// 1 
                                   gkbar_GRC_KCA = 0//.010041491     // 1 
 
                                   insert GRC_CA 
                                   usetable_GRC_CA 	= 0	// 1 
                                   gcabar_GRC_CA        = 0//.001154771     // 1 
 
                                   insert GRC_CALC 
				   beta_GRC_CALC = 1.5
 
                                   eca = 129.33 
                                   ek = -84.69  
 
                                   synG[w2] = new GRC_GABA(0.5)  
                               }
			    }	 
				 
                        // Dendrite definition: fourth compartment 
                        // 
                        for(w2=0;w2<ndend;w2=w2+1) { 
                            dend_4[w2] {
				   access dend_4[w2] 
                                   nseg = 1 
	                           diam = 0.75 
	                           L = 2.5 
	                           cm = 1 
	                           Ra = 100
				   
				   //insert extracellular                                        
	                           // Dendritic Channels 
	                           insert GRC_LKG1
				   insert GRC_LKG2
			      	   ggaba_GRC_LKG2 = 3e-05	 
 
				   insert GRC_CA
 
	                           insert GRC_KIR 
	                           usetable_GRC_KIR 	= 0	// 1 
	                           gkbar_GRC_KIR=0 
 
	                           insert GRC_KA 
	                           usetable_GRC_KA 	= 0	// 1 
	                           gkbar_GRC_KA=0 
 
                                   insert GRC_KCA 
                                   usetable_GRC_KCA 	= 0	// 1 
 
                                   insert GRC_CA 
                                   usetable_GRC_CA 	= 0	// 1 
                                  
                                   insert GRC_CALC
				   beta_GRC_CALC = 1.5  
 
                                   eca = 129.33 
                                   ek = -84.69 
 
	                           synA[w2] = new AmpaCOD(0.5) 
                                   synNS[w2] = new NMDAS(0.5) 
					//synNES[i] = new NMDAES(0.5)  
 
                               }
			    }
	    	        for(p1=0;p1<npf;p1=p1+1) { 
                      	   pf[p1] {   // pf definition
				 access pf[p1] 
	                         nseg = 1 
	                         diam = 0.15 
	                         L = 10
	                         cm = 1
	                         Ra = 100
				 
				  
	                         // Pf Channels 
	                         insert GRC_LKG3
				 insert GRC_NA 
	                     	 insert GRC_KV 
		
	 		     	 usetable_GRC_NA 	= 0	// 1 
	                     	 usetable_GRC_KV 	= 0	// 1
  

   		  	  	 //insert extracellular    					
				 ena = 87.39 
				 ek = -84.69  
			} 
				  
                    }/*
	
			branch0 {
			     access branch0 
                             nseg = 1 
                             diam = 0.15//0.1//6.06 
                             L = 3//100//6.16 
                             cm = 1 
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}
			branch1 {
			     access branch1 
                             nseg = 1 
                             diam = 0.1//0.1//6.06 
                             L = 5//100//6.16 
                             cm = 1 
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}
			branch2 {
			     access branch2 
                             nseg = 1 
                             diam = 0.05//0.1//6.06 
                             L = 10//100//6.16 
                             cm = 1 
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}
	 		branch3 {
			     access branch3 
                             nseg = 1 
                             diam = 0.025//0.1//6.06 
                             L = 20//200//6.16 
                             cm = 1 
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}
			br0 {
			     access br0 
                             nseg = 1 
                             diam = 0.15//0.1//6.06 
                             L = 3//100//6.16 
                             cm = 1
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}
			br1 {
			     access br1 
                             nseg = 1 
                             diam = 0.1//0.1//6.06 
                             L = 5//100//6.16 
                             cm = 1 
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}
			br2 {
			     access br2 
                             nseg = 1 
                             diam = 0.05//0.1//6.06 
                             L = 10//100//6.16 
                             cm = 1 
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}
	 		br3 {
			     access br3 
                             nseg = 1 
                             diam = 0.025//0.1//6.06 
                             L = 20//200//6.16 
                             cm = 1 
                             Ra = 100//e3
			     celsius=30
			     insert GRC_LKG3 	
				   // insert extracellular    
			}*/	 
                        	 
                        for(i=0;i<ndend;i=i+1){ 
                                 connect dend_4[i](1), dend_3[i](0) 
                                 connect dend_3[i](1), dend_2[i](0) 
                                 connect dend_2[i](1), dend_1[i](0) 
                                 connect dend_1[i](1), soma(0)
			}	 
			connect soma(1), hillock[0](0)
			connect hillock[0](1), hillock[1](0)
			connect hillock[1](1), hillock[2](0)
			connect hillock[2](1), hillock[3](0)
			connect hillock[3](1), hillock[4](0)
			connect hillock[4](1), axon[0](0)


			for(i=0;i<naxon-1;i=i+1) {
				connect axon[i](1), axon[i+1](0)
			}
						
			connect axon[naxon-1](1),pf[250](0.5)
			
			connect pf[0](1), pf[1](0)

			for(i=1;i<npf-1;i=i+1) {
				connect pf[i](1), pf[i+1](0)
			}
			//connect axon[naxon-1](1),branch0(0)

			/*connect branch0(0), pf[0](0)
			connect branch0(1),branch1(0)
 			connect branch1(1),branch2(0)
 			connect branch2(1),branch3(0)
						
			connect pf[npf-1](1),br0(0)
			connect br0(1),br1(0)
 			connect br1(1),br2(0)
 			connect br2(1),br3(0)*/

                        Area_soma = PI*soma.diam*soma.L*1e-8 
                        //Area_axon = 0 //not necessary (seems) 
                        //Area_dendrites = 0 //not necessary

			

		
                } 
endtemplate GrC