@@ -227,21 +227,26 @@ def importModel(self, modelParameters):
227227 finally :
228228 os .chdir (owd )
229229
230- def importCellTemplate (self , modelParameters , modFolder , compileMod ):
230+ def importCellTemplate (self , modelParameters ):
231231 try :
232- # Get Current dir
233- owd = os .getcwd ()
232+ with redirect_stdout (sys .__stdout__ ):
233+ rule = modelParameters ["label" ]
234+ # Get Current dir
235+ owd = os .getcwd ()
234236
235- self .compileModMechFiles ( compileMod , modFolder )
237+ conds = {} if rule not in self .netParams . cellParams else self . netParams . cellParams [ rule ][ 'conds' ]
236238
237- # import cell template
238- self .netParams .importCellParams (** modelParameters )
239-
240- # convert fron netpyne.specs.dict to dict
241- rule = modelParameters ["label" ]
242- self .netParams .cellParams [rule ] = self .netParams .cellParams [rule ].todict ()
239+ self .compileModMechFiles (modelParameters ["compileMod" ], modelParameters ["modFolder" ])
243240
244- return utils .getJSONReply ()
241+ del modelParameters ["modFolder" ]
242+ del modelParameters ["compileMod" ]
243+ # import cell template
244+ self .netParams .importCellParams (** modelParameters , conds = conds )
245+
246+ # convert fron netpyne.specs.dict to dict
247+ self .netParams .cellParams [rule ] = self .netParams .cellParams [rule ].todict ()
248+
249+ return utils .getJSONReply ()
245250 except :
246251 return utils .getJSONError ("Error while importing the NetPyNE cell template" , sys .exc_info ())
247252 finally :
@@ -337,6 +342,15 @@ def rename(self, path, oldValue,newValue):
337342 newModel = re .sub ("(['])(?:(?=(\\ ?))\2 .)*?\1 " , lambda x :x .group (0 ).replace (oldValue ,newValue , 1 ), model )
338343 logging .debug ("Rename funct - Model is " + model + " newModel is " + newModel )
339344 jupyter_geppetto .synched_models [newModel ]= synched_component
345+ with redirect_stdout (sys .__stdout__ ):
346+ if "popParams" in path :
347+ self .propagate_field_rename ("pop" , newValue , oldValue )
348+ elif "stimSourceParams" in path :
349+ self .propagate_field_rename ("source" , newValue , oldValue )
350+ elif "synMechParams" in path :
351+ self .propagate_field_rename ("synMech" , newValue , oldValue )
352+
353+ return 1
340354
341355 def getPlotSettings (self , plot ):
342356 if self .simConfig .analysis and plot in self .simConfig .analysis :
@@ -388,7 +402,7 @@ def getAvailableCellModels(self):
388402 cm = self .netParams .popParams [p ]['cellModel' ]
389403 if cm not in cellModels :
390404 cellModels .add (cm )
391- return cellModels
405+ return list ( cellModels )
392406
393407 def getAvailableCellTypes (self ):
394408 cellTypes = set ([])
@@ -397,7 +411,7 @@ def getAvailableCellTypes(self):
397411 ct = self .netParams .popParams [p ]['cellType' ]
398412 if ct not in cellTypes :
399413 cellTypes .add (ct )
400- return cellTypes
414+ return list ( cellTypes )
401415
402416 def getAvailableSections (self ):
403417 sections = {}
@@ -427,29 +441,51 @@ def getAvailablePlots(self):
427441
428442 return [plot for plot in plots if plot not in list (self .simConfig .analysis .keys ())]
429443
430-
444+ def getInclude (self , model ):
445+ with redirect_stdout (sys .__stdout__ ):
446+ if model in list (netpyne_geppetto .simConfig .analysis .keys ()):
447+ if 'include' in list (netpyne_geppetto .simConfig .analysis [model ].keys ()):
448+ return netpyne_geppetto .simConfig .analysis [model ]['include' ]
449+ else :
450+ return False
451+ else :
452+ return False
453+
431454 def getGIDs (self ):
432455 # pop sizes and gids returned in a dict
433456 out = {}
434457 with redirect_stdout (sys .__stdout__ ):
435- for key in self .netParams .popParams .keys ():
436- if 'numCells' in self .netParams .popParams [key ]:
437- out [key ] = self .netParams .popParams [key ]['numCells' ]
438- else :
439- out [key ] = 0
440-
441- out ['gids' ] = int (np .sum ([v for k , v in list (out .items ())]))
442-
458+ for key in self .netParams .popParams .keys ():
459+ if 'numCells' in self .netParams .popParams [key ]:
460+ out [key ] = self .netParams .popParams [key ]['numCells' ]
461+ else :
462+ out [key ] = 0
463+
464+ out ['gids' ] = int (np .sum ([v for k , v in list (out .items ())]))
465+
443466 return out
444467
445- def deleteParam (self , paramToDel ):
446- logging .debug ("Checking if netParams." + paramToDel + " is not null" )
447- if eval ("self.netParams." + paramToDel ) is not None :
448- exec ("del self.netParams.%s" % (paramToDel ))
449- logging .debug ('Parameter netParams.' + paramToDel + ' has been deleted' )
450- else :
451- logging .debug ('Parameter ' + paramToDel + ' is null, not deleted' )
452-
468+ def deleteParam (self , model , label ):
469+ try :
470+ if isinstance (model , list ): # just for cellParams
471+ if len (model )== 1 :
472+ self .netParams .cellParams [model [0 ]]["secs" ].pop (label )
473+ elif len (model )== 2 :
474+ self .netParams .cellParams [model [0 ]]["secs" ][model [1 ]]["mechs" ].pop (label )
475+ else :
476+ pass
477+ else :
478+ getattr (self .netParams , model ).pop (label )
479+ if "popParams" in model :
480+ self .propagate_field_rename ("pop" , None , label )
481+ elif "stimSourceParams" in model :
482+ self .propagate_field_rename ("source" , None , label )
483+ elif "synMechParams" in model :
484+ self .propagate_field_rename ("synMech" , None , label )
485+ return True
486+ except :
487+ return False
488+
453489 def validateFunction (self , functionString ):
454490 return validateFunction (functionString , self .netParams .__dict__ )
455491
@@ -503,6 +539,86 @@ def header(title, spacer='-'):
503539 except :
504540 return utils .getJSONError ("Error while importing the NetPyNE model" , sys .exc_info ())
505541
542+
543+ def propagate (self , obj , label , cond , new , old ):
544+ for key in obj .keys ():
545+ if label in list (obj [key ][cond ].keys ()):
546+ if isinstance (obj [key ][cond ][label ], str ):
547+ if old == obj [key ][cond ][label ]:
548+ if new == '' or new == None :
549+ obj [key ].pop (label )
550+ else :
551+ obj [key ][cond ][label ] = new
552+
553+ elif isinstance (obj [key ][cond ][label ], list ):
554+ if old in obj [key ][cond ][label ]:
555+ if new == '' or new == None :
556+ obj [key ][cond ][label ] = [ value for value in obj [key ][cond ][label ] if value != old ]
557+ else :
558+ obj [key ][cond ][label ] = [ value if value != old else new for value in obj [key ][cond ][label ] ]
559+ if len (obj [key ][cond ][label ])== 0 :
560+ obj [key ][cond ].pop (label )
561+ else :
562+ pass
563+
564+ def propagate_field_rename (self , label , new , old ):
565+ def unique (label = label , old = old ):
566+ classes = []
567+ for p in self .netParams .popParams :
568+ if label in self .netParams .popParams [p ]:
569+ classes .append (self .netParams .popParams [p ][label ])
570+ if classes .count (old )> 1 :
571+ return False
572+ else :
573+ return True
574+
575+ if label == 'source' :
576+ self .propagate_stim_source_rename (new , old )
577+ return True
578+ elif label == 'synMech' :
579+ self .propagate_syn_mech_rename (new , old )
580+ return True
581+ else :
582+ if unique ():
583+ for (model , cond ) in [['cellParams' ,'conds' ], ['connParams' , 'preConds' ], ['connParams' , 'postConds' ], ['stimTargetParams' , 'conds' ]]:
584+ self .propagate (getattr (self .netParams , model ), label , cond , new , old )
585+ return True
586+ else :
587+ return False
588+
589+ def propagate_section_rename (self , new , old ):
590+ for label in self .netParams .cellParams :
591+ if 'secs' in self .netParams .cellParams [label ]:
592+ for sec in self .netParams .cellParams [label ]['secs' ]:
593+ if 'topol' in self .netParams .cellParams [label ]['secs' ][sec ]:
594+ if 'parentSec' in self .netParams .cellParams [label ]['secs' ][sec ]['topol' ]:
595+ if self .netParams .cellParams [label ]['secs' ][sec ]['topol' ]['parentSec' ] == old :
596+ if new == None :
597+ self .netParams .cellParams [label ]['secs' ][sec ]['topol' ].pop ('parentSec' )
598+ else :
599+ self .netParams .cellParams [label ]['secs' ][sec ]['topol' ]['parentSec' ] = new
600+
601+ def propagate_stim_source_rename (self , new , old ):
602+ for label in self .netParams .stimTargetParams :
603+ if old == self .netParams .stimTargetParams [label ]['source' ]:
604+ if new == None :
605+ self .netParams .stimTargetParams [label ].pop ('source' )
606+ else :
607+ self .netParams .stimTargetParams [label ]['source' ] = new
608+
609+ def propagate_syn_mech_rename (self , new , old ):
610+ for label in self .netParams .stimTargetParams :
611+ if 'source' in self .netParams .stimTargetParams [label ]:
612+ if self .netParams .stimTargetParams [label ]['source' ] in self .netParams .stimSourceParams :
613+ if 'type' in self .netParams .stimSourceParams [self .netParams .stimTargetParams [label ]['source' ]]:
614+ if self .netParams .stimSourceParams [self .netParams .stimTargetParams [label ]['source' ]]['type' ]== 'NetStim' :
615+ if old == self .netParams .stimTargetParams [label ]['synMech' ]:
616+ if new == None :
617+ self .netParams .stimTargetParams [label ].pop ('synMech' )
618+ else :
619+ self .netParams .stimTargetParams [label ]['synMech' ] = new
620+
621+
506622logging .info ("Initialising NetPyNE UI" )
507623netpyne_geppetto = NetPyNEGeppetto ()
508624logging .info ("NetPyNE UI initialised" )
0 commit comments