Each time you xopen a file, the contents of the file may destroy previously existing variables, procedures, functions, sections, and objects. And if the file contains a template, hoc will simply refuse to continue because it will not read the same template more than once.
If the parameters you want to vary do not affect the structure of the model (do not destroy, add, or move sections), the best way to run a batch of simulations is with a procedure that is executed _after_ the entire model specification has been executed, i.e. after
--all sections have been created and connected
--all artificial spiking cells have been created
--all synaptic mechanisms have been created and attached to spike sources and postsynaptic cells
--all instrumentation code has been executed. This means code that creates signal sources (for example IClamp, SEClamp) and code that takes care of signal monitoring (for example Graphs, Vector play and/or recording)
--all user interface code has been executed
--all control constants, variables, and procedures have been set up
The typical batch procedure contains one or more "for loops" that increment one or more independent variables over a range of values, followed by a run() statement--for example
Code: Select all
/*
usage:
batchrun(5, 50)
executes 5 simulations, each lasting 50 ms,
with soma.gnabar_hh(0.5) stepping from 0 to 0.4*default gnabar_hh
*/
proc batchrun() { local i, tmp
t_stop = $2
tmp = soma.gnabar_hh(0.5)
for i=0,$1-1 {
soma.gnabar_hh(0.5) = tmp*i/10
run()
}
}
hoc's iterator (see Programmer's Reference) can be useful for iterating an independent variable over a series of values that are not easily described by a simple algebraic expression. Alternatively, the independent variable's values might be passed in a Vector argument. It is often useful to call a "postprocessing procedure" immediately after run(), for the purpose of saving simulation results to a file or performing some preliminary data analysis on simulation results before saving them to a file.
If one of your parameters affects the structure of your model, it may not be practical to use a hoc batchrun() procedure. Instead, it may be better to use a shell script and pass parameters via command line arguments, as described in this thread:
Automating tasks: -c "statement" and batch runs
viewtopic.php?f=28&t=1747