CINPLA / NeuroCNN

GNU General Public License v3.0
7 stars 4 forks source link

NameError: name 'file' is not defined in hbp_cells.py #2

Open cristi-zz opened 5 years ago

cristi-zz commented 5 years ago

Hi!
I cloned the library, created neurocnn env, (using conda and environment3.yml, and I got python 3.6.6),
installed NEURON with some trouble (neuron.__version__ is 7.6.2-3-g9f36b13) installed and compiled LFPy ran python hbp_cells.py compile and it ended with Successfully created x86_64/special and then, tried to run do_all_cell_simulations: python do_all_cell_simulations.py -probe Neuronexus-32-Kampff -n 10

I got the following errors: (13 times):

LFPy imported
neuron imported
Simulating  L5_TTPC1_cADpyr232_1
Traceback (most recent call last):
  File "hbp_cells.py", line 777, in <module>
    cell = run_cell_model(cell_folder, model, vm_im_sim_folder, int(numb))
  File "hbp_cells.py", line 281, in run_cell_model
    cell = return_cell(cell_model, model_type, cell_name, T, dt, 0)
  File "hbp_cells.py", line 123, in return_cell
    f = file("template.hoc", 'r')
NameError: name 'file' is not defined

The offending code:

def get_templatename(f):
    .........
    templatename = None
    f = file("template.hoc", 'r')
    for line in f.readlines():
    .........

(1) Is file() something that had to be imported from somewhere?

I replaced it with open() [added file=open at the beginning of the hbp_cells.py] assuming that the intention was to read the text contents of the .hoc files.

Then, I got the following error:

LFPy imported
neuron imported
Simulating  L5_TTPC1_cADpyr232_1
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
Loading constants
Setting temperature to 34.000000 C
Setting simulation time step to 0.025000 ms
...done.
loading morpho...
done.
Loading template...
    1 
    1 
    1 
done.
Initialize cell...
template cADpyr232_L5_TTPC1_0fb1ca4724 exist already
bad stack access: expecting (double); really (Object *)
NEURON: interpreter stack type error
 near line 0
 {forall all.append}
                    ^
        Import3d_GUI[0].instantiate(cADpyr232_L5_TTPC1_0fb1ca4724[0])
      morphology_0fb1ca4724[0].morphology(cADpyr232_L5_TTPC1_0fb1ca4724[0])
    cADpyr232_L5_TTPC1_0fb1ca4724[0].load_morphology()
  cADpyr232_L5_TTPC1_0fb1ca4724[0].init(0)
oc_restore_code tobj_count=2 should be 1
Traceback (most recent call last):
  File "/home/cristi/miniconda3/envs/neurocnn/lib/python3.6/site-packages/neuron/__init__.py", line 494, in _declare_contour
    center_vec = secobj.contourcenter(secobj.raw.getrow(0), secobj.raw.getrow(1), secobj.raw.getrow(2))
RuntimeError: hoc error
NEURON: PyObject method call failed: _declare_contour
 near line 0
 ^
        Import3d_GUI[0].instantiate(cADpyr232_L5_TTPC1_0fb1ca4724[0])
      morphology_0fb1ca4724[0].morphology(cADpyr232_L5_TTPC1_0fb1ca4724[0])
    cADpyr232_L5_TTPC1_0fb1ca4724[0].load_morphology()
  cADpyr232_L5_TTPC1_0fb1ca4724[0].init(0)
oc_restore_code tobj_count=2 should be 0
Traceback (most recent call last):
  File "hbp_cells.py", line 778, in <module>
    cell = run_cell_model(cell_folder, model, vm_im_sim_folder, int(numb))
  File "hbp_cells.py", line 282, in run_cell_model
    cell = return_cell(cell_model, model_type, cell_name, T, dt, 0)
  File "hbp_cells.py", line 176, in return_cell
    verbose=True)
  File "/home/cristi/miniconda3/envs/neurocnn/lib/python3.6/site-packages/LFPy-2.0.0-py3.6-linux-x86_64.egg/LFPy/templatecell.py", line 150, in __init__
    Cell.__init__(self, **kwargs)
  File "/home/cristi/miniconda3/envs/neurocnn/lib/python3.6/site-packages/LFPy-2.0.0-py3.6-linux-x86_64.egg/LFPy/cell.py", line 201, in __init__
    self._load_geometry()
  File "/home/cristi/miniconda3/envs/neurocnn/lib/python3.6/site-packages/LFPy-2.0.0-py3.6-linux-x86_64.egg/LFPy/templatecell.py", line 160, in _load_geometry
    self.template = getattr(neuron.h, self.templatename)(self.templateargs)
RuntimeError: hoc error
torbjone commented 5 years ago

Hi, this probably comes down to the NEURON version. For some reason, unknown to me, the cells from the HBP database does not appear to be working for us with version 7.6, while working just fine on 7.5, see similar problem in: https://github.com/alejoe91/MEArec/issues/6

Sadly, I do not at the moment know why this problem occurs, or how to deal with it, except switching to NEURON 7.5

cristi-zz commented 5 years ago

UPDATE Ok, I installed neuron 7.5 from conda-forge. I re-installed LFPy, removed and re-compiled the .mod files, and now I got some activity. (eg. processor is working). Unfortunately there still is an error:

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

LFPy imported
neuron imported
Simulating  L5_BP_bAC217_1
loading membrane mechanisms from ../mods/x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 CaDynamics_E2.mod Ca_HVA.mod Ca_LVAst.mod Ca.mod Ih.mod Im.mod K_Pst.mod K_Tst.mod Nap_Et2.mod NaTa_t.mod NaTs2_t.mod ProbAMPANMDA_EMS.mod ProbGABAAB_EMS.mod SK_E2.mod SKv3_1.mod
template bAC217_L5_BP_d0cc8d7615 found!
template bAC217_L5_BP_d0cc8d7615 found!
template bAC217_L5_BP_d0cc8d7615 found!
template bAC217_L5_BP_d0cc8d7615 found!
Loading constants
Setting temperature to 34.000000 C
Setting simulation time step to 0.025000 ms
...done.
loading morpho...
done.
Loading template...
    1 
    1 
    1 
done.
Initialize cell...
template bAC217_L5_BP_d0cc8d7615 exist already
...done.
Input weight:  0.23  - Num Spikes:  21
ROTATION type:  physrot
Simulating  L5_BP_bAC217_1
Mechanisms already loaded from path: ../mods.  Aborting.
template bAC217_L5_BP_d0cc8d7615 found!
template bAC217_L5_BP_d0cc8d7615 found!
template bAC217_L5_BP_d0cc8d7615 found!
template bAC217_L5_BP_d0cc8d7615 found!
Loading constants
...done.
Initialize cell...
template bAC217_L5_BP_d0cc8d7615 exist already
...done.
Cell  L5_BP_bAC217_1  extracellular spikes to be simulated
Traceback (most recent call last):
  File "hbp_cells.py", line 782, in <module>
    calc_extracellular(cell_folder, model, extra_sim_folder, vm_im_sim_folder, rotation, int(numb), probe, nobs)
  File "hbp_cells.py", line 441, in calc_extracellular
    for i in xrange(N.shape[0]):
NameError: name 'xrange' is not defined

Hm, I will let the script finish, and then focus on this xrange. I guess it is another leftover from python 2.7

torbjone commented 5 years ago

OK, I would appreciate it very much if you let us know if this solves the problem.

cristi-zz commented 5 years ago

Hi! The script ran without errors, afaik. Of course, I replaced the xrange with range.

There is still an warning, I don't know if it is relevant or not: UserWarning: Membrane currents do not sum to zero

This is the output of 13th cell type or so:

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

LFPy imported
neuron imported
Simulating  L5_TTPC1_cADpyr232_1
loading membrane mechanisms from ../mods/x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 CaDynamics_E2.mod Ca_HVA.mod Ca_LVAst.mod Ca.mod Ih.mod Im.mod K_Pst.mod K_Tst.mod Nap_Et2.mod NaTa_t.mod NaTs2_t.mod ProbAMPANMDA_EMS.mod ProbGABAAB_EMS.mod SK_E2.mod SKv3_1.mod
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
Loading constants
Setting temperature to 34.000000 C
Setting simulation time step to 0.025000 ms
...done.
loading morpho...
done.
Loading template...
    1 
    1 
    1 
done.
Initialize cell...
template cADpyr232_L5_TTPC1_0fb1ca4724 exist already
...done.
Input weight:  0.23  - Num Spikes:  3
Input weight:  0.28750000000000003  - Num Spikes:  6
Input weight:  0.35937500000000006  - Num Spikes:  7
Input weight:  0.44921875000000006  - Num Spikes:  9
Input weight:  0.5615234375000001  - Num Spikes:  10
Input weight:  0.7019042968750001  - Num Spikes:  12
ROTATION type:  physrot
Simulating  L5_TTPC1_cADpyr232_1
Mechanisms already loaded from path: ../mods.  Aborting.
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
template cADpyr232_L5_TTPC1_0fb1ca4724 found!
Loading constants
...done.
Initialize cell...
template cADpyr232_L5_TTPC1_0fb1ca4724 exist already
...done.
Cell  L5_TTPC1_cADpyr232_1  extracellular spikes to be simulated
/home/cristi/miniconda3/envs/neurocnn/lib/python3.6/site-packages/LFPy-2.0.0-py3.6-linux-x86_64.egg/LFPy/recextelectrode.py:317: UserWarning: Membrane currents do not sum to zero
  warnings.warn('Membrane currents do not sum to zero')
Cell: L5_TTPC1_cADpyr232_1 Progress: [1/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [2/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [3/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [4/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [5/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [6/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [7/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [8/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [9/10]
Cell: L5_TTPC1_cADpyr232_1 Progress: [10/10]
cristi-zz commented 5 years ago

@torbjone thank you for looking into this! If the above output looks ok, imho, you can close this issue (unil NEURON 7.7 will be deployed to conda-forge and a new pull request is made here, fixing the python 2 leftovers.)

Thank you again!

alejoe91 commented 5 years ago

Hi @cristi-zz! The output looks good. Thanks @torbjone for sorting this out

nrnhines commented 5 years ago

It is possible that this problem may be related to https://github.com/neuronsimulator/nrn/issues/130 which is fixed by changeset https://github.com/neuronsimulator/nrn/commit/f837b5cf79708723b32da2a2d0cd5efffbca137c