During my studies in computer science I've become quite fond of object oriented programming in java. Being interested in computational modelling, I've done an attempt at making my model consist mostly out of classes. However, for some reason it does not exactly do what I want it to do. I hope you can help me correct my (probably obvious) error.
What I want to do is the following:
1. Create an object representing the 'experimental rig'. This class has a bunch of functions to plot graphs, such as voltage, current and frequency.
2. I want to create a cell object, or a network of cells, and give a reference to the network to my experimental rig object.
3. Finally, I want to call a method ShowButtonSet() in object ExperimentalRig, which shows an xpanel with controls that allow me to change the parameters of the network, rerun the experiment with new parameters, and show me plots of the last run simulation.
Here´s how I tried to translate this into code:
File I actually run:
Code: Select all
load_file("nrngui.hoc")
load_file("stdrun.hoc")
nrnmainmenu()
xopen("TemplatePyramidalCell.hoc")
xopen("TemplateExperimentalRig.hoc")
objref Rig
Rig = new ExperimentalRig()
//----------------------------------------------------------------------------
// setup simulation parameters
//----------------------------------------------------------------------------
Dt = .1 // macroscopic time step <<>>
npoints = 300000
trans = 0
dt = 0.1 // must be submultiple of Dt
tstart = trans
tstop = trans + npoints * Dt
runStopAt = tstop
steps_per_ms = 5
celsius = 36
v_init = -65
run()
Rig.ShowButtonSet()
xpanel("RunControl")
xbutton("Run single experiment", "RunAndUpdate()")
xpanel(400, 800)
proc RunAndUpdate(){
printf("Run starting")
run()
printf("Run done")
Rig.ShowButtonSet()
}
Code: Select all
begintemplate ExperimentalRig
public init, ShowButtonSet, PlotVoltageGraph, CurrentCell
public PlotCurrentGraph, PlotVoltageGraph, PlotFrequencyGraph
objref CurrentVector, VoltageVector, FrequencyVector, NetworkConnection, SpikeVector
objref RecurrentConnection, SelfConnection
objref CurrentCell
objref nil, frequencyGraph, currentGraph, voltageGraph
isICAN = 1
proc init() {
CurrentCell = new PyramidalCell()
CurrentCell.soma SelfConnection = new NetCon(&CurrentCell.soma.v(.5), nil)
CurrentCell.soma RecurrentConnection = new NetCon(&CurrentCell.soma.v(.5), nil)
VoltageVector = new Vector()
CurrentVector = new Vector()
SpikeVector = new Vector()
CurrentCell.insertElectrode()
CurrentVector.record(&CurrentCell.electrode.i)
VoltageVector.record(&CurrentCell.soma.v(.5))
SelfConnection.record(SpikeVector)
access CurrentCell.soma
}
proc ShowButtonSet() {
xpanel("Spike results")
xbutton("Show voltage", "PlotVoltageGraph()")
xbutton("Show frequency", "PlotFrequencyGraph()")
xbutton("Show current", "PlotCurrentGraph()")
xcheckbox("Ican", &isICAN, "SetIcan()")
xslider(&RecurrentConnection.weight, 0, 1, 0, 0)
xpanel(100, 800)
}
proc SetIcan(){
access CurrentCell.soma
if (isICAN == 0){
CurrentCell.soma.gbar_iCAN(0.5) = 0
}
if (isICAN == 1){
CurrentCell.soma.gbar_iCAN(0.5) = 1.88e-5
}
}
proc PlotCurrentGraph(){
currentGraph = new Graph()
currentGraph.size(0,300000,-1,1)
CurrentVector.plot(currentGraph)
currentGraph.flush()
}
proc PlotVoltageGraph(){
voltageGraph = new Graph()
voltageGraph.size(0,300000,-100,50)
VoltageVector.plot(voltageGraph)
voltageGraph.flush()
}
proc PlotFrequencyGraph() {
FrequencyVector = new Vector(30)
if (SpikeVector.size > 0) {
SpikeVector.div(1000)
SpikeVector.floor()
for i=0, SpikeVector.size-1 {
currentIndex = SpikeVector.x[i]
FrequencyVector.x[currentIndex] = FrequencyVector.x[currentIndex] + 1
}
}
frequencyGraph = new Graph()
frequencyGraph.size(0, 30, 0, 30)
FrequencyVector.plot(frequencyGraph)
frequencyGraph.flush()
}
endtemplate ExperimentalRig
If possible, is there a way for me to move the RunAndUpdate() procedure into the ExperimentalRig class and make the buttons work without freezing?
Any help is very much appreciated!