1+ from this import d
12import scipy as sp
23import numpy as np
34import pylab as plt
45from scipy .integrate import odeint
6+ import sys
57
68class HodgkinHuxley ():
79 """Full Hodgkin-Huxley Model implemented in Python"""
@@ -46,6 +48,28 @@ def __init__(self, C_m=1, g_Na=120, g_K=36, g_L=0.3, E_Na=50, E_K=-77, E_L=-54.3
4648 self .I_inj_trans = I_inj_trans
4749 """ strart time of injection pulse or tranlation about time axis """
4850
51+ #vclamp parameters
52+ self .run_mode = []
53+ """default is current clamp"""
54+
55+ self .delay = 10
56+ """Delay before switching from conditioningVoltage to testingVoltage, in ms"""
57+
58+ self .duration = 30
59+ """Duration to hold at testingVoltage, in ms"""
60+
61+ self .conditioningVoltage = - 63.77
62+ """Target voltage before time delay, in mV"""
63+
64+ self .testingVoltage = 10
65+ """Target voltage between times delay and delay + duration, in mV"""
66+
67+ self .returnVoltage = - 63.77
68+ """Target voltage after time duration, in mV"""
69+
70+ self .simpleSeriesResistance = 1e7
71+ """Current will be calculated by the difference in voltage between the target and parent, divided by this value, in mOhm"""
72+
4973 def alpha_m (self , V ):
5074 """Channel gating kinetics. Functions of membrane voltage"""
5175 return 0.1 * (V + 40.0 )/ (1.0 - np .exp (- (V + 40.0 ) / 10.0 ))
@@ -123,6 +147,31 @@ def I_inj(self, t):
123147 else :
124148 return self .I_inj_max * (t > self .I_inj_trans ) - self .I_inj_max * (t > self .I_inj_trans + self .I_inj_width )
125149
150+ def I_inj_vclamp (self ,t ,v ):
151+ """
152+ External Current (vclamp)
153+
154+ | :param t: time
155+ | :return: injector current for voltage clamp
156+ |
157+ """
158+ if t > (self .delay + self .duration ):
159+ current_A = (self .returnVoltage - v ) / self .simpleSeriesResistance
160+ elif t >= self .delay :
161+ current_A = (self .testingVoltage - v ) / self .simpleSeriesResistance
162+ elif t < self .delay :
163+ current_A = (self .conditioningVoltage - v ) / self .simpleSeriesResistance
164+ else :
165+ print ('Problem in injection current calculation for voltage clamp...' )
166+ return 0
167+
168+ #convert current to current density (uA/cm^2)
169+ current_uA = current_A * 10 ** 6 #convert to ampere to micro ampere
170+ surface_area = 1000 * 10 ** - 8 #surface area of 1000 um^2 converted to cm^2
171+ current_density = current_uA / surface_area
172+
173+ return current_density
174+
126175 @staticmethod
127176 def dALLdt (X , t , self ):
128177 """
@@ -133,8 +182,11 @@ def dALLdt(X, t, self):
133182 | :return: calculate membrane potential & activation variables
134183 """
135184 V , m , h , n = X
185+ if self .run_mode == 'vclamp' :
186+ dVdt = (self .I_inj_vclamp (t ,V ) - self .I_Na (V , m , h ) - self .I_K (V , n ) - self .I_L (V )) / self .C_m
187+ else :
188+ dVdt = (self .I_inj (t ) - self .I_Na (V , m , h ) - self .I_K (V , n ) - self .I_L (V )) / self .C_m
136189
137- dVdt = (self .I_inj (t ) - self .I_Na (V , m , h ) - self .I_K (V , n ) - self .I_L (V )) / self .C_m
138190 dmdt = self .alpha_m (V )* (1.0 - m ) - self .beta_m (V )* m
139191 dhdt = self .alpha_h (V )* (1.0 - h ) - self .beta_h (V )* h
140192 dndt = self .alpha_n (V )* (1.0 - n ) - self .beta_n (V )* n
@@ -144,6 +196,22 @@ def Main(self):
144196 """
145197 Main demo for the Hodgkin Huxley neuron model
146198 """
199+ num_args = len (sys .argv )
200+ if (num_args > 2 ):
201+ print ()
202+ print ("*** Error: Only one argument is accpected (-vclamp/-iclamp) ***" )
203+ print ()
204+ sys .exit (1 )
205+
206+ if (num_args == 1 or sys .argv [1 ]== '-iclamp' ): #default mode
207+ self .run_mode = 'iclamp'
208+ elif (sys .argv [1 ]== '-vclamp' ):
209+ self .run_mode = 'vclamp'
210+ if __name__ == '__main__' : #update default time array for python script (notebook can be controlled through widgets)
211+ self .t = np .arange (0 , 50 , 0.0001 )
212+ else :
213+ print ("*** Error: Unexpected argument (use -vclamp or -iclamp ) ***" )
214+ sys .exit (1 )
147215
148216 X = odeint (self .dALLdt , [- 65 , 0.05 , 0.6 , 0.32 ], self .t , args = (self ,))
149217 V = X [:,0 ]
@@ -166,7 +234,12 @@ def Main(self):
166234 ax1 = plt .subplot (4 ,1 ,1 )
167235 plt .xlim ([np .min (self .t ),np .max (self .t )]) #for all subplots
168236 plt .title ('Hodgkin-Huxley Neuron' )
169- i_inj_values = [self .I_inj (t ) for t in self .t ]
237+
238+ if (self .run_mode == 'vclamp' ):
239+ i_inj_values = [self .I_inj_vclamp (t ,v ) for t ,v in zip (self .t ,V )]
240+ else :
241+ i_inj_values = [self .I_inj (t ) for t in self .t ]
242+
170243 plt .plot (self .t , i_inj_values , 'k' )
171244 plt .ylabel ('$I_{inj}$ ($\\ mu{A}/cm^2$)' )
172245
0 commit comments