Extracellular Stimulation

Anything that doesn't fit elsewhere.
dinkc

Extracellular Stimulation

Post by dinkc »

Dear all,
I am trying to work with Neuron software for my thesis to simulate the stimulation of neuron with extracellular electrodes. But I came across some difficulties while programming with Neuron. Could somebody kindly share their knowledge with me and help? Actually, I am trying to use ‘extracellular mechanism’ to make Neuron software understand that there is an extracellular stimulation coming from the electrodes to the neuron. However, in my case, I do not have to calculate the e_extracellular using Neuron software itself because I already have the data from the matlab. I just want the Neuron to understand that there is an extracellular potential just next to the neuron and I want the Neuron software to change the e_extracellular in response to the biphasic stimulation waveform that I am planning to fed. So, I tried programming accordingly so that the value of e_extracellular would change in response to the biphasic stimulation but every time I try running the program using ‘init&run’ in ‘runcontrol’ it says ‘changed dt’ and I see no result. I was expecting the graph of e_extracellular to change with time (in response to biphasic stimulation) but I see a blank graph with no results. I tried a lot but with no luck. Now I doubt if I am in the right tract. I would be very grateful if somebody could kindly suggest something. The program looks as following for a single neuron with one soma and dendrite. Thanks in advance.

Code: Select all

load_file("nrngui.hoc")

create soma, dend
access soma

soma {
  nseg = 1
  diam = 18.8
  L = 18.8
 insert hh
 gnabar_hh = 0.24
 gkbar_hh = 0.036
}

dend {
    nseg = 5
    diam = 3.18
    L = 701.9
    insert hh
    gnabar_hh = 0
    gkbar_hh = 0

}
//connect things together
connect dend(0), soma(1)

// passive & active membrane properties

v_init    = -69

forall {
  Ra = 100 //Ohm.cm
  cm = 1 // µF/cm2
  gl_hh = 3*1e-5  // Ohm/cm2
  insert extracellular
}
// Extracellular potential
proc insert_extracellular() {local inte
        inte = $1
        insert_extracellular_soma(inte)
        insert_extracellular_dendrite(inte)
}

proc insert_extracellular_soma() {
        inte = $1
        soma e_extracellular(0.5) = inte*0.303904097136 //value from matlab
        }

proc insert_extracellular_dendrite() {
        inte = $1
        dend e_extracellular(0.5) = inte*0.303809370157 //from matlab
        }

// biphasic stimulation  initial parameters//

intensity0_def = 0
intensity1_def = -1 // -1 for a cathodic stimulation, ...
intensity2_def = 0
intensity3_def = 1 // ... +1 for an anodic stimulation
intensity4_def = 0

length0 = 1 //time length of delay at 0 intensity
length1 = 1 //time length of duration of cathodic stimulation (-1)
length2 = 0 //time length for intensity 0
length3 = 1 //time length for anodic stimulation (1)
length4 = 45 //time length for stimulus to end at 0 intensity

time0 = 0
time1 = time0 + length0
time2 = time1 + length1
time3 = time2 + length2
time4 = time3 + length3
time5 = time4 + length4

dt0 = 0.05
intensity = 1


// Procedures //

//initialisation
proc init() {
        t=0
        tstart = 0
        tstop = 0
        dt = dt0

        finitialize(v_init)        // set all state variables
        fcurrent()

        forall{el_hh = (ina + ik + gl_hh*v_init)/gl_hh}
        
}


proc run2() {
        // (-2) Initialisation
        init()

        // (-1) Insert extracellular
        intensity0 = intensity0_def*intensity
        intensity1 = intensity1_def*intensity
        intensity2 = intensity2_def*intensity
        intensity3 = intensity3_def*intensity
        intensity4 = intensity4_def*intensity
        
        // (0) Phase 0 : delay
        tstart=tstop
        tstop=tstop+length0
        if(tstop>tstart) {run3(intensity0,tstart,tstop)}

        // (1) Phase 1 
        tstart=tstop
        tstop=tstop+length1
        if(tstop>tstart) {run3(intensity1,tstart,tstop)}

        // (2) Phase 2 
        tstart=tstop
        tstop=tstop+length2
        if(tstop=tstart) {run3(intensity2,tstart,tstop)}

        // (3) Phase 3 
        tstart=tstop
        tstop=tstop+length3
        if(tstop>tstart) {run3(intensity3,tstart,tstop)}

        // (4) Phase 4 : end of stimulation
        tstart=tstop
        tstop=tstop+length4
        if(tstop>tstart) {run3(intensity4,tstart,tstop)}
}

proc run3() {local inte, tstart, tstop
        inte = $1
        tstart = $2
        tstop = $3
        insert_extracellular(inte)
        advance(tstart,tstop)
}

proc advance() {local tstart, tstop
        tstop = $2
        tstart=$1
        t=tstart
        dt=0.05
        secondorder=0
        while (t < tstop) {
                fadvance()
                V_soma = soma.v(0.5)
                 print V_soma
                }
       }
        
run2()
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stimulation

Post by ted »

Way too complicated. Use the Vector class's play method to drive e_extracellular, and take advantage of the standard run system's run() instead of writing your own simulation flow control code. You'll have a cleaner program that is easier to maintain and debug.

Hint 1: If the time course of the field consists entirely of straight line segments, e.g. square pulses and ramps, use Vector play "with interpolation" and the pair of vectors that you use to control e_extracellular will only have to contain 0,0, every breakpoint in the time course of e_extracellular, and finally a couple of points tfin-1,0 and tfin,0 so that e_extracellular returns to 0.

Hint 2: If the extracellular medium is nondispersive, a single pair of vectors, used in conjunction with xstim.mod, will be sufficient to drive e_extracellular at all nodes.
dinkc

Re: Extracellular Stimulation

Post by dinkc »

Dear Ted,
Thank you so much for replying. As you explained, I omitted all my bulky codes and tried using the rectangular pulse for stimulating my neuron. I borrowed codes from one of your zip files that I found in FAQ section for making the waveform for this dummy program. And as you said, I tried using vector play with interpolation to change my e_extracellular in response to the input waveform but still I am not getting any output. NEURON gives me syntax error every time I try using 'xtra'. So, I tried doing it without inserting 'xtra' but I am not able to see the graph of e_extracellular which was suppose to change with respect to the rectangular waveform I fed. Am i still missing something? Could you kindly look into this code and suggest something to me please? I have attached the codes below. I have also attached the second set of codes where I tried inserting 'xtra' and tried using pointer to point to e_extracellular. However, I was not able to run this second set of codes as it always says 'syntax error' in inserting 'xtra'.

This is just a dummy program with one soma and dendrite but in reality, I have to deal with large number of such sections each with different value of e_extracellular.
I have one more query which might sound bit stupid but I would be very grateful to you if you would clear this to me as well. As far as I know, the value of e_extracellular just reflects the value of the potential in one section. But there can be a large difference in this potential even over one section. So, I was also wondering if it is also possible to define e_extracellular in terms of the number of segments of the section? Can e_extracellular be fed in such a way that it varies with each segment of the section? In my case, I am able to extract the value of e_extracellular at any position in neuron using MATLAB but however I think I can only define e_extracellular per section in NEURON program. Is there some way of handling this?
I look forward to getting your suggestions.

Code: Select all

//first set of code that I was able to run but did not generate output
create soma, dend
access soma

soma {
  nseg = 1
  diam = 18.8
  L = 18.8
insert hh
gnabar_hh = 0.24
gkbar_hh = 0.036
}

dend {
    nseg = 5
    diam = 3.18
    L = 701.9
    insert hh
    gnabar_hh = 0
    gkbar_hh = 0

}
//connect things together
connect dend(0), soma(1)

// passive & active membrane properties

v_init    = -69

forall {
  Ra = 100 //Ohm.cm
  cm = 1 // µF/cm2
  gl_hh = 3*1e-5  // Ohm/cm2
  insert extracellular
}

// create basic stimulus waveform
// for this example use a simple rectangular pulse 

// default values
DEL = 1  // ms
DUR = 1
AMP = -0.05  // mA

// this works with fixed dt and adaptive integration
objref stim_amp, stim_time
stim_amp = new Vector()
stim_time = new Vector()

proc stim_waveform() {
  // this uses interpolated play
  // index    0  1    2    3        4        5
  // stim vec 0, 0,   1,   1,       0        0
  // time vec 0, DEL, DEL, DEL+DUR, DEL+DUR, DEL+DUR+1
  //  really  0, $1,  $1,  $1+$2,   $1+$2,   $1+$2+1
  // first the stim vector
  stim_amp.resize(6)
  stim_amp.fill(0)
  stim_amp.x[2]=1
  stim_amp.x[3]=1
  stim_amp.mul($3)
  // now the time vector
  stim_time.resize(6)
  stim_time.x[1]=$1
  stim_time.x[2]=$1
  stim_time.x[3]=$1+$2
  stim_time.x[4]=$1+$2
  stim_time.x[5]=$1+$2+1
}


ATTACHED__ = 0

proc attach_stim() { local inte
  inte = 0.30 //consider it to be the value of e_extracellular obtained from MATLAB
  soma e_extracellular(0.5) = inte
  forall {
    if (ATTACHED__ == 0) {  // don't bother if stim is already attached to something
        stim_amp.play(&inte, stim_time, 1) // "interpolated" play
        ATTACHED__ = 1
    }
  }
}


proc setstim() {
  del = $1
  dur = $2
  amp = $3
  stim_waveform(del, dur, amp)
  attach_stim()
}


setstim(DEL, DUR, AMP)

print "Use setstim(del, dur, amp) to change latency (ms), duration (ms),"
print "and amplitude (mA) of extracellular stimulus current."

Code: Select all

//second set of code that gave me syntax error inserting xtra and was not able to execute
create soma, dend
access soma

soma {
  nseg = 1
  diam = 18.8
  L = 18.8
insert hh
gnabar_hh = 0.24
gkbar_hh = 0.036
}

dend {
    nseg = 5
    diam = 3.18
    L = 701.9
    insert hh
    gnabar_hh = 0
    gkbar_hh = 0

}
//connect things together
connect dend(0), soma(1)

// passive & active membrane properties

v_init    = -69

forall {
  Ra = 100 //Ohm.cm
  cm = 1 // µF/cm2
  gl_hh = 3*1e-5  // Ohm/cm2
  insert extracellular
  insert xtra
}

proc setpointers() {
  forall {
    if (ismembrane("xtra")) {
		setpointer im_xtra(x), i_membrane(x)
		setpointer ex_xtra(x), e_extracellular(x)
	}
    }
}

setpointers()

// create basic stimulus waveform
// for this example use a simple rectangular pulse 

// default values
DEL = 1  // ms
DUR = 1
AMP = -0.05  // mA

// this works with fixed dt and adaptive integration
objref stim_amp, stim_time
stim_amp = new Vector()
stim_time = new Vector()

proc stim_waveform() {
  // this uses interpolated play
  // index    0  1    2    3        4        5
  // stim vec 0, 0,   1,   1,       0        0
  // time vec 0, DEL, DEL, DEL+DUR, DEL+DUR, DEL+DUR+1
  //  really  0, $1,  $1,  $1+$2,   $1+$2,   $1+$2+1
  // first the stim vector
  stim_amp.resize(6)
  stim_amp.fill(0)
  stim_amp.x[2]=1
  stim_amp.x[3]=1
  stim_amp.mul($3)
  // now the time vector
  stim_time.resize(6)
  stim_time.x[1]=$1
  stim_time.x[2]=$1
  stim_time.x[3]=$1+$2
  stim_time.x[4]=$1+$2
  stim_time.x[5]=$1+$2+1
}


ATTACHED__ = 0

proc attach_stim() {
// since is_xtra is GLOBAL, we only need to specify Vector.play()
// for one instance of xtra, i.e. at just one internal node
// of only one section that contains xtra
  forall {  // check each section to find one that has xtra
    if (ATTACHED__ == 0) {  // don't bother if stim is already attached to something
      if (ismembrane("xtra")) {
        stim_amp.play(&is_xtra, stim_time, 1) // "interpolated" play
        ATTACHED__ = 1
      }
    }
  }
}


proc setstim() {
  del = $1
  dur = $2
  amp = $3
  stim_waveform(del, dur, amp)
  attach_stim()
}


setstim(DEL, DUR, AMP)

print "Use setstim(del, dur, amp) to change latency (ms), duration (ms),"
print "and amplitude (mA) of extracellular stimulus current."

xpanel("Extracellular Stimulus Current", 0)
  xvalue("del (ms)", "DEL", 1, "setstim(DEL,DUR,AMP)", 0, 1)
  xvalue("dur (ms)", "DUR", 1, "setstim(DEL,DUR,AMP)", 0, 1)
  xvalue("amp (mA)", "AMP", 1, "setstim(DEL,DUR,AMP)", 0, 1)
xpanel(73,497)
Last edited by dinkc on Thu Dec 08, 2016 5:49 pm, edited 1 time in total.
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stimulation

Post by ted »

Yes, it is often useful to run some tests with an extremely simple model.

1. Are you sure that your model cell is excitable? Comment out all of the stuff that performs extracellular stimulation, use an IClamp to inject a 1 ms duration current pulse into the soma, and examine the time course of soma.v(0.5) and membrane potential at a couple of different locations in the dendrite.

2. Are you sure that the stimulus waveform is what you think it is? Use the Vector class's plot method to find out.

3. After you are sure about the stimulus waveform, it's time to see how the space plot of e_extracellular varies with time. Are you setting up the space plot via the GUI? When you run a simulation, does e_extracellular change at all? Be sure to launch simulations with the Movie Run tool's Init & Run button--
NEURON Main Menu / Tools / Movie Run

If you're working under MSWin, it is possible that Movie Run's Init & Run button won't do anything useful (that's a bug in some recent versions of NEURON). If that's the case, use the Run Control panel's Init button to initialize the model, then advance the simulation manually by clicking on
Single step
or
Continue for
dinkc

Re: Extracellular Stimulation

Post by dinkc »

Thank you so much for your kind suggestions. As you asked, I tried doing all the tests and got following results:-

1. The model cell is indeed excitable. I tried using Iclamp and examined the graph of soma. v(0.5) which varied with time as expected.
2. I even tried using vector class's plot to see the nature of the waveform that I am feeding to my neuron. I had used a rectangular stimulating pulse and the result I got was exactly the same as I thought. So, the problem doesn't seem to be with the waveform.
3. I am using space plot via GUI in NEURON. When I run simulation using movie Run tool's Init& Run button, I can see the graph of e_extracellular moving towards right with each time step but the value of e_extracellular is always zero at all time. I think the default value of e_extracellular is 0. This basically means nothing is changing with my e_extracellular with the changing waveform. So, I can figure out that I messed with something while applying Vector play to drive my e_extracellular. But don't know what it is.
4. I am using OS X version 10.10.3

You asked me to use Vector play ''with interpolation'' to drive e_extracellular. Does this means I have to work with 'xtra' mechanism in conjunction with 'extracellular' mechanism? I always get a syntax error when I try inserting xtra to my neuron. In my case, I also need to feed the value of e_extracellular for each sections (from MATLAB) into the NEURON programming environment. Can I do that while using vector play to drive e_extracellular? I have attached both codes (i) the one which runs but does not produce desired output(without xtra mechanism) as well as (ii) the one which doesn't run because of syntax error that occurs after inserting xtra mechanism .
I would be very grateful if you could look into it and suggest something.
Thank you so much for your time and valuable suggestions!

Code: Select all

//first set of code that I was able to run but did not generate output
create soma, dend
access soma

soma {
  nseg = 1
  diam = 18.8
  L = 18.8
insert hh
gnabar_hh = 0.24
gkbar_hh = 0.036
}

dend {
    nseg = 5
    diam = 3.18
    L = 701.9
    insert hh
    gnabar_hh = 0
    gkbar_hh = 0

}
//connect things together
connect dend(0), soma(1)

// passive & active membrane properties

v_init    = -69

forall {
  Ra = 100 //Ohm.cm
  cm = 1 // µF/cm2
  gl_hh = 3*1e-5  // Ohm/cm2
  insert extracellular
}

// create basic stimulus waveform
// for this example use a simple rectangular pulse 

// default values
DEL = 1  // ms
DUR = 1
AMP = -0.05  // mA

// this works with fixed dt and adaptive integration
objref stim_amp, stim_time
stim_amp = new Vector()
stim_time = new Vector()

proc stim_waveform() {
  // this uses interpolated play
  // index    0  1    2    3        4        5
  // stim vec 0, 0,   1,   1,       0        0
  // time vec 0, DEL, DEL, DEL+DUR, DEL+DUR, DEL+DUR+1
  //  really  0, $1,  $1,  $1+$2,   $1+$2,   $1+$2+1
  // first the stim vector
  stim_amp.resize(6)
  stim_amp.fill(0)
  stim_amp.x[2]=1
  stim_amp.x[3]=1
  stim_amp.mul($3)
  // now the time vector
  stim_time.resize(6)
  stim_time.x[1]=$1
  stim_time.x[2]=$1
  stim_time.x[3]=$1+$2
  stim_time.x[4]=$1+$2
  stim_time.x[5]=$1+$2+1
}


ATTACHED__ = 0

proc attach_stim() { local inte
  inte = 0.30 //consider it to be the value of e_extracellular obtained from MATLAB
  soma e_extracellular(0.5) = inte
  forall {
    if (ATTACHED__ == 0) {  // don't bother if stim is already attached to something
        stim_amp.play(&inte, stim_time, 1) // "interpolated" play
        ATTACHED__ = 1
    }
  }
}


proc setstim() {
  del = $1
  dur = $2
  amp = $3
  stim_waveform(del, dur, amp)
  attach_stim()
}


setstim(DEL, DUR, AMP)

print "Use setstim(del, dur, amp) to change latency (ms), duration (ms),"
print "and amplitude (mA) of extracellular stimulus current."

Code: Select all

//second set of code that gave me syntax error on inserting xtra and was not able to execute
create soma, dend
access soma

soma {
  nseg = 1
  diam = 18.8
  L = 18.8
insert hh
gnabar_hh = 0.24
gkbar_hh = 0.036
}

dend {
    nseg = 5
    diam = 3.18
    L = 701.9
    insert hh
    gnabar_hh = 0
    gkbar_hh = 0

}
//connect things together
connect dend(0), soma(1)

// passive & active membrane properties

v_init    = -69

forall {
  Ra = 100 //Ohm.cm
  cm = 1 // µF/cm2
  gl_hh = 3*1e-5  // Ohm/cm2
  insert extracellular
  insert xtra
}

proc setpointers() {
  forall {
    if (ismembrane("xtra")) {
      setpointer im_xtra(x), i_membrane(x)
      setpointer ex_xtra(x), e_extracellular(x)
   }
    }
}

setpointers()

// create basic stimulus waveform
// for this example use a simple rectangular pulse 

// default values
DEL = 1  // ms
DUR = 1
AMP = -0.05  // mA

// this works with fixed dt and adaptive integration
objref stim_amp, stim_time
stim_amp = new Vector()
stim_time = new Vector()

proc stim_waveform() {
  // this uses interpolated play
  // index    0  1    2    3        4        5
  // stim vec 0, 0,   1,   1,       0        0
  // time vec 0, DEL, DEL, DEL+DUR, DEL+DUR, DEL+DUR+1
  //  really  0, $1,  $1,  $1+$2,   $1+$2,   $1+$2+1
  // first the stim vector
  stim_amp.resize(6)
  stim_amp.fill(0)
  stim_amp.x[2]=1
  stim_amp.x[3]=1
  stim_amp.mul($3)
  // now the time vector
  stim_time.resize(6)
  stim_time.x[1]=$1
  stim_time.x[2]=$1
  stim_time.x[3]=$1+$2
  stim_time.x[4]=$1+$2
  stim_time.x[5]=$1+$2+1
}


ATTACHED__ = 0

proc attach_stim() {
// since is_xtra is GLOBAL, we only need to specify Vector.play()
// for one instance of xtra, i.e. at just one internal node
// of only one section that contains xtra
  forall {  // check each section to find one that has xtra
    if (ATTACHED__ == 0) {  // don't bother if stim is already attached to something
      if (ismembrane("xtra")) {
        stim_amp.play(&is_xtra, stim_time, 1) // "interpolated" play
        ATTACHED__ = 1
      }
    }
  }
}


proc setstim() {
  del = $1
  dur = $2
  amp = $3
  stim_waveform(del, dur, amp)
  attach_stim()
}


setstim(DEL, DUR, AMP)

print "Use setstim(del, dur, amp) to change latency (ms), duration (ms),"
print "and amplitude (mA) of extracellular stimulus current."

xpanel("Extracellular Stimulus Current", 0)
  xvalue("del (ms)", "DEL", 1, "setstim(DEL,DUR,AMP)", 0, 1)
  xvalue("dur (ms)", "DUR", 1, "setstim(DEL,DUR,AMP)", 0, 1)
  xvalue("amp (mA)", "AMP", 1, "setstim(DEL,DUR,AMP)", 0, 1)
xpanel(73,497)
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stimulation

Post by ted »

dinkc wrote:I tried doing all the tests and got following results:-
1. The model cell is indeed excitable. I tried using Iclamp and examined the graph of soma. v(0.5) which varied with time as expected.
2. I even tried using vector class's plot to see the nature of the waveform that I am feeding to my neuron. I had used a rectangular stimulating pulse and the result I got was exactly the same as I thought. So, the problem doesn't seem to be with the waveform.
Good.

Code: Select all

3. I am using space plot via GUI in NEURON. When I run simulation using movie Run tool's Init& Run button, I can see the graph of e_extracellular moving towards right with each time step
A space plot does not move toward the right or left as the simulation advances. It moves up and down. It shows the values of a range variable as a function of distance along a path between two points in a model cell. The y coordinate of any point is the value of a range variable at a particular location in the model cell, and the x coordinate of that point is the path distance of that location from some reference point (usually the 0 end of the soma). If you're looking at a trace that grows longer as the simulation advances, you're seeing some range variable being plotted as a function of time. You might want to examine this item
How to plot a variable vs. distance
in the Hot tips area of the Forum.
I am using OS X version 10.10.3
Good. Movie run should make space plots evolve nicely under OS X.
You asked me to use Vector play ''with interpolation'' to drive e_extracellular. Does this means I have to work with 'xtra' mechanism in conjunction with 'extracellular' mechanism?
No. Please read the Programmer's Reference entry about the Vector class's play method, especially the paragraph that begins
"When continuous is 1 then linear interpolation is used to define the values between time points."
I always get a syntax error when I try inserting xtra to my neuron.
Exactly what is the error that you see?
In my case, I also need to feed the value of e_extracellular for each sections (from MATLAB) into the NEURON programming environment.
No. You do not want to use xtra AND play values directly into e_extracellular. Do just one or the other, depending on the details of what you are trying to accomplish.

If you try to use Vector play to drive e_extracellular, each segment in your model will need its own Vector of e_extracellular values (unless its extracellular potential is exactly the same as that of some other segment). That would be doable, but efficiency may suffer and you may also run into memory problems if your model cell has many compartments, and there are many model cells, and the stimulus waveform varies continuously with time.

If the extracellular medium is nondispersive (i.e. purely resistive), then extracellular potential at any point in the medium is directly proportional to the instantaneous magnitude of the stimulus current. The ratio of local extracellular potential to stimulus current has units of resistance and is actually a transfer resistance. xtra was developed for models of extracellular stimulation and recording in a purely resistive medium. The nice thing about using xtra to handle extracellular stimulation is that only a single pair of vectors is needed to specify the time course of stimulus current, and only a single Vector play statement is needed to control e_extracellular at all segments of every section into which xtra has been inserted. That's because Vector play is used to drive xtra's GLOBAL variable is (which stands for "stimulus current" of course).
dinkc

Re: Extracellular Stimulation

Post by dinkc »

Dear Ted,
First of all tons of thanks for your time and nice response. You were right, I was not using the space plot. The plot that I explained to you earlier which changed with time was in fact a simple graph of the extracellular potential versus time. Sorry for the confusion. This time I made sure and I plotted the actual space plot. However, the range variable does not change with distance at all. I observed a straight line passing through 0. So, this means e_extracellular is always 0 at all locations in my neuron. (which I think is the default value). Am I right? Please do correct me. This also means I am not able to make changes in e_extracellular with the vector play?
I also went through Vector class's play method in the Programmer's Reference again and understood the concept of 'interpolation' introduced there. Thank you for the guidance.
However despite all this, my program is not working. I tried again and again and ended up in frustration. When I try driving e_extracellular with vector play it gives me syntax error. However if I put some local variable in place of the e_extracellular in the code, the code works but definitely with no output. I just slightly modified one of your codes I found in one of the forum threads. I couldn't figure out what went wrong. The part of the code that uses vector play is as follows.

Code: Select all

ATTACHED__ = 0
proc attach_stim() { 
  soma e_extracellular(0.5) = 0.399 //consider it to be the value of e_extracellular obtained from MATLAB for section soma with 1 segment
  dend e_extracellular(0.5) = 0.355 //consider it to be the value of e_extracellular obtained from MATLAB for section dend with 1 segment
  forall {
    if (ATTACHED__ == 0) {
       soma stim_amp.play(&soma e_extracellular(0.5), stim_time, 1) //"interpolated" play
        dend stim_amp.play(&dend e_extracellular(0.5), stim_time, 1) // "interpolated" play
        ATTACHED__ = 1
    }
  }
}
In the above code, while calling interpolated vector play, if I change
soma stim_amp.play(&soma e_extracellular(0.5), stim_time, 1)
to
soma stim_amp.play(&inte, stim_time, 1)
then I don't get any syntax error. (considering inte to be some local variable). But with the first code the neuron says that I have 'syntax error' at certain line.
Since you explained that xtra is introduced to take into account the nondispersive medium, I am not using it any more because for me even the resistance of the medium is already incorporated in the MATLAB programming to calculate the final e_extracellular value. So, I think I can avoid using it. I hope I am thinking correct? All I want is to make my NEURON program to understand that there is an e_extracellular field fed from matlab which needs to change with the input waveform (example:rectangular pulse) when we run the simulation. Initially I thought it shouldn't be that hard to program this but now I am having tough time even programing with one soma and dendrite. I hope I will be able to figure out something with your guidance. Thanks a lot for your time and support!
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stimulation

Post by ted »

Going back to your post of 12/8 that ran without generating an error message--
proc attach_stim does nothing useful.
You have to iterate over each segment of each section, driving each segment's e_extracellular with a different amplitude vector, as in this rough example

Code: Select all

forall for (x,0) {
  statements that play an amplitude vector into the currently accessed section's e_extracellular, i.e. e_extracellular(x)
}
This means you have to create all those driving vectors and fill them with appropriate values. And those values will be different for each segment if the local amplitude of the extracellular potential is different (besides, it would be pointless for all of the extracellular potentials to be the same throughout the simulation, because no transmembrane current flow would be produced).

It's doable, but tedious, and it doesn't scale well at all--you really don't want to do that for a cell that has hundreds or thousands of compartments, and you especially don't want to do that if you are dealing with many such cells.

You never did say what the error message was that happened when you executed the second program in that post.
What was it?
dinkc

Re: Extracellular Stimulation

Post by dinkc »

Dear Ted,
Thank you again for your time and help. Iterating over each segment and sections that too for many cells seems to be really tedious job. I am not able to make the model work with even a single soma and a dendrite and I doubt I could handle many cells with many compartments. So, probably the best option is to use 'xtra' together with extracellular mechanism to reduce the complexity? Unfortunately, I always get error message after inserting xtra into my program. The message looks as follows:

Code: Select all

-e 
NEURON -- VERSION 7.4 (1380:90539e842093) 90539e842093
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

/Applications/NEURON-7.4/nrn/x86_64/bin/nrniv: syntax error
 in test24.txt near line 35
   insert xtra
             ^
oc>
All I did in this second program is, inserted xtra in all sections with following code
forall {
Ra = 100 //Ohm.cm
cm = 1 // µF/cm2
gl_hh = 3*1e-5 // Ohm/cm2
insert extracellular
insert xtra //Attention: this is where the Neuron shows error
}
Then after I created the pointer (in fact borrowed the codes from one of your codes, I found in forum) with following commands

Code: Select all

proc setpointers() {
  forall {
    if (ismembrane("xtra")) {
	for (x, 0) {
		setpointer im_xtra(x), i_membrane(x)
		setpointer ex_xtra(x), e_extracellular(x)
	}
    }
  }
}

setpointers() //call procedure
After creating the pointer, I again used one of your codes that I found in forum to attach stimulation with vector play as follows. However, instead of driving is_xtra, I thought I should drive ex_xtra for changing extracellular and hence made that change. I hope I am correct?

Code: Select all

ATTACHED__ = 0

proc attach_stim() {
  forall {  // check each section to find one that has xtra
    if (ATTACHED__ == 0) {
      if (ismembrane("xtra")) {
        stim_amp.play(&ex_xtra, stim_time, 1) // "interpolated" play
        ATTACHED__ = 1
      }
    }
  }
}
This is all I added to the program. The same rectangular waveform and neuron morphology with one soma and one dendrite has been used in this program as well. However, I get error message from the very beginning and couldn't see if it works or not.
Also, I am confused as to how to insert value of e_extracellular for each segment. I thought we could assign values for each section by calling section name as follows

Code: Select all

dend e_extracellular = 0.34 //say this is the value of e_extracellular I obtained from Matlab
soma[0] e_extracellular =0.38 //value of e_extracellular for soma 1
However, I have no idea how I could specify the e_extracellular value for the segment of each section. Could you also please give me an example on how we could do that? Lastly, thanks again for boosting my confidence with your replies! You helped me a lot!
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stimulation

Post by ted »

There's your first problem: you haven't compiled xtra.mod. Read
Adding new mechanisms to NEURON
which is one of the threads at the top of the Forum discussion area
Adding new mechanisms and functions to NEURON
dinkc

Re: Extracellular Stimulation

Post by dinkc »

Dear Ted,
Thank you so much for pointing out my mistake. As you said, I tried working with NMODAL codes for 'xtra' mechanism today but unfortunately with no luck. I slightly edited one of your online codes for xtra mechanism and it looks like this:

Code: Select all

NEURON {
	SUFFIX xtra
	RANGE rx
	RANGE x, y, z
	GLOBAL is
	POINTER ex
}

PARAMETER {
	: default transfer resistance between stim electrodes and axon
	rx = 1 (megohm) : mV/nA
	x = 0 (1) : spatial coords
	y = 0 (1)
	z = 0 (1)
}

ASSIGNED {
	v (millivolts)
	is (milliamp)
	ex (millivolts)
}

INITIAL {
	ex = is*rx*(1e6)
: UNITSOFF
: UNITSON
}

: I used BEFORE BREAKPOINT since I am using NEURON 7.4 

BEFORE BREAKPOINT { : before each cy' = f(y,t) setup
  ex = is*rx*(1e6)
}
I wrote the code in a text file then after dragged and dropped it in 'mknrndll' as I am using OS X. I think this is how we are suppose to work? Please correct me if I made some mistake. But then I got a huge list of errors which says 'permission denied' . The error message looks like this:

Code: Select all

-e 
Creating x86_64 directory for .o files.

mkdir: x86_64: Permission denied
/Applications/NEURON-7.4
xtra NMODAL.txt
xtra NMODAL.txt
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 94: cd: x86_64: No such file or directory
ln: ./xtra.mod: Permission denied
ln: ./NMODAL.txt.mod: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 126: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 128: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 128: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 134: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 139: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 139: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 147: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 151: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 151: mod_func.c: Permission denied
/Applications/NEURON-7.4/nrn/x86_64/bin/nrnivmodl: line 154: mod_func.c: Permission denied
make: *** No rule to make target `xtra.lo', needed by `libnrnmech.la'.  Stop.
Press 'return' key to close
Could you kindly give me an insight about this new problem? Also, I have another doubt about using 'xtra' for driving e_extracelluar (in my case). Could you please help me understand it? I am really confused. Since, I don't need to compute the value of e_extracellular (as I get it from the Matlab) and also since I don't have to incorporate the the 'transfer resistance' in my model (as it is also already incorporated in Matlab programming), is it still useful to use this xtra mechanism for attaching my stimulus to drive e_extracellular? In the NMODAL program I attached, the xtra mechanism just returns the value of e_extracellular by multiplying 'is' with 'rx' . But, in my case, I already know that value. So I was wondering if there is also a direct way to drive e_extracellular with the stimulating waveform?
dinkc

Re: Extracellular Stimulation

Post by dinkc »

Dear Ted,
I was trying to work with my model during the week and as you suggested in your post on 12/13, I tried to iterate over each segment of each section using for(x,0). I got some mixed results which I couldn't interpret. Could you please help me in understanding it?

The potential of soma was around -65mV until e_extracellular was low. When I increased the e_extracellular value abruptly to very high value like 20mV, I observed an action potential coming from the Neuron which is justifiable. So, the model seems to respond to the e_extracellular value we are feeding which is a good news.

But the bad news is, I still don't observe the graph of e_extracellular which in my opinion should vary with the waveform I feed. The graph of e_extracellular just passes through the center of the graph , through origin. This probably means the value of e_extracellular is always 0 at all time point (which is its default value). But however when I give print command to see the value of e_extracellular, I observe the high value (other than 0 which I had fed into it.)

Because of this I am not able to draw any conclusion about what I am observing. Could you please point out what mistake I did?

I first created two vectors: extracellular_soma and extracellular_dend to store the value of e_extracellular obtained from Matlab. Then I tried using this vector value to change the value of e_extracellular . The program looks like this:

Code: Select all

//part of the code to enter value of e_extracellular from matlab to a vector

objref extracellular_soma, extracellular_dend
extracellular_soma = new Vector()
extracellular_dend = new Vector()

nsoma=1
a=0
extracellular_soma.resize(nsoma)
extracellular_soma.fill(0)
extracellular_soma.x[0]=1.8 //value of e_extracellular obtained from Matlab is stored to the vector extracellular_soma

for i = 0, nsoma-1 {
a=a+1/(2*nsoma)
soma.e_extracellular(a) = extracellular_soma.x[i]  //assigning value of e_extracellular of soma to the stored value in vector (which contains Matlab value)

}
print soma.e_extracellular(0.5)//checking value stored for e_extracellular in soma

ndend=5
b=0
extracellular_dend.resize(ndend)
extracellular_dend.fill(0)
extracellular_dend.x[0]=1.5 //value of e_extracellular obtained from Matlab for 1st segment of dend is stored in vector extracellular_dend.x[0]
extracellular_dend.x[1]=1.7 //value of e_extracellular obtained from Matlab for 2nd segment of dend is stored in vector extracellular_dend.x[1]
extracellular_dend.x[2]=1.8 //value of e_extracellular obtained from Matlab for 3rd segment of dend is stored in vector extracellular_dend.x[2]
extracellular_dend.x[3]=1.6 //value of e_extracellular obtained from Matlab for 4th segment of dend is stored in vector extracellular_dend.x[3]
extracellular_dend.x[4]=1.7 //value of e_extracellular obtained from Matlab for 5th segment of dend is stored in vector extracellular_dend.x[4]

for i = 0, ndend-1 {
b=b+1/(2*ndend)
dend.e_extracellular(b) = extracellular_dend.x[i] //assigning value of e_extracellular of dend to the stored value in vector (which contains Matlab value)
print dend.e_extracellular(b) //checking the value of e_extracellular
}
After this, I just used for(x,0) , as you explained in your example to vector play my stimulation into e_extracellular(x). I used following code for doing this:

Code: Select all

ATTACHED__ = 0
access soma
//procedure called 'attach_stim' is created for driving e_extracellular with the rectangular waveform
proc attach_stim() { 
  forall {
    if (ATTACHED__ == 0) { 
	for (x,0) {
        stim_amp.play(&soma.e_extracellular(x), stim_time, 1) // "interpolated" play into currently accessed section which is soma
	//stim_amp.play(&dend.e_extracellular(x), stim_time, 1) // dend is not the currently accessed section so it is kept with comment bars
	}
        ATTACHED__ = 1
    }
  }
}

The code doesn't generate any error message but the graph of e_extracellular looks faulty to me. I would highly appreciate if you could help me interpret these results and understand my mistakes. I look forward to hearing your kind suggestions. Thanks in advance!
Sincerely, Dina
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stimulation

Post by ted »

I got a huge list of errors which says 'permission denied'
Exactly where is your source code located? In the directory that contains your source code, please execute the command
pwd
then copy and paste the result into your next message.
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stimulation

Post by ted »

The code from your Sunday Dec. 18 post is guaranteed not to work for reasons that are too numerous to detail. The approach you are trying to use (driving each compartment's e_extracellular with values stored in a corresponding vector) involves a lot of tedious complexity. None of that complexity is necessary if the extracellular medium is nondispersive, i.e. can be treated as purely resistive. That would allow the use of xtra (or a simplified xtra that involves only the part that couples a stimulus current to local potential), and the tasks of program development and debugging would be much easier. So tell me, even if you have already told me before, is the extracellular medium dispersive or not?
dinkc

Re: Extracellular Stimulation

Post by dinkc »

Dear Ted,
Thank you so much for your response. You asked me in you previous post the following question:
So tell me, even if you have already told me before, is the extracellular medium dispersive or not?
I think the extracellular medium can be considered to be as a purely resistive medium in my case too. But however, I do not have to use the value of 'transfer resistance (rx) ' in computing 'e_extracellular'. I would again like to explain the scenario of my problem to you, so that you could point out my mistake.
- I give external electric stimulation to my neurons. In my case, I am trying to stimulate the neuron from within the vasculature supplying the neuron.
- The electric stimulation generates extracellular electric field in my neurons.
- I use head model and Matlab program to calculate the exact extracellular electric field that would be generated in the neuron. (I already have this part)
- I want to see the response of the neuron to this extracellular electric field and therefore I am trying to use NEURON software for this purpose.
- So, I made a simple neuron morphology for NEURON software.
- I also made stimulating waveform (Biphasic waveform/monophasic) with different amplitude, delay and duration.
- Now, all I want to do is, apply 'extracellular electric field' (from Matlab) to the center of each compartment of my neuron and use the waveform to drive the extracellular electric field , so that I can observe the final Result. (this is where I am stuck now!)
I would highly appreciate your help in this part. I have been trying for many days with no positive results. I tried implementing 'xtra' as you explained but I couldn't understand why I always get the same error- 'permission denied'. You asked me in your post (Dec 19), following question:
Exactly where is your source code located? In the directory that contains your source code, please execute the command
pwd
I am confused about it too. I am new to Neuron programming, please forgive me if I am asking some silly question. But, I really didn't get what you mean. I write all my codes in a '.txt' file and put it in the same folder where I have installed NEURON 7.4. So, my directory path is: Macintosh HD/Applications/Neuron7.4/test1.txt for HOC code and Macintosh HD/Applications/Neuron7.4/xtra.txt for NMODAL code. So, basically both files are in the same directory. I still tried using the command 'pwd' in the xtra.txt file but I got the same error message as before.
Could you please give me some insight about how to deal with the problem I am stuck at? I was also wondering, if my code I posted on Dec 18 is not suppose to work, why is it giving 'action potentials' in response to increase in e_extracellular value that I feed? I am so much confused and frustrated. I would highly appreciate your help and guidance.
I look forward to hearing from you.
Sincerely,
Dina
Post Reply