Skip to content

Commit f833681

Browse files
authored
Merge pull request #534 from vvbragin/issue/530
#530 use netpyne method for exporting the python script
2 parents 41bdd27 + 1c8dcef commit f833681

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
@@ -938,56 +938,14 @@ def validateFunction(self, functionString):
938938
return validateFunction(functionString, self.netParams.__dict__)
939939

940940
def exportHLS(self, args):
941-
def convert2bool(string):
942-
return string.replace('true', 'True').replace('false', 'False').replace('null', 'False')
943-
944-
def header(title, spacer='-'):
945-
return '\n# ' + title.upper() + ' ' + spacer * (77 - len(title)) + '\n'
946941

947942
try:
948-
params = ['popParams', 'cellParams', 'synMechParams']
949-
params += ['connParams', 'stimSourceParams', 'stimTargetParams']
950-
951-
fname = args['fileName']
952-
if not fname:
953-
# default option
954-
fname = 'output.py'
955-
943+
fname = args.get('fileName', 'output.py')
956944
if not fname[-3:] == '.py':
957945
fname = f"{fname}.py"
958946

959-
# TODO: use methods offered by netpyne to create this script!
960-
with open(fname, 'w') as script:
961-
script.write("from netpyne import specs, sim\n")
962-
script.write(header("documentation"))
963-
script.write("Script generated with NetPyNE-UI. Please visit:\n")
964-
script.write(" - https://www.netpyne.org\n - https://github.com/MetaCell/NetPyNE-UI\n\n")
965-
script.write(header("script", spacer="="))
966-
script.write("netParams = specs.NetParams()\n")
967-
script.write("simConfig = specs.SimConfig()\n")
968-
script.write(header("single value attributes"))
969-
for attr, value in list(self.netParams.__dict__.items()):
970-
if attr not in params:
971-
if value != getattr(specs.NetParams(), attr):
972-
script.write("netParams." + attr + " = ")
973-
script.write(convert2bool(json.dumps(value, indent=4)) + "\n")
974-
975-
script.write(header("network attributes"))
976-
for param in params:
977-
for key, value in list(getattr(self.netParams, param).items()):
978-
script.write("netParams." + param + "[" + key + "] = ")
979-
script.write(convert2bool(json.dumps(value, indent=4)) + "\n")
980-
981-
script.write(header("network configuration"))
982-
for attr, value in list(self.simConfig.__dict__.items()):
983-
if value != getattr(specs.SimConfig(), attr):
984-
script.write("simConfig." + attr + " = ")
985-
script.write(convert2bool(json.dumps(value, indent=4)) + "\n")
986-
987-
script.write(header("create simulate analyze network"))
988-
script.write("# sim.createSimulateAnalyze(netParams=netParams, simConfig=simConfig)\n")
989-
990-
script.write(header("end script", spacer="="))
947+
from netpyne.conversion import createPythonScript
948+
createPythonScript(fname, self.netParams, self.simConfig)
991949

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

0 commit comments

Comments
 (0)