I'm trying to implement a neuromuscular system that has some afferent structures that depend on other softwares besides NEURON. On this effort, I found in the forum the following .mod, which implements a python callback function.
Code: Select all
NEURON {
POINT_PROCESS PyBeforeStep
POINTER callback
}
ASSIGNED {callback}
VERBATIM
extern int (*nrnpy_hoccommand_exec)(Object*);
ENDVERBATIM
BEFORE STEP {
VERBATIM
if (nrnpy_hoccommand_exec && _p_callback) {
Object** po = (Object**)(&(_p_callback));
(*nrnpy_hoccommand_exec)(*po);
}
ENDVERBATIM
}
PROCEDURE set_callback() {
VERBATIM
Object** po = (Object**)(&(_p_callback));
Object* old = *po;
*po = (Object*)0;
if (ifarg(1)) {
*po = *hoc_objgetarg(1);
hoc_obj_ref(*po);
}
if (old) { hoc_obj_unref(old); }
ENDVERBATIM
}
Code: Select all
from neuron import h
h.load_file('stdrun.hoc')
import pylab as plt
def foo(ns): #to be called at every time step
if h.t % 50 == 0.0:
ns.interval = ns.interval + 10
soma = h.Section(name = 'soma')
soma.insert('hh')
syn = h.ExpSyn(soma(0.5))
syn.tau = 20
syn.e = 0
ns = h.NetStim()
ns.interval = 20 #[ms]
ns.start = 0
ns.noise = 0
ns.number = 1e9
nc = h.NetCon(ns,syn)
nc.delay = 0
nc.weight[0] = 0.1
vx = h.Vector().record(soma(0.5)._ref_v) #Record soma voltage
t = h.Vector().record(h._ref_t)
a = h.PyBeforeStep(soma(0.5))
a.set_callback(foo(ns))
h.tstop= 500
h.run()
plt.figure()
plt.plot(t,vx)
plt.show()
I'm not sure if this is the best implementation strategy and if it would work as expected.
Do you have any sugestions to solve this muscle afferent feedback problem? What could I do have runtime control over artificial cell's spike times from other software?
Thanks in advance.