// Example parameter file
//
// Written by Shyam Kumar Sudhakar, Ivan Raikov, Tom Close, Rodrigo Publio, Daqing Guo, and Sungho Hong
// Computational Neuroscience Unit, Okinawa Institute of Science and Technology, Japan
// Supervisor: Erik De Schutter
//
// Correspondence: Sungho Hong (shhong@oist.jp)
//
// September 16, 2017


// Declaration of some globals and their calling functions
// test dat has data for spatial kernel 150 50
// RUNTIME PARAMETERS

dt           = 0.025 // Simulation time step
v_init       = -60 // Average
step_time    = dt // 0.025 ms = Sampling period
stoptime     = 2000 // ms Runtime
step_record  = 100*step_time // 100 x lower sampling freq.
Scale_factor = 0.7 // Scale down/up x,y dimensions, 1 = default volume


VLOW=-80 // lowest initial membrane potential after randomization
VHIGH=-55 // highest initial membrane potential after randomization

// parameters for the Golgi cell model by Solinas et al (2008)
// NOT used in the published model
numAMPAGolgiMF = 1
numAMPAGolgiPF = 1
numAMPAGolgiGC = 1
numGABAGoC     = 1
numNMDAGolgiPF = 1

loadtop = 0 // option for setting Golgi cell locations. See populations/GolgiPopulation.hoc


// GEOMETRICAL PARAMETERS

// maximum width for each layer in um
MLdepth = 200
GLdepth = 200
PCLdepth = 30

nband = 5 //3*2 // number of Zebrin II bands
bandwidth = 200 // mean value in um, Sillitoe et al., 2008

/// CELL COUNT RATIOS

MFdensity  = 1650 //5000  //cell/mm2 Hererro et al., 2011
GoCdensity = 9500  // GoC density in cells/mm3, default 9500 (Dugue et al, 2009)
SCdensity  = 12000 // SC density in cells/mm3, estimated number
BCdensity  = 12000 // BC density in cells/mm3, estimated number

GCtoGoCratio = 400 // default 400 (Dugue et al, 2009; Korbo et al)
GCtoPCratio  = 800 // default 800 (Lange et al, 1982)
SCtoPCratio  = 23  // default 23 (Barmack and Yakhnnitsa, 2008)
BCtoGoCratio = 6   // default 6 (Palay, 1972 for cats)



//SPATIAL DIMENSIONS OF VARIOUS PARAMETERS
//spatial dimensions of the GoC population in um
//GoCxrange = bandwidth*nband
GoCxrange = 1500 //bandwidth*nband*Scale_factor
GoCyrange = 1000*Scale_factor
GoCzrange = GLdepth

//TODO: spatial dimensions of the Purkinje cell population in um
PCxrange = GoCxrange
PCyrange = GoCyrange
PCzrange = GoCzrange

//spatial dimensions of the GC population in um
GCxrange = GoCxrange
GCyrange = GoCyrange
GCzrange = GLdepth

//TODO: spatial dimensions of the BC population in um
BCxrange = GoCxrange
BCyrange = GoCyrange
BCzrange = MLdepth/3 // Bottom third of ML, closer to PC layer

//TODO: spatial dimensions of the SC population in um
SCxrange = GoCxrange
SCyrange = GoCyrange
SCzrange = 2*MLdepth/3 // Top 2/3 of ML (Palay,1972)

//spatial dimensions of the MF population in um
MFxrange = GoCxrange
MFyrange = GoCyrange


// MOSSY FIBRE PARAMETERS

// std of Normal distribution for the connection probability that defines the glomerulus
MFstdnorm = 0.2

numseg = 1  // default 14

box_fac=2.5 // ratio of cuboid variation of y/ variation of x (experimental data; Sugihara & Shinoda)

MFxextent = 297+40
MFyextent = 474+40*box_fac

//instantiate more MF but include GL points that fall within nw

box_fac=2.5 // ratio of cuboid varion of y/ variation of x (exp data; sugihara & shinoda)

MFxextent = 64+40 //297+40
MFyextent = 84+40*box_fac //474+40*box_fac

// number of MFbundles (0 for all) stimulated and patch size in um
numBundles = 30
// maximum number of MF connections to a single GC or GoC
MFcons = 6
// mean MF frequency Hz
MFfreq = 1
// mean bundle frequency Hz
MFfreqBundle = 60
// MF Bundle radius in um
MFBundleZone = 70
// multiplicative factor to the second bundle class
factorf = 1.25
//a coefficient that controls the normally distributed noise of MF input
MFnoise = 1

// PF parameters
PFstep    = 7.5 // put PF connection points every PFstep um
PFlength  = 2000 // length of PF
PFzoffset = 250  // Z-axis offset of parallel fiber  relative to GC soma (or height of ascending fiber)

// AA parameters
AAstep    = 50 // put AA connection points every AAstep um

// OTHER PARAMETERS
// Random number generator seed
gseed=15
// Synaptic failure rate of the network
frate=0.8
//axonal transmission speed (um/ms)
TS = 50 // minumum value from Mapelli et al. 2010
TS_mf = 2000  // um/ms 2 m/s refer presentation 37
TS_pf = 500 // um/ms 0.5m/s
TS_goc = 2000  // um/ms 2m/s


// CONNECTION PROBABILITY
ProbMFGoC = 0.03
ProbMFGC = 1
probGoCtoGC = 0.05 // for full 0.03 for scale
probAxontoGoC = 0.05//for full 0.1 for scale

ProbPFtoSC = 0.8 // TODO: Not yet tested
ProbPFtoBC = 0.8 // TODO: Not yet tested
ProbPFtoGoC = 0.6// 0.9 ctrl

//POST SYNAPTIC RECEPTOR DENSITY
numAMPA=5000 // max number of activated receptors/cells
numGABA = 5000

// GOLGI PARAMETERS FOR CONNECTIVITY

// 0 to Turn off Random PF position
RandomPF=1

// GoCs Dendrite variability factor
sigmad = 0.1

// GoCs dendrites ML position variability factor
MLdev = 0.2

// sets the connection zone (cylinder diameter) in um which a MF will connect to a GoC or GRC.
// the default is zone = to MF mean separation
MFtoGCzone = 30 //((GoCxrange)/(nMFx))
MFtoGoCzone = 70   //160 um for arborization rule, considering that the GoC dendritic area on XY can connect any MF

// sets the connection zone (sphere diameter) in um which a PF will connect to a GoC.
PFtoGoCzone=5 //4.4 ctrl

// sets the connection zone (sphere diameter) in um which an AA will connect to a GoC.
AAtoGoCzone=15

// sets the connection zone (sphere diameter) in um which a GoC will form an inhibitory connection to another GoC.
GoCtoGoCzone=100

// sets the connection zone (sphere diameter) in um which a GoC will form an electrical synapse to another GoC.
GoCtoGoCgapzone=80

// sets the connection zone in um which a GoC will connect to a GC.
// the default sagittal extension is 650 um (Barmack and Yakhnnitsa, 2008)
// the default mediolateral extention is 180 um
GoCtoGCsagittal = 650
GoCtoGCmedio = 180


// Parameters in um for Volumetric distribution

dendradius = 100 // 100 default
dendz = 160   // 160 default
//dendsagittal = 100 // y-axis
//dendcoronal = 100  // x-axis

// Golgi cell geometric parameters

numAxonGolgi         = 20

GoC_AxonL            = 1200 //450

// Golgi cell axon point generation limits
//
// A uniform random number between [min .. max] is chosen and then is
// added to the soma coordinates in order to obtain each axonal point
//
GoC_Axon_Xmin        = -GoCtoGCmedio/4
GoC_Axon_Xmax        = GoCtoGCmedio/4
GoC_Axon_Ymin        = -GoCtoGCsagittal/4
GoC_Axon_Ymax        = GoCtoGCsagittal/4
GoC_Axon_Zmin        = -75
GoC_Axon_Zmax        = 75

GoC_d_lambda         = 0.1
GoC_d_diam           = 3
GoC_d_Ra             = 100
GoC_cm               = 1
GoC_d_freq           = 100 //100 Hz
GoC_d_lambda_f       = 1e5*sqrt(GoC_d_diam/(4*PI*GoC_d_freq*GoC_d_Ra*GoC_cm)) //AC length constant at 100 Hz
//printf("AC length cont at 100 Hz is %d\n",GoC_d_lambda_f)

numDendGolgi         = 4
GoC_nDendML          = 2 // number of dendrites that connect to the PF in the ML
GoC_nDendGL          = numDendGolgi - GoC_nDendML
GoC_ApicalDendL      = 166 // dendritic lengths used by compartmental model
GoC_BasolateralDendL = 60  // dendritic lengths used by compartmental model

GoC_PhysApicalDendH      = 2 * GoC_ApicalDendL  // dendritic cone height used for geometric connectivity
GoC_PhysBasolateralDendH = -0.1 * GoC_BasolateralDendL // dendritic cone height lengths used for geometric connectivity
GoC_PhysApicalDendR      = 100  // dendritic cone radius used for geometric connectivity
GoC_PhysBasolateralDendR = 60 // dendritic cone radius used for geometric connectivity

GoC_Ad_nseg          = int((GoC_ApicalDendL/(GoC_d_lambda*GoC_d_lambda_f)+0.9)/2)*2 + 1
GoC_Bd_nseg          = int((GoC_BasolateralDendL/(GoC_d_lambda*GoC_d_lambda_f)+0.9)/2)*2 + 1
printf("Nseg for APical is %d and Basal is %d\n",GoC_Ad_nseg,GoC_Bd_nseg)
GoC_Ad_nsegpts       = 5
GoC_Bd_nsegpts       = 4
GoC_Atheta_min       = 30
GoC_Atheta_max       = 120
GoC_Btheta_min       = -20
GoC_Btheta_max       = -240
GoC_Atheta_stdev    = 50
GoC_Btheta_stdev    = 1

// TODO: MLI PARAMETERS

// Sagittal Circular zone for PFto SCs connections in um (Palay, 1972)

SCzone = 110 // default 40
BCzone = 120 // default 60
// TODO: 1 for full net with ML, 0 for GL only
MLplug = 0
// Gap Junction variables
Gapcond = 0.2 // Gap conductance in nano Siemens from Mann-Metzer, P., & Yarom, Y. (2000). Electrotonic coupling synchronizes interneuron activity in the cerebellar cortex.
connectacrossbands = 0 // flag for connecting MLI's across sagittal bands
saggwidth = 100 // sagittal width for Gap junctions
nsag = GoCxrange/saggwidth

ENABLE_GRAPHICAL_INTERFACE=1
flag_vecstim = 1 // if spike times for mossy fibers are loadde from an external file

BC_ampa_rise =0.19
BC_ampa_decay= 1.5
SC_ampa_rise =0.19
SC_ampa_decay =1.5
BC_gaba_rise = 0.6
BC_gaba_decay = 7
SC_gaba_rise = 0.6
SC_gaba_decay = 7

// Parallel fiber to Golgi cell connections
PF_GoC_con = 1
Golgi_den_con = 0

// Golgi to Golgi inhibitory connections
GoC_GoC_inh_con = 1
ProbGoCtoGoCbase = 0.99
GoCtoGoCdecayrate = 3.6e-3

// Golgi to Golgi gap junction connections
GoC_GoC_gap_con = 1

// Parameters for Boltzmann distribution representing Golgi gap junction probability (Vervaeke et al, 2010)
GoC_GoC_gap_A1 = 91
GoC_GoC_gap_A2 = -1745.
GoC_GoC_gap_x0 = 267.
GoC_GoC_gap_dx = 39.

// Parameters for exponential distribution represention Golgi gap junction conductance (Dugue et al, 2009)
GoC_GoC_gap_beta    = 1.659
GoC_GoC_gap_lambda  = 0.01259
CV_gmax = 0.25 // coefficient of variation

// for saving data. See run.hoc
clear_ds=1

// MF to GC connections
MF_GC_con = 0
AA_GoC_con = 0

// positions of the stimulated MF kernels.
// Membrane potentials will be recorded only for those cells. See run.hoc.
x_c1=750
y_c1=350
x_c2=1250
y_c2=350