As NEURON user, I am very beginner. Thus, I have been facing several problems to deal with the use.
In my work, I need to simulate the membrane dynamics considering in a sample of 91 *.asc morphologies. Therefore, I have to import such *.asc morphologies to NEURON and set the "experiment" on each of them. However, I have not been able to import such *.asc morphologies. If I use the NEURON GUI, I have no problems to import the *.asc morphologies. In addition, I have been checking the morphologies using this NEURON GUI and there is nothing wrong with them.
I adapted my code from ModelDBhttps://senselab.med.yale.edu/ModelDB/s ... .py#tabs-2 (I tried to make an adaptation, since this example from ModelDB refers to *.swc morphology). My code is ('0409_H50_01.asc' is the morphology and it is in the same folder of the code):
Code: Select all
from neuron import h,gui
from matplotlib import pyplot as plt
import numpy as np
from numpy import random as rand
import datetime as dame
import sys
import os.path
arquivo = '0409_H50_01.asc'
################~Importing morphology~########################################
#The load_swc function at the following link inserts an SWC morphology
#into a Python class. Just change Import3d_SWC_read to Import3d_Neurolucida3
#to work with ASC files instead.
def load(arquivo, cell, use_axon=True, xshift=0, yshift=0, zshift=0):
"""load an SWC from filename and instantiate inside cell"""
name_form = {1: 'soma[%d]', 2: 'axon[%d]', 3: 'dend[%d]', 4: 'apic[%d]'}
# a helper library, included with NEURON
h.load_file('stdlib.hoc')
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.
morph = h.Import3d_Neurolucida3()
morph.input(arquivo)
# 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(morph, 0)
# get a list of the swc section objects
asc_secs = i3d.asc.sections
asc_secs = [asc_secs.object(i) for i in xrange(int(asc_secs.count()))]
# initialize the lists of sections
cell.soma, cell.apic, cell.dend, cell.axon = [], [], [], []
sec_list = {1: cell.soma, 2: cell.axon, 3: cell.dend, 4: cell.apic}
# name and create the sections
real_secs = {}
for asc_sec in asc_secs:
cell_part = int(asc_sec.type)
# skip everything else if it's an axon and we're not supposed to
# use it... or if is_subsidiary
if (not(use_axon) and cell_part == 2) or asc_sec.is_subsidiary:
continue
# figure out the name of the new section
if cell_part not in name_form:
raise Exception('unsupported point type')
name = name_form[cell_part] % len(sec_list[cell_part])
# create the section
sec = h.Section(cell=cell, name=name)
# connect to parent, if any
if asc_sec.parentsec is not None:
sec.connect(real_secs[asc_sec.parentsec.hname()](asc_sec.parentx))
# define shape
if asc_sec.first == 1:
h.pt3dstyle(1, asc_sec.raw.getval(0, 0), asc_sec.raw.getval(1, 0),
asc_sec.raw.getval(2, 0), sec=sec)
j = asc_sec.first
xx, yy, zz = [asc_sec.raw.getrow(i).c(j) for i in xrange(3)]
dd = asc_sec.d.c(j)
if asc_sec.iscontour_:
# never happens in SWC files, but can happen in other formats supported
# by NEURON's Import3D GUI
raise Exception('Unsupported section style: contour')
if dd.size() == 1:
# single point soma; treat as sphere
x, y, z, d = [dim.x[0] for dim in [xx, yy, zz, dd]]
for xprime in [x - d / 2., x, x + d / 2.]:
h.pt3dadd(xprime + xshift, y + yshift, z + zshift, d, sec=sec)
else:
for x, y, z, d in zip(xx, yy, zz, dd):
h.pt3dadd(x + xshift, y + yshift, z + zshift, d, sec=sec)
# store the section in the appropriate list in the cell and lookup table
sec_list[cell_part].append(sec)
real_secs[asc_sec.hname()] = sec
cell.all = cell.soma + cell.apic + cell.dend + cell.axon
def main(filename=arquivo):
"""demo test program"""
class Cell:
def __str__(self):
return 'neuron'
cell = Cell()
load(arquivo, cell)
return cell
if __name__ == '__main__':
cell = main()
###############~Visualize imported neuron~####################################
shape_window = h.PlotShape()
shape_window.exec_menu('Show Diam')
input("Press <enter> to continue")
Code: Select all
NEURON -- VERSION 7.5 master (6b4c19f) 2017-09-25
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits
NEURON: unable to open font "*helvetica-medium-r-normal*--14*", using "fixed"
could not open 0409_H50_01.asc
NEURON: 0409_H50_01.asc :file is not open
near line 0
^
File[0].eof()
Import3d_Neurolucida3[0].rdfile("0409_H50_01.asc")
Import3d_Neurolucida3[0].input("0409_H50_01.asc")
oc_restore_code tobj_count=1 should be 0
Traceback (most recent call last):
File "load_teste_from_github.py", line 110, in <module>
cell = main()
File "load_teste_from_github.py", line 106, in main
load(arquivo, cell)
File "load_teste_from_github.py", line 34, in load
morph.input(arquivo)
RuntimeError: hoc error
In advance, thank you very much for attention.
Regards,
Helio