NEURON with Python code - Error related to FUNCTION_TABLE

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

Moderator: hines

Post Reply
SaiNitin
Posts: 6
Joined: Sun May 05, 2019 10:41 am

NEURON with Python code - Error related to FUNCTION_TABLE

Post by SaiNitin » Mon May 06, 2019 6:56 am

Hello everyone,

I have a query, as follows:
Background: There is a detailed validated model in hoc with several mod files for ion channels. These ion channels access FUNCTION_TABLE (Tautables) from a hoc file. I am rebuilding this existing model from scratch in Python. However, I am stuck with a fatal error.

Issue: To figure out the error, I have made a simplified dummy model in Python with a tautable for the NaF channel in tautable.hoc file. The NaF channel is getting inserted and the gui is opening but when I initialize and/or run, the entire NEURON crashes. The validated hoc model works perfectly but the Python model doesn’t.

Additionally, I am able to print values (in Spyder IPython shell) from the hoc vectors present in ‘tautable.hoc’ indicating h.load_file has worked.

Python code for dummy model:

Code: Select all

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

soma = h.Section(name='cell_soma')
#GEOMETRY
soma.insert('NaF')
soma.L = soma.diam = 12.6157  
#Biophysical mechanisms
soma.Ra = 100   
soma.cm = 1       
h.psection()
tautable.hoc

Code: Select all

objref vecv_NaF, vecmtau_NaF, vechtau_NaF
vecv_NaF = new Vector()
vecv_NaF.indgen(-90, 30, 10)

vecmtau_NaF = new Vector()
vecmtau_NaF.append(0.02,0.023,0.03,0.037,0.043,0.067,0.107,0.053,0.05,0.04,0.027,0.02,0.02)
table_tabmtau_NaF(&vecmtau_NaF.x[0], vecv_NaF.size, &vecv_NaF.x[0])

vechtau_NaF = new Vector()
vechtau_NaF.append(0.433,0.433,0.433,0.433,0.433,0.433,0.433,0.283,0.167,0.15,0.107,0.1,0.093)
table_tabhtau_NaF(&vechtau_NaF.x[0], vecv_NaF.size, &vecv_NaF.x[0])
chan_NaF.mod

Code: Select all

TITLE Fast Sodium current 
: Unit check passed

INDEPENDENT { t FROM 0 TO 1 WITH 1 (ms) }

UNITS { 
	(mV) = (millivolt) 
	(mA) = (milliamp) 
} 
NEURON { 
	SUFFIX NaF
	USEION na READ ena WRITE ina
	RANGE g, gmax, ina
	GLOBAL minf, mtau, hinf, htau
	POINTER mu
}
PARAMETER { : PARAMETERS ARE BY DEFAULT GLOBAL VARIABLES
	gmax = 0.0195 	(mho/cm2)
	:gmax = 0
	ena (mV)
	m_vh = -23.9	(mV)	: half activation 
	m_ve = -11.8	(mV)	: slope
	h_vh = -62.9	(mV) : half activation
	h_ve = 10.7	(mV) : slope
} 
ASSIGNED { 
	v 		(mV)
	g		(mho/cm2)
	ina 		(mA/cm2) 
	minf 		(1)
	mtau 	(ms)
	hinf 		(1)
	htau 		(ms) 
	mu (1)
} 
STATE {
	m h
}
BREAKPOINT { 
	SOLVE states METHOD cnexp
	g = gmax * m*m*m*h * (1-(mu-1)*0.05)
	ina = g * (v - ena) 
} 
INITIAL { 
	rates(v) 
	m = minf
	h = hinf
} 
DERIVATIVE states { 
	rates(v)
	m' = ( minf - m ) / mtau 
	h' = ( hinf - h ) / htau
}
FUNCTION_TABLE tabmtau(v(mV)) (ms) 
FUNCTION_TABLE tabhtau(v(mV)) (ms) 

PROCEDURE rates(v(mV)) { 
	TABLE mtau, htau, minf, hinf DEPEND h_vh FROM -120 TO 40 WITH 160
:	TABLE mtau, htau, minf, hinf DEPEND h_vh FROM -120 TO 40 WITH 320
	mtau = tabmtau(v)
	htau = tabhtau(v)
	minf = 1/(1 + exp((v - m_vh)/m_ve))
	hinf = 1/(1 + exp((v - h_vh)/h_ve))
}
How do I make my model work with these tautables? I don't want to manually rewrite the entire tautables for all channels from hoc to Python as there are many in the original model.

Thanks in advance!

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

Re: NEURON with Python code - Error related to FUNCTION_TABLE

Post by ted » Mon May 06, 2019 12:46 pm

First, a couple of comments:
1. I'm sure you have your reasons for using Python to reimplement the "detailed validated model in hoc," but for the benefit of others who may read this thread, it is generally more efficient of one's time to use Python to access hoc-created variables than it is to reimplement hoc code in Python--especially if the model is detailed.
2. Having run into a problem, it's good that you made a simplified model to try to diagnose the cause. That's a very useful way to discover what's going on.

Next a question: how do you know that the symptom has anything to do with the mechanism's use of tables?
With NEURON 7.7.0-25-gb277896 master (b277896) 2019-03-14 (and probably with at least some earlier recent verisons), initialization after failure to load tables generates an error message something like this:

Code: Select all

NEURON: table not specified in hoc_func_table
 near line 1
 {stdinit()}
            ^
        finitialize(-65)
      init()
    stdinit()
  doNotify()
Exception in gui thread
Exactly what error message do you see? With recent versions of NEURON, the example Python code in your post will probably just trigger a segmentation fault and no complaint about tables. Why? Because the Python code hasn't resolved the mechanism's pointer variable mu.

For the benefit of others who may read this thread, this is done with a setpointer statement. Of course, Python doesn't have pointers, so there's a documented workaround, but the otherwise quite useful Programmer's Reference doesn't make it easy to find. Go to the Programmer's Reference entry page
https://www.neuron.yale.edu/neuron/stat ... index.html and use the "Quick search" widget to search for
setpointer
Currently, this search will return 4 hits, of which the most informative is titled
NEURON Extension to NMODL
Click on that to bring up the "NEURON Extension to NMODL" page, which has its own local Table of Contents. In that table of contents, find the link to Connecting Mechanisms Together and start reading.

Let me know if this is enough to help fix the problem. Also, for the sake of subsequent readers, please indicate how you fixed it.

SaiNitin
Posts: 6
Joined: Sun May 05, 2019 10:41 am

Re: NEURON with Python code - Error related to FUNCTION_TABLE

Post by SaiNitin » Wed May 08, 2019 10:36 am

I overlooked the POINTER variable as my mod files with pointers usually have a different name.

So I first removed the pointer variable to check if the simpler model is working and it does.
However, I have to use pointers for my model so I went ahead and tried pointing 'mu' to a variable called msr in a point process called 'D1R'. The code segment I used is as follows:

Code: Select all

d1 = h.D1R(soma(0.5))
h.setpointer(d1._ref_msr , 'mu' ,soma(0.5).NaF)

After adding this code, the model is now working with the pointer. Thank you for pointing me out to the resources and for the prompt response.

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

Re: NEURON with Python code - Error related to FUNCTION_TABLE

Post by ted » Wed May 08, 2019 3:45 pm

Thanks for the followup. POINTERs have many uses, so it is highly likely that this thread will be of interest to others.

Post Reply