/* -----------------------------------------------------
    Layer V Cortical Pyramidal Cell
    
    Based on Yu Yuguo ( May 1, 2008)
----------------------------------------------------- */


objref somatodendritic, dendritic




// --------------------------------------------------
//    Parameter Settings
// --------------------------------------------------

/* Global */
  dt = 0.01
  celsius   = 37
  steps_per_ms = 1/dt
  tstop = 100
  v_init = -70
  
/* Others */
  delay = 2  // global delay for preparing
  axonOnSoma=1
  
/* Passive membrane */
  ra        = 150  // decrease ad to decrease of soma vth variability, increase axon's vth variability
  global_ra = ra
  rm        = 30000   // g_pas=1/rm
  c_m       = 0.5
  cm_myelin = 0.02
  g_pas_node = 0.02

/* Active channels */
  // Nav
  Ena = 60
  gna12_soma = 80
  gna12_dend = 80 
  gna12_ais_max = 3200   // Nav1.2 
  gna16_ais_max = 3200   // Nav1.6
  gna16_nakeaxon= 300    
  gna12_myelin=20       // Nav1.2 at myelins
  gna16_node = 3200     // Nav1.6 at node
  
  vhalf_na12 = -30
  vhalf_na16 = -43
  vhalf_na = -30
  
  // Kv
  Ek = -90  
  gkv_soma = 20
  gkv_dend = 10 
  gkv_axon = 1000
  
  // Km
  gkm = .3
  gkm_soma = gkm
  
  // Kca
  gkca = 3
  gkca_soma = gkca
  
  // Ca
  Eca=140
  gca = .3
  gca_soma = gca




// ------------------------------------------------
//    Cell Geometry
// ------------------------------------------------
 

/* Clean up */  
  forall delete_section()

/* Soma and Dendrites */
  load_file("morphology/P_Soma_Dendrites.hoc")

  // build a sectionlist for soma and dendrites
  somatodendritic = new SectionList()
  forall {
    if (L/nseg>40) {
      nseg = L/40 + 1 
    }    // make sure no segments exceed 40 uM length. Note, soma.nseg remains 10.
    somatodendritic.append()  // soma and dendrites are all included
  }

    
  // build a sectionlist for dendrites only
  dendritic = new SectionList()
  forsec somatodendritic dendritic.append()
  soma  dendritic.remove()     // remove soma for pure dendritic sectionlist

/* Axon */
  load_file ("morphology/P_Axon.hoc") 
  create_axon()

  
/* Spines */
  aspiny = 0  // 0 for spiny
  if (!aspiny) {
    load_file ("morphology/P_Spines.hoc")
    add_spines(dendritic,spine_dens)
  }
  
  
  distance(0,axonOnSoma)  // set the point where axon seated on soma as the origin


// ----------------------------------------------------
//  Insert Density Mechanisms
// ----------------------------------------------------

load_file ("lib/P_DensityMech.hoc") 

// Install passive membrane properties
install_passive()  
// Install active channels
install_channels()

    
    
  
// -----------------------------------------------------------
//  Experiments: Insert Point Processes or Something Else
// -----------------------------------------------------------



xpanel("Pyramidal Cell",0)
{
  xbutton( " 1. Free play", " freePlay()")
  xbutton( " 2. AP initiation site test", " APinit()")
  xbutton( " 3. AP backpropagation failure threshold test (Figure 5e,f)", " APback()")
  }
xpanel(100,100)

proc freePlay(){
  p.hide(3)
  /*  Recording and Graphing   */
  // Call the Recording Section  
  xopen("lib/P_Recording.hoc")
  // Call the Session "hu_full" 
  xopen ("session/P_full.ses")  

  /* Inject soma, the oringinal one */
  xopen("experiment/Pyramidal/inject_soma.hoc")
  
  
  }
  
proc APinit(){
  p.hide(3)
  /*  Recording and Graphing   */
  // Call the Recording Section  
  xopen("lib/P_Recording.hoc")
  // Call the Session "hu_all" 
  xopen ("session/P_simple.ses")  
 
  /* Where Ini */
  xopen("experiment/Pyramidal/inject_soma.hoc")
  xopen("experiment/Pyramidal/whereini.hoc") 
  
 
}


proc APback(){
  p.hide(3)
  /*  Recording and Graphing   */
  // Call the Recording Section  
  xopen("lib/P_Recording.hoc")
  // Call the Session "hu_all" 
  xopen ("session/P_simple.ses")  


  /* backpropagation failure */
  xopen ("experiment/Pyramidal/inject_axon.hoc")
  xopen ("experiment/Pyramidal/failureThres.hoc")    
}

/* test */
//xopen ("experiment/Pyramidal/play.hoc")