Error on loading the SWC file using neuron

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

Moderator: hines

Post Reply
dilawar
Posts: 13
Joined: Mon May 26, 2014 9:12 am
Location: NCBS Bangalore

Error on loading the SWC file using neuron

Post by dilawar » Sat Apr 25, 2015 2:14 pm

I am using the following script to load a SWC file. I am using Neuron-7.4 build from source code.

Code: Select all

from neuron import h
import sys

def instantiate_swc(filename):
    """load an swc file and instantiate it"""
    
    # load the NEURON library (just in case h is defined otherwise elsewhere)
    
    # a helper library, included with NEURON
    h.load_file('import3d.hoc')
    
    # load the data. Use Import3d_SWC_read for swc, Import3d_Neurolucida3 for
    # Neurolucida V3, Import3d_MorphML for MorphML (level 1 of NeuroML), or
    # Import3d_Eutectic_read for Eutectic. (There is also an 
    # Import3d_Neurolucida_read for old Neurolucida files, but I've never seen one
    # in practice; try Import3d_Neurolucida3 first.)
    cell = h.Import3d_SWC_read()
    cell.input(filename)

    # easiest to instantiate by passing the loaded morphology to the Import3d_GUI
    # tool; with a second argument of 0, it won't display the GUI, but it will allow
    # use of the GUI's features
    i3d = h.Import3d_GUI(cell, 0)
    i3d.instantiate(None)

def main(filename):
    instantiate_swc(filename)

if __name__ == '__main__':
    filename = sys.argv[1]
    main(filename)
I am getting following error:

Code: Select all

NEURON -- VERSION 7.4 (1316:353c7c3ecd8d) 2015-04-03
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

NEURON: hoc_sf_ not declared at the top level
 in import3d/read_swc.hoc near line 10
 external hoc_sf_
                ^
        xopen("import3d/r...")
      xopen("import3d.hoc")
    execute1("{xopen("im...")
  load_file("import3d.hoc")

Command terminated
Some thread suggest to load `mosinit.hoc` file but I can't find such file in this distribution.

dilawar
Posts: 13
Joined: Mon May 26, 2014 9:12 am
Location: NCBS Bangalore

Re: Error on loading the SWC file using neuron

Post by dilawar » Sun Apr 26, 2015 2:00 am

Importing `gui` along with `h` seems to fix the problem.

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

Re: Error on loading the SWC file using neuron

Post by ted » Sun Apr 26, 2015 5:25 pm

Both the error message

Code: Select all

NEURON: hoc_sf_ not declared at the top level
in import3d/read_swc.hoc near line 10
external hoc_sf_
                ^
and the fix
dilawar wrote:Importing `gui` along with `h` seems to fix the problem.
make sense, in retrospect at least. hoc_sf_ is defined in share/nrn/lib/hoc/stdlib.hoc, and stdlib.hoc is one of the files that NEURON loads automatically if you start by
nrngui -python

However, if you start by
nrniv -python
or if you start python and then
from neuron import h
NEURON won't load those files, so if you try to execute code that depends on them you'll have to first either
from neuron import gui
or you'll have to do something else that makes NEURON read them, like executing an h.load_file or h.xopen statement that reads one of the following files:
nrngui.hoc
noload.hoc
stdgui.hoc

My preference, if I need to use NEURON's gui, is to just
nrngui -python
but you might prefer to start python, then
from neuron import h, gui

Post Reply