using compiled mod files from python script in a different direcory

NMODL and the Channel Builder.
Post Reply
nicholasmg
Posts: 7
Joined: Sat Feb 29, 2020 11:16 am
Location: University of Colorado

using compiled mod files from python script in a different direcory

Post by nicholasmg »

I am trying to organize my code for a simulation which uses several external mod files. I compile the mod files using nrnivmodl (Mac OS) and can use the channels without a problem as long as the nrnivmodl generated x86_64 directory is in the working directory from which I start my python script.

However, this will not always be the case, and starting my python script from any other directory fails to load the channels. Is there a specific, unambiguous way to load the compiled channels directly in a script (hoc or python) so that I do not have to depend on the simulation being run from the same directory as the compiled files?
I looked at

Code: Select all

 nrn_load_dll("path/to/x86_64") 
but this does not seem to work (and there does not appear to be any .dll created on compilation with Mac OS or Linux.

The main reason I want to do this is for code organization. I would like to have all my mod files separate from my hoc and python files in an nmodl/ subdirectory and compile them within that directory whenever I change them.

My workaround now uses a makefile to copy then compile the mod files in all the directories of my project then delete them the mods, which is not ideal.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: using compiled mod files from python script in a different direcory

Post by ramcdougal »

When you run nrnivmodl on macOS (and I assume Linux, but I didn't check), it puts the compiled version of the mod files in the x86_64/.libs/libnrnmech.so file. (You won't see this if you just do an "ls" because macOS and Linux hide file and folder names beginning with a . by default but you can see it with e.g. "ls -a".)

Thus, for example, on my Mac, I can load the compiled mechanisms from a modeI I downloaded recently (not linking to the model because the equivalent approach works for all models as long as the mechanisms are compiled):

Code: Select all

h.nrn_load_dll('/Users/ramcdougal/Downloads/CA1_abeta/x86_64/.libs/libnrnmech.so')
The only thing that remains is to handle windows separately from macOS and linux. Fortunately you can easily detect the platform in the standard Python way:

Code: Select all

>>> import platform
>>> platform.system()
'Darwin'
Or by using the NEURON function h.unix_mac_pc()

Code: Select all

>>> h.unix_mac_pc()
4.0
nicholasmg
Posts: 7
Joined: Sat Feb 29, 2020 11:16 am
Location: University of Colorado

Re: using compiled mod files from python script in a different direcory

Post by nicholasmg »

awesome, thank you for your quick response that took care of it!
Post Reply