Page 1 of 1

running hoc files accompanied by comand line arguments, in Python

Posted: Wed Sep 25, 2019 3:44 pm
by alexandrapierri
Hello Developers

I am having some difficulty finding an answer to the following question in the NEURON-Python documentation so far and was hoping for some guidance or pointing to the right direction.
My question is: How can I load (and thus execute) a hoc file from a python script that is accompanied by command line arguments?
For a simple hoc script I know that the statements load_file("temp.hoc) in NEURON and h('load_file("temp.hoc")') in Python are equivalent. However how can I execute more complex NEURON statements from within a python script, like the one below?

Code: Select all

nrniv -c gidOI=0 -c cellindOI=0 -c stimflag=0 -c "strdef runname" -c runname="\"some name\""  -c "strdef origRunName" -c origRunName="\"some name\""  -c "strdef celltype2use" -c celltype2use="\"some cell\""     -c "strdef resultsfolder" -c resultsfolder="\"00055\"" ./folder_results/run_name/00055/run.hoc -c "quit()"
thank you very much

Re: running hoc files accompanied by comand line arguments, in Python

Posted: Thu Sep 26, 2019 10:09 am
by ted
The answer is "don't". That's a lousy user interface--it's inconvenient, tedious, prone to user error, not very readable, and guarantees irreproducibility ("now, what command line did I use to get this interesting result?"). And it's a great way to make sure that nobody else wants to use your code. Suggest instead that you put all of the options into a file called something like options.py or options.hoc that is loaded at runtime.

"Suppose I want to try many different sets of options?"

For each set of options
create an options file with a unique name, e.g. options321.py (or .hoc)
create a script called run321 that copies options321.py to options.py, then launches Python or NEURON

Then when you want to execute a run with that particular set of options, just execute the script called run321

Re: running hoc files accompanied by comand line arguments, in Python

Posted: Wed Oct 02, 2019 5:53 pm
by alexandrapierri
thanks Ted!