@@ -342,6 +342,15 @@ def rename(self, path, oldValue,newValue):
342342 newModel = re .sub ("(['])(?:(?=(\\ ?))\2 .)*?\1 " , lambda x :x .group (0 ).replace (oldValue ,newValue , 1 ), model )
343343 logging .debug ("Rename funct - Model is " + model + " newModel is " + newModel )
344344 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
345354
346355 def getPlotSettings (self , plot ):
347356 if self .simConfig .analysis and plot in self .simConfig .analysis :
@@ -393,7 +402,7 @@ def getAvailableCellModels(self):
393402 cm = self .netParams .popParams [p ]['cellModel' ]
394403 if cm not in cellModels :
395404 cellModels .add (cm )
396- return cellModels
405+ return list ( cellModels )
397406
398407 def getAvailableCellTypes (self ):
399408 cellTypes = set ([])
@@ -402,7 +411,7 @@ def getAvailableCellTypes(self):
402411 ct = self .netParams .popParams [p ]['cellType' ]
403412 if ct not in cellTypes :
404413 cellTypes .add (ct )
405- return cellTypes
414+ return list ( cellTypes )
406415
407416 def getAvailableSections (self ):
408417 sections = {}
@@ -431,14 +440,27 @@ def getAvailablePlots(self):
431440 plots = ["plotRaster" , "plotSpikeHist" , "plotSpikeStats" ,"plotRatePSD" , "plotTraces" , "plotLFP" , "plotShape" , "plot2Dnet" , "plotConn" , "granger" ]
432441 return [plot for plot in plots if plot not in list (self .simConfig .analysis .keys ())]
433442
434- def deleteParam (self , paramToDel ):
435- logging .debug ("Checking if netParams." + paramToDel + " is not null" )
436- if eval ("self.netParams." + paramToDel ) is not None :
437- exec ("del self.netParams.%s" % (paramToDel ))
438- logging .debug ('Parameter netParams.' + paramToDel + ' has been deleted' )
439- else :
440- logging .debug ('Parameter ' + paramToDel + ' is null, not deleted' )
441-
443+ def deleteParam (self , model , label ):
444+ try :
445+ if isinstance (model , list ): # just for cellParams
446+ if len (model )== 1 :
447+ self .netParams .cellParams [model [0 ]]["secs" ].pop (label )
448+ elif len (model )== 2 :
449+ self .netParams .cellParams [model [0 ]]["secs" ][model [1 ]]["mechs" ].pop (label )
450+ else :
451+ pass
452+ else :
453+ getattr (self .netParams , model ).pop (label )
454+ if "popParams" in model :
455+ self .propagate_field_rename ("pop" , None , label )
456+ elif "stimSourceParams" in model :
457+ self .propagate_field_rename ("source" , None , label )
458+ elif "synMechParams" in model :
459+ self .propagate_field_rename ("synMech" , None , label )
460+ return True
461+ except :
462+ return False
463+
442464 def validateFunction (self , functionString ):
443465 return validateFunction (functionString , self .netParams .__dict__ )
444466
@@ -492,6 +514,86 @@ def header(title, spacer='-'):
492514 except :
493515 return utils .getJSONError ("Error while importing the NetPyNE model" , sys .exc_info ())
494516
517+
518+ def propagate (self , obj , label , cond , new , old ):
519+ for key in obj .keys ():
520+ if label in list (obj [key ][cond ].keys ()):
521+ if isinstance (obj [key ][cond ][label ], str ):
522+ if old == obj [key ][cond ][label ]:
523+ if new == '' or new == None :
524+ obj [key ].pop (label )
525+ else :
526+ obj [key ][cond ][label ] = new
527+
528+ elif isinstance (obj [key ][cond ][label ], list ):
529+ if old in obj [key ][cond ][label ]:
530+ if new == '' or new == None :
531+ obj [key ][cond ][label ] = [ value for value in obj [key ][cond ][label ] if value != old ]
532+ else :
533+ obj [key ][cond ][label ] = [ value if value != old else new for value in obj [key ][cond ][label ] ]
534+ if len (obj [key ][cond ][label ])== 0 :
535+ obj [key ][cond ].pop (label )
536+ else :
537+ pass
538+
539+ def propagate_field_rename (self , label , new , old ):
540+ def unique (label = label , old = old ):
541+ classes = []
542+ for p in self .netParams .popParams :
543+ if label in self .netParams .popParams [p ]:
544+ classes .append (self .netParams .popParams [p ][label ])
545+ if classes .count (old )> 1 :
546+ return False
547+ else :
548+ return True
549+
550+ if label == 'source' :
551+ self .propagate_stim_source_rename (new , old )
552+ return True
553+ elif label == 'synMech' :
554+ self .propagate_syn_mech_rename (new , old )
555+ return True
556+ else :
557+ if unique ():
558+ for (model , cond ) in [['cellParams' ,'conds' ], ['connParams' , 'preConds' ], ['connParams' , 'postConds' ], ['stimTargetParams' , 'conds' ]]:
559+ self .propagate (getattr (self .netParams , model ), label , cond , new , old )
560+ return True
561+ else :
562+ return False
563+
564+ def propagate_section_rename (self , new , old ):
565+ for label in self .netParams .cellParams :
566+ if 'secs' in self .netParams .cellParams [label ]:
567+ for sec in self .netParams .cellParams [label ]['secs' ]:
568+ if 'topol' in self .netParams .cellParams [label ]['secs' ][sec ]:
569+ if 'parentSec' in self .netParams .cellParams [label ]['secs' ][sec ]['topol' ]:
570+ if self .netParams .cellParams [label ]['secs' ][sec ]['topol' ]['parentSec' ] == old :
571+ if new == None :
572+ self .netParams .cellParams [label ]['secs' ][sec ]['topol' ].pop ('parentSec' )
573+ else :
574+ self .netParams .cellParams [label ]['secs' ][sec ]['topol' ]['parentSec' ] = new
575+
576+ def propagate_stim_source_rename (self , new , old ):
577+ for label in self .netParams .stimTargetParams :
578+ if old == self .netParams .stimTargetParams [label ]['source' ]:
579+ if new == None :
580+ self .netParams .stimTargetParams [label ].pop ('source' )
581+ else :
582+ self .netParams .stimTargetParams [label ]['source' ] = new
583+
584+ def propagate_syn_mech_rename (self , new , old ):
585+ for label in self .netParams .stimTargetParams :
586+ if 'source' in self .netParams .stimTargetParams [label ]:
587+ if self .netParams .stimTargetParams [label ]['source' ] in self .netParams .stimSourceParams :
588+ if 'type' in self .netParams .stimSourceParams [self .netParams .stimTargetParams [label ]['source' ]]:
589+ if self .netParams .stimSourceParams [self .netParams .stimTargetParams [label ]['source' ]]['type' ]== 'NetStim' :
590+ if old == self .netParams .stimTargetParams [label ]['synMech' ]:
591+ if new == None :
592+ self .netParams .stimTargetParams [label ].pop ('synMech' )
593+ else :
594+ self .netParams .stimTargetParams [label ]['synMech' ] = new
595+
596+
495597logging .info ("Initialising NetPyNE UI" )
496598netpyne_geppetto = NetPyNEGeppetto ()
497599logging .info ("NetPyNE UI initialised" )
0 commit comments