Page 2 of 3

Re: SWC files

Posted: Fri Feb 13, 2015 4:37 am
by Kolorek
Great now almost (problem with record voltage) everything work fine
problem is that I make vector

vrec1 = h.Vector()
and I want to record voltage from cell1 but like you write the cells has got morphology so i want to record from for example (In future i want to record from soma, dend and axon) soma
but always I have RuntimeError: hoc error
how to fix this problem - what I am doing wrong ?

Code: Select all


Traceback (most recent call last):
  File "C:\Users\Właściciel\Desktop\komórki\hh.py", line 248, in <module>
    vrec1.record(cell1.soma[0])
RuntimeError: hoc error
>>> ================================ RESTART ================================

Traceback (most recent call last):
  File "C:\Users\Właściciel\Desktop\komórki\hh.py", line 248, in <module>
    vrec1.record(cell1.soma)
RuntimeError: hoc error
>>> ================================ RESTART ================================

Traceback (most recent call last):
  File "C:\Users\Właściciel\Desktop\komórki\hh.py", line 248, in <module>
    vrec1.record(0.5, cell1.soma)
RuntimeError: hoc error
>>> ================================ RESTART ================================

Traceback (most recent call last):
  File "C:\Users\Właściciel\Desktop\komórki\hh.py", line 248, in <module>
    vrec1.record(0.5, cell1.soma[0])
RuntimeError: hoc error
I download nrn-7.3.i686-pc-cygwin-setup.exe but how can I upgrade in Python this (I mean I work in python and I have pyNEURON 7.2.536.16 what to do to have pyNEURON 7.3 - from where I can download (i try to find in internet but there is only this nrn-7.3.i686-pc-cygwin-setup.exe))

The reaction-diffusion (rxd) module was introduced in NEURON 7.3; you're running 7.2. If you don't have an extensive Python setup that you need to preserve, on Windows I'd recommend using the cygwin version; the NEURON download page is here; the direct link for the 32-bit cygwin version for Windows is: http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe.

Thank you

Re: SWC files

Posted: Sun Feb 15, 2015 9:18 pm
by ramcdougal
Vector.record takes a pointer which is denoted with the _ref_ syntax. You want

Code: Select all

vec1 = h.Vector()
vec1.record(cell1.soma(0.5)._ref_v)
That's cell dot section parens location dot _ref_ variable of interest (v, nai, etc...).

NB: This assumes that soma is a Section not an array; if not, replace `soma` with `soma[0]` (or whichever).

NEURON can always* be programmed in Python. pyNEURON is a third-party repackaging that lets one install NEURON 7.2 via pip. Unfortunately, the people who set that up have yet to update it to NEURON 7.3.

Re: SWC files

Posted: Mon Feb 16, 2015 7:49 am
by Kolorek
Now I can record voltage to vector but
it's empty after record (I don't have nothing in time vector and voltage vector)

here is my all code:

Code: Select all

# -*- coding: cp1250 -*-
import btmorph
import matplotlib.pyplot as plt
import neuron
from neuron import h, gui, rxd 
import numpy as np
import pylab as py
from mpl_toolkits.mplot3d.axes3d import Axes3D

## Here I plot cell in 2D that I will use in my network (only to show how the cell looks like)
##btmorph.btviz.plot_2D_SWC("51-2b.CNG.swc",outN='neuron2D')
##plt.show()

## Here I plot cell in 3D that I will use in my network (only to show how the cell looks like)
##btmorph.btviz.plot_3D_SWC("51-2b.CNG.swc",outN='neuron3D')
##plt.show()

## Here I plot a network
##fig = plt.figure()
##plt.subplot(241)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 1")
##
##plt.subplot(242)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 2")
##
##plt.subplot(243)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 3")
##
##plt.subplot(244)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 4")
##
##plt.subplot(245)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 5")
##
##plt.subplot(246)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 6")
##
##plt.subplot(247)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 7")
##
##plt.subplot(248)
##btmorph.plot_2D_SWC("51-2b.CNG.swc",new_fig=False)
##plt.axis('off')
##plt.title("cell 8")
##plt.suptitle("Small network build from 8 pyramidal cells", fontsize=20)
##plt.show()


from neuron import h
h.load_file('neu.hoc')

cell1 = h.pira('cell1')
cell2 = h.pira('cell2')
cell3 = h.pira('cell3')
cell4 = h.pira('cell4')
cell5 = h.pira('cell5')
cell6 = h.pira('cell6')
cell7 = h.pira('cell7')
cell8 = h.pira('cell8')

cell1.position(1,2,0)
cell2.position(1,1,0)
cell3.position(2,2,0)
cell4.position(2,1,0)
cell5.position(3,2,0)
cell6.position(3,1,0)
cell7.position(4,2,0)
cell8.position(4,1,0)

post_syn1 = h.ExpSyn(0.5, sec=cell1.dend[0])
post_syn2 = h.ExpSyn(0.5, sec=cell2.dend[0])
post_syn3 = h.ExpSyn(0.5, sec=cell3.dend[0])
post_syn4 = h.ExpSyn(0.5, sec=cell4.dend[0])
post_syn5 = h.ExpSyn(0.5, sec=cell5.dend[0])
post_syn6 = h.ExpSyn(0.5, sec=cell6.dend[0])
post_syn7 = h.ExpSyn(0.5, sec=cell7.dend[0])
post_syn8 = h.ExpSyn(0.5, sec=cell8.dend[0])

post_syn1.e = 10
post_syn1.i = 3
post_syn1.tau = 3

connection1 = cell1.connect2target(post_syn2)
connection2 = cell1.connect2target(post_syn3)
connection3 = cell1.connect2target(post_syn4)
connection4 = cell1.connect2target(post_syn5)
connection5 = cell1.connect2target(post_syn6)
connection6 = cell1.connect2target(post_syn7)
connection7 = cell1.connect2target(post_syn8)

connection8 = cell2.connect2target(post_syn1)
connection9 = cell2.connect2target(post_syn3)
connection10 = cell2.connect2target(post_syn4)
connection11 = cell2.connect2target(post_syn5)
connection12 = cell2.connect2target(post_syn6)
connection13 = cell2.connect2target(post_syn7)
connection14 = cell2.connect2target(post_syn8)

connection15 = cell3.connect2target(post_syn1)
connection16 = cell3.connect2target(post_syn2)
connection17 = cell3.connect2target(post_syn4)
connection18 = cell3.connect2target(post_syn5)
connection19 = cell3.connect2target(post_syn6)
connection20 = cell3.connect2target(post_syn7)
connection21 = cell3.connect2target(post_syn8)

connection22 = cell4.connect2target(post_syn1)
connection23 = cell4.connect2target(post_syn2)
connection24 = cell4.connect2target(post_syn3)
connection25 = cell4.connect2target(post_syn5)
connection26 = cell4.connect2target(post_syn6)
connection27 = cell4.connect2target(post_syn7)
connection28 = cell4.connect2target(post_syn8)

connection29 = cell5.connect2target(post_syn1)
connection30 = cell5.connect2target(post_syn2)
connection31 = cell5.connect2target(post_syn3)
connection32 = cell5.connect2target(post_syn4)
connection33 = cell5.connect2target(post_syn6)
connection34 = cell5.connect2target(post_syn7)
connection35 = cell5.connect2target(post_syn8)

connection36 = cell6.connect2target(post_syn1)
connection37 = cell6.connect2target(post_syn2)
connection38 = cell6.connect2target(post_syn3)
connection39 = cell6.connect2target(post_syn4)
connection40 = cell6.connect2target(post_syn5)
connection41 = cell6.connect2target(post_syn7)
connection42 = cell6.connect2target(post_syn8)

connection43 = cell7.connect2target(post_syn1)
connection44 = cell7.connect2target(post_syn2)
connection45 = cell7.connect2target(post_syn3)
connection46 = cell7.connect2target(post_syn4)
connection47 = cell7.connect2target(post_syn5)
connection48 = cell7.connect2target(post_syn7)
connection49 = cell7.connect2target(post_syn8)

connection50 = cell8.connect2target(post_syn1)
connection51 = cell8.connect2target(post_syn2)
connection52 = cell8.connect2target(post_syn3)
connection53 = cell8.connect2target(post_syn4)
connection54 = cell8.connect2target(post_syn5)
connection55 = cell8.connect2target(post_syn6)
connection56 = cell8.connect2target(post_syn7)

connection1.weight[0] = 1
connection2.weight[0] = 1
connection3.weight[0] = 1
connection4.weight[0] = 1
connection5.weight[0] = 1
connection6.weight[0] = 1
connection7.weight[0] = 1
connection8.weight[0] = 1
connection9.weight[0] = 1
connection10.weight[0] = 1
connection11.weight[0] = 1
connection12.weight[0] = 1
connection13.weight[0] = 1
connection14.weight[0] = 1
connection15.weight[0] = 1
connection16.weight[0] = 1
connection17.weight[0] = 1
connection18.weight[0] = 1
connection19.weight[0] = 1
connection20.weight[0] = 1
connection21.weight[0] = 1
connection22.weight[0] = 1
connection23.weight[0] = 1
connection24.weight[0] = 1
connection25.weight[0] = 1
connection26.weight[0] = 1
connection27.weight[0] = 1
connection28.weight[0] = 1
connection29.weight[0] = 1
connection30.weight[0] = 1
connection31.weight[0] = 1
connection32.weight[0] = 1
connection33.weight[0] = 1
connection34.weight[0] = 1
connection35.weight[0] = 1
connection36.weight[0] = 1
connection37.weight[0] = 1
connection38.weight[0] = 1
connection39.weight[0] = 1
connection40.weight[0] = 1
connection41.weight[0] = 1
connection42.weight[0] = 1
connection43.weight[0] = 1
connection44.weight[0] = 1
connection45.weight[0] = 1
connection46.weight[0] = 1
connection47.weight[0] = 1
connection48.weight[0] = 1
connection49.weight[0] = 1
connection50.weight[0] = 1
connection51.weight[0] = 1
connection52.weight[0] = 1
connection53.weight[0] = 1
connection54.weight[0] = 1
connection55.weight[0] = 1
connection56.weight[0] = 1


connection1.active(1)
connection2.active(1)
connection3.active(1)
connection4.active(1)
connection5.active(1)
connection6.active(1)
connection7.active(1)

connection8.active(1)
connection9.active(1)
connection10.active(1)
connection11.active(1)
connection12.active(1)
connection13.active(1)
connection14.active(1)

connection15.active(1)
connection16.active(1)
connection17.active(1)
connection18.active(1)
connection19.active(1)
connection20.active(1)
connection21.active(1)

connection22.active(1)
connection23.active(1)
connection24.active(1)
connection25.active(1)
connection26.active(1)
connection27.active(1)
connection28.active(1)

connection29.active(1)
connection30.active(1)
connection31.active(1)
connection32.active(1)
connection33.active(1)
connection34.active(1)
connection35.active(1)

connection36.active(1)
connection37.active(1)
connection38.active(1)
connection39.active(1)
connection40.active(1)
connection41.active(1)
connection42.active(1)

connection43.active(1)
connection44.active(1)
connection45.active(1)
connection46.active(1)
connection47.active(1)
connection48.active(1)
connection49.active(1)

connection50.active(1)
connection51.active(1)
connection52.active(1)
connection53.active(1)
connection54.active(1)
connection55.active(1)
connection56.active(1)

ic = h.IClamp(0.5, sec=cell1.soma[0])
ic.delay = 2
ic.dur = 2
ic.amp = 1000

h.tstop = 100   
h.v_init = 0
h.dt = 0.025 
h.run(100)

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

vec1 = h.Vector()
vec1.record(cell1.dend[0](0.5)._ref_v)

v1 = []
t = []
for i in range(len(trec)):
    t.append(trec[i])
    v1.append(vrec1[i])

plt.figure('Connections in cell 1')
#plt.subplot(421)
plt.subplots_adjust(hspace =0.4)
plt.plot(t,v1,'b',linewidth=2)
plt.xlim((0,h.tstop))
plt.ylabel('Vm (mV)')
plt.title('cell1 voltage change')
plt.show()
How to fix this ?


NEURON can always* be programmed in Python. pyNEURON is a third-party repackaging that lets one install NEURON 7.2 via pip. Unfortunately, the people who set that up have yet to update it to NEURON 7.3.[/quote]

how can I use rxd package if it's not in pyNEURON - from NEURON 7.3 i can use in python? (if yes - how to do this)?

Re: SWC files

Posted: Tue Feb 17, 2015 11:42 am
by ramcdougal
Set up the recording before h.run()'ing the simulation and you should be good.

A few tips:
- You'd have much shorter and more readable code if you used lists (think arrays) because then you could use for loops to automate things.
- Actually, even as-is, you could still use a for loop to handle some things, it'd just need a long preamble:

Code: Select all

connections = [connection1, connection2, connection3, connection4, connection5, connection6, connection7, connection8, connection9, connection10, connection11, connection12, connection13, connection14, connection15, connection16, connection17, connection18, connection19, connection20, connection21, connection22, connection23, connection24, connection25, connection26, connection27, connection28, connection29, connection30, connection31, connection32, connection33, connection34, connection35, connection36, connection37, connection38, connection39, connection40, connection41, connection42, connection43, connection44, connection45, connection46, connection47, connection48, connection49, connection50, connection51, connection52, connection53, connection54, connection55, connection56]
for connection in connections:
    connection.weight[0] = 1
    connection.active(1)
- matplotlib.pyplot (plt) is perfectly happy using a NEURON vector; there's no need to convert it to a list. You can just:

Code: Select all

plt.plot(trec, vrec1, 'b', linewidth=2)
- If you did want to make a list for some other reason, you can do that in one line with:

Code: Select all

t = list(trec)
Installing the cygwin version should give you a nrngui with python icon that you can click to get to a python interpreter. NEURON supports Python. pyNeuron is a third party's attempt to make NEURON easier to install; it has nothing to do with whether-or-not NEURON supports Python.

Re: SWC files

Posted: Tue Feb 17, 2015 2:48 pm
by Kolorek
Installing the cygwin version should give you a nrngui with python icon that you can click to get to a python interpreter. NEURON supports Python. pyNeuron is a third party's attempt to make NEURON easier to install; it has nothing to do with whether-or-not NEURON supports Python.

I install Neuron 7.3, I click nrngui_python, I have menu from NEURON and interpreter for python but I have this information

Code: Select all

cygwin warning:
  MS-DOS style path detected: C:\Python27\neuronhome\iv
  Preferred POSIX equivalent is: /cygdrive/c/Python27/neuronhome/iv
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Can't load NEURON resources from C:\Python27\neuronhome/lib/nrn.def[aults]
NEURON -- VERSION 7.3 ansi (1078:2b0c984183df) 2014-04-04
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2014
See http://www.neuron.yale.edu/neuron/credits

first instance of j
first instance of itmp
first instance of using_cvode_
first instance of movie_frame_dur_
first instance of realtime
first instance of running_
first instance of rtstart
first instance of stdrun_quiet
first instance of screen_update_invl
first instance of tstop
first instance of steps_per_ms
first instance of nstep_steprun
first instance of runStopAt
first instance of runStopIn
first instance of global_ra
first instance of mapped_nrnmainmenu_
first instance of v_init
first instance of n_graph_lists
first instance of i
first instance of eventslow
first instance of eventcount
first instance of cnt
>>>
If I want to run program.py it says an error,

Code: Select all

>>> run hh.py
  File "stdin", line 1
    run hh.py
         ^
SyntaxError: invalid syntax

should I do something like you write few post later

Code: Select all

If you're using PyNEURON, you have to manually set a NEURONHOME environment variable in order for it to find the HOC libraries. The need for this extra step is unfortunate, but it's a simple process (see, for example, here.

The correct location for this is in principle system-dependent, but for a default Python 2.7 installation, it should be: C:\python27\neuronhome

With that environment variable set, if you launch a new terminal, run python, and enter the three lines from my last post, you should get a non-empty result (and all the rest should work).

(I tested this with Windows 7, 32-bit Python 2.7.9, PyNEURON, and nothing else installed.)
or there is another way ?

Thank you for Your help

Re: SWC files

Posted: Tue Feb 17, 2015 2:55 pm
by ramcdougal
To run a file in Python use execfile. For your example you would:

Code: Select all

execfile('hh.py')

Re: SWC files

Posted: Tue Feb 17, 2015 4:23 pm
by Kolorek
ramcdougal wrote:To run a file in Python use execfile. For your example you would:

Code: Select all

execfile('hh.py')
OK, but now its another problem :(

I have error that

Code: Select all

>>> execfile('hh.py')
Traceback (most recent call last):
  File "stdin", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'hh.py'
or that
"No module named neuron"

in properties of nrngui_python the target is C:\nrn73\bin\mintty.exe -c /cygdrive/c/nrn73/lib/minttyrc /cygdrive/c/nrn73/bin/bash --rcfile /cygdrive/c/nrn73/lib/nrnstart.bsh -i -c 'nrniv -python /cygdrive/c/nrn73/lib/hoc/nrngui.hoc'

Should i change the target ?
I try to put hh.py and 51-2b.CNG.swc in one folder with nrngui_python but this didn't work to :(

Could you help me fix this ?

Re: SWC files

Posted: Tue Feb 17, 2015 6:29 pm
by ramcdougal
I'm command-line centric, but this is how I would do it:
  • Open the NEURON 7.3 folder on your desktop (assuming you kept the default install options)
  • Double click "mintty bash"; this gives you a terminal starting from your C:\ drive (which it calls /cygdrive/c/... ignore that)
  • Change to the place that has your files; if they're on a folder called mymodel on your desktop and your user name is kolorek, then that's: (yes, forward slash not backward slash here)

    Code: Select all

    cd Users/kolorek/Desktop/mymodel
  • Compile the MOD files, if any:

    Code: Select all

    nrnivmodl
  • Run hh.py:

    Code: Select all

    nrniv -python hh.py

Re: SWC files

Posted: Wed Feb 18, 2015 1:59 pm
by Kolorek
I do what you write and I have this message

Code: Select all

bash-4.1$ cd C:/Users/Właściciel/Desktop/komórki
bash-4.1$ nrnivmodl
ls: cannot access *.[mM][oO][dD]: No such file or directory
gcc -DDLL_EXPORT -DPIC -I/cygdrive/c/nrn73/src/scopmath -I/cygdrive/c/nrn73/src/                                                  nrnoc -I/cygdrive/c/nrn73/src/oc -I/cygdrive/c/nrn73/lib -I/cygdrive/c/nrn73/gcc                                                  inc -I/cygdrive/c/nrn73/gcc3inc -L/cygdrive/c/nrn73/gcclib -c mod_func.c
gcc -I/cygdrive/c/nrn73/lib -I/cygdrive/c/nrn73/gccinc -I/cygdrive/c/nrn73/gcc3i                                                  nc -L/cygdrive/c/nrn73/gcclib -shared -o nrnmech.dll mod_func.o  \
  -L/cygdrive/c/nrn73/bin -lnrniv -lpthread
rebase -b 0x64000000 -v nrnmech.dll
/cygdrive/c/Users/Właściciel/Desktop/komórki/nrnmech.dll: new base = 64000000, n                                                  ew size = 20000
bash-4.1$ nrniv -python hh.py
cygwin warning:
  MS-DOS style path detected: C:\Python27\neuronhome\iv
  Preferred POSIX equivalent is: /cygdrive/c/Python27/neuronhome/iv
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Can't load NEURON resources from C:\Python27\neuronhome/lib/nrn.def[aults]
NEURON -- VERSION 7.3 ansi (1078:2b0c984183df) 2014-04-04
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2014
See http://www.neuron.yale.edu/neuron/credits

loading membrane mechanisms from nrnmech.dll
Additional mechanisms from files

  File "hh.py", line 1
SyntaxError: encoding problem: with BOM
>>> execfile('hh.py')
Traceback (most recent call last):
  File "stdin", line 1, in <module>
  File "hh.py", line 1, in <module>
    import btmorph
ImportError: No module named btmorph
>>> execfile('hh.py')
Traceback (most recent call last):
  File "stdin", line 1, in <module>
  File "hh.py", line 3, in <module>
    import neuron
ImportError: No module named neuron
>>>
I don't know what to do :(

Re: SWC files

Posted: Wed Feb 18, 2015 5:08 pm
by ted
See if this helps:
mod files: what they are, and how to use them
viewtopic.php?f=28&t=3263
Also go to http://www.neuron.yale.edu/neuron/docs and look at the Guides and Tutorials, especially Help for the total beginner and Suggestions for how to develop models

Re: SWC files

Posted: Thu Feb 19, 2015 3:28 pm
by Kolorek
Ted thank you for the links :)
I read them but I didn't find solution for my problem :(
Maybe you know how to fix this ?
ted wrote:See if this helps:
mod files: what they are, and how to use them
viewtopic.php?f=28&t=3263
Also go to http://www.neuron.yale.edu/neuron/docs and look at the Guides and Tutorials, especially Help for the total beginner and Suggestions for how to develop models

Re: SWC files

Posted: Thu Feb 19, 2015 5:46 pm
by ramcdougal
Now that I know you're trying to use other Python packages (e.g. btmorph), let me revise my earlier advice.

The mingw version (and not the cygwin version) on the download page is the best for working with other packages. The reason I didn't recommend it earlier is because the GUI doesn't work in that version, but if you don't usually use that, then maybe that's not a big deal, and it's basically the same situation you were in with pyNEURON, just more up to date.

Re: SWC files

Posted: Thu Feb 19, 2015 7:08 pm
by ted
Maybe you'll be better off with the latest alpha version implemented with mingw
http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe

Re: SWC files

Posted: Fri Feb 20, 2015 10:29 am
by Kolorek
I download what you wite but still there is a problem:

Code: Select all

Traceback (most recent call last):
  File "C:\Users\Właściciel\Desktop\cell\hh.py", line 4, in <module>
    from neuron import h, rxd
ImportError: cannot import name rxd
Maybe I am so stupid that I can't run this program, could someone explain in points what to do ?
Thanks and sorry

Re: SWC files

Posted: Fri Feb 20, 2015 10:46 am
by ramcdougal
Can you copy and paste the NEURON banner that displays when you do the import?

For example, on my computer, from inside Python:

Code: Select all

>>> import neuron
NEURON -- VERSION 7.4 (1332:477da879a623) 2015-02-11
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits