How to load and replace hoc files within a loop

The basics of how to develop, test, and use models.
Post Reply
fabien tell
Posts: 43
Joined: Mon Mar 25, 2013 1:36 pm
Location: france
Contact:

How to load and replace hoc files within a loop

Post by fabien tell » Mon Jan 29, 2018 10:12 am

Hello Ted,
Hope everything is fine with you.
I'm currently working using different morphological files (hoc files obtained form cell builder) from neurons to analyse the impact of morphology on cell firing.

Each file contains a detailed morphology with similar topology by different length or diameter. Channels are inserted by calling an hoc file (biophysic.hoc). See le init file for the cell1.

Code: Select all

 load_file("nrngui.hoc")

objectvar g[20]
ngraph=0

proc addgraph() { local ii	// define subroutine to add a new graph
				// addgraph("variable", minvalue, maxvalue)
	ngraph = ngraph+1
	ii = ngraph-1
	g[ii] = new Graph()
	g[ii].size(0,tstop,$2,$3)
	g[ii].xaxis()
	g[ii].yaxis()
	g[ii].addvar($s1,1,0)
	g[ii].save_name("graphList[0].")
	graphList[0].append(g[ii])
}
nrnmainmenu()			// create main menu
nrncontrolmenu()		// create control menu

/* Globals */

tstop=500
dt=0.01
celsius=32
v_init=-65
finitialize(v_init)


load_file("subiter.hoc")
load_file("cell1.hoc")
load_file("biophys.hoc")
load_file("fixnseg.hoc")
load_file("analysis.hoc")


proc celldef() {
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()
}
celldef()


addgraph("soma.v(0.5)",-100,30)

run()
analysis () 
/* this proc analyses spiking and write data to a file */
My question is : is it possible (i GUESS IT IS) after a run and analysis to open another cell2 (up to n) , run again and write the output to the same file within a loop.

I tried to put en index to the name of the file cell[1] but it did not work :

Code: Select all

for i=1 , 20 {

load_file("cell[i].hoc") 

load_file("subiter.hoc")
load_file("biophys.hoc")
load_file("fixnseg.hoc")
load_file ("analysis.hoc") 

proc celldef() {
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()
}
celldef()


addgraph("soma.v(0.5)",-100,30)
run ()
analysis ()
Thanks a lot

Fabien

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

Re: How to load and replace hoc files within a loop

Post by ted » Tue Jan 30, 2018 9:22 pm

The problem is how to "clean up" after each simulation. You can't simply load the new model cell's specification and assume that stuff left over from the previous model cell will not interfere. The way to prevent such problems is to execute a set of independent simulations. This can be done by taking advantage of NEURON's own bulletin-board style parallelization--see the Programmer's Reference documentation of the ParallelContext class--or by using some other software to launch and control a set of independent NEURON simulations.

This file contains a complete example of how to do bulletin-board parallelization of a program that executes a family of simulations:
https://www.neuron.yale.edu/ftp/ted/neu ... zation.zip
The code and how to use it are described in the files bulletin_board_parallelization.html and walkthroughs.html
Be sure to read the relevant entries in the Programmer's Reference.

This approach is generally used to explore the effects of varying one or more parameters. For your particular problem, instead of iterating over a set of parameter values, you'd be iterating over a set of file names, with each file containing the code that recreates a particular model cell.

fabien tell
Posts: 43
Joined: Mon Mar 25, 2013 1:36 pm
Location: france
Contact:

Re: How to load and replace hoc files within a loop

Post by fabien tell » Wed Jan 31, 2018 5:45 am

Thanks a lot Ted.
I understand the idea.
However, I thought it was possible to "destroy" the hoc file containing the topology of the cell (or any hoc file containing the biophysic) after a run by calling (loading) new hoc files (or by inserting a special instruction ?). You mean that if I intend to run sequentially different models coded in different hoc files (e.g files that would contain everything needed for a run) , I must exit neuron and restart it (nrngui and then load the next hoc file ) to prevent potential conflicts? So I may write a script under linux to do it?

Thanks again

Fabien

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

Re: How to load and replace hoc files within a loop

Post by ted » Wed Jan 31, 2018 9:28 am

The main problem is how to clean up "top level" user-created variables (user-created variables, including objects, that are not embedded in an object instance). The only way to make sure that one can destroy all user-created variables happens is to embed all user-written code in an object. I know one person who does that occasionally. I can't even point you to an entry in ModelDB that illustrates the approach.
to run sequentially different models coded in different hoc files (e.g files that would contain everything needed for a run) , I must exit neuron and restart it (nrngui and then load the next hoc file ) to prevent potential conflicts? So I may write a script under linux to do it?
That would work. So would NEURON's own bulletin-board style parallelization.

fabien tell
Posts: 43
Joined: Mon Mar 25, 2013 1:36 pm
Location: france
Contact:

Re: How to load and replace hoc files within a loop

Post by fabien tell » Wed Jan 31, 2018 9:39 am

Thanks again Ted

Have a good day.

Fabien

Post Reply