Page 1 of 1

3D Dimensional RXD/CRXD

Posted: Fri Jan 25, 2019 2:51 pm
by RBJ
Hello, I wonder if you could help further. Simply adding

Code: Select all

rxd.set_solve_type(dimension=3) 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” [ 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
Python 3.5+, NEURON 7.6+

Re: 3D Dimensional RXD/CRXD

Posted: Mon Jan 28, 2019 9:33 pm
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

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,

# 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:

# 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], 

# run for 5ms and plot the results

              origin='lower', extent=(0, dend.L, 0, dend.diam/2.0),
pyplot.xlabel('x ($\mu$m)')
pyplot.ylabel('r ($\mu$m)')

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.

Re: 3D Dimensional RXD/CRXD

Posted: Tue Jan 29, 2019 8:30 am
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,
ps... so dx? How do I change that please?

Re: 3D Dimensional RXD/CRXD

Posted: Wed Jan 30, 2019 11:56 am
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.

Re: 3D Dimensional RXD/CRXD

Posted: Thu Jan 31, 2019 2:59 pm
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.