2727from matplotlib .figure import Figure
2828import neuron
2929from shutil import copyfile
30- from jupyter_geppetto import jupyter_geppetto , synchronization
30+ from jupyter_geppetto import jupyter_geppetto , synchronization , utils
3131import imp
3232from contextlib import redirect_stdout , redirect_stderr
3333
@@ -61,7 +61,7 @@ def instantiateNetPyNEModelInGeppetto(self, args):
6161
6262 return json .loads (GeppettoModelSerializer ().serialize (self .geppetto_model ))
6363 except :
64- return self .getJSONError ("Error while instantiating the NetPyNE model" ,traceback . format_exc ())
64+ return utils .getJSONError ("Error while instantiating the NetPyNE model" , sys . exc_info ())
6565
6666 def simulateNetPyNEModelInGeppetto (self , args ):
6767 try :
@@ -84,7 +84,7 @@ def simulateNetPyNEModelInGeppetto(self, args):
8484
8585 cp = subprocess .run (["mpiexec" , "-n" , args ['cores' ], "nrniv" , "-mpi" , "-python" , "init.py" ], capture_output = True )
8686 print (cp .stdout .decode ()+ cp .stderr .decode ())
87- if cp .returncode != 0 : return self .getJSONError ("Error while simulating the NetPyNE model" , cp .stderr .decode ())
87+ if cp .returncode != 0 : return utils .getJSONError ("Error while simulating the NetPyNE model" , cp .stderr .decode ())
8888 sim .load ('model_output.json' )
8989 self .geppetto_model = self .model_interpreter .getGeppettoModel (sim )
9090 netpyne_model = sim
@@ -100,19 +100,7 @@ def simulateNetPyNEModelInGeppetto(self, args):
100100
101101 return json .loads (GeppettoModelSerializer ().serialize (self .geppetto_model ))
102102 except :
103- return self .getJSONError ("Error while simulating the NetPyNE model" ,traceback .format_exc ())
104-
105- def getJSONReply (self ):
106- data = {}
107- data ['type' ] = 'OK'
108- return json .dumps (data )
109-
110- def getJSONError (self , message , details ):
111- data = {}
112- data ['type' ] = 'ERROR'
113- data ['message' ] = message
114- data ['details' ] = details
115- return json .dumps (data )
103+ return utils .getJSONError ("Error while simulating the NetPyNE model" , sys .exc_info ())
116104
117105 def compileModMechFiles (self , compileMod , modFolder ):
118106 #Create Symbolic link
@@ -140,13 +128,13 @@ def remove(dictionary):
140128 remove (value )
141129
142130 if not any ([args [option ] for option in ['loadNetParams' , 'loadSimCfg' , 'loadSimData' , 'loadNet' ]]):
143- return self .getJSONError ("Error while loading data" , 'You have to select at least one option' )
131+ return utils .getJSONError ("Error while loading data" , 'You have to select at least one option' )
144132
145133 try :
146134 owd = os .getcwd ()
147135 self .compileModMechFiles (args ['compileMod' ], args ['modFolder' ])
148136 except :
149- return self .getJSONError ("Error while importing/compiling mods" ,traceback . format_exc ())
137+ return utils .getJSONError ("Error while importing/compiling mods" , sys . exc_info ())
150138 finally :
151139 os .chdir (owd )
152140
@@ -197,11 +185,11 @@ def remove(dictionary):
197185 sim .loadSimData (args ['jsonModelFolder' ])
198186 self .geppetto_model = self .model_interpreter .getGeppettoModel (sim )
199187
200- return GeppettoModelSerializer ().serialize (self .geppetto_model )
188+ return json . loads ( GeppettoModelSerializer ().serialize (self .geppetto_model ) )
201189 else :
202- return self .getJSONReply ()
190+ return utils .getJSONReply ()
203191 except :
204- return self .getJSONError ("Error while loading the NetPyNE model" ,traceback . format_exc ())
192+ return utils .getJSONError ("Error while loading the NetPyNE model" , sys . exc_info ())
205193
206194 def importModel (self , modelParameters ):
207195 try :
@@ -233,9 +221,9 @@ def importModel(self, modelParameters):
233221 # Import Model attributes
234222 self .simConfig = getattr (simConfigModuleName , str (modelParameters ["simConfigVariable" ]))
235223
236- return self .getJSONReply ()
224+ return utils .getJSONReply ()
237225 except :
238- return self .getJSONError ("Error while importing the NetPyNE model" ,traceback . format_exc ())
226+ return utils .getJSONError ("Error while importing the NetPyNE model" , sys . exc_info ())
239227 finally :
240228 os .chdir (owd )
241229
@@ -253,45 +241,45 @@ def importCellTemplate(self, modelParameters, modFolder, compileMod):
253241 rule = modelParameters ["label" ]
254242 self .netParams .cellParams [rule ] = self .netParams .cellParams [rule ].todict ()
255243
256- return self .getJSONReply ()
244+ return utils .getJSONReply ()
257245 except :
258- return self .getJSONError ("Error while importing the NetPyNE cell template" ,traceback . format_exc ())
246+ return utils .getJSONError ("Error while importing the NetPyNE cell template" , sys . exc_info ())
259247 finally :
260248 os .chdir (owd )
261249
262250 def exportModel (self , args ):
263251 try :
264252 with redirect_stdout (sys .__stdout__ ):
265253 if not args ['netCells' ]:
266- sim .initialize (netParams = netParams , simConfig = simConfig )
254+ sim .initialize (netParams = self . netParams , simConfig = self . simConfig )
267255 sim .cfg .filename = args ['fileName' ]
268256 include = [el for el in specs .SimConfig ().saveDataInclude if el in args .keys () and args [el ]]
269257 if args ['netCells' ]: include += ['netPops' ]
270258 sim .cfg .saveJson = True
271259 sim .saveData (include )
272260 sim .cfg .saveJson = False
273- return self .getJSONReply ()
261+ return utils .getJSONReply ()
274262 except :
275- return self .getJSONError ("Error while exporting the NetPyNE model" ,traceback . format_exc ())
263+ return utils .getJSONError ("Error while exporting the NetPyNE model" , sys . exc_info ())
276264
277265 def exportNeuroML (self , modelParams ):
278266 try :
279267 with redirect_stdout (sys .__stdout__ ):
280268 sim .exportNeuroML2 (modelParams ['fileName' ], specs .SimConfig ())
281- return self .getJSONReply ()
269+ return utils .getJSONReply ()
282270 except :
283- return self .getJSONError ("Error while exporting the NetPyNE model" , traceback . format_exc ())
271+ return utils .getJSONError ("Error while exporting the NetPyNE model" , sys . exc_info ())
284272
285273 def importNeuroML (self , modelParams ):
286274 try :
287275 with redirect_stdout (sys .__stdout__ ):
288276 sim .initialize ()
289277 sim .importNeuroML2 (modelParams ['neuroMLFolder' ], simConfig = specs .SimConfig (), simulate = False , analyze = False )
290278 self .geppetto_model = self .model_interpreter .getGeppettoModel (sim )
291- return GeppettoModelSerializer ().serialize (self .geppetto_model )
279+ return json . loads ( GeppettoModelSerializer ().serialize (self .geppetto_model ) )
292280
293281 except :
294- return self .getJSONError ("Error while exporting the NetPyNE model" ,traceback . format_exc ())
282+ return utils .getJSONError ("Error while exporting the NetPyNE model" , sys . exc_info ())
295283
296284 def deleteModel (self , modelParams ):
297285 try :
@@ -302,10 +290,10 @@ def deleteModel(self, modelParams):
302290 self .netParams .todict ()
303291 if self .doIhaveInstOrSimData ()['haveInstance' ]: sim .clearAll ()
304292 self .geppetto_model = None
305- return self .getJSONReply ()
293+ return utils .getJSONReply ()
306294
307295 except :
308- return self .getJSONError ("Error while exporting the NetPyNE model" ,traceback . format_exc ())
296+ return utils .getJSONError ("Error while exporting the NetPyNE model" , sys . exc_info ())
309297
310298 def instantiateNetPyNEModel (self ):
311299 with redirect_stdout (sys .__stdout__ ):
@@ -494,10 +482,10 @@ def header(title, spacer='-'):
494482
495483 script .write (header ('end script' , spacer = '=' ))
496484
497- return self .getJSONReply ()
485+ return utils .getJSONReply ()
498486
499487 except :
500- return self .getJSONError ("Error while importing the NetPyNE model" , traceback . format_exc ())
488+ return utils .getJSONError ("Error while importing the NetPyNE model" , sys . exc_info ())
501489
502490logging .info ("Initialising NetPyNE UI" )
503491netpyne_geppetto = NetPyNEGeppetto ()
0 commit comments