Page 1 of 1

updating Species and Rates inputs

Posted: Wed Jan 16, 2019 2:41 pm
by bschneiders
Hi, I have a question about updating rxd.Species inputs. Up until now, I simply restart python when I need to update initial concentrations, etc. However, I'm now running scripts to rapidly run through parameter values, and it would be very convenient not to exit Python between runs.

First of all, let me clarify the problem I have that I have been ignoring until now. I often want to update reaction rates, which trickles down to initial concentrations. This doesn't automatically get seen by rxd.species, as I can verify visually in my plots. But if I rerun a species statement to try to have it run with the updated initial concentration, I get:

Code: Select all

RxDException: Species "ca" previously defined: Species(regions=[Region(..., nrn_region='i', geometry=inside, dx=None, name=None)], d=0.6, name='ca', charge=2, initial=4.9999999999999996e-05)
I have tried reloading the RxD module ("reload(rxd)") and then rerunning the species definitions, but somehow I get the same error - "ca" isn't forgotten. So I thought maybe I reloaded it in python but hoc still remembered these species definitions. I tried deleting the species within hoc via two methods (the second was suggested on Neuron Forum when the first threw another error):

Code: Select all

In [3]: h.delete(ca)
TypeError                                 Traceback (most recent call last)
<ipython-input-6-eab18e722765> in <module>()
----> 1 h.delete(ca)

TypeError: Cannot access delete (NEURON type 262) directly.
In [4]: ca = None
but neither erased 'ca', and I got the same RxDException error when I ran the rxd.Species statement again.

Note that I also tried doing without updating the species and just updating the rxd.Rate definitions since that's where the reaction rates directly come into play, and I could just not worry about initial conditions and let the system equilibrate for longer before stimulating. However, when I reran the rxd.Rate statements, it simply zeroed out all rxd activity. So my backup workaround also did not work.

Any thoughts? I am less familiar with hoc syntax - perhaps I deleting 'ca' incorrectly? Or is there a better way to restart/reload RxD without restarting python? Or better yet, is there a way update these parameters directly within RxD without getting any errors?

Any advice is much appreciated!

Re: updating Species and Rates inputs

Posted: Thu Jan 17, 2019 2:50 pm
by adamjhn
There are several ways of changing the initial concentration of a species, but the easiest is to use its `.initial` attribute, e.g.

Code: Select all

from neuron import h, rxd

soma = h.Section('soma')
cyt = rxd.Region([soma], name='cyt', nrn_region='i')
ca = rxd.Species(cyt, name='ca', charge=2, initial=50e-6)

# first "simulation"
print(soma(0.5).cai)  # prints 5e-05

# prepare for new "simulation"
ca.initial = 60e-6

# second simulation
print(soma(0.5).cai)  # prints 6e-05

Re: updating Species and Rates inputs

Posted: Fri Jan 18, 2019 3:08 pm
by bschneiders
Thank you, I will try that!