Skip to content

Commit 1c8dcef

Browse files
committed
#530 use netpyne method for exporting the python script
1 parent 0f50696 commit 1c8dcef

1 file changed

Lines changed: 3 additions & 45 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -908,56 +908,14 @@ def validateFunction(self, functionString):
908908
return validateFunction(functionString, self.netParams.__dict__)
909909

910910
def exportHLS(self, args):
911-
def convert2bool(string):
912-
return string.replace('true', 'True').replace('false', 'False').replace('null', 'False')
913-
914-
def header(title, spacer='-'):
915-
return '\n# ' + title.upper() + ' ' + spacer * (77 - len(title)) + '\n'
916911

917912
try:
918-
params = ['popParams', 'cellParams', 'synMechParams']
919-
params += ['connParams', 'stimSourceParams', 'stimTargetParams']
920-
921-
fname = args['fileName']
922-
if not fname:
923-
# default option
924-
fname = 'output.py'
925-
913+
fname = args.get('fileName', 'output.py')
926914
if not fname[-3:] == '.py':
927915
fname = f"{fname}.py"
928916

929-
# TODO: use methods offered by netpyne to create this script!
930-
with open(fname, 'w') as script:
931-
script.write("from netpyne import specs, sim\n")
932-
script.write(header("documentation"))
933-
script.write("Script generated with NetPyNE-UI. Please visit:\n")
934-
script.write(" - https://www.netpyne.org\n - https://github.com/MetaCell/NetPyNE-UI\n\n")
935-
script.write(header("script", spacer="="))
936-
script.write("netParams = specs.NetParams()\n")
937-
script.write("simConfig = specs.SimConfig()\n")
938-
script.write(header("single value attributes"))
939-
for attr, value in list(self.netParams.__dict__.items()):
940-
if attr not in params:
941-
if value != getattr(specs.NetParams(), attr):
942-
script.write("netParams." + attr + " = ")
943-
script.write(convert2bool(json.dumps(value, indent=4)) + "\n")
944-
945-
script.write(header("network attributes"))
946-
for param in params:
947-
for key, value in list(getattr(self.netParams, param).items()):
948-
script.write("netParams." + param + "[" + key + "] = ")
949-
script.write(convert2bool(json.dumps(value, indent=4)) + "\n")
950-
951-
script.write(header("network configuration"))
952-
for attr, value in list(self.simConfig.__dict__.items()):
953-
if value != getattr(specs.SimConfig(), attr):
954-
script.write("simConfig." + attr + " = ")
955-
script.write(convert2bool(json.dumps(value, indent=4)) + "\n")
956-
957-
script.write(header("create simulate analyze network"))
958-
script.write("# sim.createSimulateAnalyze(netParams=netParams, simConfig=simConfig)\n")
959-
960-
script.write(header("end script", spacer="="))
917+
from netpyne.conversion import createPythonScript
918+
createPythonScript(fname, self.netParams, self.simConfig)
961919

962920
with open(fname) as f:
963921
file_b64 = base64.b64encode(bytes(f.read(), 'utf-8')).decode()

0 commit comments

Comments
 (0)