Play a Unique Vector to Each Model Segment

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
ajpc6d
Posts: 28
Joined: Mon Oct 24, 2022 6:33 pm

Play a Unique Vector to Each Model Segment

Post by ajpc6d »

How can I play a unique vector into an arbitrary variable in each of an arbitrary number of cell segments? For example, in this NMODL file

Code: Select all

 
NEURON {
    SUFFIX playtest
    :RANGE xx           : doesn't work
    :NONSPECIFIC_CURRENT xx     : doesn't work
    :GLOBAL xx          : works, but inflexible
    :ELECTRODE_CURRENT xx   : doesn't work
    :POINTER xx         : can't figure out proper usage
    NONSPECIFIC_CURRENT ixi
}

UNITS {
    (mV) = (millivolt)
    (mA) = (milliamp)
    (mS) = (millisiemens)
    (S) = (siemens)
    (nW) = (nanowatts)
    (uA) = (microamp)
    (uF) = (microfarads)
}

PARAMETER {
}

ASSIGNED {
    celsius (degC) 

    v (mV)

    xx (mA)
    ixi (mA)
}

INITIAL { ixi = 0
}

BREAKPOINT {
    ixi = xx*2
}
I would like to play into the variable xx. I've tried several keywords to define xx, as you can see.

This Python script is how I am using vector.play()

Code: Select all

from neuron import h
from matplotlib import pyplot as plt
h.load_file("stdrun.hoc")

data = h.Vector([ 1,5,17,2,4,38,22,43,1, 1])
time = h.Vector([1,2,3,4,5,6,7,8,9,10])


cell = h.Section(name='neurite')
cell.nseg = 2 	# arbitrary
cell.L = 40		# arbitrary
cell.diam = 5	# arbitrary
for sec in h.allsec():
    sec.insert(h.playtest)
    sec.insert(h.hh)
    for seg in sec:
        data.play(seg.playtest.xx, time, True)

t = h.Vector().record(h._ref_t)
v = h.Vector().record(cell(0.5)._ref_v)
xxp = h.Vector().record(cell(0.5).playtest._ref_xx)

# xxp = h.Vector().record(h._ref_xx_playtest)   # for GLOBAL implementation
# data.play(h._ref_xx_playtest, time, True) # for GLOBAL implementation

h.finitialize(-65)
h.continuerun(10)

plt.plot(t,xxp)
plt.show()
Is my .mod file bad? Or my Python? In all the cases except GLOBAL (which functions, but doesn't appear to enable me to play in unique vector to each segment) and POINTER (doesn't function, but I can't determine why), there is no error.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Play a Unique Vector to Each Model Segment

Post by ramcdougal »

Whenever recording a variable or playing into a variable, you must use a pointer; that is, play into seg.playtest._ref_xx not into .xx.

To store different values of xx at different locations, you must declare xx as a RANGE. (If you use GLOBAL, it is the same at all locations.) (POINTERs do not locally store values and simply allow reading them from other locations; this is not what you're trying to do here.)

A working version of your MOD file and Python script follow:

Code: Select all

NEURON {
    SUFFIX playtest
    RANGE xx
    NONSPECIFIC_CURRENT ixi
}


ASSIGNED {
    xx (mA)
    ixi (mA)
}

INITIAL {
    ixi = 0
    xx = 0
}

BREAKPOINT {
    ixi = xx + 1
}

Code: Select all

from neuron import h
from neuron.units import mV, ms, um
import matplotlib.pyplot as plt

h.load_file("stdrun.hoc")

data = h.Vector([0, 1, 5, 17, 2, 4, 38, 22, 43, 1, 1])
time = h.Vector([1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

cell = h.Section("neurite")
cell.nseg = 3  # always use an odd nseg
cell.L = 30 * um  # arbitrary
cell.diam = 5 * um  # arbitrary

# most modular to loop over a wholetree (i.e. one cell at a time)
# instead of looping over allsec, in case your model changes in
# the future
for sec in cell.wholetree():
    sec.insert(h.playtest)
    # this plays the same thing into all segments, but could
    # easily play different things into different segments
    for seg in sec:
        data.play(seg.playtest._ref_xx, time, True)

t = h.Vector().record(h._ref_t)
xxp1 = h.Vector().record(cell(0.1).playtest._ref_xx)
xxp2 = h.Vector().record(cell(0.9).playtest._ref_xx)

h.finitialize(-65 * mV)
h.continuerun(10 * ms)

plt.plot(t, xxp1, label="xxp1")
plt.plot(t, xxp2, label="xxp2")
plt.legend()
plt.show()
(You'll only see the orange line for xxp2 because it overlaps exactly with xxp1, but you could either play different vectors into the two locations or just check and you'll see that they have the same values.)
Post Reply