Wow, everything old is new again. Or at least some old things are new. Thank you, Python!
Is there another way to do it.
There are many ways that would work.
Maybe using a mod file which simplifys this?
There is no mod file that would simplify this.
when I run a simulation the program dies without giving an error.
Not very helpful. In such cases, it is up to the programmer to locate the cause of the problem. Did you happen to develop your program in an incremental manner, starting with something simple that works, then proceeding iteratively, that is,
Code: Select all
REPEAT
make a small change
test to make sure that the latest change works
UNTIL the whole program exists and works correctly
If not, then maybe you can embed print statements at key points in your program, then execute it to see where the failure occurs, and use that information to refine your bug search.
I think you mentioned this already in your comment:
If synapses are scattered over multiple nodes, you'll just have to keep track of them when you set them up, and compute a "sum on the fly" as the simulation advances.
Can you elaborate on that or send some code?
First, my opinion now is that I wouldn't bother adding up the currents during a run. I'd capture their time courses to hoc Vectors, and add those up after the simulation ends.
"How do I keep track of the synapses as I set them up?"
Append each synaptic mechanism to a list when you create it. Then you can iterate over the contents of that list without having to keep track of "magic numbers" such as the number of synaptic mechanisms you created. Example:
Code: Select all
# create the instances of the synaptic mechanism
syns = [] # syns is a Python list
NSYN = 3
for ii in range(0,NSYN):
tmp = h.AlphaSynapse(0.5, sec = soma)
tmp.onset = 1.0+ii*0.4
tmp.gmax = 1e-3
tmp.e = 0
syns.append(tmp)
Now you can set up Vector record by doing this
Code: Select all
ivecs = [] # for the individual synaptic currents
for abc in syns:
tmp = h.Vector()
tmp.record(abc._ref_i)
ivecs.append(tmp)
Notice that I'm iterating over the elements of one list in order to populate another list. Also notice the absence of magic numbers--not a 3 nor its symbolic representation NSYN in sight. No need to remember either the number or what you called it.
"OK, how do I add them up after the simulation ends?"
Code: Select all
def myrun():
h.run() # initializes and runs a simulation, and also updates NEURON's InterViews graphs
# you may prefer to call finitialize and continuerun directly
itotal = np.array(ivecs[0]) # get the first Vector into a numpy array
for ii in range(1,len(ivecs)):
itotal += ivecs[ii].as_numpy()
#
pyplot.plot(tvec.as_numpy(), itotal)
pyplot.show()