Playing a vector

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

Moderator: hines

Playing a vector

Postby wvangeit » Mon Oct 05, 2009 10:53 pm

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: 19
Joined: Wed Jun 11, 2008 2:14 am

Re: Playing a vector

Postby wvangeit » Tue Oct 06, 2009 12:21 am

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.
wvangeit
 
Posts: 19
Joined: Wed Jun 11, 2008 2:14 am

Re: Playing a vector

Postby hines » Mon Oct 12, 2009 11:55 am

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.
hines
Site Admin
 
Posts: 572
Joined: Wed May 18, 2005 3:32 pm

Re: Playing a vector

Postby wvangeit » Wed Oct 14, 2009 4:12 am

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
wvangeit
 
Posts: 19
Joined: Wed Jun 11, 2008 2:14 am


Return to NEURON + Python

Who is online

Users browsing this forum: Exabot [Bot], mattions and 1 guest