Skip to content

Commit da81217

Browse files
author
facu.r
committed
generate NetPyNE script from GUI state
1 parent bcceb9a commit da81217

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,55 @@ def deleteParam(self, paramToDel):
401401
def validateFunction(self, functionString):
402402
return utils.ValidateFunction(functionString, netParams.__dict__)
403403

404+
def generateScript(self, metadata):
405+
def convert2bool(string):
406+
return string.replace('true', 'True').replace('false', 'False')
407+
408+
def header(title):
409+
sep = (76-len(title))//2
410+
return '\n# ' + '-'*sep + ' ' + title.upper() + ' ' + '-'*sep + '\n'
411+
412+
try :
413+
params = ['popParams' , 'cellParams', 'synMechParams']
414+
params += ['connParams', 'stimSourceParams', 'stimTargetParams']
415+
416+
with open(metadata['scriptName']+'.py', 'w') as script:
417+
script.write('from netpyne import specs, sim\n')
418+
script.write(header('documentation '))
419+
script.write("''' Script generated with NetPyNE-UI. Please visit:\n")
420+
script.write(" - https://www.netpyne.org\n - https://github.com/MetaCell/NetPyNE-UI\n'''\n")
421+
script.write(header('script'))
422+
script.write('netParams = specs.NetParams()\n')
423+
script.write('simConfig = specs.SimConfig()\n')
424+
script.write(header('single value attributes'))
425+
for attr, value in netParams.__dict__.items():
426+
if attr not in params:
427+
if value!=getattr(specs.NetParams(), attr):
428+
script.write('netParams.' + attr + ' = ')
429+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
430+
431+
script.write(header('network attributes'))
432+
for param in params:
433+
for key, value in getattr(netParams, param).items():
434+
script.write("netParams." + param + "['" + key + "'] = ")
435+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
436+
437+
script.write(header('network configuration'))
438+
for attr, value in simConfig.__dict__.items():
439+
if value!=getattr(specs.SimConfig(), attr):
440+
script.write('netParams.' + attr + ' = ')
441+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
442+
443+
script.write(header('create simulate analyze network'))
444+
script.write('sim.createSimulateAnalyze(netParams=netParams, simConfig=simConfig)\n')
445+
446+
script.write(header('end script'))
447+
448+
return self.getJSONReply()
449+
450+
except:
451+
return self.getJSONError("Error while importing the NetPyNE model", traceback.format_exc())
452+
404453
class LoopTimer(threading.Thread):
405454
"""
406455
a Timer that calls f every interval

0 commit comments

Comments
 (0)