use a hoc statement to "load" a compiled mechanism?

NMODL and the Channel Builder.
Post Reply
stephanmg
Posts: 68
Joined: Tue Jul 03, 2012 4:40 am

use a hoc statement to "load" a compiled mechanism?

Post by stephanmg » Thu Mar 27, 2014 6:21 am

After I compiled with nrnivmodl my Channel Model, let's say MyChannel.mod i want to load it with a hoc statement.
I don't want to execute nrngui, but instead when i call ivoc_main() in my C code. Is this possible? If how please state.

Thanks in advance.

Best,
Stephan

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

Re: use a hoc statement to "load" a compiled mechanism?

Post by ted » Thu Mar 27, 2014 10:58 am

First, I should mention that your latest post is about a topic that is very different from the discussion thread it was in, so I moved it into its own new thread.

I am assuming that you are somehow executing NEURON from your own compiled C code. If you are using MSWindows or OS X, you might be able to do something like this

Code: Select all

if (ropen("nrnmech.dll")) {
  ropen()
  nrn_load_dll("nrnmech.dll")
}
It may be necessary to first use chdir() to change to the directory that contains the dll, then load the dll, then chdir() back to the original directory. However, this won't work for UNIX or Linux; I'll have to find out what would work and get back to you.

If you're not careful, you might end up with a program that is not very portable; that could be a future problem for you, your collaborators, and anyone else who tries to reuse your code.

stephanmg
Posts: 68
Joined: Tue Jul 03, 2012 4:40 am

Re: use a hoc statement to "load" a compiled mechanism?

Post by stephanmg » Thu Mar 27, 2014 11:21 am

Ah thanks, ted.

So, yes, basically it should be working for Linux/UNIX too, so that's the only possibility? Would be glad to here any suggestions or any solution for making it work on Linux/Unix.

Best,
Stephan

hines
Site Admin
Posts: 1577
Joined: Wed May 18, 2005 3:32 pm

Re: use a hoc statement to "load" a compiled mechanism?

Post by hines » Thu Mar 27, 2014 11:33 am

The char** argv arg of ivoc_main can have -dll filepath pairs.
At the interpreter level
nrn_load_dll("filepath")
can be used.
Finally, if the dll or .so file has the proper relation to the folder where the program is launched, the dll will be automatically loaded.
(for mswin this is just a nrnmech.dll in the folder. for mac and linux it is usually found in the subfolder x86_64/.libs/libnrnmech.so)

stephanmg
Posts: 68
Joined: Tue Jul 03, 2012 4:40 am

Re: use a hoc statement to "load" a compiled mechanism?

Post by stephanmg » Thu Mar 27, 2014 11:59 am

Ah okay,

i thought it could be done with ivoc_main's args array, but i could not figure out. sorry for that.

it works.

best,
Stephan

stephanmg
Posts: 68
Joined: Tue Jul 03, 2012 4:40 am

Re: use a hoc statement to "load" a compiled mechanism?

Post by stephanmg » Thu Jun 05, 2014 6:52 am

To clarify this: it works!

Basically, you can just assume the behaviour of the standalone NEURON version (N1), iff the compiled membrane mechanism (.mod - NMODL file) is compiled by N1 and N1 is included in another C/C++ project as a shared library (dynamically linked).

Then basically if you init your hoc interpreter by invoking your main executable in your C/C++ project, then it loads the membrane mechanism from the current directory by x86_64/.libs/ correctly - or in analogue also if you change directory by providing ivoc_main() a path as suggested by you guys

I tested this on Mac OSX Mavericks - compiled everything with g++-mp-4.8 / gcc-mp-4.8 from MacPorts - whereas the N1 is the last stable snapshot from the NEURON official download page.

This is as a documentation for people wondering how it would work - and for me. :)

Best,
Stephan

stephanmg
Posts: 68
Joined: Tue Jul 03, 2012 4:40 am

Re: use a hoc statement to "load" a compiled mechanism?

Post by stephanmg » Fri Aug 15, 2014 4:05 am

Hey,

i just want to let you know some issue, maybe you can help out again dear users.

If i'm compiling my NEURON from the hg repository as indicated above dynamically, everything fine.
That is, i compile a mod file and then i can load it.

If i'm compiling my NEURON from the hg repository instead as STATIC build, my NEURON still works.
However, i'm not able to load compiled mod files, i. e. NEURON won't load additional membrane mechanisms,
but it does not give me an error, it seems just that the mod files aren't in the correct place.

If i'm using my statically compiled NEURON standalone, i. e. i don't use ivoc_main in my own C code, the mechanisms get loaded only if i use nrngui,
when i use nrniv it does not load my mechanism.

I guess this has to do something with the path where NEURON is launched in the static case. May the path be different from the path
where NEURON is launched in the dynamically linked case? Note, that i'm using in my own C code ivoc_main, which imho corresponds then to nrniv maybe, but
i am nit sure. My best guess is, that the path is different if i use ivoc_main in the case if build NEURON static.

So maybe it would be nice to give ivoc_main the -dll and filepath to the mod files directory, but i don't know how to do this.

Also i tried to use hoc_valid_stmt("nrn_load_dll(\”path/to/my/compiled/mod/directory/\")", 0) but then nrn_load_dll is not available in the STATIC build case, whereas in the DYNAMICALLY build case nrn_load_dll is available

Can anybody enlighten me please?

Best,
Stephan

Post Reply