1414"""Main importer of bluecellulab."""
1515
1616import os
17+ from types import ModuleType
1718import pkg_resources
19+ import neuron
1820
21+ from bluecellulab .exceptions import BluecellulabError
1922
20- def _nrn_disable_banner ():
21- """Disable NEURON banner."""
2223
23- import importlib .util
24- import ctypes
25-
26- neuron_spec = importlib .util .find_spec ("neuron" )
27- nrnpy_path = neuron_spec .submodule_search_locations [0 ]
28- import glob
29- hoc_so_list = \
30- glob .glob (os .path .join (nrnpy_path , 'hoc*.so' ))
31-
32- if len (hoc_so_list ) != 1 :
33- raise Exception (
34- 'hoc shared library not found in %s' %
35- nrnpy_path )
36-
37- hoc_so = hoc_so_list [0 ]
38- nrndll = ctypes .cdll [hoc_so ]
39- ctypes .c_int .in_dll (nrndll , 'nrn_nobanner_' ).value = 1
40-
41-
42- def import_neuron ():
43- """Import NEURON simulator."""
44- _nrn_disable_banner ()
45-
46- import neuron
47-
48- return neuron
49-
50-
51- def import_mod_lib (neuron ):
24+ def import_mod_lib (neuron : ModuleType ) -> str :
5225 """Import mod files."""
53-
54- mod_lib_list = None
55- if 'BGLIBPY_MOD_LIBRARY_PATH' in os .environ :
56-
26+ res = ""
27+ if 'BLUECELLULAB_MOD_LIBRARY_PATH' in os .environ :
5728 # Check if the current directory contains 'x86_64'.
58-
5929 if os .path .isdir ('x86_64' ):
60- raise Exception ( "BGLIBPY_MOD_LIBRARY_PATH is set"
61- " and current directory contains the x86_64 folder."
62- " Please remove one of them." )
30+ raise BluecellulabError ( "BLUECELLULAB_MOD_LIBRARY_PATH is set"
31+ " and current directory contains the x86_64 folder."
32+ " Please remove one of them." )
6333
64- mod_lib_path = os .environ ["BGLIBPY_MOD_LIBRARY_PATH" ]
65- mod_lib_list = mod_lib_path .split (':' )
66- for mod_lib in mod_lib_list :
67- neuron .h .nrn_load_dll (mod_lib )
34+ mod_lib_path = os .environ ["BLUECELLULAB_MOD_LIBRARY_PATH" ]
35+ neuron .load_mechanisms (mod_lib_path )
36+ res = mod_lib_path
37+ elif os .path .isdir ('x86_64' ):
38+ # NEURON 8.* automatically load these mechamisms
39+ res = os .path .abspath ('x86_64' )
40+ else :
41+ res = "No mechanisms are loaded."
6842
69- return mod_lib_list
43+ return res
7044
7145
72- def import_neurodamus (neuron ) :
46+ def import_neurodamus (neuron : ModuleType ) -> None :
7347 """Import neurodamus."""
7448 neuron .h .load_file ("stdrun.hoc" ) # nrn
7549 hoc_files = [
@@ -83,13 +57,12 @@ def import_neurodamus(neuron):
8357 neuron .h .load_file (hoc_file_path )
8458
8559
86- def print_header (neuron , mod_lib_path ) :
60+ def print_header (neuron : ModuleType , mod_lib_path : str ) -> None :
8761 """Print bluecellulab header to stdout."""
88- print ("Imported neuron from %s" % neuron .__file__ )
89- print ('Mod libs : ' , mod_lib_path )
62+ print ("Imported NEURON from: %s" % neuron .__file__ )
63+ print ('Mod lib : ' , mod_lib_path )
9064
9165
92- neuron = import_neuron ()
9366mod_lib_paths = import_mod_lib (neuron )
9467import_neurodamus (neuron )
95- # print_header(neuron, mod_lib_paths)
68+ print_header (neuron , mod_lib_paths )
0 commit comments