Insert an ion channel written in a .mod file

NMODL and the Channel Builder.
Post Reply
cassiehu
Posts: 35
Joined: Tue Sep 06, 2022 10:41 am

Insert an ion channel written in a .mod file

Post by cassiehu »

I met a problem when I added an ion channel to the soma by self.soma.insert('SHL1_pas'). However, when I ran the code, it came up with the error which said "argument not a density mechanism name". I have already used NEURON to compile the .mod file again and again, but there was still the error. And I tried to insert 'hh', Python can run the code successfully. I want to know how to solve this problem. Is it some bugs of .mod file or something? The following URL are for pictures.
https://pic.imgdb.cn/item/631e9a4916f2c2beb1f0d15d.png
https://pic.imgdb.cn/item/631e9a9b16f2c2beb1f11f4f.png
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Insert an ion channel written in a .mod file

Post by ted »

Time to read some documentation. Go to
https://nrn.readthedocs.io/en/latest/gu ... ith-neuron
and find the part about NMODL. Read the referenced articles (you'll find links to them at https://nrn.readthedocs.io/en/latest/publications.html, but the most complete reference on NMODL is available from https://neuron.yale.edu/neuron/static/p ... /nmodl.htm)
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Insert an ion channel written in a .mod file

Post by ted »

Hints:

First make sure that SHL1_pas is supposed to be the name of a density mechanism. How can you find out? An NMODL file's NEURON block will contain a statement that declares the name of the mechanism. For a density mechanism, the statement is of the form
SUFFIX foo
and for a point process the statement is of the form
POINT_PROCESS Bah
where foo and Bah are the name of the mechanism.
An aside: a commonly used naming convention in NMODL (but not in hoc or Python) is to use lower case for density mechanism names, but to capitalize point process names. Why? Because the NMODL code for a point process actually adds a new class to NEURON (and class names are capitalized in some programming languages). However, the NMODL code for a density mechanism doesn't; instead, the NMODL code for a density mechanism adds a new potential section attribute.

If SHL1_pas is actually the name of a density mechanism, verify that NEURON actually loads that mechanism when it starts. In the same directory as your main hoc or python file, launch NEURON by executing nrngui. The first few lines that NEURON prints to the terminal will include a list of the names of the mod files whose compiled mechanisms have been loaded. If that list doesn't include the name of the mod file that defines the SHL1_pas mechanism, then you're probably starting NEURON in a directory that doesn't contain the compiled mechanisms.

Under MSWin the mechanisms will be in a file called something like nrnmech.dll. Under Linux or OS X (or macOS or whatever Apple is calling it now), there will be a subdirectory called x86_64 that contains, among other stuff, a file called "special".
cassiehu
Posts: 35
Joined: Tue Sep 06, 2022 10:41 am

Re: Insert an ion channel written in a .mod file

Post by cassiehu »

ted wrote: Tue Sep 13, 2022 2:50 pm Hints:

First make sure that SHL1_pas is supposed to be the name of a density mechanism. How can you find out? An NMODL file's NEURON block will contain a statement that declares the name of the mechanism. For a density mechanism, the statement is of the form
SUFFIX foo
and for a point process the statement is of the form
POINT_PROCESS Bah
where foo and Bah are the name of the mechanism.
An aside: a commonly used naming convention in NMODL (but not in hoc or Python) is to use lower case for density mechanism names, but to capitalize point process names. Why? Because the NMODL code for a point process actually adds a new class to NEURON (and class names are capitalized in some programming languages). However, the NMODL code for a density mechanism doesn't; instead, the NMODL code for a density mechanism adds a new potential section attribute.

If SHL1_pas is actually the name of a density mechanism, verify that NEURON actually loads that mechanism when it starts. In the same directory as your main hoc or python file, launch NEURON by executing nrngui. The first few lines that NEURON prints to the terminal will include a list of the names of the mod files whose compiled mechanisms have been loaded. If that list doesn't include the name of the mod file that defines the SHL1_pas mechanism, then you're probably starting NEURON in a directory that doesn't contain the compiled mechanisms.

Under MSWin the mechanisms will be in a file called something like nrnmech.dll. Under Linux or OS X (or macOS or whatever Apple is calling it now), there will be a subdirectory called x86_64 that contains, among other stuff, a file called "special".
Many thanks for your reply. I also began to watch the references you given on the former reply, and I was learning how to modify .mod document. Moreover, I checked the mechanism name of the ion channel and changed it to the lower cas, but there was still the error appeared on Python. So I think the reason is like what you said that NEURON does not load that mechanism. Then I met the problem of launching NEURON in the same directory as my main hoc or python file. Actually I don't know how to operate it successfully. What I tried is to open windows (My OS is Windows) powershell in my directory and type nrngui. However, then a window poped to let me choose what software to open it. I mean it shouldn't be like that, right? Also I met some problems of opening .dll file. I just searched on the Internet about opening it to watch the content, but it isn't successful.(I am a total beginner of
using NEURON)The following url are for pictures of more detailed describing.
https://pic.imgdb.cn/item/63219c7416f2c2beb1c4d5a8.png
https://pic.imgdb.cn/item/63219c8b16f2c2beb1c4ea57.png
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Insert an ion channel written in a .mod file

Post by ted »

Which Python are you using? If you're using Anaconda, just open an Anaconda terminal (they probably call it a "shell") and use the commad line to do everything--cd to the directory that contains your source code, run nrnivmodl to compile mod files, execute
nrngui someprogram.hoc
or
python anotherprogram.py
or
python -i yetanotherprogram.py
and everything should work fine.

For help with usage ("how do I do X") and a great deal more, check out the videos from our most recent one-day introductory course, and our much more thorough multi-day course. These are viewable on YouTube on the NEURON Simulation Envrionment channel https://www.youtube.com/channel/UCs9ujT ... QfCJIk0XpQ. Check out the INCF/CNS 2022 course playlist and the 2021 NEURON Online Course playlist.
cassiehu
Posts: 35
Joined: Tue Sep 06, 2022 10:41 am

Re: Insert an ion channel written in a .mod file

Post by cassiehu »

Thanks for your reply first. I use PyCharm to run my python files. And I think I have some problems of my NEURON installing. This is because when I run nrngui some errors poped out. And I post a new topic in installing module of forum. Therefore, I cannot know whether NEURON actually loads the mechanisms written by .mod files when it starts by now. Maybe there are some problems of connecting NEURON with my Python. I also typed "h.nrn_load_dll('nrn/demo/release/nrnmech')" in Python(I am not sure it is the right way, I just referenced a past topic that met a similar problem with me) to check the loaded compiled mechanisms but there was still the error. Looking forward to the new solutions and I will keep on learning from the forum and documents.
cassiehu
Posts: 35
Joined: Tue Sep 06, 2022 10:41 am

Re: Insert an ion channel written in a .mod file

Post by cassiehu »

I have successfully reinstalled NEURON and I operated step by step as you said before. From the photograph we can see that the NEURON has loaded those mechanisms written by .mod files. However, when I ran Python files, the "argument not density mechanism" error was still there. Therefore, it is probably the content of .mod file that has mistakes. I will check it by the reference provided before.
https://pic.imgdb.cn/item/632b077616f2c2beb1341f79.png
cassiehu
Posts: 35
Joined: Tue Sep 06, 2022 10:41 am

Re: Insert an ion channel written in a .mod file

Post by cassiehu »

It is successful now. Actually, all I need to do is add sentence"h.nrn_load_dll('D:/download/yanjjiusheng/hukangxin/hukangxin/mod/nrnmech.dll')". Only in this way can NEURON load the compiled mod file in Python.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Insert an ion channel written in a .mod file

Post by ted »

That's because you put the NMODL files in a directory other than the one that contains your hoc and Python files. When NEURON starts, it automatically looks in the current directory for a library of compiled mechanisms; under MSWin, that library is called nrnmech.dll. If that file is in some directory other than the one that contains your hoc and Python files, you have to tell NEURON where to find nrnmech.dll.

Or you could conmpile the mod files in a way that wrrites the nrnmech.dll file to the directory that contains your mod files. For example, if the mod files are in a subdirectory of your hoc and Python files and that subdirectory is called foo, then cd to the directory that contains your hoc and Python files, and then execute the command
mknrndll foo
This will compile the mod files and write the nrnmech.dll file in foo's parent directory
Post Reply