Page 1 of 1

Beginner needs help: Questions arise from tutorials

Posted: Thu Dec 29, 2016 10:42 pm
by magnolls
I just started to learn NEURON + Python for my undergrad project and 2 problems occur when I try to run the codes from the tutorials.
http://neuron.yale.edu/neuron/static/do ... tick1.html

1. I often go into this libnrnoc error: "Python quit unexpectedly while using the libnrnoc.0.dylib plug-in."
when I run

Code: Select all

dend.connect(soma(1))
in:

Code: Select all

import sys
sys.path.append('/Applications/NEURON-7.3/nrn/lib/python')
from neuron import h, gui
soma = h.Section(name = 'soma')
dend = h.Section(name = 'dend')
dend.connect(soma(1))
It also occurs in codes like

Code: Select all

asyn = h.AlphaSynapse(soma(0.5))
and

Code: Select all

stim = h.IClamp(dend(1))
How should I fix it?

2. In the third tutorial, the following codes rotate the cells but I don't know how it is achieved mathematically.

Code: Select all

def rotateZ(self, theta):
        """Rotate the cell about the Z axis."""   
        for sec in self.all:
            for i in range(2):
                x = h.x3d(i) * sin(theta) + h.y3d(i) * cos(theta)
                y = h.x3d(i) * cos(theta) + h.y3d(i) * -sin(theta)
                h.pt3dchange(i, x, y, h.z3d(i), h.diam3d(i))
Any help is greatly appreciated. And happy New Year guys.

Re: Beginner needs help: Questions arise from tutorials

Posted: Sat Dec 31, 2016 11:25 pm
by ted
What operating system are you using, and what is its version number?
When you start nrngui, what message does NEURON print on the screen?

Re: Beginner needs help: Questions arise from tutorials

Posted: Tue Jan 03, 2017 10:25 am
by ramcdougal
From the path adjustment:

Code: Select all

sys.path.append('/Applications/NEURON-7.3/nrn/lib/python')
I gather you're running NEURON 7.3 on a Mac. Unless you have a strong reason for using 7.3 try updating to 7.4 (the current release version), and tell us if the problem persists.

If so: what version of Python are you using? (i.e. the one that came with the mac? Anaconda? Something else?)

Re: Beginner needs help: Questions arise from tutorials

Posted: Tue Jan 03, 2017 10:37 am
by ramcdougal
That code is supposed to multiply each point by a standard rotation matrix, see Wikipedia. You can find rotation matrices in any intro text on linear algebra.

That said, the code you found isn't ideal. It's not optimal because: (1) a rotation of 0 swaps the x and y axes, (2) if self.all is a list (not the case there but could be in another implementation), then iterating over it doesn't set the cas, and (3) it assumes a specific number of 3D points (again okay for the example, but not in general).

A better code is:

Code: Select all

def rotateZ(self, theta):
    """Rotate the cell about the Z axis."""   
    for sec in self.all:
        for i in range(int(h.n3d(sec=sec))):
            x = h.x3d(i, sec=sec)
            y = h.y3d(i, sec=sec)
            c = cos(theta)
            s = sin(theta)
            xprime = x * c - y * s
            yprime = x * s + y * c
            h.pt3dchange(i, xprime, yprime, h.z3d(i, sec=sec), h.diam3d(i, sec=sec), sec=sec)
I have now updated the tutorial with this code.

Re: Beginner needs help: Questions arise from tutorials

Posted: Wed Jan 04, 2017 9:49 pm
by magnolls
ted wrote:What operating system are you using, and what is its version number?
When you start nrngui, what message does NEURON print on the screen?
Also to ramcdougal:
So I changed to 7.4 version. I am using OS X 10.11.6 with python newest 2.7 on PyCharm CE. And the message was:
NEURON -- VERSION 7.4 (1380:90539e842093) 90539e842093
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015

After the changing,

Code: Select all

dend.connect(soma(1))
won't produce any error but

Code: Select all

stim = h.IClamp(dend(1))
still produces the same error.
Also I found that it happens again when I try to run

Code: Select all

h.psection(soma)
.

Thank you

Re: Beginner needs help: Questions arise from tutorials

Posted: Sat Jan 07, 2017 5:57 pm
by hines
Please drag your present installation of /Applications/NEURON... to the trash and download and install
http://www.neuron.yale.edu/ftp/neuron/v ... 64-osx.pkg
The substantive change that I believe fixes the problem is indicated in the log message of
https://github.com/nrnhines/nrn/commit/ ... 9d8fcc7459

I was able to reproduce your problem on Sierra (10.12) but not El Capitan (10.11) so please indicate if
this fixes the problem on your machine.