RxD in Neuron

Extending NEURON to handle reaction-diffusion problems.

Moderators: hines, wwlytton, ramcdougal

Post Reply
ahmed.hamzah
Posts: 49
Joined: Thu Jun 07, 2018 10:57 am

RxD in Neuron

Post by ahmed.hamzah »

Hi

I am trying to use rxd and find the na, k concentration using NEURON, but I read many web talking how to use rxd in Python. can any one guide me to use RXD in NEURON itself. thank you.
ahmed.hamzah
Posts: 49
Joined: Thu Jun 07, 2018 10:57 am

Re: RxD in Neuron

Post by ahmed.hamzah »

Do I have to use Python in rxd or I can use just NEURON ? can anyone help me please
adamjhn
Posts: 54
Joined: Tue Apr 18, 2017 10:05 am

Re: RxD in Neuron

Post by adamjhn »

Python must be installed to use rxd and is the prefered interface for specifying new models. If you are working with an existing model created in hoc, there are three ways you could include rxd in the simulation.


1] The simplest way is to specify rxd in python and load it in your hoc file with `nrnpython`.
For example, adding calcium buffering to a very simple hoc model (just a soma), by creating a python file (here called “cabuf.py”) defining the reaction-diffusion dynamics.

Code: Select all

from neuron import h, rxd

# Where? -- specify the regions 
cyt = rxd.Region(h.allsec(), "i")

# Who? -- define the species involved
ca = rxd.Species(cyt, d=0, name='ca', charge=2, initial=1)
buf = rxd.Species(cyt, d=0, name='buf', initial=1)
cabuf = rxd.Species(cyt, d=0, name='cabuf', initial=0)

# What? -- define the reactions
buffering = rxd.Reaction(ca + buf, cabuf, 1, 0.1)
Then load the rxd model in hoc;

Code: Select all

create soma

nrnpython("import cabuf") // load the rxd model
finitialize(-65)

// create a graph to show for the rxd species
load_file("stdrun.hoc")
objref g
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)

tstop = 20
run()

2] You can use ‘nrnpython’ in your hoc file to load rxd, however you can't use operators on rxd species (so buffering reaction here is specified with `ca.__add__(buf)` rather than `ca + buf`).

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)
    finitialize(-65)
}
{
    // 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()
}
3] Finally you can load the hoc simulation in python then add rxd. But you must remove calls that run the simulation from the hoc file, for example;
With the existing simulation ‘simple.hoc’;

Code: Select all

create soma
tstop = 20
// run() -- don't run until rxd has been specified.
Can be loaded in python with `h.load_file` and rxd can be used as normal;

Code: Select all

from neuron import h, rxd
from matplotlib import pyplot
h.load_file("stdrun.hoc")

h.load_file("simple.hoc") # the original model (here it just creates the soma)

# Where? -- specify the regions 
cyt = rxd.Region(h.allsec(), "i")

# Who? -- define the species involved
ca = rxd.Species(cyt, d=0, name='ca', charge=2, initial=1)
buf = rxd.Species(cyt, d=0, name='buf', initial=1)
cabuf = rxd.Species(cyt, d=0, name='cabuf', initial=0)

# What? -- define the reactions
buffering = rxd.Reaction(ca + buf, cabuf, 1, 0.1)

h.finitialize(-65)

# record results
ca_vec = h.Vector()
ca_vec.record(h.soma(0.5)._ref_cai)
cabuf_vec = h.Vector()
cabuf_vec.record(h.soma(0.5)._ref_cabufi)
t_vec = h.Vector()
t_vec.record(h._ref_t)

h.run() # run the simulation

#plot the results
pyplot.plot(t_vec, ca_vec, label="ca")
pyplot.plot(t_vec, cabuf_vec, label="buf")
pyplot.legend()
pyplot.show()
ahmed.hamzah
Posts: 49
Joined: Thu Jun 07, 2018 10:57 am

Re: RxD in Neuron

Post by ahmed.hamzah »

I will try it. thanks
ahmed.hamzah
Posts: 49
Joined: Thu Jun 07, 2018 10:57 am

Re: RxD in Neuron

Post by ahmed.hamzah »

I have tried the first one and I got error
rxd not a public number of PythonObject
Post Reply