Page 1 of 1

Extracellular Stimuli with Python + Vector Play

Posted: Fri Nov 04, 2022 4:35 pm
by Kayco
I am new to NEURON and am trying to implement an extracellular voltage stimulus using Python. For now, I am using a basic axon with H-H kinetics. I am assuming the field is spatially uniform (linear step increase in Vext at each segment) and its direction is parallel with the neuron's length, and that it turns on and off in steps based on an import csv file.

So far, I have used the vector play command successfully to drive a current clamp with this external file, but I am struggling to get it to work properly to drive my extracellular potential.

For some reason, within my "for seg" loop that sets up the temporal Vext at each segment, only the last segment in the neuron seems to adopt the assigned characteristics. I have done a RangeVarPlot on Vext[0] at times when the field should be "on", and rather than being a linear increase across the length of the axon, it is 0 across the whole length until the last segment. Any help would be appreciated.

Here is my code (csv can be found here: https://drive.google.com/drive/folders/ ... share_link):

Code: Select all

from neuron import h
from neuron.units import ms, mV
import matplotlib.pyplot as plt
import numpy as np
h.load_file("stdrun.hoc")

# Simulation Params
trun = 10

# Set Up Axon Properties
axon = h.Section(name = "axon")
axon.L = 1000
axon.nseg = 101
axon.diam = 1
seglen = axon.L/axon.nseg # um

# Set Up External Field
Field = 100 # V/cm
FieldScaled = Field*1e-4*1e3 # need mV/um multiply by 1 cm/10000 um and by 1000 mV/V

axon.insert(h.hh)
h.nlayer_extracellular(1)
axon.insert(h.extracellular)

# Extracellular Stimulus
Data = np.loadtxt("wform.csv",delimiter=",")
tvals = Data[:,0]
Ivals = Data[:,1]
AMPvec = h.Vector().from_python(Ivals)
tvec = h.Vector(np.linspace(0,tvals[-1],len(tvals)))
h.dt = tvals[1]-tvals[0]

for seg in axon:
    potential = seg.x*FieldScaled*axon.L
    holdvec = AMPvec.c()
    tmpvec = holdvec.mul(potential)
    tmpvec.play(axon(seg.x)._ref_e_extracellular,tvec)

t = h.Vector().record(h._ref_t)
v = h.Vector().record(axon(0.1)._ref_v)
ik = h.Vector().record(axon(0.1)._ref_ik)
ina = h.Vector().record(axon(0.1)._ref_ina)
vex0 = h.Vector().record(axon(0.5)._ref_vext[0])
vex1 = h.Vector().record(axon(1)._ref_vext[0])

# Run
h.tstop = trun*ms
h.run()

# Plots
plt.figure()
plt.plot(t,v)

plt.figure()
plt.plot(t,vex0,label = "Vext at middle")
plt.plot(t,vex1,label = "Vext at end")
plt.legend()

plt.figure()
plt.plot(t,ina,label = "ina")
plt.plot(t,ik, label = "ik")
plt.legend()
plt.show()

Re: Extracellular Stimuli with Python + Vector Play

Posted: Tue Nov 08, 2022 3:44 pm
by ted
I suspect that each pass through the loop

Code: Select all

for seg in axon:
    potential = . . .
discards the vector that was created on the previous pass, thus breaking vector play into the previous seg. See what happens if you change the loop to

Code: Select all

ffvecs = [] # a list to hold the forcing function vectors
for seg in axon:
    potential = seg.x*FieldScaled*axon.L
    tmpvec = AMPvec.c() # tmpvec no longer references any previously created vector
    tmpvec.mul(potential)
    tmpvec.play(axon(seg.x)._ref_e_extracellular,tvec)
    ffvecs.append(tmpvec)

Re: Extracellular Stimuli with Python + Vector Play

Posted: Thu Nov 10, 2022 11:03 am
by Kayco
Hi Ted,
Thanks so much! That seems to have fixed my issue.