1313import json
1414import logging
1515import os
16+ from pathlib import Path
1617import pprint
1718import re
1819import sys
@@ -511,7 +512,32 @@ def _create3D_shapes(self, json_path: str):
511512 # Load again because gatherData removed simData
512513 sim .loadSimData (json_path )
513514
515+ def loadFromIndexFile (self , json_path : str ):
516+ cfg , netParams = sim .loadModel (json_path , loadMechs = True , ignoreMechAlreadyExistsError = True )
517+ self .simConfig = cfg
518+ self .netParams = netParams
514519
520+ if isinstance (self .netParams , dict ):
521+ self .netParams = specs .NetParams (self .netParams )
522+
523+ if isinstance (self .simConfig , dict ):
524+ self .simConfig = specs .SimConfig (self .simConfig )
525+
526+ for key , value in self .netParams .cellParams .items ():
527+ if hasattr (value , 'todict' ):
528+ self .netParams .cellParams [key ] = value .todict ()
529+
530+ # TODO: when should sim.initialize be called?
531+ # Only on import or better before every simulation or network instantiation?
532+ sim .initialize ()
533+
534+ def saveToIndexFile (self , srcPath , dstPath , exportNetParamsAsPython , exportSimConfigAsPython ):
535+ sim .saveModel (netParams = self .netParams ,
536+ simConfig = self .simConfig ,
537+ srcPath = srcPath ,
538+ dstPath = dstPath ,
539+ exportNetParamsAsPython = exportNetParamsAsPython ,
540+ exportSimConfigAsPython = exportSimConfigAsPython )
515541
516542 def importModel (self , modelParameters ):
517543 """ Imports a model stored in form of Python files.
@@ -575,7 +601,7 @@ def importModel(self, modelParameters):
575601
576602 def importNeuroML (self , modelParameters ):
577603 from netpyne_ui .helpers import neuroml
578-
604+
579605
580606 try :
581607 # Get Current dir
@@ -584,9 +610,9 @@ def importNeuroML(self, modelParameters):
584610 with redirect_stdout (sys .__stdout__ ):
585611 # NetParams
586612 filename = str (modelParameters ["fileName" ])
587-
613+
588614 json_fname = neuroml .convertNeuroML2 (filename , compileMod = modelParameters ["compileMod" ])
589-
615+
590616 return self .loadModel (args = dict (
591617 compileMod = True ,
592618 modFolder = os .path .dirname (json_fname ),
@@ -605,7 +631,7 @@ def importNeuroML(self, modelParameters):
605631
606632 def importLEMS (self , modelParameters ):
607633 from netpyne_ui .helpers import neuroml
608-
634+
609635
610636 try :
611637 # Get Current dir
@@ -614,7 +640,7 @@ def importLEMS(self, modelParameters):
614640 with redirect_stdout (sys .__stdout__ ):
615641 # NetParams
616642 filename = str (modelParameters ["fileName" ])
617-
643+
618644 json_fname = neuroml .convertLEMSSimulation (filename )
619645
620646 return self .loadModel (args = dict (
@@ -789,10 +815,21 @@ def getPlotSettings(self, plot_name):
789815 return self .simConfig .analysis [plot_name ]
790816 return {}
791817
792- def getDirList (self , dir = None , onlyDirs = False , filterFiles = False ):
793- # Get Current dir
818+ def checkFileExists (self , path ):
819+ path = Path (path or '' )
820+ return path .exists ()
821+
822+ def getFullPath (self , dir , subDir ):
794823 if dir is None or dir == '' :
795- dir = os .path .join (os .getcwd (), constants .NETPYNE_WORKDIR_PATH )
824+ base = constants .NETPYNE_WORKDIR_PATH
825+ if subDir :
826+ base = os .path .join (base , subDir )
827+ dir = os .path .join (os .getcwd (), base )
828+ return dir
829+
830+ def getDirList (self , dir = None , onlyDirs = False , filterFiles = False , subDir = None ):
831+ # Get Current dir
832+ dir = self .getFullPath (dir , subDir )
796833 dir_list = []
797834 file_list = []
798835 for f in sorted (os .listdir (str (dir )), key = str .lower ):
@@ -810,6 +847,13 @@ def checkAvailablePlots(self):
810847 def getPlot (self , plotName , LFPflavour , theme = 'gui' ):
811848 try :
812849 with redirect_stdout (sys .__stdout__ ):
850+ availablePlots = self .checkAvailablePlots ()
851+ checkCondition = availablePlots .get (plotName .replace ('iplot' , 'plot' ), False )
852+
853+ if checkCondition is False :
854+ logging .info ("Plot " + plotName + " not available" )
855+ return - 1
856+
813857 args = self .getPlotSettings (plotName )
814858 if LFPflavour :
815859 args ['plots' ] = [LFPflavour ]
0 commit comments