Strangeness when recording state variable

NMODL and the Channel Builder.
Post Reply
NickHananeia
Posts: 10
Joined: Fri Jun 14, 2019 1:09 pm

Strangeness when recording state variable

Post by NickHananeia »

So, I'm checking that our calcium concentration stuff is working properly (we're using a few v-gated Ca channels) with the Ca_DynamicsE2.mod that looks like this:

Code: Select all

: Dynamics that track inside calcium concentration
: modified from Destexhe et al. 1994

NEURON	{
	SUFFIX CaDynamics_E2
	USEION ca READ ica WRITE cai
	RANGE decay, gamma, minCai, depth
}

UNITS	{
	(mV) = (millivolt)
	(mA) = (milliamp)
	FARADAY = (faraday) (coulombs)
	(molar) = (1/liter)
	(mM) = (millimolar)
	(um)	= (micron)
}

PARAMETER	{
	gamma = 0.05 : percent of free calcium (not buffered)
	decay = 80 (ms) : rate of removal of calcium
	depth = 0.1 (um) : depth of shell
	minCai = 1e-4 (mM)
}

ASSIGNED	{ica (mA/cm2)}

STATE	{
	cai (mM)
	}

BREAKPOINT	{ SOLVE states METHOD cnexp }

DERIVATIVE states	{
	cai' = -(10000)*(ica*gamma/(2*FARADAY*depth)) - (cai - minCai)/decay
}

I'm trying to write some code to track the value of cai, to see how well this particular calcium dynamic mod correlates with another calcium dynamic simulation we're doing.

I write this:
objref caivec
caivec = new Vector()
caivec.record(cell.soma.cai(0.5))

This doesn't seem to work - NEURON throws an error saying that cai is not a range variable. Oddly if I track ica instead, cai does exist when I check in the command line.

I presume I'm addressing this wrong? I've tried addressing it as cai_CaDynamics_E2 but that doesn't work either.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Strangeness when recording state variable

Post by ted »

Good question.

First, at the oc> prompt verify that the variable exists.
print cell.soma.cai(0.5)
If that doesn't work, try
cell.soma print cai(0.5)

Vector record() expects a pointer.
Try
caivec.record(&cell.soma.cai(0.5))
or
cell.soma caivec.record(&cai(0.5))

It's best to not use cnexp for ion accumulation mechanisms described by an ODE of the form
x' = influx - (xi - minxi)/tau
especially when the state variable is likely to be very small. It risks dropping xi to or below 0. Instead use derivimplicit. Check out the note about NMODL methods in the Hot tips area of the Forum.

Let me know if you picked up the NMODL source code from ModelDB--if you did, we need to revise that particular file and others like it.
NickHananeia
Posts: 10
Joined: Fri Jun 14, 2019 1:09 pm

Re: Strangeness when recording state variable

Post by NickHananeia »

It seems that the variable does not exist (or at least doesn't exist when the code goes to look for it). Trying to print it gives me the error "cai suffix not a range variable or section property", or "cai undefined function" if I use your second print line.

The parameters of the mod file certainly do exist - if I try to print gamma, decay, depth, or minCai, they show fine.

I did in fact find this on ModelDB - this CaDynamics_E2 mod file is used by quite a few peoples' cortical pyramidal cell models.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Strangeness when recording state variable

Post by ted »

For me

objref caivec
caivec = new Vector()
caivec.record(&soma.cai(0.5))

works just fine using version 8.0a-575-gd9462cc master (d9462cc) 2021-05-27
and 7.7.1-28.... from way back 2019-08-07 (ah those halcyon pre-viral days).

That said, under 8.0.... _THIS_

objref tvec
tvec = new Vector()
tvec.record(&t)

doesn't work. Which I don't recall being announced as a "feature" of 8, so maybe it's a bug (I hope); otherwise it's going to break a lot of code.

Back to your issue: exactly what version of NEURON are you using? Please let me know. You might want to switch to 7.8.something (see https://www.neuron.yale.edu/ftp/neuron/versions/v7.8/) unless you don't need to capture t, in which case you might want to use the latest 8.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Strangeness when recording state variable

Post by ted »

Suggestions about your CaDyn... mod file:

I don't know how you're initializing cai, but it might make life easier to do the following:

In the NEURON block insert
RANGE cai0

In the PARAMETER block insert
cai0 = 1e-4 (mM)

Insert this new block:

Code: Select all

INITIAL {
  cai = cai0
}
Why? This mechanism is WRITEing cai, so it might as well also specify the initial value of cai. No need for a separate cai0_ca_ion statement in hoc.

BTW for any given set of channels that write ica, and any particular resting potential, this ca accumulation mechanism will probably need some adjustment of decay and minCai to insure that resting cai equals cai0. And of course changing decay will alter the rate at which cai goes back to cai0 after a perturbation. You probably already knew that, but others might not even be aware of these considerations.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Strangeness when recording state variable

Post by ted »

under 8.0.... _THIS_

objref tvec
tvec = new Vector()
tvec.record(&t)

doesn't work.
Well, that's strange. I tried to reproduce this error message, but couldn't, perhaps because I didn't save the version of my model implementation that generated the messge. I thought I had saved it, but apparently not so. What I do have differs from that earlier implementation in that the current implementation displays more variables of interest in Graphs, instead of recording their time courses in vectors.

So go ahead, use Vector.record and if you run into what looks like a bug, please be sure to save the code that is needed to reproduce it, and report the bug.

--Ted
NickHananeia
Posts: 10
Joined: Fri Jun 14, 2019 1:09 pm

Re: Strangeness when recording state variable

Post by NickHananeia »

Still working on this...

Moving back to an older version of NEURON didn't remedy the situation but at this point I'd want to be sure that nothing is wrong with Vector.record.


Testing my code - calcium accumulation does work - if I ask for cai after the simulation has run, it gives me an answer that is not equal to the initial value.

That said, if I ask for cai just before init, it says it doesn't exist (and this is where I'm attempting to record the vector). I have also altered the mod file to initialize cai = cai0, and if I ask NEURON to print cai0, indeed, it gives the correct result.
Post Reply