Page 1 of 1

Reaction-Diffusion in HOC

Posted: Fri Oct 27, 2017 10:09 am
by ramcdougal
The reaction-diffusion module can be used in HOC almost identically to how it is used in Python if you begin your HOC code with:

Code: Select all

objref pyobj, h, rxd

{
    // load reaction-diffusion support and get convenient handles
    nrnpython("from neuron import h, rxd")
    pyobj = new PythonObject()
    rxd = pyobj.rxd
    h = pyobj.h
}
This provides easy access to NEURON's rxd and h Python modules. You might not need to use h since you're working in HOC, but it does provide certain convenient functions like h.allsec(), which returns an iterable of all sections usable with rxd without you having to explicitly construct a SectionList.

The main gotchas of using rxd in HOC is that (1) rxd in Python uses operator overloading to specify reactants and products; in HOC, you have to use __add__, etc instead. (2) rxd in Python is usually used with keyword arguments; in HOC, these must be specified using positional notation.

Here's a full working example that simulates a calcium buffering reaction: Ca + Buf <> CaBuf:

Code: Select all

objref pyobj, h, rxd, cyt, ca, buf, cabuf, buffering, g

{
    // load reaction-diffusion support and get convenient handles
    nrnpython("from neuron import h, rxd")
    pyobj = new PythonObject()
    rxd = pyobj.rxd
    h = pyobj.h
}

{
    // define the domain and the dynamics
    create soma
    
    cyt = rxd.Region(h.allsec(), "i")
    ca = rxd.Species(cyt, 0, "ca", 2, 1)
    buf = rxd.Species(cyt, 0, "buf", 0, 1)
    cabuf = rxd.Species(cyt, 0, "cabuf", 0, 0)

    buffering = rxd.Reaction(ca.__add__(buf), cabuf, 1, 0.1)
}

{
    // if launched with nrniv, we need this to get graph to update automatically
    // and to use run()
    load_file("stdrun.hoc")
}

{
    // define the graph
    g = new Graph()
    g.addvar("ca", &soma.cai(0.5), 1, 1)
    g.addvar("cabuf", &soma.cabufi(0.5), 2, 1)
    g.size(0, 10, 0, 1)
    graphList[0].append(g)
}

{
    // run the simulation
    tstop = 20
    run()
}

Re: Reaction-Diffusion in HOC

Posted: Mon Aug 27, 2018 7:43 pm
by ahmed.hamzah
I tried and I got error:
rxd is not a public member of Python0bject

Re: Reaction-Diffusion in HOC

Posted: Mon Aug 27, 2018 8:07 pm
by ramcdougal
Most likely that means that either Python is not installed, or it is installed but NEURON can't connect to it (likely a path issue).

You're free to program NEURON models in HOC or Python, but to use the rxd module, Python must be installed and loadable by NEURON

To check for this, check the return value of the nrnpython. If it returns 0, something is wrong with your Python setup.

See https://www.neuron.yale.edu/neuron/stat ... #nrnpython for more.

Re: Reaction-Diffusion in HOC

Posted: Tue Aug 28, 2018 3:04 pm
by ahmed.hamzah
Thank you. I already installed python but i do not know how to fix the path problem. is there video or document to help me please to configure system variables

Re: Reaction-Diffusion in HOC

Posted: Tue Aug 28, 2018 3:38 pm
by adamjhn
If python is install nrniv should find it.

Try installing the latest version of NEURON from the website https://neuron.yale.edu/neuron/download, the installer has the option to set the correct paths for you.

Re: Reaction-Diffusion in HOC

Posted: Sat Nov 17, 2018 2:28 am
by Darshan
Hi,

I get the following error when I run the working example given in the first post:

Code: Select all

C:\nrn\bin\nrniv.exe: cai not a section variable
 in D:/NEURON_Tools/rxd_hoc/rxd_hoc.hoc near line 32
     g.addvar("ca", &soma.cai(0.5), 1, 1)
NEURON -- VERSION 7.6.2 master (f5a1284) 2018-08-15
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2018
See http://neuron.yale.edu/neuron/credits

C:\nrn\bin\nrniv.exe: cai not a section variable
 in D:/NEURON_Tools/rxd_hoc/rxd_hoc.hoc near line 32
     g.addvar("ca", &soma.cai(0.5), 1, 1)
                            ^
Traceback (most recent call last):
  File "c:/nrn/lib/python\neuron\nonvint_block_supervisor.py", line 148, in nonv
int_block
    c[method](*args)
  File "c:/nrn/lib/python\neuron\rxd\rxd.py", line 597, in _w_setup
    def _w_setup(): return _setup()
  File "c:/nrn/lib/python\neuron\rxd\rxd.py", line 569, in _setup
    initializer._do_init()
  File "c:/nrn/lib/python\neuron\rxd\initializer.py", line 29, in _do_init
    obj._do_init1()
  File "c:/nrn/lib/python\neuron\rxd\species.py", line 344, in _do_init1
    self._ion_register()
  File "c:/nrn/lib/python\neuron\rxd\species.py", line 411, in _ion_register
    raise RxDException('Unable to register species: %s' % self._name)
neuron.rxd.rxdException.RxDException: Unable to register species: ca
C:\nrn\bin\nrniv.exe: nrn_nonvint_block error
 near line 32
 ^
Using Init & Run gives this error:

Code: Select all

oc>Traceback (most recent call last):
  File "c:/nrn/lib/python\neuron\rxd\initializer.py", line 10, in _do_ion_regist
er
    obj._ion_register()
  File "c:/nrn/lib/python\neuron\rxd\species.py", line 411, in _ion_register
    raise RxDException('Unable to register species: %s' % self._name)
neuron.rxd.rxdException.RxDException: Unable to register species: ca
C:\nrn\bin\nrniv.exe: Python Callback failed
 near line 1
 {run()}
        ^
        finitialize(-65)
      init()
    stdinit()
  run()
I am using NEURON 7.6.2 on Windows

Darshan