-
Notifications
You must be signed in to change notification settings - Fork 0
/
hvc.py
233 lines (201 loc) · 7.78 KB
/
hvc.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
from dataclasses import dataclass
import numpy as np
from brian2 import *
import json
@dataclass
class Parameters:
"""
defining common parameter values for different hvc neuron types
"""
def __init__(neuron) -> None:
"""
Constructor for defining constant values
"""
neuron.Vl = -70*mV
neuron.Vk = -90*mV
neuron.VNa = 50*mV
neuron.Vh = -30*mV
neuron.g_l = 2*nS
neuron.g_Cal = 19*nS
neuron.g_Nap = 1*nS
neuron.tau_bar_n = 10*msecond
neuron.tau_bar_hp = 1_000*msecond
neuron.tau_e = 20*msecond
neuron.tau_h = 1*msecond
neuron.tau_rs = 1_500*msecond
neuron.tau_r0 = 200*msecond
neuron.tau_r1 = 87.5*msecond
neuron.theta_m = -35*mV
neuron.theta_n = -30*mV
neuron.theta_s = -20*mV
neuron.theta_mp = -40*mV
neuron.theta_hp = -48*mV
neuron.theta_a = -20*mV
neuron.theta_e = -60*mV
neuron.theta_rf = -105*mV
neuron.theta_rs = -105*mV
neuron.theta_at = -65*mV
neuron.theta_b = 0.4*mV
neuron.theta_rt = -67*mV
neuron.theta_rrt = 68*mV
neuron.sigma_m = -5*mV
neuron.sigma_n = -5*mV
neuron.sigma_s = -0.05*mV
neuron.sigma_mp = -6*mV
neuron.sigma_hp = 6*mV
neuron.sigma_a = -10*mV
neuron.sigma_e = 5*mV
neuron.sigma_rf = 5*mV
neuron.sigma_rs = 25*mV
neuron.sigma_at = -7.8*mV
neuron.sigma_b = -0.1*mV
neuron.sigma_rt = 2*mV
neuron.sigma_rrt = 2.2*mV
neuron.f = 0.1
neuron.epsilon = 0.0015*umolar*(1/(pamp*msecond))
neuron.k_Ca = 0.3*(1/msecond)
neuron.b_Ca = 0.1*umolar
neuron.k_s = 0.5*umolar
neuron.R_pump = 0.0006*(mmolar/msecond)
neuron.K_p = 15*mmolar
neuron.p_rf = 100
neuron.Ca_ex = 2.5*mmolar
neuron.F = 96_485*(coulomb/mole)
neuron.R = 8.314*(joule/(mole*kelvin))
neuron.T = 298*kelvin
neuron.alpha_Na = 0.0001*mmolar*((msecond*uamp)**(-1))
neuron.Naeq = 8.0*mmolar
class HVCX_Params(Parameters):
"""
defines all the parameter values for a model HVC_X neuron
"""
def __init__(neuron, config_file=None) -> None:
"""
@params
config_file -> json file path(as string) containing the name and value of the parameter (as key-value pairs)that is changed for performing a particular simulation
Constructor for defining parameters specific to HVC_X neurons
"""
super().__init__()
neuron.g_Na = 450*nS
neuron.g_K = 50*nS
neuron.g_SK = 6*nS
neuron.g_KNa = 40*nS
neuron.g_h = 4*nS
neuron.g_A = 5*nS
neuron.g_CaT = 2.7*nS
neuron.C_m = 100*pfarad
neuron.k_r = 0.3
# if the path of json file is passed as a argument while constructing an object of HVCX_Params class, the keys in the json file are set as instance attributes with their corresponding values
if config_file:
with open(config_file) as f:
content = json.loads(f.read())
for key, value in content.items():
exec(f"neuron.{key} = {value}")
class HVCRA_Params(Parameters):
"""
defines all the parameter values for a model HVC_RA neuron
"""
def __init__(neuron, config_file=None) -> None:
"""
@params
config_file -> json file path(as string) containing the name and value of the parameter (as key-value pairs)that is changed for performing a particular simulation
Constructor for defining parameters specific to HVC_RA neurons
"""
super().__init__()
neuron.g_Na = 300*nS
neuron.g_K = 400*nS
neuron.g_SK = 27*nS
neuron.g_KNa = 500*nS
neuron.g_h = 1*nS
neuron.g_A = 150*nS
neuron.g_CaT = 0.6*nS
neuron.C_m = 20*pfarad
neuron.k_r = 0.95
if config_file:
with open(config_file) as f:
content = json.loads(f.read())
for key, value in content.items():
exec(f"neuron.{key} = {value}")
class HVCINT_Params(Parameters):
"""
defines all the parameter values for a model HVC_INT neuron
"""
def __init__(neuron, config_file=None) -> None:
"""
@params
config_file -> json file path(as string) containing the name and value of the parameter (as key-value pairs)that is changed for performing a particular simulation
Constructor for defining parameters specific to HVC_INT neurons
"""
super().__init__()
neuron.g_Na = 800*nS
neuron.g_K = 1700*nS
neuron.g_SK = 1*nS
neuron.g_KNa = 1*nS
neuron.g_h = 4*nS
neuron.g_A = 1*nS
neuron.g_CaT = 1.1*nS
neuron.C_m = 75*pfarad
neuron.k_r = 0.01
if config_file:
with open(config_file) as f:
content = json.loads(f.read())
for key, value in content.items():
exec(f"neuron.{key} = {value}")
def stimuli(df, mag, stim='pulse', dur=3, st=1, pwidth=0.05, gap=2, base=0, noise=0.2, ramp=1, rampup_t=None, rampdown_t=None, psp_dur=0.04, freq=1/(0.02), synaptize=False, noisy=False):
"""
@params
df -> dataframe
mag: int -> magnitude of the injected stimulus
stim: str -> type of the stimulus
dur: int -> duration of the stimulus
st: int -> start time of the stimulus
etc
generates a stimulus
"""
T = np.round(df['t'].max()) #maximum time
#step current
if stim == 'step':
df['step'] = np.ones(np.size(df['t']))*base
step = (df['t']>st) & (df['t']<st+dur)
df['step'][step] = mag
#sine current
elif stim == 'sin':
df['sin'] = np.ones(np.size(df['t']))*base
step = (df['t']>st) & (df['t']<st+dur)
df['sin'][step] = mag*0.1*np.sin(1e2*df['t'][step]+5)+mag
#linear increase
elif stim == 'lin':
df['lin'] = np.ones(np.size(df['t']))*base
step = (df['t']>st) & (df['t']<st+dur)
t_step = df['t'][step]; l_t_step = np.max(t_step)-np.min(t_step);
df['lin'][step] = (mag/l_t_step)*(t_step)-(mag/l_t_step)*(t_step.iloc[0])
#pulsatile
elif stim == 'pulse':
df['pulse'] = np.ones(np.size(df['t']))*base
step = (df['t']<0)
for i in np.arange(st, st+dur, pwidth+gap):
step = step|((df['t']>=i)&(df['t']<=i+pwidth))
df['pulse'][step] = mag
#bump
elif stim == 'bump':
df['bump'] = np.ones(np.size(df['t']))*base
bump = (df['t']>st) & (df['t']<st+dur)
df['bump'][bump] = mag
rampup_t = ramp/2 if (rampup_t is None) else rampup_t; rampdown_t = ramp/2 if (rampdown_t is None) else rampdown_t
rampup = (df['t']>st) & (df['t']<st+rampup_t); rampdown = (df['t']>st+dur-rampdown_t) & (df['t']<st+dur)
t_step = df['t'][rampup]; l_t_step = np.max(t_step)-np.min(t_step);
df['bump'][rampup] = (mag/l_t_step)*(t_step)-(mag/l_t_step)*(t_step.iloc[0])
t_step = df['t'][rampdown]; l_t_step = np.max(t_step)-np.min(t_step);
df['bump'][rampdown] = (-mag/l_t_step)*(t_step)+(mag/l_t_step)*(t_step.iloc[-1])
#synaptize the stimulus - makes the stimulus high frequency pulse like (realistic)
if synaptize==True:
step = (df['t']<0)
for i in np.arange(0, T, psp_dur+(1/freq)):
step = step|((df['t']>=i)&(df['t']<=i+(1/freq)))
df[stim][step] = 0
#make the stimulus noisy
if noisy==True:
df[stim] = df[stim]+(np.ones(np.size(df['t']))*noise*np.random.uniform(-1,1,np.size(df['t'])))
return df[stim] #return the stimulus asked for
if __name__ == "__main__":
my_neuron = HVCRA_Params("./configs/rahvc1.json")