How to refer to numeric value of crxd.v?

Extending NEURON to handle reaction-diffusion problems.

Moderators: hines, wwlytton, ramcdougal

sangwonc
Posts: 7
Joined: Sun Nov 07, 2021 7:13 pm

How to refer to numeric value of crxd.v?

Hello! I am trying to implement voltage-dependent calcium channels using the Hodgkin-Huxley model through the RXD module. The equation that I'm using to define calcium current involves an if-statement:

Code: Select all

temp1 = 0.0853*T/2
temp2 = v/temp1
temp3 = 0
if abs(temp2) < 1.10e-4:
temp3 = 1-temp2/2
else:
temp3 = temp2/(exp(temp2)-1)

dvf = 0.001/(0.001+cai)*temp1*temp3(1-cai/cao*exp(temp2))
But it spits out the following error message:
---------------------------------------------------------------------------
RxDException Traceback (most recent call last)
/var/folders/g8/zb3mbhcx77jbf0z1yz92s51w0000gn/T/ipykernel_15917/542443844.py in <module>
2 temp2 = v/temp1
3 temp3 = 0
----> 4 if abs(temp2) < 1.10e-4:
5 temp3 = 1-temp2/2
6 else:

/Applications/NEURON/lib/python/neuron/rxd/rxdmath.py in __lt__(self, other)
634 def __lt__(self, other):
635 other = _ensure_arithmeticed(other)
--> 636 _validate_reaction_terms(self, other)
637 return _Reaction(self, other, '<')
638

/Applications/NEURON/lib/python/neuron/rxd/rxdmath.py in _validate_reaction_terms(r1, r2)
123 def _validate_reaction_terms(r1, r2):
124 if not(r1._valid_reaction_term or r2._valid_reaction_term):
--> 125 raise RxDException('lhs=%r and rhs=%r not valid in a reaction' % (r1, r2))
126 elif not r1._valid_reaction_term:
127 raise RxDException('lhs=%r not valid in a reaction' % r1)

RxDException: lhs=abs((v)/(13.2278975)) and rhs=0.00011 not valid in a reaction
And I have isolated the problem to crxd.v, the purpose of which is "to make HH model work with rxd with have added crxd.v to represent the voltage in Rates and Reactions." https://neuron.yale.edu/neuron/docs/hod ... -using-rxd In the line temp2 = v/temp1, I cannot refer to the numeric value of 'v'. As a result, when I run the following lines of code:

Code: Select all

temp1 = 0.0853*T/2
temp2 = v/temp1
print(abs(temp2))
This is the output:

abs((v)/(13.2278975))

Which is not the numeric value that I need to properly process the if statement.

Any suggestions on how I can fix/work around this? Thank you!
Posts: 47
Joined: Tue Apr 18, 2017 10:05 am

Re: How to refer to numeric value of crxd.v?

Hi,
The problem is rxdmath.v is not a number, it is a symbol that is mapped to the membrane potential of a segment at runtime, so if-statements in the reaction scheme are not supported. However you can represent something like the if-statement using a thresholds;
https://neuron.yale.edu/neuron/docs/rea ... thresholds

e.g.

Code: Select all

from neuron import h, rxd
from neuron.units import nM
from neuron.rxd.rxdmath import v, exp, tanh

dend = h.Section(name='dend')
cyt = rxd.Region([dend], name='cyt', nrn_region='i')
ecs = rxd.Region([dend], name='ecs', nrn_region='o')
ca = rxd.Species([cyt,ecs], name='ca', charge=2, initial=60 * nM)
cai = ca[cyt]
cao = ca[ecs]

T = 310.15
threshold = 1.10e-4
m = 100 # steepness of switch
temp1 = 0.0853*T/2
temp2  = v/temp1

# switch goes to 0 for abs(temp2) < threshold and 1 for abs(temp2) > threshold
switch = (1 + tanh(((abs(temp2) - threshold)*100)))/2
temp3 = (1-switch)*(1-temp2/2) + switch*(temp2/exp(temp2)-1)
dvf = 0.001/(0.001+cai)*temp1*temp3*(1-cai/cao*exp(temp2))
sangwonc
Posts: 7
Joined: Sun Nov 07, 2021 7:13 pm

Re: How to refer to numeric value of crxd.v?

So I implemented your code and when it attempted to execute the following lines:
h.finitialize(-70)
h.continuerun(100)
it spat back the following warning/error message:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
/Applications/NEURON/lib/python/neuron/rxd/rxd.py in _init()
1486 clear_rates()
1487 _setup_memb_currents()
-> 1488 _compile_reactions()
1489
1490

/Applications/NEURON/lib/python/neuron/rxd/rxd.py in _compile_reactions()
1246 numpy.array(mc_mult_list, dtype=ctypes.c_double),
1247 _list_to_pyobject_array(creg._vptrs),
-> 1248 _c_compile(fxn_string))
1249
1250 #Setup intracellular 3D reactions

/Applications/NEURON/lib/python/neuron/rxd/rxd.py in _c_compile(formula)
487 #TODO: Find a better way of letting the system locate librxdmath.so.0
488 rxdmath_dll = ctypes.cdll[_find_librxdmath()]
--> 489 dll = ctypes.cdll['%s.so' % os.path.abspath(filename)]
490 reaction = dll.reaction
491 reaction.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]

~/opt/anaconda3/lib/python3.8/ctypes/__init__.py in __getitem__(self, name)
454
455 def __getitem__(self, name):
--> 456 return getattr(self, name)
457

~/opt/anaconda3/lib/python3.8/ctypes/__init__.py in __getattr__(self, name)
449 if name == '_':
450 raise AttributeError(name)
--> 451 dll = self._dlltype(name)
452 setattr(self, name, dll)
453 return dll

~/opt/anaconda3/lib/python3.8/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
379
380 if handle is None:
--> 381 self._handle = _dlopen(self._name, mode)
382 else:
383 self._handle = handle

NEURON: Python Callback failed
near line 0
^
finitialize(-70)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/var/folders/g8/zb3mbhcx77jbf0z1yz92s51w0000gn/T/ipykernel_51952/2680823855.py in <module>
----> 1 h.finitialize(-70)
2 h.continuerun(100)
3

RuntimeError: hoc error
Obviously, 'h.finitialize' and 'h.continuerun' was executed after successfully executing the code that you suggested. Along with the above error message, there was a warning message (which I did not include) that suggested that I use 'fabs', which always returns a float, from 'math' library instead of abs, which returns an integer. When I imported 'fabs' and changed the code accordingly, it returns the following message:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/var/folders/g8/zb3mbhcx77jbf0z1yz92s51w0000gn/T/ipykernel_53351/1251560558.py in <module>
18
19 # switch goes to 0 for abs(temp2) < threshold and 1 for abs(temp2) > threshold
---> 20 switch = (1 + tanh(((fabs(temp2) - threshold)*100)))/2
21 temp3 = (1-switch)*(1-temp2/2) + switch*(temp2/exp(temp2)-1)
22 dvf = 0.001/(0.001+cai)*temp1*temp3*(1-cai/cao*exp(temp2))

TypeError: must be real number, not _Arithmeticed
As you can see, the above error message was produced when it executed the line of code defining the switch variable. I think it's reasonable that I stick with 'fabs', but I fear that it might still produce the following error when NEURON executes 'h.finitialize':
Any suggestions on how I can fix this?