Beginner needs help: Questions arise from tutorials

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

Moderator: hines

Post Reply
magnolls
Posts: 2
Joined: Wed Dec 28, 2016 3:38 am

Beginner needs help: Questions arise from tutorials

Post by magnolls » Thu Dec 29, 2016 10:42 pm

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.

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Beginner needs help: Questions arise from tutorials

Post by ted » Sat Dec 31, 2016 11:25 pm

What operating system are you using, and what is its version number?
When you start nrngui, what message does NEURON print on the screen?

ramcdougal
Posts: 154
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

Re: Beginner needs help: Questions arise from tutorials

Post by ramcdougal » Tue Jan 03, 2017 10:25 am

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?)

ramcdougal
Posts: 154
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

Re: Beginner needs help: Questions arise from tutorials

Post by ramcdougal » Tue Jan 03, 2017 10:37 am

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.

magnolls
Posts: 2
Joined: Wed Dec 28, 2016 3:38 am

Re: Beginner needs help: Questions arise from tutorials

Post by magnolls » Wed Jan 04, 2017 9:49 pm

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

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

Re: Beginner needs help: Questions arise from tutorials

Post by hines » Sat Jan 07, 2017 5:57 pm

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.

Post Reply