DIfferent results with Neuron + Python and with HOC

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
Feanor
Posts: 26
Joined: Fri Nov 28, 2014 3:03 pm

DIfferent results with Neuron + Python and with HOC

Post by Feanor »

Hello to all!

When trying out a ball-and-stick model, one written using nrnpython and the other using HOC, I get different results from each of them. I think I have written the equivalent code statements in each example, and I can't see what is going wrong. The codes are below, and I can send the files also if it's easier that way. A remark: when changing the 'connect' statement in the nrnpython version with the one in the comment after it, the result is more similar to the one gotten with HOC (the measurement from the soma still differs).

If someone has the time to look at this and give an opinion, that would be great! (I have been looking at this code for so long, I can't see the mistake(s) anymore.)

Thank you,
Daniel

Code in Python

Code: Select all

from neuron import h
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

soma = h.Section()
dend = h.Section()

soma.L = 10
soma.diam = 10
soma.Ra = 1000
soma.insert('pas')
soma.g_pas = 1e-5
soma.cm = 1

dend.L = 200
dend.nseg = 47
dend.diam = 3
dend.Ra = 1000
dend.insert('pas')
dend.g_pas = 1e-3
dend.cm = 1

dend.connect(soma(0), 0) # dend.connect(soma(0), 1)
    
istim = h.IClamp(1.0, dend)
istim.amp = 0.2
istim.delay = 100
istim.dur = 30

vdlist = []
vdlist.append(h.Vector())
vdlist.append(h.Vector())
vdlist.append(h.Vector())

vs = h.Vector()
t = h.Vector()

vdlist[0].record(dend(1.0)._ref_v)
vdlist[1].record(dend(0.5)._ref_v)
vdlist[2].record(dend(0.0)._ref_v)
vs.record(soma(0.5)._ref_v)
t.record(h._ref_t)

h.load_file("stdrun.hoc")
h.init()
h.tstop = 200

h.run()

# Plotting code from here

rows = 2
fig = plt.figure(); 
plot_num = 1;
ax2 = fig.add_subplot(rows, 1, plot_num); plot_num += 1;
ax2.set_ylabel('Vd')
ax2.set_xlabel('t')
ax2.xaxis.set_ticks(np.arange(0, h.tstop, 10))
plt.hold(True)

ax2.plot(t, vdlist[0],'b')
ax2.plot(t, vdlist[1],'g')
ax2.plot(t, vdlist[2],'r')
ax2.legend(['dend(1.0)','dend(0.5)','dend(0.0)'])

ax3 = fig.add_subplot(rows, 1, plot_num); plot_num += 1;
ax3.set_ylabel('Vs')
ax3.set_xlabel('t')
ax3.plot(t, vs)
sns.set_context(font_scale = 5.0)
plt.show()
Code in HOC

Code: Select all

create soma, dend
access soma
    
soma.L = 10
soma.diam = 10
soma.Ra = 1000
soma insert pas
soma.g_pas = 1e-5
soma.cm = 1

dend.L = 200
dend.nseg = 47
dend.diam = 3
dend.Ra = 1000
dend insert pas 
dend.g_pas = 1e-3
dend.cm = 1

connect dend(0), soma(0)
 
objectvar istim   
dend istim = new IClamp(1.0)
istim.amp = 0.2
istim.del = 100
istim.dur = 30

objref vdlist[3], vs, time
vdlist[0] = new Vector()
vdlist[1] = new Vector()
vdlist[2] = new Vector()

vs = new Vector()
time = new Vector()

vdlist[0].record(&dend.v(1.0))
vdlist[1].record(&dend.v(0.5))
vdlist[2].record(&dend.v(0.0))
vs.record(&soma.v(0.5))
time.record(&t)

load_file("stdrun.hoc")
init()
tstop = 200

run()

//At this point I use the plotting tools from nrngui to see the results.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: DIfferent results with Neuron + Python and with HOC

Post by ramcdougal »

In the Python version, your current clamp does not do what you think it does. You write:

Code: Select all

istim = h.IClamp(1.0, dend)
which places the current clamp at soma(1) not dend(1). The correct (link to docs) thing to do is:

Code: Select all

istim = h.IClamp(dend(1))
What's going on? The "dend" parameter you're sending in is ignored. Why? Because the IClamp constructor only takes one argument: either a normalized position or a segment. The section in the normalized position form is the default section, which is the first one created (here: the soma) unless otherwise changed. To override the default section for just one use of the IClamp constructor, write: "istim = h.IClamp(1, sec=dend)"... but don't do that, because it's cleaner to use the segment form above.
Feanor
Posts: 26
Joined: Fri Nov 28, 2014 3:03 pm

Re: DIfferent results with Neuron + Python and with HOC

Post by Feanor »

Thank you so much! I wouldn't have guessed.

Daniel
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: DIfferent results with Neuron + Python and with HOC

Post by ted »

This is a perfect example of the importance of verifying that the actual model implementation is a close match to what you think it is. Of course there would have been no confusion about the location of the IClamp if you had used the GUI to attach it to the model cell. However, even though you didn't use the GUI, you could have executed
h.psection(sec=dend)
which would reveal that the IClamp was not attached to dend. Then
h.psection(sec=soma)
would have told you where the IClamp was.
Post Reply