Problem initializing with rxd.Rate

Extending NEURON to handle reaction-diffusion problems.

Moderators: hines, wwlytton, ramcdougal

Post Reply
mandy
Posts: 2
Joined: Thu Apr 16, 2020 2:27 pm

Problem initializing with rxd.Rate

Post by mandy »

I'm working on a model that includes changes in intracellular calcium as a function of several calcium currents and a pump for calcium efflux. I've implemented calcium as a reaction-diffusion Species, the currents are defined in mod files using GHK permeability, and I was hoping to use a reaction-diffusion Rate for the pump/efflux. No problem simulating changes in concentration due to influx from the currents, but when I tried to add the Rate for the calcium efflux, I got an exception when initializing the model. Here's my code - I commented out the parts that are dependent on my mod files so it can be tested w/o them, but left the code there for context/clarity:

Code: Select all

import sys
import matplotlib.pyplot as plt

# to prevent errors caused by accidentally importing twice
if 'neuron' not in sys.modules:
    from neuron import h, rxd
    h.load_file('stdrun.hoc')
    
# build sections
soma = h.Section(name='soma')
soma.L = soma.diam = 25

# insert mechs
#soma.insert('naf')
#soma.insert('kdr')
#soma.insert('nal')
#soma.insert('cal')
#soma.insert('sk')

pumpTau = -0.01

cyt = rxd.Region(h.allsec(), name='cyt', nrn_region='i')
ca = rxd.Species(cyt, name='ca', charge=2, initial=5E-5)
caPump = rxd.Rate(ca,pumpTau,regions=cyt)   # problem is here

# record time
t = h.Vector().record(h._ref_t)

# record membrane potential
#v = h.Vector().record(soma(0.5)._ref_v)

# record currents
#inaf = h.Vector().record(soma(0.5)._ref_ina_naf)
#ikdr = h.Vector().record(soma(0.5)._ref_ik_kdr)
#isk = h.Vector().record(soma(0.5)._ref_ik_sk)

# record intracellular ca
caDat = h.Vector().record(ca.nodes[0]._ref_concentration)

h.finitialize(-45)
h.continuerun(1000)

# plots
#plt.subplot(3,1,1)
#plt.plot(t,v)
#plt.ylabel('v (mV)')

#plt.subplot(2,1,2)
#plt.plot(t,inaf)
#plt.plot(t,ikdr)
#plt.plot(t,isk)

#plt.subplot(3,1,3)
plt.plot(t,caDat)
plt.ylabel('cai (mM)')

plt.show()
With the caPump declaration commented out, it runs as expected, both as shown and with the mechanisms inserted. When the caPump declaration is added in, I get this:

Code: Select all

runfile('C:/pathgoeshere/runCell.py', wdir='C:/pathgoeshere')
Traceback (most recent call last):

  File "_ctypes/callbacks.c", line 232, in 'calling callback function'

  File "c:\nrn\lib\python\neuron\rxd\rxd.py", line 536, in _setup
    initializer._do_init()

  File "c:\nrn\lib\python\neuron\rxd\initializer.py", line 52, in _do_init
    rxd._init()

  File "c:\nrn\lib\python\neuron\rxd\rxd.py", line 1498, in _init
    _compile_reactions()

  File "c:\nrn\lib\python\neuron\rxd\rxd.py", line 1333, in _compile_reactions
    _c_compile(fxn_string))

  File "c:\nrn\lib\python\neuron\rxd\rxd.py", line 595, in _c_compile
    dll = ctypes.cdll['./%s.so' % filename]

  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 439, in __getitem__
    return getattr(self, name)

  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 434, in __getattr__
    dll = self._dlltype(name)

  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)

OSError: [WinError 126] The specified module could not be found

Traceback (most recent call last):

  File "c:\nrn\lib\python\neuron\rxd\rxd.py", line 1498, in _init
    _compile_reactions()

  File "c:\nrn\lib\python\neuron\rxd\rxd.py", line 1333, in _compile_reactions
    _c_compile(fxn_string))

  File "c:\nrn\lib\python\neuron\rxd\rxd.py", line 595, in _c_compile
    dll = ctypes.cdll['./%s.so' % filename]

  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 439, in __getitem__
    return getattr(self, name)

  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 434, in __getattr__
    dll = self._dlltype(name)

  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)

OSError: [WinError 126] The specified module could not be found

NEURON: Python Callback failed
 near line 0
 ^
        finitialize(-45)
Traceback (most recent call last):

  File "C:\pathgoeshere\runCell.py", line 40, in <module>
    h.finitialize(-45)

RuntimeError: hoc error
I'm running NEURON 7.7 with Python 3.7.6 on Windows 10 Pro. The declaration of the rxd.Rate is based on several examples I found in the forums and documentation, so I'm guessing that either this is weirdly platform-specific or I've just done something very silly and can't spot it. Any thoughts?
adamjhn
Posts: 54
Joined: Tue Apr 18, 2017 10:05 am

Re: Problem initializing with rxd.Rate

Post by adamjhn »

Thanks for getting in touch. Unfortunately I cannot reproduce the error on my machine. It looks like there is a mismatch between the directory where the compiled reactions are stored and the directory we try to load them from.

Could you try running the simulation directly, e.g.

Code: Select all

python -i runCell.py
Please let me know whether or not you get the same error.
mandy
Posts: 2
Joined: Thu Apr 16, 2020 2:27 pm

Re: Problem initializing with rxd.Rate

Post by mandy »

Running the simulation directly triggered a different error (basically, the kernel couldn't find or import numpy at all), and troubleshooting that problem eventually uncovered an issue with Anaconda that seems to have also caused my original problem: the Anaconda environment containing all the Python packages installed through Anaconda isn't getting loaded when launching a Python kernel from anywhere other than Anaconda itself. If I start a terminal or Python kernel using the Anaconda navigator, the simulation runs with no errors. Launching the kernel from my IDE or the command line does not run, even though they all seem to be pointed at the same path - at least, sys.executable returns the same location regardless of how I started up the kernel. Not sure why running the sim from the IDE should cause a different exception than running it directly, but maybe that's beside the point.

I'm not particularly attached to Anaconda as anything other than a package manager, so I'm going to try getting rid of it and using a standalone Python installation instead - I'll update if that solves the problem entirely. Thanks for the suggestion!
Post Reply