forked from robban80/striatal_SPN_lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_network_models_add_spines.py
196 lines (132 loc) · 5.7 KB
/
example_network_models_add_spines.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
#
'''
Example script showing how to run network models outside of BluePyOpt.
Models are optained from Hjorth et al., 2020 (PNAS)
--------------------------------------------------------------------------------------
The models use uniform channel distribution in the dendrites due to earlier bug.
Implementation of conversion done by:
Robert Lindroos (RL) <robert.lindroos at ki.se>
Optimized models and original framework by:
Alexander Kozlov (AK) <akozlov at kth.se>
'''
from __future__ import print_function, division
from neuron import h
import glob, json, pickle
import numpy as np
import CELL_builder_netw as build
import Add_spine as spine
#import common_functions as use
# Load model mechanisms
import neuron as nrn
nrn.load_mechanisms('./mechanisms/network/')
h.load_file('stdlib.hoc')
h.load_file('import3d.hoc')
# TODO: add chin and lts?
cells_dirs = {
'dspn': [
'str-dspn-e150917_c10_D1-mWT-P270-20-v20190521',
'str-dspn-e150917_c6_D1-m21-6-DE-v20190503',
'str-dspn-e150602_c1_D1-mWT-0728MSN01-v20190508',
'str-dspn-e150917_c9_d1-mWT-1215MSN03-v20190521'
],
'ispn': [
'str-ispn-e150917_c11_D2-mWT-MSN1-v20190603',
'str-ispn-e160118_c10_D2-m46-3-DE-v20190529',
'str-ispn-e150908_c4_D2-m51-5-DE-v20190611',
'str-ispn-e151123_c1_D2-mWT-P270-09-v20190527'
]
}
ffactor = 1.05
sps = 10
N = 40.0
# main ==================================================================================
def main( cell_type=None,
mdl_ID=0 ):
modeldir = './Striatal_network_models/{}/{}'.format(cell_type, cells_dirs[cell_type][mdl_ID])
par = '{}/parameters_with_modulation.json'.format(modeldir)
mech = '{}/mechanisms.json'.format(modeldir)
protocols = '{}/protocols.json'.format(modeldir)
morphology = glob.glob(modeldir+'/*.swc')[0] # ONLY 1 swc file / model allowed.
# initiate cell
cell = build.CELL( params=par,
mechanisms=mech,
morphology=morphology,
replace_axon=True,
N=40.0,
ffactor=ffactor )
# ADD SPINES----
SPINES = {}
ID = 0
for sec in cell.dendlist:
SPINES[sec.name()] = {}
for i,seg in enumerate(sec):
for j in range(10):
SPINES[sec.name()][ID] = spine.Spine(h,sec,seg.x)
ID += 1
print(ID)
#return [1,1]
#h.topology()
# THIS PART IS OPTIONAL oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
# set input here
# set current injection
with open(protocols) as file:
prot = json.load(file)
# select first spiking prot
all_keys = sorted(prot.keys())
key = all_keys[0]
i=1
while 'sub' in key:
key = all_keys[i]
i += 1
print(key)
stim = h.IClamp(0.5, sec=cell.soma)
s0 = h.IClamp(0.5, sec=cell.soma)
for stim_prot, stimuli, j in zip(prot[key]['stimuli'], [stim,s0], [0,1]):
stimuli.amp = stim_prot['amp']
stimuli.delay = [200,0][j]
stimuli.dur = stim_prot['duration']
# oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
# record vectors: set recordings here
tm = h.Vector()
tm.record(h._ref_t)
vm = h.Vector()
vm.record(cell.soma(0.5)._ref_v)
tstop = 600 # sim time (ms)
h.finitialize(cell.v_init)
# run simulation
while h.t < tstop:
h.fadvance()
# save output ------------------------------------------------------------------------
time = tm.to_python()
voltage = vm.to_python()
return [time, voltage]
# Start the simulation and save results
if __name__ == "__main__":
res = {}
cell_types = ['dspn','ispn']
# model id's. 4 for each spn
for cell_type in cell_types:
res[cell_type] = {}
for mdl_ID in range(4):
print(cells_dirs[cell_type][mdl_ID])
res[cell_type][mdl_ID] = main( mdl_ID=mdl_ID,
cell_type=cell_type )
# save traces
save_dict = {'time': res[cell_type][mdl_ID][0]}
for key,item in res.items():
save_dict[key] = {}
for k,trace in item.items():
save_dict[key][k] = trace[1]
# UNCOMMENT TO SAVE
with open('val_spine_{}sps_N{:0.0f}_ffactor{}.json'.format(sps, N, ffactor), 'w') as outfile:
json.dump(save_dict, outfile)
# plot
import matplotlib.pyplot as plt
fig,ax = plt.subplots(2,1)
for i,cell_type in enumerate(cell_types):
for mdl_ID in range(4):
t = res[cell_type][mdl_ID][0]
v = res[cell_type][mdl_ID][1]
ax[i].plot(t,v, 'k')
ax[i].set_ylim([-90,40])
plt.show()