Skip to content

Commit 411feac

Browse files
author
facu.r
committed
import json models
1 parent 9fa73fb commit 411feac

1 file changed

Lines changed: 44 additions & 23 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,35 +98,54 @@ def compileModMechFiles(self, compileMod, modFolder):
9898
subprocess.call(["nrnivmodl"])
9999

100100
# Load mechanism if mod path is passed
101-
if modFolder:
102-
neuron.load_mechanisms(str(modFolder))
101+
return neuron.load_mechanisms(str(modFolder))
102+
103+
103104

104105
def importModel(self, modelParameters):
105106
try:
106107
# Get Current dir
107108
owd = os.getcwd()
108109

109-
self.compileModMechFiles(modelParameters['compileMod'], modelParameters['modFolder'])
110+
if not self.compileModMechFiles(modelParameters['compileMod'], modelParameters['modFolder']):
111+
return self.getJSONError("Error loading mechanisms", "We coundn't find libnrnmech.so.\n(*) Is '%s' the right path?\n(*) Are the mod files compiled?\n(*) Try importing with compile-mod option selected." %(modelParameters['modFolder']))
110112

111113
import netpyne_geppetto
112-
# NetParams
113-
netParamsPath = str(modelParameters["netParamsPath"])
114-
sys.path.append(netParamsPath)
115-
os.chdir(netParamsPath)
116-
# Import Module
117-
netParamsModuleName = importlib.import_module(str(modelParameters["netParamsModuleName"]))
118-
# Import Model attributes
119-
netpyne_geppetto.netParams = getattr(netParamsModuleName, str(modelParameters["netParamsVariable"]))
120-
121-
# SimConfig
122-
simConfigPath = str(modelParameters["simConfigPath"])
123-
sys.path.append(simConfigPath)
124-
os.chdir(simConfigPath)
125-
# Import Module
126-
simConfigModuleName = importlib.import_module(str(modelParameters["simConfigModuleName"]))
127-
# Import Model attributes
128-
netpyne_geppetto.simConfig = getattr(simConfigModuleName, str(modelParameters["simConfigVariable"]))
129114

115+
if modelParameters['jsonModelFolder']=='':
116+
# NetParams
117+
netParamsPath = str(modelParameters["netParamsPath"])
118+
sys.path.append(netParamsPath)
119+
os.chdir(netParamsPath)
120+
# Import Module
121+
netParamsModuleName = importlib.import_module(str(modelParameters["netParamsModuleName"]))
122+
# Import Model attributes
123+
netpyne_geppetto.netParams = getattr(netParamsModuleName, str(modelParameters["netParamsVariable"]))
124+
125+
# SimConfig
126+
simConfigPath = str(modelParameters["simConfigPath"])
127+
sys.path.append(simConfigPath)
128+
os.chdir(simConfigPath)
129+
# Import Module
130+
simConfigModuleName = importlib.import_module(str(modelParameters["simConfigModuleName"]))
131+
# Import Model attributes
132+
netpyne_geppetto.simConfig = getattr(simConfigModuleName, str(modelParameters["simConfigVariable"]))
133+
else:
134+
with open(modelParameters['jsonModelFolder'], 'r') as file:
135+
jsonData = json.load(file)
136+
137+
if 'net' in jsonData:
138+
if 'params' in jsonData['net'] and 'simConfig' in jsonData:
139+
netpyne_geppetto.netParams = specs.NetParams(jsonData['net']['params'])
140+
netpyne_geppetto.simConfig = specs.SimConfig(jsonData['simConfig'])
141+
# in cellParams.conds --> cellModel, cellType and pop get value {} if this is type specs.Dict
142+
# so, by converting from specs.Dict to python regular dict solves the problem. I tried to solve it from the GUI but I coudn't
143+
netpyne_geppetto.netParams.cellParams = jsonData['net']['params']['cellParams']
144+
else:
145+
return self.getJSONError("Assertion error while importing the NetPyNE model", "The json file does not contain the following keys: [params, simConfig]")
146+
else:
147+
return self.getJSONError("Assertion error while importing the NetPyNE model", "The json file does not contain the following keys: [net]")
148+
130149
return self.getJSONReply()
131150
except:
132151
return self.getJSONError("Error while importing the NetPyNE model",traceback.format_exc())
@@ -137,11 +156,12 @@ def importCellTemplate(self, modelParameters, modFolder, compileMod):
137156
try:
138157
# Get Current dir
139158
owd = os.getcwd()
140-
159+
160+
if not self.compileModMechFiles(compileMod, modFolder):
161+
return self.getJSONError("Error loading mechanisms", "We coundn't find libnrnmech.so.\n(*) Is '%s' the right path?\n(*) Are the mod files compiled?\n(*) Try importing with compile-mod option selected." %(modFolder))
162+
141163
from netpyne_geppetto import netParams
142164

143-
self.compileModMechFiles(compileMod, modFolder)
144-
145165
# import cell template
146166
netParams.importCellParams(**modelParameters)
147167

@@ -416,6 +436,7 @@ def deleteParam(self, paramToDel):
416436
def validateFunction(self, functionString):
417437
return utils.ValidateFunction(functionString, netParams.__dict__)
418438

439+
419440
class LoopTimer(threading.Thread):
420441
"""
421442
a Timer that calls f every interval

0 commit comments

Comments
 (0)