forked from robban80/striatal_SPN_lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodulation_lib.py
556 lines (468 loc) · 21.4 KB
/
modulation_lib.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
#import numpy as np
from neuron import h
import common_functions as cf
class DA():
'''
class for setting DA modulation of cell.
arguments:
cell = cell object to modulate
mod_dict = dict with chan:factor pairs
additional arguments carries default behavior of modulation.
The 'naf', 'kas', 'kir', 'cal12','cal13','can' and 'car channels are reported to be modulated by DA in dspn. Aditionally the car channel is modulated in ispn.
By default the AIS is not modulated, since this was found to increase chance of positive modulation in dspn.
---OBS. if uniform modulation is wanted this has to be stated!!!!
Modulation has in some channel(s?) been reported to be a shift in gating. This is not
implemented for DA (but see ACh class for example).
Modulation can be set individually for gaba, glut and intrinsic.
by default all are used.
The _reset_mod method can be used to turn of modulation.
'''
def __init__(self, cell, mod_dict,
modulation='noAxon',
intrinsic_mod=1,
gaba_mod=1,
glut_mod=1,
play=[],
syn_dict={},
dt=0.025
):
self.cell = cell
self.mod_dict = mod_dict
self.syn_dict = syn_dict
self.play = play
self.dt = dt
if modulation == 'uniform':
self.compartments = [cell.dendlist, cell.somalist, cell.axonlist]
elif modulation == 'noAxon':
self.compartments = [cell.dendlist, cell.somalist]
else: raise Exception('Error, "{}" modulation, not permitted\n\tuse "uniform" or "noAxon"'.format(modulation))
self._set_modulation( intrinsic_mod,
gaba_mod,
glut_mod
)
def _set_modulation(self,
intrinsic_mod,
gaba_mod,
glut_mod):
for comp in self.compartments:
for sec in comp:
for seg in sec:
if intrinsic_mod: self._update_conductance(seg)
if gaba_mod: self._set_gaba(seg)
if glut_mod: self._set_glut(seg)
def _update_conductance(self, seg, reset=0):
for mech in seg:
if mech.name() in self.mod_dict:
# set shift
mech.damod = 1
mech.maxMod = self.mod_dict[mech.name()]
if reset:
mech.level = 0
elif len(self.play) and mech.name() in self.play:
self.play[mech.name()].play(mech._ref_level, self.dt)
else:
mech.level = 1
def _set_gaba(self, seg, reset=0):
for syn in seg.point_processes():
if 'gaba' in syn.hname():
syn.damod = 1
syn.maxMod = self.syn_dict['GABA']
if reset:
syn.level = 0
elif len(self.play) and 'gaba' in self.play:
self.play['gaba'].play(syn._ref_level, self.dt)
else:
syn.level = 1
def _set_glut(self, seg, reset=0):
for syn in seg.point_processes():
if 'glut' in syn.hname():
syn.damod = 1
syn.maxModNMDA = self.syn_dict['NMDA']
syn.maxModAMPA = self.syn_dict['AMPA']
if reset:
syn.l1AMPA = 0; syn.l1NMDA = 0
elif len(self.play) and 'glut' in self.play:
self.play['glut'].play(syn._ref_l1NMDA, self.dt)
self.play['glut'].play(syn._ref_l1AMPA, self.dt)
else:
syn.l1AMPA = 1; syn.l1NMDA = 1
def _reset_mod(self):
if len(self.play):
for trans in self.play.values():
trans.play_remove()
for comp in self.compartments:
for sec in comp:
for seg in sec:
self._update_conductance(seg, reset=1)
self._set_glut(seg, reset=1)
self._set_gaba(seg, reset=1)
class ACh():
'''
class for setting ACh modulation of cell.
arguments:
cell = cell object to modulate
mod_dict = dict with chan:factor pairs
additional arguments carries default behavior of modulation.
The 'naf', 'kir','cal12','cal13','can' and 'im' channels are reported to be modulated by ACh.
Additionally "kaf" is (by default) shifted 20 mv more negative
Modulation can be set individually for gaba, glut, intrinsic and kaf shift.
by default all are used.
'''
def __init__(self, cell, mod_dict,
modulation='uniform',
intrinsic_mod=1,
shift_kaf=1,
gaba_mod=1,
glut_mod=1,
mv_shift_kaf=20,
syn_dict={},
play=[],
dt=0.025
):
self.cell = cell
self.mod_dict = mod_dict
self.mv_shift_kaf = mv_shift_kaf
self.syn_dict = syn_dict
self.play = play
self.dt = dt
if modulation == 'uniform':
self.compartments = [cell.dendlist, cell.somalist, cell.axonlist]
elif modulation == 'noAxon':
self.compartments = [cell.dendlist, cell.somalist]
else: raise Exception('Error, "{}" modulation, not permitted\n\tuse "uniform" or "noAxon"'.format(modulation))
self._set_modulation( intrinsic_mod,
shift_kaf,
gaba_mod,
glut_mod
)
def _set_modulation(self,
intrinsic_mod,
shift_kaf,
gaba_mod,
glut_mod):
for comp in self.compartments:
for sec in comp:
for seg in sec:
if intrinsic_mod: self._update_conductance(seg)
if shift_kaf: self._shift_kaf(seg)
if gaba_mod: self._set_gaba(seg)
if glut_mod: self._set_glut(seg)
def _update_conductance(self, seg, reset=0):
for mech in seg:
if mech.name() in self.mod_dict:
# set shift
mech.damod = 1
mech.max2 = self.mod_dict[mech.name()]
if reset:
mech.lev2 = 0
if len(self.play) and mech.name() in self.play:
self.play[mech.name()].play(mech._ref_lev2, self.dt) # ._ref_
else:
mech.lev2 = 1
def _shift_kaf(self, seg, reset=0):
for mech in seg:
if mech.name() == 'kaf':
# set shift
if reset:
mech.modShift = 0
elif len(self.play) and 'kaf' in self.play:
self.play['kaf'].play(mech._ref_modShift, self.dt) # ._ref_
else:
mech.modShift = self.mv_shift_kaf
def _set_gaba(self, seg, reset=0):
for syn in seg.point_processes():
if 'gaba' in syn.hname():
syn.damod = 1
syn.max2 = self.syn_dict['GABA']
if reset:
syn.lev2 = 0
elif len(self.play) and 'gaba' in self.play:
self.play['gaba'].play(syn._ref_lev2, self.dt) # ._ref_
else:
syn.lev2 = 1
def _set_glut(self, seg, reset=0):
for syn in seg.point_processes():
if 'glut' in syn.hname():
syn.damod = 1
syn.max2NMDA = self.syn_dict['NMDA']
syn.max2AMPA = self.syn_dict['AMPA']
if reset:
syn.l2AMPA = 0
syn.l2NMDA = 0
elif len(self.play) and 'glut' in self.play:
self.play['glut'].play(syn._ref_l2NMDA, self.dt) # ._ref_
self.play['glut'].play(syn._ref_l2AMPA, self.dt) # ._ref_
else:
syn.l2AMPA = 1
syn.l2NMDA = 1
def _reset_mod(self):
if len(self.play):
for trans in self.play.values():
trans.play_remove()
for comp in self.compartments:
for sec in comp:
for seg in sec:
self._shift_kaf(seg, reset=1)
self._update_conductance(seg, reset=1)
self._set_glut(seg, reset=1)
self._set_gaba(seg, reset=1)
class set_ACh():
'''
Class for setting cholinergic modulation of the cell. The 'naf', 'kir',
'cal12','cal13','can' and 'im' channels are reported to be modulated by
ACh. Additionally "kaf" is shifted to a more negative voltage.
'''
def __init__(self, cell,
mod_dict,
target = ['all'],
target_x = 'all',
play=[],
shift_kaf = 5,
dt=0.025):
'''
Class initialisation and modulation of cell.
INPUT(S):
- cell: cell to modulate [MSN object]
- mod_dict: mechanism:modulation value pairs [dict]
- target: section(s) of cell to modulate (default all sections)
[list of section names]
- target_x: segment of section(s) to modulate (default: all
segments). Can specify a specific segment as a number (e.g. 0.5
to modulate the middle segment) [str or number]
- play: key:value pairs containing time-specific scaling of each
mechanism's modulation (default: 1*scaling of modulation
throughout the simulation). Specify time-dependent modulation
as a hoc vector in which the value of vector[t/dt] == scaling
of modulation at time t in the simulation (see h.Vector.play
documentation for more information) [dict of h.Vector(s)]
- shift_kaf: voltage by which the mechanism 'kaf' is shifted * -1
(i.e. default: shift_kaf = 10 -> kaf shifted -10 mV). If 'play'
is given and contains a 'kaf' key, 'shift_kaf' is ignored in
favour of that specified by 'play' [number]
==== N.B. the 'kaf' scaling in 'play' (if given) should follow
this same logic (i.e. for a voltage shift from 0 mV at time
t to -10 mV at time t+1, play['kaf'][t/dt] == 0 and
play['kaf'][t+1/dt] == 10)
- dt: size of the time step in the simulation used for determining
when to apply modulation scaling associated with 'play'
(default: 0.025; units of ms) [number]
OUTPUT(S):
None
Thomas Binns (modified), 30/01/21
'''
# checks for appropriate inputs
if isinstance(target_x,str):
if target_x != 'all':
raise ValueError("The requested segment target '{}' is not recognised.\nThis should be 'all' or a number, e.g. 0.5.".format(target_x))
# assigns values to class
self.cell = cell
self.mod_dict = mod_dict
self.target = target
self.target_x = target_x
self.play = play
self.shift_kaf = shift_kaf
self.dt = dt
# gets targets for modulation
if 'all' in self.target:
self.target = [str(x) for x in self.cell.allseclist]
# performs modulation of cell
self._set_modulation()
def _set_modulation(self):
'''
Modulates the requested segments of the requested sections.
'''
for tar in self.target:
for sec in self.cell.allseclist:
if sec.name() == tar:
if self.target_x == 'all':
for seg in sec:
self._mod_mech(seg)
self._mod_chan(seg)
else:
self._mod_mech(sec(self.target_x))
self._mod_chan(sec(self.target_x))
def _mod_mech(self, seg, reset=False): # shift conductance
'''
Modulates kaf and other mechanisms (but not GABA, NMDA, or AMPA).
'''
for mech in seg:
if mech.name() in self.mod_dict:
if mech.name() == 'kaf': # shift kaf
if reset:
mech.modShift = 0
elif len(self.play) and 'kaf' in self.play:
self.play['kaf'].play(mech._ref_modShift, self.dt)
else:
mech.modShift = self.shift_kaf
else: # apply other mechanism conductance changes
mech.damod = 1
mech.max2 = self.mod_dict[mech.name()]
if reset:
mech.lev2 = 0
if len(self.play) and mech.name() in self.play:
self.play[mech.name()].play(mech._ref_lev2, self.dt)
else:
mech.lev2 = 1
def _mod_chan(self, seg, reset=False):
'''
Modulates GABA, NMDA, and AMPA mechanisms.
'''
for syn in seg.point_processes(): # modulate channels if applicable
if 'gaba' in syn.hname() and 'GABA' in self.mod_dict:
syn.damod = 1
syn.max2 = self.mod_dict['GABA']
if reset:
syn.lev2 = 0
elif len(self.play) and 'GABA' in self.play:
self.play['GABA'].play(syn._ref_lev2, self.dt)
else:
syn.lev2 = 1
elif 'glut' in syn.hname()and 'GLUT' in self.mod_dict:
syn.damod = 1
syn.max2NMDA = self.mod_dict['NMDA']
syn.max2AMPA = self.mod_dict['AMPA']
if reset:
syn.l2AMPA = 0
syn.l2NMDA = 0
elif len(self.play) and 'NMDA' in self.play() and 'AMPA' in self.play:
self.play['NMDA'].play(syn._ref_l2NMDA, self.dt)
self.play['AMPA'].play(syn._ref_l2AMPA, self.dt)
else:
syn.l2AMPA = 1
syn.l2NMDA = 1
def _reset_mod(self):
'''
Reverses modulation to return cell status to normal.
'''
if len(self.play):
for trans in self.play.values():
trans.play_remove()
for tar in self.target:
for sec in self.cell.allseclist:
if sec.name() == tar:
self._mod_mech(sec(self.target_x), reset=True)
self._mod_chan(sec(self.target_x), reset=True)
class set_DA():
'''
Class for setting dopaminergic modulation of the cell.
'''
def __init__(self, cell,
mod_dict,
target = ['all'],
target_x = 'all',
play=[],
dt=0.025):
'''
Class initialisation and modulation of cell.
INPUT(S):
- cell: cell to modulate [MSN object]
- mod_dict: mechanism:modulation value pairs [dict]
- target: section(s) of cell to modulate (default all sections)
[list of section names]
- target_x: segment of section(s) to modulate (default: all
segments). Can specify a specific segment as a number (e.g. 0.5
to modulate the middle segment) [str or number]
- play: key:value pairs containing time-specific scaling of each
mechanism's modulation (default: 1*scaling of modulation
throughout the simulation). Specify time-dependent modulation
as a hoc vector in which the value of vector[t/dt] == scaling
of modulation at time t in the simulation (see h.Vector.play
documentation for more information) [dict of h.Vector(s)]
- shift_kaf: voltage by which the mechanism 'kaf' is shifted * -1
(i.e. default: shift_kaf = 10 -> kaf shifted -10 mV). If 'play'
is given and contains a 'kaf' key, 'shift_kaf' is ignored in
favour of that specified by 'play' [number]
==== N.B. the 'kaf' scaling in 'play' (if given) should follow
this same logic (i.e. for a voltage shift from 0 mV at time
t to -10 mV at time t+1, play['kaf'][t/dt] == 0 and
play['kaf'][t+1/dt] == 10)
- dt: size of the time step in the simulation used for determining
when to apply modulation scaling associated with 'play'
(default: 0.025; units of ms) [number]
OUTPUT(S):
None
Thomas Binns (modified), 30/01/21
'''
# checks for appropriate inputs
if isinstance(target_x,str):
if target_x != 'all':
raise ValueError("The requested segment target '{}' is not recognised.\nThis should be 'all' or a number, e.g. 0.5.".format(target_x))
# assigns values to class
self.cell = cell
self.mod_dict = mod_dict
self.target = target
self.target_x = target_x
self.play = play
self.dt = dt
# gets targets for modulation
if 'all' in self.target:
self.target = [str(x) for x in self.cell.allseclist]
# performs modulation of cell
self._set_modulation()
def _set_modulation(self):
'''
Modulates the requested segments of the requested sections.
'''
for tar in self.target:
for sec in self.cell.allseclist:
if sec.name() == tar:
if self.target_x == 'all':
for seg in sec:
self._mod_mech(seg)
self._mod_chan(seg)
else:
self._mod_mech(sec(self.target_x))
self._mod_chan(sec(self.target_x))
def _mod_mech(self, seg, reset=False): # shift conductance
'''
Modulates mechanisms (but not GABA, NMDA, or AMPA).
'''
for mech in seg:
if mech.name() in self.mod_dict:
mech.damod = 1
mech.maxMod = self.mod_dict[mech.name()]
if reset:
mech.level = 0
if len(self.play) and mech.name() in self.play:
self.play[mech.name()].play(mech._ref_level, self.dt)
else:
mech.level = 1
def _mod_chan(self, seg, reset=False):
'''
Modulates GABA, NMDA, and AMPA mechanisms.
'''
for syn in seg.point_processes(): # modulate channels if applicable
if 'gaba' in syn.hname() and 'GABA' in self.mod_dict:
syn.damod = 1
syn.maxMod = self.mod_dict['GABA']
if reset:
syn.level = 0
elif len(self.play) and 'GABA' in self.play:
self.play['GABA'].play(syn._ref_level, self.dt)
else:
syn.level = 1
elif 'glut' in syn.hname()and 'GLUT' in self.mod_dict:
syn.damod = 1
syn.maxModNMDA = self.mod_dict['NMDA']
syn.maxModAMPA = self.mod_dict['AMPA']
if reset:
syn.l1AMPA = 0
syn.l1NMDA = 0
elif len(self.play) and 'NMDA' in self.play() and 'AMPA' in self.play:
self.play['NMDA'].play(syn._ref_l1NMDA, self.dt)
self.play['AMPA'].play(syn._ref_l1AMPA, self.dt)
else:
syn.l1AMPA = 1
syn.l1NMDA = 1
def _reset_mod(self):
'''
Reverses modulation to return cell status to normal.
'''
if len(self.play):
for trans in self.play.values():
trans.play_remove()
for tar in self.target:
for sec in self.cell.allseclist:
if sec.name() == tar:
self._mod_mech(sec(self.target_x), reset=True)
self._mod_chan(sec(self.target_x), reset=True)