-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathneuroml2_spec.py
205 lines (154 loc) · 5.54 KB
/
neuroml2_spec.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import modelspec
from modelspec import field, instance_of, optional
from modelspec.base_types import Base
from typing import List
import sys
# Example showing ...
@modelspec.define
class population(Base):
"""
Some description...
Args:
id: The id of the population
component: the component to use in the population
size: the size of the population
"""
id: str = field(validator=instance_of(str))
component: str = field(default=None, validator=optional(instance_of(str)))
size: int = field(default=None, validator=optional(instance_of(int)))
@modelspec.define
class explicitInput(Base):
"""
Some description...
Args:
target: the target of the input
input: the input, e.g. pulseGenerator
"""
target: str = field(default=None, validator=optional(instance_of(str)))
input: str = field(default=None, validator=optional(instance_of(str)))
@modelspec.define
class network(Base):
"""
Some description...
Args:
id: The id of the network
populations: the pops in the net
"""
id: str = field(validator=instance_of(str))
populations: List[population] = field(factory=list)
explicitInputs: List[explicitInput] = field(factory=list)
@modelspec.define
class pulseGenerator(Base):
"""
Some description...
Args:
id: The id of the pulseGenerator
delay: the delay
duration: the duration
amplitude: the amplitude
"""
id: str = field(validator=instance_of(str))
delay: str = field(validator=instance_of(str))
duration: str = field(validator=instance_of(str))
amplitude: str = field(validator=instance_of(str))
@modelspec.define
class izhikevich2007Cell(Base):
"""
Some description...
Args:
id: The id of the cell...
"""
id: str = field(validator=instance_of(str))
C: str = field(validator=instance_of(str))
v0: str = field(validator=instance_of(str))
k: str = field(validator=instance_of(str))
vr: str = field(validator=instance_of(str))
vt: str = field(validator=instance_of(str))
vpeak: str = field(validator=instance_of(str))
a: str = field(validator=instance_of(str))
b: str = field(validator=instance_of(str))
c: str = field(validator=instance_of(str))
d: str = field(validator=instance_of(str))
@modelspec.define
class neuroml(Base):
"""
Some description...
Args:
id: The id of the NeuroML 2 document
xmlns: Default namespace for the NeuroML file, usually http://www.neuroml.org/schema/neuroml2
xmlns_xsi: Namespace for XMLSchema-instance
xmlns_loc: Specifies location of the main namespace
izhikevich2007Cells: The izhikevich2007Cells
pulseGenerators: The pulse current generators
networks: The networks present
"""
id: str = field(validator=instance_of(str))
xmlns: str = field(
validator=instance_of(str), default="http://www.neuroml.org/schema/neuroml2"
)
xmlns_xsi: str = field(
validator=instance_of(str), default="http://www.w3.org/2001/XMLSchema-instance"
)
xmlns_loc: str = field(
validator=instance_of(str),
default="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.3.xsd",
)
izhikevich2007Cells: List[izhikevich2007Cell] = field(factory=list)
pulseGenerators: List[pulseGenerator] = field(factory=list)
networks: List[network] = field(factory=list)
if __name__ == "__main__":
nml_doc = neuroml(id="TestNeuroML")
izh = izhikevich2007Cell(
id="izh2007RS0",
C="100pF",
v0="-60mV",
k="0.7nS_per_mV",
vr="-60mV",
vt="-40mV",
vpeak="35mV",
a="0.03per_ms",
b="-2nS",
c="-50.0mV",
d="100pA",
)
nml_doc.izhikevich2007Cells.append(izh)
pg = pulseGenerator(
id="pulseGen_0", delay="100ms", duration="800ms", amplitude="0.07 nA"
)
nml_doc.pulseGenerators.append(pg)
net = network(id="IzNet")
nml_doc.networks.append(net)
net.populations.append(population("IzhPop0", component="izh2007RS0", size=1))
net.explicitInputs.append(explicitInput(target="IzhPop0[0]", input="pulseGen_0"))
print(nml_doc)
print(nml_doc.id)
nml_doc.to_json_file("%s.json" % nml_doc.id)
nml_doc.to_yaml_file("%s.yaml" % nml_doc.id)
print(" >> Full document details in YAML format:\n")
print(nml_doc.to_yaml())
nml_doc.to_bson_file("%s.bson" % nml_doc.id)
if sys.version_info >= (3, 8):
nml_doc.to_xml_file("%s.xml" % nml_doc.id)
print(" >> Full document details in XML format:\n")
print(nml_doc.to_xml())
print("Generating documentation...")
doc_md = nml_doc.generate_documentation(format="markdown")
with open("NeuroML2.md", "w") as d:
d.write(doc_md)
doc_rst = nml_doc.generate_documentation(format="rst")
with open("NeuroML2.rst", "w") as d:
d.write(doc_rst)
print("\n >> Generating specification in dict form...")
doc_dict = nml_doc.generate_documentation(format="dict")
import json
import yaml
with open("NeuroML2.specification.json", "w") as d:
d.write(json.dumps(doc_dict, indent=4))
print(" >> Generating specification in YAML...\n")
with open("NeuroML2.specification.yaml", "w") as d:
yy = yaml.dump(doc_dict, indent=4, sort_keys=False)
# print(yy)
d.write(yy)
from modelspec.utils import load_xml
new_neuroml = load_xml("hello_world_neuroml.net.nml")
print(new_neuroml)