Playing a vector

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

Moderator: hines

Post Reply
wvangeit
Posts: 21
Joined: Wed Jun 11, 2008 2:14 am

Playing a vector

Post by wvangeit »

I've problems with playing a vector into a variable in python. The following code works:

Code: Select all

  h('objref tempvec, tvec')
  h('tempvec = new Vector(2)')
  h('tvec = new Vector(2)')
  h('tempvec.x[0] = 30')
  h('tvec.x[0] = 0')
  h('tempvec.x[1] = 32')
  h('tvec.x[1] = 1100')

  h('tempvec.play(&axon.enax_Na(0.5), tvec, 1)')
  h('tempvec.play(&soma.enax_Na(0.5), tvec, 1)')
When I print the enax parameter from the mod file with printf, it is changing during the simulation
But when I replace it with:

Code: Select all

  tvec = h.Vector(2)
  tvec.x[0] = 0
  tvec.x[1] = 1100

  tempvec = h.Vector(2)
  tempvec.x[0] = 30
  tempvec.x[1] = 32

  tempvec.play(h.axon(0.5)._ref_enax_Na, tvec, 1, sec=h.axon)
  tempvec.play(h.soma(0.5)._ref_enax_Na, tvec, 1, sec=h.soma)
It doesn't work, and the enax variable is set to its initial value during the simulation.

What am I doing wrong ?

Thx,

Werner Van Geit

(NEURON -- VERSION 7.1 (351+:db83e591f4a9+))
wvangeit
Posts: 21
Joined: Wed Jun 11, 2008 2:14 am

Re: Playing a vector

Post by wvangeit »

Mmm, I've found another solution that works:

Code: Select all

  h('objref tempvec, tvec')
 
  h.tvec = h.Vector(2)
  h.tvec.x[0] = 0
  h.tvec.x[1] = 1100 
  
  h.tempvec = h.Vector(2)
  h.tempvec.x[0] = 30.0
  h.tempvec.x[1] = 32.0 
  
  h.tempvec.play(h.axon(0.5)._ref_enax_Na, h.tvec, 1)
  h.tempvec.play(h.soma(0.5)._ref_enax_Na, h.tvec, 1)
Need still the objref hoc code for this though.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Playing a vector

Post by hines »

I'm afraid I was unable to reproduce the error using the second code fragment of your first
message. Please send me a zip file of your hoc, ses, py, mod files and I'll look into it further.
Send to michael dot hines at yale dot edu.
wvangeit
Posts: 21
Joined: Wed Jun 11, 2008 2:14 am

Re: Playing a vector

Post by wvangeit »

Okay, I have found the problem when I tried to make an easy-reproducible testcase. It was a (tricky) mistake I made.
The following code works:

Code: Select all

#!/usr/bin/env nrngui -nogui -python

import neuron
from neuron import *
import nrn
from nrn import *

h('create soma')

h('access soma')

h.soma.insert("Na")

tvec = h.Vector(2)
tvec.x[0] = 0
tvec.x[1] = h.tstop

tempvec = h.Vector(2)
tempvec.x[0] = 20
tempvec.x[1] = 40

tempvec.play(h.soma(0.5)._ref_ena, tvec, 1)

h.tstop = 10

#connectelectrode()

h.run()
But I was creating the tvec, tempvec inside a function, and they were destroyed after I left the function, so that's why this doesn't work:

Code: Select all

#!/usr/bin/env nrngui -nogui -python

import neuron
from neuron import *
import nrn
from nrn import *

def connectelectrode():
  tvec = h.Vector(2)
  tvec.x[0] = 0
  tvec.x[1] = h.tstop
  tempvec = h.Vector(2)
  tempvec.x[0] = 20
  tempvec.x[1] = 40
  tempvec.play(h.soma(0.5)._ref_ena, tvec, 1)

h('create soma')
h('access soma')
h.soma.insert("Na")
h.tstop = 10
connectelectrode()
h.run()
Didn't give any error though, only kept the ena at the same value. Pointers 'are' dangerous ;-)

Werner Van Geit
breynaert
Posts: 6
Joined: Mon May 10, 2010 4:13 pm

Re: Playing a vector

Post by breynaert »

Hi everybody,

Im trying to play a vector into an IClamp Electrode in order to stimulate with a time dependent current,
but my efforts have been unfruitful.

Here is a test case:

Code: Select all


from neuron import *
from nrn import *

axon = Section()
axon.L = 3000
axon.nseg = 3000
axon.insert('hh')
axon.insert('pas')

VecAxon = h.Vector()
VecAxon.record(axon(0.1)._ref_v)

time = h.Vector()
time.record(h._ref_t)

VecT = h.Vector([0, 1000])
VecStim = h.Vector([50, 0])

stim = h.IClamp(axon(0))
#stim.dur = 0
#stim.amp = 1e9

h.VecStim.play(stim._ref_amp, VecT, 1)
#h.VecStim.play(stim.amp, h.VecT, 1)
#h.VecStim.play(stim, VecT, 1)

h.finitialize(-68)
run(10)
I've tried everything which is commented, but no luck.
How should this be accomplished from Python?

Regards

Bryan
wvangeit
Posts: 21
Joined: Wed Jun 11, 2008 2:14 am

Re: Playing a vector

Post by wvangeit »

Hi,

Doesn't

Code: Select all

VecStim.play(stim._ref_amp, VecT, 1)
without the 'h.', work ?

Werner
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Playing a vector

Post by hines »

You need
stim.dur = 1e9
so that the IClamp is not off during the falling ramp.
Also elminate the h. in
h.VecStim.play(stim._ref_amp, VecT, 1)
as mentioned by wvangeit.
breynaert
Posts: 6
Joined: Mon May 10, 2010 4:13 pm

Re: Playing a vector

Post by breynaert »

It works!

Thank you very much.
breynaert
Posts: 6
Joined: Mon May 10, 2010 4:13 pm

Re: Playing a vector

Post by breynaert »

I checked the documentation (maybe I am using the wrong source?)
http://web.mit.edu/neuron_v6.1/doc/help ... /mech.html

And there is a little mistake where it says to set amp to 0 instead of del.
Just a detail that when read carefuly is obvious but I thought it could help
careless people like me if it was corrected.

Regards
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Playing a vector

Post by hines »

Thanks. Fixed the typo.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

NEURON documentation

Post by ted »

breynaert wrote:I checked the documentation (maybe I am using the wrong source?)
. . . web.mit.edu/neuron_v6.1/doc/ . . .
Well, you were at the wrong source, but apparently the documentation error persisted until you pointed it out.

neuron_v6.1 ?? I hope nobody is still using NEURON version 6.1. The most recent standard distribution is v. 7.1, and the Programmer's Reference for the most recent standard distribution will always be browsable at this URL
http://www.neuron.yale.edu/neuron/stati ... tents.html
and downloadable as a (pk)zipped archive from a link near the top of this page
http://www.neuron.yale.edu/neuron/docs
(MSWin users who use the nrn*exe installer don't have to bother with this, since the installer puts a copy of the Programmer's Reference on their machines).

As far as the files at web.mit.edu/neuron_v6.1 are concerned, please note that anybody can post anything they like, anywhere on the WWW (subject to censorship laws and other government interference), so caveat lector ("let the reader beware!"). To repeat: the official documentation of NEURON is distributed from links at http://www.neuron.yale.edu/
romain.caze

Re: Playing a vector

Post by romain.caze »

Dear all,

I am using VecStim regularly to stimulate NEURON models with a (or multiple) train of presynaptic activity. This could be, without python wrapping, a tedious process

Code: Select all

import numpy as np
from neuron import h

"""There should be some code here to create a neuron model with a soma"""

#To create a numpy array containing the stimulation time
tstim = np.array([10,20])
#To convert this array into a NEURON vector
tstim_n = h.Vector(tstim)
#Then create a VecStim object and play the NEURON vector
vplay = h.VectStim()
vplay.play(tstim_n)
#This is the pointprocess object
syn = h.ExpSyn(soma(0.5))
#To connect the pointprocess and play vector using a netcon
netcon = h.NetCon(vplay, syn)
netcon.weight[0] = 0.001

"""There should be some code here to launch a NEURON simulation"""

Wouldn't it better to have instead a single line of code to define the where, when, and what?

Code: Select all


tstims = np.array([10,20])
stimulation = connect(soma(0.5), tstims, {"ExpSyn", 0.001})

I have a git repository storing a code performing this action without too much steam (https://github.com/rcaze/PlosCB2013). To do that I wrap things into python objects. But I am sure that the code could be cleaner, and I am curious to know how hard it would be to modify the underlying hoc, in order to get rid of the VecStim object (and the NetCon if possible). You are more than welcome to contribute and modify the code I posted on git, and to tell me if I am making my life too complicated.

Best,
Romain
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Playing a vector

Post by hines »

stimulation = connect(soma(0.5), tstims, {"ExpSyn", 0.001})
It would not be very convenient to implement this using HOC code. Best to just factor the statements you used to implement the functionality into a new class.
It is important to keep the ExpSyn, VecPlay, NetCon in existence via explicit references. And you need them to modify parameters anyway.
I'd just go slightly further and create the ExpSyn at the time of call by using h.ExpSyn instead of putting it in a string.
Post Reply