//genesis

float dt = 20e-6

str disk = "results/"

int amp = {1 / dt} * 125 // 1 // 700 // 140 // {1 / dt + 1}
str a = (amp)
int i, k, l
str  name, elem
float t

/*********************************************************************
** Simple Granule cell model script  (#1)
** Carl Piaf BBF 1994
*********************************************************************/


 str filename = (disk) @ "G_soma-CaTI+10x4-KA+8x10-inject20"
// str filename = (disk) @ "G_soma-AMPA30dend3"
// str filename = (disk) @ "G30_soma_GABAAcorrdend0amp25"

str ascii_filename = (filename) @ ".ascii"
str history_filename = (filename) @ ".history"

/* always include these default definitions! */
include defaults 
str cellpath = "/Golgi"

/* Golgi cell constants */
include Golg_const.g 

/* special scripts  to create the prototypes */
// include Golg_chan.g
 include Golg_chan_tab.g
include Golg_synchan.g 
// include Golg_comp_soma_dend.g 
include Golg_comp_passivedend.g

/* Set the clocks */
for (i = 0; i <= 7; i = i + 1)
	setclock {i} {dt}
end
setclock 8 4e-5 // 2e-5 // 4.0e-5
setclock 9 1

/* To ensure that all subsequent elements are made in the library */
ce /library

/* These make the prototypes of channels and compartments that can be
**  invoked in .p files */

make_Golgi_chans

make_Golgi_syns

// make_Golgi_comps_soma_dend

/*
call Gran_InNa TABSAVE tabInNa37.data
call Gran_KDr  TABSAVE tabKDr37.data
call Gran_KA   TABSAVE tabKA37.data
call Gran_CaHVA TABSAVE tabCaHVA37.data
call Gran_H    TABSAVE tabH37.data
call Moczyd_KC TABSAVE tabKCa37.data
*/

make_Golgi_comps_soma_dend

//make_Vmgraph

/* create the model and set up the run cell mode */
// read cell data from .p file
echo STARTING READ CELL
 readcell Stc_3D30.p {cellpath}


   create spikegen {cellpath}/soma/spike
   setfield {cellpath}/soma/spike thresh -0.02 \
                                  abs_refract 0.001 \
                                  output_amp 1
   addmsg {cellpath}/soma {cellpath}/soma/spike INPUT Vm

   echo  {cellpath}
   foreach name ({el {cellpath}/##[][TYPE=compartment]/GABAA})
     echo {name}
   setfield {name} tau2 {{getfield {name} tau2} / 3} 
   setfield {name} tau1 {{getfield {name} tau1} / 3} 
   setfield {name} gmax {{getfield {name} gmax} * 3}
   end // foreach



create neutral /library/interneuron/soma/mf_presyn
disable /library/interneuron/soma/mf_presyn
setfield /library/interneuron/soma/mf_presyn z 0
// Comment out whichever one to switch it off 
//addmsg /library/interneuron/soma/mf_presyn /Golgi/soma/GABAA ACTIVATION z
//addmsg /library/interneuron/soma/mf_presyn /Golgi/soma/mf_NMDA ACTIVATION z
//addmsg /library/interneuron/soma/mf_presyn /Golgi/soma/pf_AMPA ACTIVATION z
//addmsg /library/interneuron/soma/mf_presyn /Golgi/dend3[8]/pf_AMPA ACTIVATION z
addmsg /library/interneuron/soma/mf_presyn /Golgi/dend1[0]/GABAA ACTIVATION z

/* Create the ascii output element */
create asc_file /output/plot_out
useclock /output/plot_out 8
enable /output
enable /output/plot_out

echo {ascii_filename}

setfield /output/plot_out filename {ascii_filename} initialize 1 leave_open 1  \
    flush 1
echo Output to {ascii_filename}

echo   {getfield   /output/plot_out   filename}

useclock /output/plot_out 8
enable /output
enable /output/plot_out

/* Create the spikehistory output element */
create spikehistory /output/history
echo  {history_filename}
setfield /output/history ident_toggle 0 \ // index
                                    filename {history_filename} \
                                    initialize 1 leave_open 1 flush 1
      addmsg {cellpath}/soma/spike /output/history SPIKESAVE

ce {cellpath}

// setup the hines solver

echo preparing hines solver...


create hsolve solve
ce solve
// if this is set then reset will NOT change Vm in Hines
setfield . path "../##[][TYPE=compartment]" comptmode 1 chanmode 4 
/*    Vm_reset 1   !! geeft foutboodschap  cannot find field 'Vm_reset' 
on '/Golgi/solve'  */
call . SETUP

setfield . computeIm 1

setmethod 11

elem = ({findsolvefield {cellpath}/solve soma Vm})       //#4
addmsg {cellpath}/solve /output/plot_out SAVE {elem}

/*
elem = ({findsolvefield {cellpath}/solve dend1[0] Vm})       //#4
addmsg {cellpath}/solve /output/plot_out SAVE {elem}

elem = ({findsolvefield {cellpath}/solve dend1[0]/GABAA Gk})       //#4
addmsg {cellpath}/solve /output/plot_out SAVE {elem}

elem = ({findsolvefield {cellpath}/solve dend1[0]/GABAA Ik})       //#4
addmsg {cellpath}/solve /output/plot_out SAVE {elem}
*/

/*

el = ({findsolvefield {cellpath}/solve dend3[8]/pf_AMPA Gk})       //#4
addmsg {cellpath}/solve /output/plot_out SAVE {el}

el = ({findsolvefield {cellpath}/solve dend3[8]/pf_AMPA Ik})       //#4
addmsg {cellpath}/solve /output/plot_out SAVE {el}
*/

/*
el = ({findsolvefield {cellpath}/solve soma/H Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#2

el = ({findsolvefield {cellpath}/solve soma/Ca_pool Ca})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#3
*/

/*
el = ({findsolvefield {cellpath}/solve soma/pf_AMPA Gk})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#9

el = ({findsolvefield {cellpath}/solve soma/pf_AMPA Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#9
*/

/*
el = ({findsolvefield {cellpath}/solve soma/Moczyd_KC Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#5

el = ({findsolvefield {cellpath}/solve soma/KDr Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#6

el = ({findsolvefield {cellpath}/solve soma/InNa Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#7

el = ({findsolvefield {cellpath}/solve soma/KA Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#8

el = ({findsolvefield {cellpath}/solve soma/CaHVA Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#9

el = ({findsolvefield {cellpath}/solve dend[4]/mf_AMPA Ik})
addmsg {cellpath}/solve /output/plot_out SAVE {el}    //#10

*/


//check

reset



// step 1.0 -time


call {cellpath}/solve HGET {cellpath}/soma
setfield {cellpath}/soma inject 0e-12 // -12e-12
call {cellpath}/solve HPUT {cellpath}/soma

step 1.0 -t


call {cellpath}/solve HGET {cellpath}/soma
setfield {cellpath}/soma inject 20e-12 // -22e-12
call {cellpath}/solve HPUT {cellpath}/soma

step 1.0 -t

call {cellpath}/solve HGET {cellpath}/soma
setfield {cellpath}/soma inject 0 // -10e-12 // -22e-12
call {cellpath}/solve HPUT {cellpath}/soma

step 1.0 -t


// Synaptic stimulation protocol

/*
call {cellpath}/solve HGET {cellpath}/soma
setfield {cellpath}/soma inject -15e-12 // -5e-12 // -12e-12
call {cellpath}/solve HPUT {cellpath}/soma

step 0.2 -t
*/
/*
 setfield /library/interneuron/soma/mf_presyn z {amp}
 step 1
 setfield /library/interneuron/soma/mf_presyn z 0
 step 0.5 -time

*/

// Current injection protocol

/*
step 0.5 -time

call {cellpath}/solve HGET {cellpath}/soma
setfield {cellpath}/soma inject 10e-12
call {cellpath}/solve HPUT {cellpath}/soma

step 1.0 -time

call {cellpath}/solve HGET {cellpath}/soma
setfield {cellpath}/soma inject 0e-12
call {cellpath}/solve HPUT {cellpath}/soma

step 0.5 -time
*/

/*
call {cellpath}/solve HGET {cellpath}/soma
setfield {cellpath}/soma inject -22.5e-12
call {cellpath}/solve HPUT {cellpath}/soma
step 0.5 -time
*/