-
Notifications
You must be signed in to change notification settings - Fork 0
/
importer.py
82 lines (65 loc) · 2.12 KB
/
importer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import lems.api as lems
m = lems.Model()
INCLUDE_DIRECTORY = ''
if not os.path.isdir(INCLUDE_DIRECTORY):
raise ImportError('Set INCLUDE_DIRECTORY to the NeuroML2/NeuroML2CoreTypes directory')
m.add_include_directory(INCLUDE_DIRECTORY)
def getComponents(Model):
return Model.components
def getParameters(Component):
return Component.parameters
def getDynamics(ComponentType):
return ComponentType.dynamics
def getExposures(ComponentType):
return ComponentType.exposures
def getChildren(ComponentType):
return ComponentType.children
def getTimederivatives(Dynamics):
return Dynamics.time_derivatives
def getRegimes(Dynamics):
return Dynamics.regimes
def getStatevariables(Dynamics):
return Dynamics.state_variables
def getDerivedvaribales(Dynamics):
return Dynamics.derived_variables
def getEventhandlers(Dynamics):
return Dynamics.event_handlers
def tobrian(filepath):
s = ""
m.import_from_file(filepath)
comp = getComponents(m)
for c in comp:
name_space = "{"
params = getParameters(c)
first = True
for p in params:
if(first!=True):
name_space+=", "
name_space+="'" + p + "' : " + params.get(p)
first=False
name_space+= "}"
ct = m.component_types[c.type]
dyn = getDynamics(ct)
svs = getStatevariables(dyn)
tds = getTimederivatives(dyn)
eqs = "Equations('''\n"
if(tds):
for t in tds:
eqs+=" d" + t.variable + "/dt = " + t.value + " : " + "\n"
rgs = getRegimes(dyn)
for r in rgs:
rtds = getTimederivatives(r)
if(rtds):
for rt in rtds:
eqs+=" d" + rt.variable + "/dt = " + rt.value + "\n"
dvs = getDerivedvaribales(dyn)
for d in dvs:
if(d.value):
eqs+= " " + d.name + " = "
eqs+=d.value + "\n"
eqs+="''')"
size = 1
G = "NeuronGroup( 1" + ", model = " + eqs + ", namespace = " + name_space + ")\n"
print G
tobrian('LEMS_NML2_Ex0_IaF.xml')