//  ******************************************************
// 
//     File generated by: neuroConstruct v1.7.1
// 
//  ******************************************************

{load_file("nrngui.hoc")}

//  Initialising stopwatch for timing setup

{startsw()}

print ""
print "*****************************************************"
print ""
print "    neuroConstruct generated NEURON simulation "
print "    for project: https://github.com/Simon-at-Ely/NML2_Test/blob/master/AOB_MC_neuroConstruct/AOB_MC_neuroConstruct.ncx "
print ""
print "    Description: "
print ""
print "    Simulation Configuration: SimConfig: Default Simulation Configuration "
print "    This is the default configuration of the Cell Groups, stimulations, plots, etc for this project "
print " "
print  "*****************************************************"

strdef pwd
{system("pwd", pwd)}
print ""
print "Current working dir: ", pwd

objectvar allCells
{allCells = new List()}


//  A flag to signal simulation was generated by neuroConstruct 

{nC = 1}


//  Getting hostname

objref strFuncs
{strFuncs = new StringFunctions()}
strdef host
{system("hostname", host)}
if (strFuncs.len(host)>0) {
    strFuncs.left(host, strFuncs.len(host)-1) 
} else {
    host = "????" 
}


//  Simulation running in serial mode, setting default host id

{hostid = 0}


//  Initializes random-number generator

{use_mcell_ran4(1)}

{mcell_ran4_init(640018898)}

//////////////////////////////////////////////////////////////////////
//   Cell group 0: CellGroup_0 has cells of type: iMC1_cell_1_origin
//////////////////////////////////////////////////////////////////////


//  Adding cell template file: iMitral_cell_Fig_10Hiii.hoc for cell group CellGroup_0

{ load_file("iMitral_cell_Fig_10Hiii.hoc") }

//  Adding 1 cells of type iMitral_cell_Fig_10Hiii in region Regions_1

{n_CellGroup_0 = 1}

{n_CellGroup_0_local = 0 } // actual number created on this host

objectvar a_CellGroup_0[n_CellGroup_0]

proc addCell_CellGroup_0() {
    strdef reference
    sprint(reference, "CellGroup_0_%d", $1)
    a_CellGroup_0[$1] = new iMitral_cell_Fig_10Hiii(reference, "iMitral_cell_Fig_10Hiii", "This is an AOB mitral cell that exhibited intrinsic oscillations  reconstructed using Imaris confocal microscope software by Katja Watznauer  cell split from iMC1 as:  iMC1_cell_1  Imaris exported file name:  130918_MC_labelled_slice1_oscillating_MC_d1.ims.hoc")
    allCells.append(a_CellGroup_0[$1])
}

for i = 0, n_CellGroup_0-1 {
    addCell_CellGroup_0(i)
    n_CellGroup_0_local = n_CellGroup_0_local +1 

}


//  Placing these cells in a region described by: Rectangular Box from point: (0.0, 0.0, 0.0) to (120.0, 50.0, 120.0)


//  Packing has been generated by: Random: num: 1, edge: 1, overlap: 1, other overlap: 1

{a_CellGroup_0[0].position(90.86363,10.532186,85.20397)}






//////////////////////////////////////////////////////////////////////
//   Setting initial parameters
//////////////////////////////////////////////////////////////////////

strdef simConfig
{simConfig = "Default Simulation Configuration"}
{celsius = 35.0}


//      Note: the following values are from IonProperties in Cell


proc initialiseValues0() {


//  Setting initial vals in cell group: CellGroup_0 which has 1 cells


//  Giving all cells an initial potential of: -74.1

    for i = 0, n_CellGroup_0-1 {
        forsec a_CellGroup_0[i].all  v = -74.1

    }

}

objref fih0
{fih0 = new FInitializeHandler(0, "initialiseValues0()")}


proc initialiseValues1() {

    for i = 0, n_CellGroup_0-1 {
        forsec a_CellGroup_0[i].soma_group { eca = 80.0}
        forsec a_CellGroup_0[i].dendrite_group { eca = 80.0}
        forsec a_CellGroup_0[i].soma_group {
            cai = 7.55E-5
            cao = 2.4
        }
        forsec a_CellGroup_0[i].dendrite_group {
            cai = 7.55E-5
            cao = 2.4
        }
        forsec a_CellGroup_0[i].all { ena = 67.0}
        forsec a_CellGroup_0[i].all { ek = -86.5}
    }

}

objref fih1
{fih1 = new FInitializeHandler(1, "initialiseValues1()")}



//////////////////////////////////////////////////////////////////////
//   Adding Network Connections
//////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
//   Adding 0 stimulation(s)
//////////////////////////////////////////////////////////////////////


access iMitral_cell_Fig_10Hiii[0].filament_100000001_0

//////////////////////////////////////////////////////////////////////
//   Settings for running the demo
//////////////////////////////////////////////////////////////////////


tstop = 60000.0
dt = 0.025
steps_per_ms = 40.0

//////////////////////////////////////////////////////////////////////
//   Adding 1 plot(s)
//////////////////////////////////////////////////////////////////////


//   This code pops up a plot of a_CellGroup_0[0].filament_100000001_0.v(0.04017303)

objref CellGroup_0_v
CellGroup_0_v = new Graph(0)
{CellGroup_0_v.size(0, tstop,-90.0,50.0)}
{CellGroup_0_v.view(0, -90.0, tstop, 140.0, 80, 330, 330, 250)}
{
    CellGroup_0_v.addexpr("a_CellGroup_0[0].filament_100000001_0.v", "a_CellGroup_0[0].filament_100000001_0.v(0.04017303)", 1, 1, 0.8, 0.9, 2)
    graphList[0].append(CellGroup_0_v)
}

//////////////////////////////////////////////////////////////////////
//   This will run a full simulation of 2400001 steps when the hoc file is executed
//////////////////////////////////////////////////////////////////////


//  Recording 0 variable(s)

objref v_time
objref f_time
objref propsFile

//  Single simulation run...

strdef date
// Note: not showing date/time of start/stop of simulation. This requires Cygwin to be installed// which includes the "date" unix command. Install under c:\cygwin

setuptime = stopsw()

print "Setup time for simulation: ",setuptime," seconds"


{currenttime = startsw()}
//////////////////////////////////////////////////////////////////////
//   Main run statement
//////////////////////////////////////////////////////////////////////

{run()}

{realruntime = startsw() - currenttime}
print "Finished simulation in ", realruntime ,"seconds"


//   This code pops up a simple Run Control

{
xpanel("RunControl", 0)
v_init = -60.0
xbutton("Init & Run","run()")
xbutton("Stop","stoprun=1")
t = 0
xvalue("t","t", 2 )
tstop = 60000.0
xvalue("Tstop","tstop", 1,"tstop_changed()", 0, 1 )
dt = 0.025
 xvalue("dt","dt", 1,"setdt()", 0, 1 )
xpanel(80,80)
}