-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtested_script.py
222 lines (164 loc) · 8.5 KB
/
tested_script.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
"""This should set up and run a simple simulation where a granule cell
is stimulated with a number of "on" (10Hz) inputs and a number of
"off" (80Hz) inputs. The inputs are "refractory Poisson" spike trains,
generated with a custom LEMS element. Each input is connected to the
GrC with a synapse that comprises an AMPA and an NMDA component. These
synaptic models are also defined as custom LEMS elements. The GrC
model itself is a conductance-based integrate-and-fire (IaFRefCell
NeuroML2 componentType). The definitions of custom LEMS componentTypes
must be loaded from external files. Some of the components used (both
LEMS and NeuroML) are defined by this script, while others are loaded
from external files.
The simulation that should be created should be the same as that
contained in the 'simulation.xml' file in this folder.
The key thing would be to have an import_lems() function that would
read an external file and return an whose attributes represent all the
top-level components and componentTypes defined in the external
file. In particular, attributes associated to componentTypes should be
callable, consisting essentially in constructors for Python
classes. Like in libneuroml, but defined on the fly from the
information in the external file instead than from the schema. In
other words, import_lems() would work in a way analogous to Python's
'import' statement, knowing how to create classes and other objects
from a LEMS/NeuroML file.
"""
import neuroml as nml
from pyneuroml import pynml
from pyneuroml.lems.LEMSSimulation import LEMSSimulation
import lems.api as lems
display_save_conductances = False
# set parameters controlling the number of "on" and "off" synaptic
# inputs. We do this to show why it is convenient to generate the
# simulation procedurally, rather than writing by hand the LEMS code.
n_inputs_ON = 4
n_inputs_OFF = 4
# load NeuroML components, LEMS components and LEMS componentTypes from external files
spike_generator_file_name = "lemsDefinitions/spikeGenerators.xml"
spike_generator_doc = pynml.read_lems_file(spike_generator_file_name)
###spike_recorder_file_name = "lemsDefinitions/spikeRecorder.xml"
###spike_recorder_doc = pynml.read_lems_file(spike_recorder_file_name)
iaf_nml2_file_name = "lemsDefinitions/IaF_GrC.nml"
iaF_GrC_doc = pynml.read_neuroml2_file(iaf_nml2_file_name)
ampa_syn_filename="lemsDefinitions/RothmanMFToGrCAMPA.xml"
nmda_syn_filename="lemsDefinitions/RothmanMFToGrCNMDA.xml"
rothmanMFToGrCAMPA_doc = pynml.read_lems_file(ampa_syn_filename)
rothmanMFToGrCNMDA_doc = pynml.read_lems_file(nmda_syn_filename)
# define some components from the componentTypes we just loaded
####spike_recorder = spike_recorder_doc.spikeRecorder(id="spikeRecorder")
spike_generator_ref_poisson_type = spike_generator_doc.component_types['spikeGeneratorRefPoisson']
lems_instances_doc = lems.Model()
spike_generator_on = lems.Component("mossySpikerON",
spike_generator_ref_poisson_type.name)
spike_generator_on.set_parameter("minimumISI", "5 ms")
spike_generator_on.set_parameter("averageRate", "80 Hz")
lems_instances_doc.add(spike_generator_on)
spike_generator_off = lems.Component("mossySpikerOFF",
spike_generator_ref_poisson_type.name)
spike_generator_off.set_parameter("minimumISI", "2 ms")
spike_generator_off.set_parameter("averageRate", "8 Hz")
lems_instances_doc.add(spike_generator_off)
# rename some components for convenience
iaF_GrC = iaF_GrC_doc.iaf_ref_cells[0] # note that here iaF_GrC_doc.iaf_ref_cells[0] is
# already a component, not a
# componentType, so it doesn't need to
# be instantiated.
rothmanMFToGrCAMPA = rothmanMFToGrCAMPA_doc.components['RothmanMFToGrCAMPA'].id
rothmanMFToGrCNMDA = rothmanMFToGrCNMDA_doc.components['RothmanMFToGrCNMDA'].id
# create populations
GrCPop = nml.Population(id="GrCPop",
component=iaF_GrC.id,
size=1)
'''
SpikeRecorderPop = nml.Population(id="SpikeRecorderPop",
component="iaF_GrC",
size=1)'''
mossySpikersPopON = nml.Population(id=spike_generator_on.id+"Pop",
component=spike_generator_on.id,
size=n_inputs_ON)
mossySpikersPopOFF = nml.Population(id=spike_generator_off.id+"Pop",
component=spike_generator_off.id,
size=n_inputs_OFF)
# create network and add populations
net = nml.Network(id="network")
net_doc = nml.NeuroMLDocument(id=net.id)
net_doc.networks.append(net)
net.populations.append(GrCPop)
####net.populations.append(SpikeRecordersPop)
net.populations.append(mossySpikersPopON)
net.populations.append(mossySpikersPopOFF)
# set up connections
for stim_pop in [mossySpikersPopON, mossySpikersPopOFF]:
for k in range(stim_pop.size):
for synapse in [rothmanMFToGrCAMPA, rothmanMFToGrCNMDA]:
connection = nml.SynapticConnection(from_="{}[{}]".format(stim_pop.id, k),
synapse=synapse,
to="GrCPop[0]")
net.synaptic_connections.append(connection)
'''
# set up fake connection for counting spikes
net.append(nml.SynapticConnection(from_="GrCPop[0]",
to="SpikeRecorderPop[0]",
synapse=spikeRecorder.id))
'''
# Write network to file
net_file_name = 'generated_network.net.nml'
pynml.write_neuroml2_file(net_doc, net_file_name)
# Write LEMS instances to file
lems_instances_file_name = 'instances.xml'
pynml.write_lems_file(lems_instances_doc, lems_instances_file_name)
# Create a LEMSSimulation to manage creation of LEMS file
duration = 300 # ms
dt = 0.05 # ms
ls = LEMSSimulation("sim", duration, dt)
# Point to network as target of simulation
ls.assign_simulation_target(net.id)
# Include generated/existing NeuroML2 files
ls.include_neuroml2_file(iaf_nml2_file_name)
ls.include_lems_file(spike_generator_file_name, include_included=False)
ls.include_lems_file(lems_instances_file_name)
ls.include_lems_file(ampa_syn_filename, include_included=False)
ls.include_lems_file(nmda_syn_filename, include_included=False)
###ls.include_lems_file(spike_recorder_file_name)
ls.include_neuroml2_file(net_file_name)
# Specify Displays and Output Files
disp0 = "display_voltages"
ls.create_display(disp0, "Voltages", "-95", "-38")
disp1 = "display_spike_generators"
ls.create_display(disp1, "Spike generators", "-10", "80")
of0 = 'Volts_file'
ls.create_output_file(of0, "v.dat")
of_on = 'prespike_on_file'
ls.create_output_file(of_on, "prespike_on.dat")
of_off = 'prespike_off_file'
ls.create_output_file(of_off, "prespike_off.dat")
if display_save_conductances:
disp2 = "display_syn_conductances"
ls.create_display(disp2, "Synaptic conductances", "-1", "1")
of2 = 'conds_file'
ls.create_output_file(of2, "syncond.dat")
quantity = "%s[%i]/v"%(GrCPop.id, 0)
ls.add_line_to_display(disp0, "GrC: Vm", quantity, "1mV", "#66c2a5")
ls.add_column_to_output_file(of0, 'v0', quantity)
if display_save_conductances:
quantity = "%s[%i]/RothmanMFToGrCAMPA/g"%(GrCPop.id, 0)
ls.add_line_to_display(disp2, "GrC: AMPA g", quantity, "1mV", "#66c2a5")
ls.add_column_to_output_file(of2, 'AMPAg', quantity)
quantity = "%s[%i]/RothmanMFToGrCNMDA/g"%(GrCPop.id, 0)
ls.add_line_to_display(disp2, "GrC: NMDA g", quantity, "1mV", "#FF0000")
ls.add_column_to_output_file(of2, 'NMDA', quantity)
for i in range(n_inputs_ON):
quantity = "%s[%i]/tsince"%(mossySpikersPopON.id, i)
ls.add_line_to_display(disp1, "mossySpikersPopON %i"%i, quantity, "1ms", "#000000")
ls.add_column_to_output_file(of_on, 'tsince', quantity)
for i in range(n_inputs_OFF):
quantity = "%s[%i]/tsince"%(mossySpikersPopOFF.id, i)
ls.add_line_to_display(disp1, "mossySpikersPopOFF %i"%i, quantity, "1ms", "#FF0000")
ls.add_column_to_output_file(of_off, 'tsince', quantity)
# Save to LEMS XML file
lems_file_name = ls.save_to_file()
# Run with jNeuroML
results1 = pynml.run_lems_with_jneuroml(lems_file_name, nogui=True, load_saved_data=True, plot=True)
'''
# Run with jNeuroML_NEURON
'''
results2 = pynml.run_lems_with_jneuroml_neuron(lems_file_name, nogui=True, load_saved_data=True, plot=True)