3D Dimensional RXD/CRXD

Extending NEURON to handle reaction-diffusion problems.

Moderators: hines, wwlytton, ramcdougal

Post Reply
RBJ
Posts: 62
Joined: Sun Aug 02, 2015 4:28 am
Location: UK
Contact:

3D Dimensional RXD/CRXD

Post by RBJ »

Hello, I wonder if you could help further. Simply adding

Code: Select all

rxd.set_solve_type(dimension=3)
...to the simple rxd model you helped me with before makes my PC workstations and mac really struggle. I have not had success with the mac at all, and one PC has taken 4 hrs to complete the task (<1 minute 1D), the other is up to 12 hrs now and nearly done. This is with just 1 segment. After the succcesful run, I took a look at what I had in variables.
There were over a million nodes (“Too many nodes Mozart” came to mind), I am wondering if this is just too much memory for my systems (20GB ram I think). (1) IS there a way to decrease nodes? I tried to add nthreads, but could not find that function in rxd at all. However, I did find it in crxd and so recoded entirely with crxd. Usually I get a HOC error, it is actually quite unusual for the 3D versions to get to completion however long I wait. (2) Should I be using rxd or crxd?
The error that is usually thrown is within the finitialise () and includes (i find it tricky in Python to spot the route cause) “euler_matrix_nonzero referenced before assignment” [rxd.py line 795]. I am tempted to dive into debugging, but I expect that this would be baking up the wrong tree, since I expect it is something I am doing.
Have you any tips on how to proceed? I presume these are my errors rather than bugs, but does that code run OK in 3D with your system?
Kind Regards
Richard
Python 3.5+, NEURON 7.6+
adamjhn
Posts: 54
Joined: Tue Apr 18, 2017 10:05 am

Re: 3D Dimensional RXD/CRXD

Post by adamjhn »

1) You can reduce the number of nodes by changing dx. Also nthreads is only currently implemented for crxd extracellular reaction-diffusion.
Would a radial diffusion model be sufficient?
Radial diffusion can be implemented in rxd using multicompartment reactions, for example;

Code: Select all

from neuron import h, crxd as rxd
from matplotlib import pyplot
import numpy
h.load_file('stdrun.hoc')

dend = h.Section('dend')
dend.L = 100  
dend.diam = 5
dend.nseg = 101

N = 5                   # number of shells -- must be >= 2
dr = dend.diam/(2.0*N)  # the thickness of the shells

# scale factor so the flux (Dca/dr)*Ca has units molecules/um^2/ms 
mM_to_mol_per_um = 6.0221409e+23 * 1e-18

# Where -- shells and border between them
shells = []
border = []
for i in range(N-1):
    shells.append(rxd.Region(h.allsec(), name='shell%i' % i,
                  geometry=rxd.Shell(float(i)/N, (1.0+i)/N)))
    border.append(rxd.Region(h.allsec(), name='border%i' % i,
                  geometry=rxd.FixedPerimeter(2.0*h.PI*(1.0+i))))

# the outer shell corresponds NEURON section concentration e.g. dend(0.5).cai
shells.append(rxd.Region(h.allsec(), nrn_region='i', name='shell%i' % N,
                  geometry=rxd.Shell((N-1.0)/N, 1.0)))

# Who -- calcium with an inhomogeneous initial condition
Dca = 1.0   #um^2/ms
ca = rxd.Species(shells, d=Dca, name='ca', charge=2, initial=lambda nd: 
                 1.0 if 49.5 < nd.x3d < 50.5 and nd.region == shells[0] else 60e-6)


# What -- use reactions to setup diffusion between the shells
cas = []    # calcium on the shells
for reg in shells:
    cas.append(ca[reg])

# create the multi-compartment reactions between the pairs of shells
diffusions = []
for i in range(N-1):
    diffusions.append(rxd.MultiCompartmentReaction(cas[i], cas[i+1], 
                      mM_to_mol_per_um*Dca, 
                      mM_to_mol_per_um*Dca,
                      border=border[i]))

# run for 5ms and plot the results
h.finitialize(-65)
h.continuerun(5)

pyplot.imshow(numpy.array(ca.nodes.concentration).reshape(N,dend.nseg),
              origin='lower', extent=(0, dend.L, 0, dend.diam/2.0),
              aspect='auto')
pyplot.colorbar()
pyplot.xlabel('x ($\mu$m)')
pyplot.ylabel('r ($\mu$m)')
pyplot.show()

2) Thanks for letting us know, this is not a bug per se as currently crxd supports 1D intracellular and 3D extracellular reaction-diffusion. We are actively developing a C/C++ version of intracellular 3D reaction-diffusion to add to crxd.
As crxd is faster but also less stable than rxd, I’d recommend trying your models in crxd first, if you run into difficulties, let us know and try rxd.
RBJ
Posts: 62
Joined: Sun Aug 02, 2015 4:28 am
Location: UK
Contact:

Re: 3D Dimensional RXD/CRXD

Post by RBJ »

Thanks there are some useful ideas. I really I want to press on with full-scale3-D simulation, however, so I can get smooth surfaces (with microdomains etc). How do I change dx? I googled for hours! Also to clarify, the 10 hours that that 3D script takes to execute is spent waiting in the Finitialise function not in the solving itself. Only rxd completes, not crxd. I didn't know that was for extracellular only. thanks.
The workaround I have adopted is to use mini cells, that means my scale everything by factor of 10 up or down depending (size down, diffusion rates up), with a view to rescaling once I get the output grade. That decreases finitialize() time to an acceptable 10 mins or so. Note that unless you re-start the kernel, Each nth run takes n times as long in finitialize().
For the record this is all Python 3.6, Neuron 7.6.5. I couldnt run it with Python 3.5, not tried 3.7 or anything else recently.
Thanks again,
R.
ps... so dx? How do I change that please?
adamjhn
Posts: 54
Joined: Tue Apr 18, 2017 10:05 am

Re: 3D Dimensional RXD/CRXD

Post by adamjhn »

The discretization used to build the mesh (dx), is an optional argument for rxd.Region, it defaults to 0.25μm. You should be able to get similar performance by scaling it up by 10, rather than reducing the cell sizes. E.g.

Code: Select all

cyt = rxd.Region(h.allsec(), name='cyt', nrn_region='i', dx=2.5)
Finitialise is building the 3d mesh, that is why it takes so long. We are developing intracellular 3D support for crxd, it is not currently available.
RBJ
Posts: 62
Joined: Sun Aug 02, 2015 4:28 am
Location: UK
Contact:

Re: 3D Dimensional RXD/CRXD

Post by RBJ »

Thank you, yes charging dx Is so easy and speeds up processing enormously. I am sorry I didn't find that myself in the documentation. Regards R.
Post Reply