Skip to content

Commit b561ad0

Browse files
author
Facu_r
authored
Merge branch 'development' into load_json_model
2 parents f83fef6 + 5309c24 commit b561ad0

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,57 @@ def deleteParam(self, paramToDel):
440440

441441
def validateFunction(self, functionString):
442442
return utils.ValidateFunction(functionString, netParams.__dict__)
443-
444443

444+
def generateScript(self, metadata):
445+
def convert2bool(string):
446+
return string.replace('true', 'True').replace('false', 'False')
447+
448+
def header(title, spacer='-'):
449+
return '\n# ' + title.upper() + ' ' + spacer*(77-len(title)) + '\n'
450+
451+
try :
452+
params = ['popParams' , 'cellParams', 'synMechParams']
453+
params += ['connParams', 'stimSourceParams', 'stimTargetParams']
454+
455+
fname = metadata['scriptName'] if metadata['scriptName'][-3:]=='.py' else metadata['scriptName']+'.py'
456+
457+
with open(fname, 'w') as script:
458+
script.write('from netpyne import specs, sim\n')
459+
script.write(header('documentation'))
460+
script.write("''' Script generated with NetPyNE-UI. Please visit:\n")
461+
script.write(" - https://www.netpyne.org\n - https://github.com/MetaCell/NetPyNE-UI\n'''\n")
462+
script.write(header('script', spacer='='))
463+
script.write('netParams = specs.NetParams()\n')
464+
script.write('simConfig = specs.SimConfig()\n')
465+
script.write(header('single value attributes'))
466+
for attr, value in netParams.__dict__.items():
467+
if attr not in params:
468+
if value!=getattr(specs.NetParams(), attr):
469+
script.write('netParams.' + attr + ' = ')
470+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
471+
472+
script.write(header('network attributes'))
473+
for param in params:
474+
for key, value in getattr(netParams, param).items():
475+
script.write("netParams." + param + "['" + key + "'] = ")
476+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
477+
478+
script.write(header('network configuration'))
479+
for attr, value in simConfig.__dict__.items():
480+
if value!=getattr(specs.SimConfig(), attr):
481+
script.write('netParams.' + attr + ' = ')
482+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
483+
484+
script.write(header('create simulate analyze network'))
485+
script.write('sim.createSimulateAnalyze(netParams=netParams, simConfig=simConfig)\n')
486+
487+
script.write(header('end script', spacer='='))
488+
489+
return self.getJSONReply()
490+
491+
except:
492+
return self.getJSONError("Error while importing the NetPyNE model", traceback.format_exc())
493+
445494
class LoopTimer(threading.Thread):
446495
"""
447496
a Timer that calls f every interval

0 commit comments

Comments
 (0)