running hoc files accompanied by comand line arguments, in Python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
alexandrapierri
Posts: 21
Joined: Wed Jun 17, 2015 5:31 pm

running hoc files accompanied by comand line arguments, in Python

Post by alexandrapierri » Wed Sep 25, 2019 3:44 pm

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

ted
Site Admin
Posts: 5620
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

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

Post by ted » Thu Sep 26, 2019 10:09 am

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

alexandrapierri
Posts: 21
Joined: Wed Jun 17, 2015 5:31 pm

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

Post by alexandrapierri » Wed Oct 02, 2019 5:53 pm

thanks Ted!

Post Reply