PyNEURON and .mod files

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

Moderator: hines

Post Reply
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

PyNEURON and .mod files

Post by lb5999 »

Hi all,

I have just started using PyNEURON and am having trouble using custom made .mod files.

The code I am running is simple, and inserts a mechanism called nad.mod

Code: Select all

Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.

PS C:\Users\lbriant> python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on wi
Type "help", "copyright", "credits" or "license" for more information.
>>> from neuron import h
Found NEURON at C:\Python27\neuronhome
NEURON -- VERSION 7.2 (527+:a38b8d137de6+) 2011-07-26
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008
See http://www.neuron.yale.edu/credits.html

>>> h.chdir("C:/Python27/neuronhome/lib/hoc")
0.0
>>> h.load_file('stdrun.hoc')
1.0
>>> soma = h.Section(name='soma')
>>> dend = h.Section(name='dend')
>>> h.psection(sec=soma)
soma { nseg=1  L=100  Ra=35.4
        /*location 0 attached to cell 0*/
        /* First segment only */
        insert morphology { diam=500}
        insert capacitance { cm=1}
}
1.0
>>> dend.connect(soma(1))
<nrn.Section object at 0x01F551B8>
>>> h.psection(sec=dend)
dend { nseg=1  L=100  Ra=35.4
        soma connect dend (0), 1
        /* First segment only */
        insert morphology { diam=500}
        insert capacitance { cm=1}
}
1.0
>>>
>>> soma.L = soma.diam = 12.6157 # Makes a soma of 500 microns squared.
>>> dend.L = 200 # microns
>>> dend.diam = 1 # microns
>>>
>>> shape_window = h.PlotShape()
>>>
>>> for sec in h.allsec():
...     sec.Ra = 100    # Axial resistance in Ohm * cm
...     sec.cm = 1      # Membrane capacitance in micro Farads / cm^2
...
>>> # Insert active Hodgkin-Huxley current in the soma
... soma.insert('hh')
<nrn.Section object at 0x01F55230>
>>> soma.gnabar_hh = 0.12  # Sodium conductance in S/cm2
>>> soma.gkbar_hh = 0.036  # Potassium conductance in S/cm2
>>> soma.gl_hh = 0.0003    # Leak conductance in S/cm2
>>> soma.el_hh = -54.3     # Reversal potential in mV
>>> h.chdir("C:/example_cell/mod")
0.0
>>> soma.insert('nad')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: argument not a density mechanism name.
I assumed I had to compile the .mod files using mknrndll. So I installed NEURON and compiled then (I learnt a lesson: not to click "Set DOS Environment" during the installation of NEURON as this seems to make the python version installed with NEURON the new interpreter.)

So then I change the directory to where the compiled nrnmech.dll file is, but when I type the following to load the nrnmech file I get the following error message:

Code: Select all

>>> h.nrn_load_dll("nrnmech.dll")
loading membrane mechanisms from nrnmech.dll
LoadLibrary("nrnmech.dll") failed with error 193
dlopen failed -

0.0
Does anyone know what I am missing? Any help with this would be really appreciated.

I am using Python 2.7.13 and Windows PowerShell on a Windows 8.1 Enterprise.

Thanks!
Linford
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: PyNEURON and .mod files

Post by ramcdougal »

Personally I never use nrn_load_dll.

What I do:

Compile the files with mknrndll/nrnivmodl, and import neuron from the directory that contains the x86_64 (or whatever) folder. During the initial import, NEURON will load the previously compiled MOD files.
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: PyNEURON and .mod files

Post by lb5999 »

Hi ramcdougal, thanks for your reply.

I have followed your advise (I think).

I have attempted to import the version of neuron.exe that I used to compile the .mod files:

Code: Select all

import os
os.chdir("C:/nrn/bin")
from neuron import h
However it says:

Code: Select all

Found NEURON at C:\Python27\neuronhome
so it looks like it is not recognizing the version of neuron/folders that I used to compile the .mod files.

Moreover, the x_86_64-w64-mingw32 directory is actually located in:

Code: Select all

C:\nrn\mingw
(At least this is I think where mknrndll dumps this x_86_64 folder - is there a way to check?) As far as I can see, this mingw folder does not have neuron.exe in it.

Any thoughts on how to proceed would be really appreciated.

lb5999
lb5999
Posts: 56
Joined: Mon Oct 11, 2010 9:12 am

Re: PyNEURON and .mod files

Post by lb5999 »

I also tried to change directory to the location of my nrnmech.dll file before I import neuron, but I got the following erro:

Code: Select all

import os
os.chdir("H:/models/jo/mod")
from neuron import h
Found NEURON at C:\Python27\neuronhome
NEURON -- VERSION 7.2 (527+:a38b8d137de6+) 2011-07-26
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008

loading membrane mechanisms from nrnmech.dll
LoadLibrary("nrnmech.dll") failed with error 193
dlopen failed -
I have had a google and it looks like this error is associated with importing a 32bit dll into a 64 application.

Any ideas on what to do would be appreciated!
Post Reply