NameError: Name Not Defined for Distributed Mechanism

NMODL and the Channel Builder.
Post Reply
TrZ
Posts: 7
Joined: Wed May 31, 2023 12:37 am

NameError: Name Not Defined for Distributed Mechanism

Post by TrZ »

Hello NEURON users and contributors,
I am new to NEURON with no NMODL experience, but am wondering if there are any suggestions or comments on how to fix an error I have been getting:
After being given the mod file for a distributed mechanism, I am trying to insert a user-defined distributed mechanism into a model of an axon Section. The code of the model is in Python, and running it with Python should simulate an axon being injected with current. The SUFFIX for the mechanism that I am intending to be inserted through the code is 'mathews_KLVA'. When I run the code in Python, the NEURON gui pops up but I get a NameError stating that the name 'mathews_KLVA' is not defined.
Contextual information: I am using a macOS Monterey version 12.0.1 operating system and a 3.8 version of Python. The mod files for all the user-defined distributed mechanisms have been compiled and loaded into NEURON. My .py and mod files are in the same folder but the NEURON package is not. The code of the .py file for my model is below. Sorry, I do not know how to format the code yet. I would appreciate comments on why I am getting the error and how to fix it. Thank you!


from neuron import h, gui
h.load_file("stdrun.hoc")

axon = h.Section(name="axon")
h.hh.insert(axon)
mathews_KLVA.insert(axon)

#t = h.Vector().record(h._ref_t)
#v = h.Vector().record(axon(0.5)._ref_v)

ic = h.IClamp(axon(0))
ic.delay = 2 # ms
ic.dur = 0.1 # ms
ic.amp = 100 # nA

h.finitialize(-65)
h.continuerun(5)
AMaxion
Posts: 3
Joined: Wed Jun 14, 2023 3:23 am

Re: NameError: Name Not Defined for Distributed Mechanism

Post by AMaxion »

Hi,

you need to do it the other way around:

Code: Select all

axon.insert('mathews_KLVA')
Best,
Anna
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NameError: Name Not Defined for Distributed Mechanism

Post by ted »

It is too bad that the NEURON Python documentation https://nrn.readthedocs.io/en/8.2.2/pyt ... umentation at nrn.readthedocs.io does not list insert among the various section methods. A side comment: it is also extremely odd that "Section" itself does not even appear under the heading "Quick Links / Commonly used". SectionList and SectionRef are included among the "Commonly used", but SectionBrowser?? I can't recall seeing a single instance of user-written code that employed the SectionBrowser class.

Back to Section and insert. One might imagine that the NEURON Python documentation would cover such a centrally important item as Section under "Model Specification / Programmatic Model Specification", but no. The "Programmatic Model Specification" page https://nrn.readthedocs.io/en/8.2.2/pyt ... matic.html starts promisingly enough with a discussion of Topology, but then slips off without warning into what could have been a clear and concise treatment of how to specify Biophysical properties but instead wanders off into the weeds in a way that is bound to confuse anyone who isn't already an expert NEURON user.

And whatever happened to insert? Well, go back to https://nrn.readthedocs.io/en/8.2.2/python/index.html and click on Index to bring up the alphabetical index, and what does one find? A link to the hoc keyword insert, complete with the correct syntax for using that keyword in hoc! hoc indeed! No mention of proper Python usage.

So what is one to do? Go back to the readthedocs home page https://nrn.readthedocs.io/en/8.2.2/index.html and use the search tool in the left upper corner of that page? Result: "Search finished, found 50 page(s) matching the search query." 50 pages. That's just swell.

Fortunately, the very first of those 50 pages contains an example of Python usage of insert. It's the link to Step 4: Insert ion channels https://nrn.readthedocs.io/en/8.2.2/tut ... n-channels

This should have been much easier. Clearly the documentation needs more than a bit of thoughtful restructuring. Anybody want to help?
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: NameError: Name Not Defined for Distributed Mechanism

Post by ramcdougal »

@AMaxion's approach works, but for the record, the original was also correct except that it was missing a leading h.. That is, you can do any of the following:

Code: Select all

h.mathews_KLVA.insert(axon)
axon.insert(h.mathews_KLVA)
axon.insert('mathews_KLVA')
Personally, I like the first one because you can insert into lists of sections as well, e.g.

Code: Select all

h.pas.insert(apical.subtree())
Post Reply