Page 1 of 1

Initial conditions

Posted: Thu Oct 30, 2008 5:10 pm
by rosaqi
Hi,
If I have a small network of neurons, is there a way to specify different initial membrane voltages for each of these neurons?

Re: Initial conditions

Posted: Thu Oct 30, 2008 10:06 pm
by ted
Yes. Several. The proper choice for your particular application depends on many unspecified details, such as (but not necessarily limited to):
Is the initial potential of each cell supposed to be the same as its resting potential?
If a cell is represented by multiple compartments, is each compartment supposed to start at the same potential?

Re: Initial conditions

Posted: Fri Oct 31, 2008 8:57 am
by rosaqi
I would like all of the cells to start close to the resting potential, but all at slightly different potentials (eg. at -65, -62, -68mV etc). All the compartments for each cell, however, would start at the same potential.

Re: Initial conditions

Posted: Fri Oct 31, 2008 10:01 am
by ted
Are all cells represented by single compartments, i.e. single section with nseg = 1?

Re: Initial conditions

Posted: Fri Oct 31, 2008 10:23 am
by rosaqi
Some cells have one or two axons, but they are all single comparments, so a cell with a cell body and two axons will have 3 compartments in total.

Re: Initial conditions

Posted: Fri Oct 31, 2008 10:50 am
by ted
Do you want all voltage-dependent variables to start with the steady state values that correspond to the initial potential? as if each compartment was voltage clamped to its starting potential for a long time before the begining of the simulation?

Re: Initial conditions

Posted: Fri Oct 31, 2008 12:06 pm
by rosaqi
Yes, that would be what I would like to have.

Re: Initial conditions

Posted: Fri Oct 31, 2008 12:54 pm
by ted
Create a file called custominit.hoc that contains this code:

Code: Select all

proc custominit() {
  for each cell that needs to start at some potential different from v_init {
    for each section in this cell {
      v = whatever the starting potential of this cell should be
    }
  }
  finitialize()
}

proc init() {
  finitialize(v_init)
  custominit()
  if (cvode.active()) {
    cvode.re_init()
  } else {
    fcurrent()
  }
  frecord_init()
}
Load this file after the code that sets up your model has been executed.

Details of how to iterate over all cells that need custom initialization, how to iterate over all the sections of each such cell, and how you associate each cell with its own starting potential depend entirely on your strategy for creating each cell. The best programming practice for network modeling is for each cell to be an instance of a cell class, and to keep track of each cell instance by appending its objref to a List. This suggests that you also create another List (maybe called needcustominit, or customcells), but append to this second List just those objrefs of cells that need custom initialization.

You must also deal with the fact that different cell classes may have different numbers of sections. The simplest approach, from the standpoint of development, debugging, and maintentance, would be for each cell class to have a public SectionList (maybe called all) that is initialized at the time of cell creation by appending each section to it. Then your code to iterate over any cell instance's sections becomes very simple--just iterate over the sections in that cell's all SectionList. proc custominit() is easy--

Code: Select all

proc custominit() { local i, vinitial
  for i = 0, needcustominit.count()-1 {
    vinitial = f(i) // f(i) returns the desired initial potential for cell i
    forsec needcustominit.o(i).all {
      v = vinitial
    }
  }
  finitialize()
}

Re: Initial conditions

Posted: Fri Oct 31, 2008 3:30 pm
by rosaqi
Thank you for your suggestion. After creating the custominit.hoc file, do I simply add load_file("custominit.hoc") at the end of my original hoc file? Is there a way to check whether the membrane voltages are initialized correctly? When I tried to access the soma of one of the cells and checked the membrane voltage before I ran the program, it was still the previous initialized voltage instead of the new one.

Re: Initial conditions

Posted: Fri Oct 31, 2008 5:43 pm
by ted
rosaqi wrote:After creating the custominit.hoc file, do I simply add load_file("custominit.hoc") at the end of my original hoc file?
After the code that specifies model properties has been executed, and before calling run().
Is there a way to check whether the membrane voltages are initialized correctly?
Sure. Seeing is believing. Make a small net with just a few cells. Create a graph that shows v(0.5) for each section of each cell. Make each trace use a different color (I really am talking about a tiny model, with just a very few sections). Run a simulation that stops after 1 ms. Examine all the traces using the graph's crosshairs feature (click on each trace, then drag the cursor back to t = 0) to verify that each trace starts at the correct potential at t = 0.

For printed verification, define a custom proc run() that, immediately after calling stdinit(), calls another proc that compares all membrane potentials against the values that you wanted, and prints an error message if any discrepancy is detected.

Code: Select all

proc verifyinit() { local i, vinitial
  for i = 0, needcustominit.count()-1 {
    vinitial = f(i) // f(i) returns the desired initial potential for cell i
    forsec needcustominit.o(i).all {
      if (v != vinitial) {
        print needcustominit.o(i), "-- bad initialization of ", secname(), "-- v is ", v, " instead of ", vinitial
      }
    }
  }
}

proc run() {
        running_ = 1
        stdinit()
        verifyinit()
        continuerun(tstop)
}
I should point out that this custom run(), and the custom finitialize() of my previous message, are slight modifications of the run() and finitialize() that are part of NEURON's standard run system, which you can see for yourself by examining nrn/lib/hoc/stdrun.hoc