load several geomtery file

The basics of how to develop, test, and use models.
Post Reply
thats_karlo

load several geomtery file

Post by thats_karlo »

Hi,

I'm not sure i select a good title for my post, however what i like to do is run a specific test for several cells.

For one cell i have the following code

Code: Select all

load_file("C1.hoc")
load_file("run_simulation")
print "print the result" , val 
My question is : how can i run the code for several c1.hoc, c2.hoc,....c10.hoc , something like

Code: Select all

proc test ($1){

//filename=$1

 load_file($1)
load_file("run_simulation")
print "print the result" , val 

}
unfortunately, when the code calls next cell to run_simulation, suddenly program is closed. please let me know your advise,
ted
Site Admin
Posts: 6358
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: load several geomtery file

Post by ted »

Presumably each of your c*.hoc files contains a specification of the properties of a different model cell. To avoid problems such as conflicts in variable name space, orphaned point processes, and incorrect initialization of user-specified hoc variables, each model cell must be exercised in its own NEURON session. In other words, you have to
start NEURON and make it load cell1.hoc
run a simulation
save results
exit NEURON
start NEURON and make it load cell2.hoc
run a simulation
save results
exit NEURON
. . .

The easiest way to do this is by writing a shell script ("batch file") using whatever command line utilities your operating system provides. Or you could use a scripting language such as perl, python, or ruby.

You need to create a loop that calls NEURON as many times as necessary, each time with a different argument that makes NEURON load a different c*.hoc file. Execute
nrngui -h
and you'll discover that one of its command line switches is -c, which allows you to pass nrngui a hoc statement.

Here's a hoc program that uses this feature to create a file name that includes an integer that is passed on the command line:

Code: Select all

/*
test.hoc
demonstration how to use the command line to pass NEURON a parameter

Command line        makes NEURON print
nrngui test.hoc     filename is c0.hoc
nrngui -c "zzz=1"   filename is c1.hoc
nrngui -c "zzz=PI"  filename is c3.hoc
nrngui -c "zzz=-PI" filename is c9999.hoc
*/

load_file("nrngui.hoc")

strdef filename

num = 0

if (name_declared("zzz")==5) { // zzz has been assigned a numerical value
  if (zzz>=0) {
    num = int(zzz)
  } else {
    num = 9999
  }
}

sprint(filename,"c%d.hoc",num)

print "filename is ", filename
Be sure to read about sprint and name_declared in the Programmer's Reference.

The rest is up to you.
reza_rzm

Re: load several geomtery file

Post by reza_rzm »

Hello,

I have tried to write a shell script to run Neuron and unfortunately, never succeed. I was wondering if you already have a solution for that, you can share with me!

i am using Neuron 7.1, winxp (32 -bit) and don't have cygwin!

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

Re: load several geomtery file

Post by ted »

reza_rzm wrote:i am using Neuron 7.1, winxp (32 -bit) and don't have cygwin!
Oh, yes you do! Not much of cygwin, but enough to create and execute some simple shell scripts. See
rxvt sh under MSWin
viewtopic.php?f=28&t=1391

Here's a shell script that I tried right now:

Code: Select all

for foo in alpha beta gamma
do
  echo $foo
done
and here's its output:

Code: Select all

alpha
beta
gamma
The shell is bash, and nrniv (plus a few cygwin ports of UNIX commands) is in /cygdrive/c/nrnxx/bin
where the "xx" means the version number.

For more information and examples, see
rxvt sh under MSWin
viewtopic.php?f=28&t=1391
reza_rzm

Re: load several geomtery file

Post by reza_rzm »

Dear Ted,
thanks so much for your prompt reply, and thanks for this link :viewtopic.php?f=28&t=1391:
luciana
Posts: 17
Joined: Sun Mar 09, 2014 2:29 pm

Re: load several geomtery file

Post by luciana »

Hello,

I have wrote a shell script that calls NEURON many times, each time with a different argument that makes NEURON load a different c*.hoc file.
Inside the loop (in the batch file) I have:

nrngui -c "zzz=$file" test.hoc

and like Ted wrote above, the hoc program create a file name that is passed on the command line to nrngui, as a hoc statement.

Now, I would like to save certain values from each run into a text file. This action should be outside the test.hoc, because in this case it would be being overwritten on each loop. Is that correct?

Hope have writing clearly, thanks in advance!,

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

Re: load several geomtery file

Post by ted »

Since you're using a shell script to control a series of simulations--that is, implementing a loop that does something like this algorithm in pseudocode

Code: Select all

repeat
  run a simulation with a new condition
until done
it seems most natural to revise your shell script so that the output file is given a new name on each pass through the loop. That is, the algorithm you want your new shell script to implement is (in pseudocode)

Code: Select all

repeat
  run a simulation with a new condition
  change the name of the output file to something unique 
until done
The unique name is completely up to you. You might prefer the new name to reflect the name of the morphology file, or you might simply include an index number (a number that is incremented on each pass through the loop). Either of these is doable with bash. If you need a good, free reference, see the Advanced Bash-Scripting Guide by Mendel Cooper, which is available in its most recent online revision from http://tldp.org/LDP/abs/html/. If you want to have a copy on your own machine, get one of the files from https://archive.org/details/AdvancedBashScriptingGuide
luciana
Posts: 17
Joined: Sun Mar 09, 2014 2:29 pm

Re: load several geomtery file

Post by luciana »

Hi Ted!
Thanks for your answer. What you say, make me sense.
But, I have figured out it this way:
In the shell script:

Code: Select all

repeat
   run a simulation with a new condition
   read LINE of the output file
   echo $LINE >> textfile.txt
until done
Ah! and thank you for the reference,
Luciana.
ted
Site Admin
Posts: 6358
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: load several geomtery file

Post by ted »

Cooper's article is very clear and practical.
menica
Posts: 71
Joined: Wed Sep 02, 2015 11:02 am

Re: load several geomtery file

Post by menica »

hi, I am having a similar problem.
I want to load and scan 10 files named "namefile_#number".
I tried different ways but I am stuck to this.

for i=1:10 {
objref m,f
f = new File()
load_file("gnacl_%d.txt", i)
f.ropen("gnacl_%d.txt", i)
m = new Matrix()
m.scanf(f)
print m.nrow, m.ncol
}

this command load_file("gnacl_%d.txt", i) is not working.
It returns the error " Expecting string argument". I tried to substitute %d with %s, but without success.
How can I use load_file() properly in a loop?

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

Re: load several geomtery file

Post by ted »

How can I use load_file() properly
Start by reading the Programmer's Reference entry for load_file(). Then read the first two posts in this thread.
menica
Posts: 71
Joined: Wed Sep 02, 2015 11:02 am

Re: load several geomtery file

Post by menica »

Dear Ted,
I read the documentation and the post, but I don't want to use the command line to pass NEURON a set of parameter.
I am always using the same cell and I would like to change only a couple of parameters stored in txt file.
I tried to run the example you mentioned but it is not working.
There is a simple way to load a txt file in a loop? Should be something similar to the procedure to create files in a loop? Like here:
viewtopic.php?f=8&t=3553

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

Re: load several geomtery file

Post by ted »

The second post in this thread contains an example of the use of sprint() to create a file name that includes a number
sprint(filename,"c%d.hoc",num)
but, as you point out, the Forum also contains other examples of the same thing.

You're most of the way to solving your own problem.
Now what you need to do is combine
"using sprint to create a file name"
with
"using a loop to perform a sequence of tasks"

And it would help to check the Programmer's Reference if the interpreter gives you an error message.
menica
Posts: 71
Joined: Wed Sep 02, 2015 11:02 am

Re: load several geomtery file

Post by menica »

Hi Ted,
now it is working. I am able to open in a loop a series of files

objref m
m=new Matrix()
//m=new Vector()
strdef fname
objref f
for i=1,2 {
sprint(fname, "gnacl%d", i)
print fname
f = new File(fname)
f.ropen()
m.scanf(f)
print m.nrow, m.ncol
//print m.size()
}

the problem is when I want to fill a matrix with the values contained in the files. it returns 0 values for the number of rows and columns, but if I fill a vector it returns the right numbers of elements in the files.
I am using txt files with 2 columns generated with matlab.
How can I work with the matrix? Should I specify something more in the scanf? What is wrong in the code?

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

Re: load several geomtery file

Post by ted »

You have the data file that you generated with Matlab, and you have the NEURON Programmer's Reference which contains documentation of the Matrix and Vector classes. Start reading.
Post Reply