Extracellular Stim using python and/or xtra.mod

Anything that doesn't fit elsewhere.
Post Reply
gabrielggn
Posts: 10
Joined: Fri May 20, 2022 8:07 am

Extracellular Stim using python and/or xtra.mod

Post by gabrielggn »

Dear colleagues,

I am quite new at NEURON programming and I'm a python programmer if I can say that. I am currently working in the field of transcranial stimulation and I am interested by the capabilities of NEURON to predict the effect of extracellular stimulation on complex geometrical neurons to predict/ understand neuromodulation.

For know I'm just doing basics and I write some code to reproduced the results from 10.1113/jphysiol.2012.247171 using the e_extracellular mechanism. The results of my script have deviations and I don't know if I'm doing it properly using python. In fact I set the values of e_extracellular in each segment but not using any waveform ( and so the play function of NEURON). But visualizing the v and e_extracellular recorded at soma it seems to work (at least as a DC stimulation). You can find the associated script here https://drive.google.com/file/d/1Ppzisw ... sp=sharing.

In a second time I tried to use the xtra.mod file (that I've compiled) and seems to work at the invocation but when I run the script, nothing happen. If I look the recorded e_extracellular at soma it is 0 all the long while I entered the desired voltage at rx_xtra and use a signal with ones all the time. Here are the lines :
I first load xtra using the following function

Code: Select all

    def load_xtra(self):
        for sec in self.all:
            sec.insert('xtra')
        h.load_file(1,"interpxyz.hoc")    #only interpolates sections that have extracellular
        h.load_file(1,"setpointers.hoc")  #automatically calls grindaway() in interpxyz.hoc        

Then I add my value to rx_xtra using

Code: Select all

    def apply_Eext_uniform_xtra(self, E0):
        """
        Trying to apply extracellular stim with xtra mechanism
        """
        for sec in self.all:
            x_c = sec(0.5).x_xtra
            y_c = sec(0.5).y_xtra
            z_c = sec(0.5).z_xtra
            v_ext = -1e-3*( E[0] * x_c  +  E[1] * y_c  +  E[2] * z_c )    
            sec.rx_xtra = v_ext * 1e-6  # 1e-6 to remove the MOhm factor in the xtra.mod file 
    ## END apply_Eext_uniform_xtra()
    
Finally I run the simulation with these parameters and assgning ones array to is_xtra:

Code: Select all

h.load_file("stdrun.hoc")
h.init()
h.finitialize(-70 * mV)
h.fcurrent()
h.tstop = 200 #ms

times =np.arange(0,h.tstop+h.dt,h.dt)
sig = np.ones(times.shape)

t = h.Vector(times)
stim = h.Vector(sig)
stim.play(h._ref_is_xtra, t , 0)

t = h.Vector().record(h._ref_t)
v = h.Vector().record(c.soma[0](0.5)._ref_v)
ve = h.Vector().record(c.soma[0](0.5)._ref_e_extracellular)

h.run()
It seems the play with is_xtra is not working and I don't know why...

PS: I know I should have used x_xtra, y_xtra and z_xtra for better results but that does not explain why it is not working I guess.



Finally, I have two basic theoretical questions.
1) Indeed, the extracellular mechanism seems to use a potential to stimulate the neuron but and so the extracellular mechanism is linear (with electric field too if the position does not change if I am not wrong ?). But is there a theoretical reason of such a mechanism ?

2) If the resistor are pseudo infinite (1 MOhms) and the capacitors set to zero (open circuit), it should not act as if it was directly connected to the membrane or I'm thinking at this wrong ?

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

Re: Extracellular Stim using python and/or xtra.mod

Post by ted »

Thank you for your interest in using NEURON in your research.
For know I'm just doing basics and I write some code to reproduced the results from 10.1113/jphysiol.2012.247171
Nice paper. That's a good way to start.
visualizing the v and e_extracellular recorded at soma it seems to work (at least as a DC stimulation
Visualization is very important for debugging and understanding results of simulations of cells with complex dendritic structure, and especially when extracellular fields are involved. For further verification of results, and as practice for debugging your own applications that use e_extracellular, don't just look at v at one point. Plot v and e_extracellular as functions of path distance from the soma (use a RangeVarPlot--read about this in the Programmer's Reference https://nrn.readthedocs.io/en/latest/py ... arplt.html

Do v and e_extracellular vary with position in the way that you thought they should?
In a second time I tried to use the xtra.mod file . . . and use a signal with ones all the time . . . It seems the play with is_xtra is not working and I don't know why
Before trying an unfamiliar method on a model that has complex architecture, it is best to start with something very simple--an unbranched cable (e.g. 1000 um long and 1 um diameter), or a "ball and stick" (500 um x 1 um axon, 10x10 um soma, and 500 um x 2 um dendrite); specify these via the pt3d method so you have full control of how they are oriented in space. Leave the models passive at first, but change Ra to 100 ohm cm (much closer to mammalian cytoplasmic resistivity than the default 35.4 ohm cm value). and choose nseg according to the d_lambda method.

And before I forget to mention it, your python code for this exercise should start with the following

# after importing whatever Python modules you like to have
# then do this:
from neuron import h
h.load_file("stdgui.hoc") # gets stdrun.hoc and some other useful libraries

Use RangeVarPlots to visualize v and e_extracellular throughout the model as functions of distance from the soma. Do these results match your expectations? If not, why not?

Try another simulation in which the stimulus waveform starts at 0, then jumps to 1 mV at t = 1 ms (keep tstop short--5 ms would be fine for this toy problem). What do you see, and why did it happen?
gabrielggn
Posts: 10
Joined: Fri May 20, 2022 8:07 am

Re: Extracellular Stim using python and/or xtra.mod

Post by gabrielggn »

Dear Ted,

Many thanks for your answer. I did plot RangeVarPlot and as I expected the "e_extracellular" potential is following the trend of the "v" over the soma to apical axis (in the direction of the electric field). It is not linear but It should be due to the fact that apical structures is not only fully oriented to the y-axis and so y does not vary linearly along the distance to the soma ( and so do "e_extracellular" since it is proportional to " Ey*y "). Here are the plots from soma to the 10th apical dendrite trunk for 'v' and 'e_extracellular' :

https://drive.google.com/file/d/1FKB3l- ... sp=sharing

As I pointed out, I guess the code works as I expect since the EF does not vary over time so far. I think the difference I get to the results of this insightfull paper comes from their calculation of coordinates that differs from your intopolatexyz.hoc implementation. They calculated the center of mass of each segment to calculate the x,y,z. I will try to apply the same formula to compare the results.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Extracellular Stim using python and/or xtra.mod

Post by ted »

"I guess the code works" isn't exactly a sound starting point for a modeling project. A little effort now to verify correctness could save you a lot of time in the future. I understand you're eager to get started working with complex model cells, but you really should start by verifying that your code does work, and that means running tests with "something very simple" (the figure linked to your post was clearly generated from a model with some anatomical complexity).
gabrielggn
Posts: 10
Joined: Fri May 20, 2022 8:07 am

Re: Extracellular Stim using python and/or xtra.mod

Post by gabrielggn »

Dear Ted,

I used a complex model since this is what interest me here to compare with the results of the study I've mentionned. I did figured out how to replicate the results by the way and it involed another way to calculate x,y,z, with some center of mass of the cylinders as I explained in my previous post.

I understand that for basics it is better to work with simple architectures, I did the tutorial on youtube and the one on the python tutorials in the programmer's references. However here, I don't see why should I expect to have as a result even with a simple morphology. Indeed with a passive model and a low extracellular electric field, there should be a polarisation of the cell (depolarisation on one side and hyperpolarisation on the other side). The value of the membrane polarisation is related by the v_ext (and so the E_ext) but what should I expect more than that ? I mean if I wait long enough the steady state give me the value of this depolarisation but I don"t understand, what should I understand more ?

Also, my first post here was about the fact that xtra "is" variable with the combination of the play method and a time array contraining the values of the waveform did not work and I still don't know why it is not working. The full xtra variable exist but the e_extracellular is always 0 while the "rx" is not 0 and the vectore played in "is" is for now an array full of ones (DC signal). Do you have any clue of what could go wrong ?

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

Re: Extracellular Stim using python and/or xtra.mod

Post by ted »

Maybe I should have been more explicit. This is what I had in mind:
1. You use your code to run a simulation in which a simple model is subjected to a simple extracellular stimulus.
2. I run a simulation using my own code that replicates your model and stimulus.
3. We compare results. The results should be identical (within the finite precison of digital computation). If they aren't, we figure out what needs to be fixed, and fix it.

Then we address the problem you have with a time varying stimulus.
gabrielggn
Posts: 10
Joined: Fri May 20, 2022 8:07 am

Re: Extracellular Stim using python and/or xtra.mod

Post by gabrielggn »

Dear Ted,

As you ask I made a simple ball and stick model to test my extracellular stimulation script. I did a soma (10um x 10um) connected to a dendrite (500 um x 2um) with passive mechanism (Ra =155 O.cm-1, Rm = 17.5 O.cm-2, e_pas=-60 mV) to reproduced the study.

Here are my results :
https://drive.google.com/file/d/17KLdi1 ... sp=sharing
https://drive.google.com/file/d/18kkcM ... sp=sharing

We can see a linear depolarisation and linear extracellular potential along the y-axis (somato-dendritic axis too) as expected.

Best
Post Reply