How to call multiple morphologies

Particularly useful chunks of hoc and/or NMODL code. May be pedestrian or stunningly brilliant, may make you gasp or bring tears to your eyes, but always makes you think "I wish I had written that; I'm sure going to steal it."
Post Reply
mferran1
Posts: 5
Joined: Fri Jan 19, 2007 3:13 pm
Contact:

How to call multiple morphologies

Post by mferran1 »

Dear all,
I have a problem with the following file:

Code: Select all

load_file("nrngui.hoc")

objref general
strdef infilename

general = new File()
general.ropen("neurons.txt")

while (!general.eof()) {

general.scanstr(infilename)
xopen(infilename)

TOTALDEND = APIDENDMAX + BASDENDMAX + 3 
objref dend[TOTALDEND]

index = 0

forsec "dendrite" {
    dend[index] = new SectionRef()
    index += 1
}

forall delete_section()
}
general.close()
I think that for some reason NEURON is not going inside the while to define TOTALDEND.
The "neurons.txt" file is just a list of neurons:

Code: Select all

1.hoc
2.hoc
"1.hoc" and "2.hoc" are identical and with the following code:

Code: Select all

{create axon[29]}
{create soma[3]}
{create dendrite[89]}
{create apical_dendrite[72]}
{create user5[59]}

USER5MAX = 58
APIDENDMAX = 71
BASDENDMAX  = 88
I would really appreciate any of your suggestions.
Thanks a lot for your help,
Michele
Last edited by mferran1 on Wed Nov 24, 2010 2:05 pm, edited 1 time in total.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: How to call multiple morphologies

Post by ted »

mferran1 wrote:I think that for some reason NEURON is not going inside the while to define TOTALDEND.
Think, shmink. Prove to yourself that it does or doesn't by inserting one or more print statements, or other statements, that inform you of progress.

What are you trying to accomplish with your hoc file? My guess is that, expressed in pseudocode, your aim is something like this:

Code: Select all

REPEAT
  execute a hoc file that contains the specification of a model cell
  do something with this model cell
  throw away this model cell
UNTIL the last model specification file has been executed
Have you verified that the contents of any of the model specification files are actually executed? Easy enough to do:
1. Insert a print statement that reports the name of the file that you think the code should read next.
2. At the point at which you think the model specification code has been executed, insert a
topology()
statement that will print out the branched architecture of the model cell. Study its output to make sure that it is correct (see last suggestion below).

And are you absolutely sure that your code discards all traces of the previous model before it starts to work on the next one? This can be verified by inserting a topology() statement at the appropriate point.

Only by such tests will you discover whether things are working as you thought, and without that knowledge you're in the dark.
The "neurons.txt" file is just a list of neurons
Actually it's just a list of names of files that contain hoc code. Whether any of the code is ever executed remains to be discovered.
"1.hoc" and "2.hoc" are identical and with the following code:

Code: Select all

{create axon[29]}
{create soma[3]}
 . . .[code][/quote]Do yourself a big favor and run tests with tiny model cells--maybe three or four neurites each. And make them different so you can be sure that the two different files are actually executed. Only after your program works with tiny models will it be time to try it with models that have more than a very few neurites.
mferran1
Posts: 5
Joined: Fri Jan 19, 2007 3:13 pm
Contact:

Re: How to call multiple morphologies

Post by mferran1 »

Thanks Ted,
The shmink thought and... It worked :-) your suggestions have been very useful. Also, for all the others, this is how I solved this problem:
Now I have an external file:

Code: Select all

load_file("nrngui.hoc")

objref general
strdef infilename

general = new File()
general.ropen("neurons.txt")

while (!general.eof()) {
general.scanstr(infilename)
xopen(infilename)
xopen("simulation.hoc")

forall delete_section()
}
general.close()
This file is reading the morphology names from "neurons.txt" and passing them one at the time (infilename) to “simulation.hoc”. “simulation.hoc” runs every time on a different morphology till the end of the list.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: How to call multiple morphologies

Post by ted »

Excellent; nice and clean final result.

With hoc, there are only a few ways to figure out why a program doesn't work, and at the top of the very short list is the strategic use of print statements. Even with programming environments that have powerful debugging tools, a few print statements can be very helpful.
Post Reply