import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import find_peaks
def HodHux_ELEC380(I, dt, plot_activation = 0):
#Hodgkin Huxley model of a neuron
#ELEC 480 Fall 2014
#JTRobinson
#
#Converted from MATLAB to Python by CATuppen Fall 2021
#
#Input:
#I = a vector of current values [uA]
#dt = time step between I measurements [ms]
#plot_activation (optional) = 1 to plot the activation state variables vs V (default 0)
#
#Output:
#V = membrane voltage in mV
#n = sodium activation
#m = potassium activation
#h = 1 - potassium inactivation
#Im = membrane current in uA
#
#State variables: V, n, m, h
#
#DV = 1/C (I - Ik - Ina - Il)
#
# Il = gl(V-El)
# Ik = gk*n^4(V-Ek)
# Ina = gna*m^3*h(V-Ena)
#
#Dn = (ninf(V) - n)/taun(V)
#Dm = (minf(V) - m)/taum(V)
#Dh = (hinf(V) - h)/tauh(V)
# can move these to outside of function for efficiency if desired
global V
global m
global n
global h
global gkt
global gnat
global Ik
global Ina
global Il
#starting membrane potential;
Vstart = -65.625 #[mV]
#Constants:
#reversal potentials for various ions
Ek = -77 #[mV]
Ena = 50 #[mV]
El = -54.4 #[mV] H&H used approx -55 mV
#Membrane capacitance:
C = 1 #[uF]
#maximum conductances [mS]
gna = 120
gk = 36
gl = 0.3
#Constants for GHK eq for channel activation
#from J. Bossu, J Physiol. 496.2 (1996)
#V50n = 57;
#kn = 13.5;
#from Izhikevich pg. 46 (2007)
#K+ Delayed Rectifier 1: Ik = g*n^4*(V-Ek)
#activation
V50n = -50
kn = 15
Vmaxn = -79
sig_n = 50
Campn = 4.7
Cbasen = 1.1
#from Izhikevich pg. 46 (2007)
#Na+ Fast Transient 1: Ina = g*m^3*h*(V-Ena)
#activation:
V50m = -40
km = 8 #adjusted to match Fig. 2.3 on Pg. 39. probably a typo in the table
Vmaxm = -38
sig_m = 30
Campm = 0.46
Cbasem = 0.04
#inactivation
V50h = -60
kh = -7
Vmaxh = -67
sig_h = 20
Camph = 7.4
Cbaseh = 1.2
#initialize the vector sizes
n = np.zeros(len(I))
m = np.zeros(len(I))
h = np.zeros(len(I))
V = np.zeros(len(I))
Im = np.zeros(len(I))
#set initial conditions:
n[0] = 0.3
m[0] = 0.006
h[0] = 0.626
V[0] = Vstart #[mV]
#iterate through the input sequence and calculate the response
for ii in range(len(I)-1):
#display progress (can remove this block if desired)
#if (ii % 1000) == 0:
#print(ii)
#print(V[ii],n[ii],m[ii],h[ii])
#update voltage state variable
#DV = 1/C (I - Ik - Ina - Il)
#units:
#I = uA
#V = mV, g = mS; g*V = uA
#C = uF
#uA/uC*ms = mV
#full model
V[ii+1] = V[ii] + dt/C*(I[ii] - gl*(V[ii]-El) - gk*n[ii]**4*(V[ii]-Ek)
- gna*m[ii]**3*h[ii]*(V[ii]-Ena))
#steady state activation values at the given voltage
ninf = 1/( 1 + np.exp( (V50n-V[ii])/kn ) )
minf = 1/( 1 + np.exp( (V50m-V[ii])/km ) )
hinf = 1/( 1 + np.exp( (V50h-V[ii])/kh ) )
#time constants
#Izhikevich pg. 45
taun = Cbasen + Campn*np.exp(-(Vmaxn-V[ii])**2/sig_n**2)
taum = Cbasem + Campm*np.exp(-(Vmaxm-V[ii])**2/sig_m**2)
tauh = Cbaseh + Camph*np.exp(-(Vmaxh-V[ii])**2/sig_h**2)
#update activation state variables
n[ii+1] = n[ii] + dt*(ninf - n[ii])/taun
m[ii+1] = m[ii] + dt*(minf - m[ii])/taum
h[ii+1] = h[ii] + dt*(hinf - h[ii])/tauh
#define conductances and currents for this v[ii]
gkt_ii = gk*n[ii]**4
gnat_ii = gna*m[ii]**3*h[ii]
Ik_ii = gkt_ii*(V[ii]-Ek)
Ina_ii = gnat_ii * (V[ii] - Ena)
Il_ii = gl*(V[ii] - El)
#this is wrong lol.
Ic_ii = (V[ii+1] - V[ii]) * C / dt
#add em up to get total membrane current
Im[ii] = Il_ii + Ic_ii + Ina_ii + Ik_ii
gkt = gk*n**4
gnat = gna*m**3*h
Ik = gkt*(V-Ek)
Ina = gnat*(V-Ena)
Il = gl*(V-El)
#Diagnostics
if plot_activation:
Vtest = np.arange(-100,11)
#steady state activation vs Voltage
ninfV = 1/( 1 + np.exp((V50n-Vtest)/kn))
minfV = 1/( 1 + np.exp((V50m-Vtest)/km))
hinfV = 1/( 1 + np.exp((V50h-Vtest)/kh))
line1, = plt.plot(Vtest, ninfV, color = 'b', label = r'$n_{infty}$')
line2, = plt.plot(Vtest, minfV, color = 'r', label = r'$m_{infty}$')
line3, = plt.plot(Vtest, hinfV, color = 'k', label = r'$h_{infty}$')
plt.legend(handles=[line1, line2, line3])
plt.suptitle('steady state activations')
plt.show()
#time constants vs Voltage
taunV = Cbasen + Campn*np.exp(-(Vmaxn-Vtest)**2/sig_n**2)
taumV = Cbasem + Campm*np.exp(-(Vmaxm-Vtest)**2/sig_m**2)
tauhV = Cbaseh + Camph*np.exp(-(Vmaxh-Vtest)**2/sig_h**2)
line1, = plt.plot(Vtest, taunV, color = 'b', label = r'$tau_{n}$')
line2, = plt.plot(Vtest, taumV, color = 'r', label = r'$tau_{m}$')
line3, = plt.plot(Vtest, tauhV, color = 'k', label = r'$tau_{h}$')
plt.suptitle('activation time constants')
plt.legend(handles=[line1, line2, line3])
plt.show()
return V, Im
inject_time = 60 #inject for 60 ms
I_inject = 10 #10 uA
total_time = 100 #total time of 100 ms
def create_I_list(I_inject, dt, inject_time, total_time):
'''
Make current injection of I_inject (mA) for inject_time in intervals of dt. Total_time in ms.
'''
I = [I_inject] * int(inject_time / dt) # inject at intervals of dt for inject_time
I.extend([0]*int((total_time-inject_time) / dt)) #add on inject current of 0 for the rest of the time after injections
return I
I_1 = create_I_list(I_inject, 0.1, inject_time, total_time) #dt = 0.1
I_01 = create_I_list(I_inject, 0.01, inject_time, total_time) #dt = 0.01
I_001 = create_I_list(I_inject, 0.001, inject_time, total_time) #dt = 0.001
print(len(I_01))
10000
Vm, Im= HodHux_ELEC380(I_1, 0.1, 0)
plt.plot(np.arange(0,100, 0.1), Vm)
print(len(Vm))
plt.xlabel('time (ms)')
plt.ylabel('Membrane Voltage (mV)')
plt.title('10 uA current injection with dt = 0.1')
plt.savefig('Q1.2dt0.1.png')
1000
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:145: RuntimeWarning: overflow encountered in exp
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:143: RuntimeWarning: overflow encountered in exp
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:144: RuntimeWarning: overflow encountered in exp
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:149: RuntimeWarning: overflow encountered in double_scalars
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:150: RuntimeWarning: overflow encountered in double_scalars
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:151: RuntimeWarning: overflow encountered in double_scalars
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:139: RuntimeWarning: overflow encountered in double_scalars
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:162: RuntimeWarning: overflow encountered in double_scalars
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:169: RuntimeWarning: invalid value encountered in double_scalars
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:139: RuntimeWarning: invalid value encountered in double_scalars
/shared-libs/python3.7/py-core/lib/python3.7/site-packages/ipykernel_launcher.py:175: RuntimeWarning: overflow encountered in multiply
Vm, Im = HodHux_ELEC380(I_01, 0.01, 0)
plt.plot(np.arange(0,100, 0.01), Vm)
plt.xlabel('time (ms)')
plt.ylabel('Membrane Voltage (mV)')
plt.title('10 uA current injection with dt = 0.01')
plt.savefig('Q1.2dt0.01.png')
Vm, Im = HodHux_ELEC380(I_001, 0.001, 0)
plt.plot(np.arange(0,100, 0.001), Vm)
plt.xlabel('time (ms)')
plt.ylabel('Membrane Voltage (mV)')
plt.title('10 uA current injection with dt = 0.001')
plt.savefig('Q1.2dt0.001.png')
def when_action_potential(I_inject, dt, total_time):
'''
check when the first action potential occurs
I_inject: constant input current in uA
dt: incremental time counter (s)
total_time: total time recorded (s)
'''
time = 0
mV = -100
while mV < 0:
I_list = create_I_list(I_inject, dt, time, total_time)
V_list, Im= HodHux_ELEC380(I_list, dt, plot_activation = 0) #needs to be if any V in this list is above zero, not just the whole list.
mV = max(V_list)
print("mV:" + str(mV) + "," + "time:" + str(time))
time += dt
return time
when_action_potential(2, 0.1, 10)
mV:-62.40155257807115,time:0
mV:-62.44229584479218,time:0.1
mV:-62.48405752120308,time:0.2
mV:-62.52687646432305,time:0.30000000000000004
mV:-62.57067666631416,time:0.4
mV:-62.61540012500182,time:0.5
mV:-62.61540012500182,time:0.6
mV:-62.66100040559428,time:0.7
mV:-62.707437310910024,time:0.7999999999999999
mV:-62.75465901148112,time:0.8999999999999999
mV:-62.802445349224136,time:0.9999999999999999
mV:-62.85064900374945,time:1.0999999999999999
mV:-62.89837673049578,time:1.2
mV:-62.95563546774229,time:1.3
mV:-62.80721199330029,time:1.4000000000000001
mV:-62.626995656389475,time:1.5000000000000002
mV:-62.44975984533724,time:1.6000000000000003
mV:-62.27528568830118,time:1.7000000000000004
mV:-62.10335472720782,time:1.8000000000000005
mV:-61.933750092137345,time:1.9000000000000006
mV:-61.76625675554557,time:2.0000000000000004
mV:-61.60066121122909,time:2.1000000000000005
mV:-61.436750780562235,time:2.2000000000000006
mV:-61.27431266153094,time:2.3000000000000007
mV:-61.11313278234804,time:2.400000000000001
mV:-60.95299448754541,time:2.500000000000001
mV:-60.79367706224407,time:2.600000000000001
mV:-60.63495408479935,time:2.700000000000001
mV:-60.47659158607946,time:2.800000000000001
mV:-60.31834598324235,time:2.9000000000000012
mV:-60.15996174563671,time:3.0000000000000013
mV:-60.001168739309705,time:3.1000000000000014
mV:-59.8416791836303,time:3.2000000000000015
mV:-59.68118413779672,time:3.3000000000000016
mV:-59.51934941542599,time:3.4000000000000017
mV:-59.35581080070989,time:3.5000000000000018
mV:-59.19016840807102,time:3.600000000000002
mV:-59.02197998661276,time:3.700000000000002
mV:-58.85075291788061,time:3.800000000000002
mV:-58.67007439592237,time:3.900000000000002
mV:-58.44039183682058,time:4.000000000000002
mV:-58.179869739193954,time:4.100000000000001
mV:-57.87070102352451,time:4.200000000000001
mV:-57.471230594135065,time:4.300000000000001
mV:-56.83596177783186,time:4.4
mV:62.028362743184815,time:4.5
total_time = 60
dt = 0.01
Istim = 2
time = np.arange(0, total_time, dt)
I = create_I_list(Istim, dt, when_action_potential(Istim, dt, total_time), total_time + dt)
print(len(I))
Vm, Im = HodHux_ELEC380(I, dt, 0)
fig, (ax1, ax3, ax4, ax5) = plt.subplots(4, sharex=True)
fig.suptitle('Questions 1.3 to 1.6')
#plot vm
ax1.plot(time, Vm, color="red")
ax1.set_ylabel("Vm",color="red",fontsize=14)
#plot im on same graph
ax2 = ax1.twinx()
ax2.plot(time, Im)
ax2.set_ylabel("Im", color="blue", fontsize=14)
ax3.plot(time, n)
ax3.plot(time, m)
ax3.plot(time, h)
ax3.legend(["n", "m", "h"])
ax4.plot(time, gkt)
ax4.plot(time, gnat)
ax4.legend(['gK', 'gNa'])
ax5.plot(time, Ina)
ax5.plot(time, Ik)
ax5.legend(['INa', 'IK'])
ax5.set_xlabel("time (ms)")
#axs[1].plot(x, -y)
mV:-62.43094704175956,time:0
mV:-62.43468696975134,time:0.01
mV:-62.43843681082968,time:0.02
mV:-62.44219805911347,time:0.03
mV:-62.44597077801536,time:0.04
mV:-62.44975490547525,time:0.05
mV:-62.45355037688603,time:0.060000000000000005
mV:-62.45735553347466,time:0.07
mV:-62.46117184412891,time:0.08
mV:-62.464999322301345,time:0.09
mV:-62.464999322301345,time:0.09999999999999999
mV:-62.468837896552806,time:0.10999999999999999
mV:-62.47268749434284,time:0.11999999999999998
mV:-62.47654670243769,time:0.12999999999999998
mV:-62.480416577821295,time:0.13999999999999999
mV:-62.48818875061009,time:0.15
mV:-62.49209089882644,time:0.16
mV:-62.496002786212564,time:0.17
mV:-62.49992463066618,time:0.18000000000000002
mV:-62.50385696667871,time:0.19000000000000003
mV:-62.507799720726844,time:0.20000000000000004
mV:-62.51175281976531,time:0.21000000000000005
mV:-62.515716031367035,time:0.22000000000000006
mV:-62.51968826517439,time:0.23000000000000007
mV:-62.52367066157198,time:0.24000000000000007
mV:-62.52766315044982,time:0.25000000000000006
mV:-62.531665662494916,time:0.26000000000000006
mV:-62.53567812922972,time:0.2700000000000001
mV:-62.539700066469685,time:0.2800000000000001
mV:-62.54373104948378,time:0.2900000000000001
mV:-62.54777182171078,time:0.3000000000000001
mV:-62.55182231857021,time:0.3100000000000001
mV:-62.55588247641666,time:0.3200000000000001
mV:-62.559952232544305,time:0.3300000000000001
mV:-62.564031405735435,time:0.34000000000000014
mV:-62.56811913848169,time:0.35000000000000014
mV:-62.572216323310556,time:0.36000000000000015
mV:-62.57632290156323,time:0.37000000000000016
mV:-62.58043881549407,time:0.38000000000000017
mV:-62.58456400825734,time:0.3900000000000002
mV:-62.5886984238914,time:0.4000000000000002
mV:-62.59284191132121,time:0.4100000000000002
mV:-62.59699377490863,time:0.4200000000000002
mV:-62.60115473691534,time:0.4300000000000002
mV:-62.605324745058205,time:0.4400000000000002
mV:-62.609503747840975,time:0.45000000000000023
mV:-62.61369169453153,time:0.46000000000000024
mV:-62.61788853513809,time:0.47000000000000025
mV:-62.62209422038518,time:0.48000000000000026
mV:-62.626308701689155,time:0.49000000000000027
mV:-62.630531692544146,time:0.5000000000000002
mV:-62.634763085813134,time:0.5100000000000002
mV:-62.63900317439994,time:0.5200000000000002
mV:-62.64325191258705,time:0.5300000000000002
mV:-62.64750925522606,time:0.5400000000000003
mV:-62.65177515771224,time:0.5500000000000003
mV:-62.656049575959834,time:0.5600000000000003
mV:-62.66033246637741,time:0.5700000000000003
mV:-62.664623785842934,time:0.5800000000000003
mV:-62.66892349167984,time:0.5900000000000003
mV:-62.67323154163256,time:0.6000000000000003
mV:-62.67754789384361,time:0.6100000000000003
mV:-62.681872506829244,time:0.6200000000000003
mV:-62.68620533945718,time:0.6300000000000003
mV:-62.69054635092368,time:0.6400000000000003
mV:-62.6948955007312,time:0.6500000000000004
mV:-62.699252748666694,time:0.6600000000000004
mV:-62.703618054780094,time:0.6700000000000004
mV:-62.7079913793631,time:0.6800000000000004
mV:-62.71237268292877,time:0.6900000000000004
mV:-62.71676192619117,time:0.7000000000000004
mV:-62.72115907004527,time:0.7100000000000004
mV:-62.72556407554798,time:0.7200000000000004
mV:-62.729976903899,time:0.7300000000000004
mV:-62.73439751642182,time:0.7400000000000004
mV:-62.73882587454595,time:0.7500000000000004
mV:-62.743261831958264,time:0.7600000000000005
mV:-62.747704913360494,time:0.7700000000000005
mV:-62.75215557398774,time:0.7800000000000005
mV:-62.75661377509012,time:0.7900000000000005
mV:-62.761079477934196,time:0.8000000000000005
mV:-62.76555264378789,time:0.8100000000000005
mV:-62.770032324909074,time:0.8200000000000005
mV:-62.77451926583939,time:0.8300000000000005
mV:-62.77901349939053,time:0.8400000000000005
mV:-62.78351450250641,time:0.8500000000000005
mV:-62.788021935150006,time:0.8600000000000005
mV:-62.792536486448995,time:0.8700000000000006
mV:-62.797057151388,time:0.8800000000000006
mV:-62.80158431207521,time:0.8900000000000006
mV:-62.806117733266845,time:0.9000000000000006
mV:-62.810657039561555,time:0.9100000000000006
mV:-62.815202239934294,time:0.9200000000000006
mV:-62.81975321894299,time:0.9300000000000006
mV:-62.824309203550904,time:0.9400000000000006
mV:-62.828870664064986,time:0.9500000000000006
mV:-62.83343712831753,time:0.9600000000000006
mV:-62.83800767712923,time:0.9700000000000006
mV:-62.84258257123392,time:0.9800000000000006
mV:-62.84716135756566,time:0.9900000000000007
mV:-62.85174357798888,time:1.0000000000000007
mV:-62.85632876922857,time:1.0100000000000007
mV:-62.860916462799274,time:1.0200000000000007
mV:-62.86550561215216,time:1.0300000000000007
mV:-62.870095945680376,time:1.0400000000000007
mV:-62.874686797409844,time:1.0500000000000007
mV:-62.87927687907824,time:1.0600000000000007
mV:-62.88386533955115,time:1.0700000000000007
mV:-62.88845110764726,time:1.0800000000000007
mV:-62.893032765248535,time:1.0900000000000007
mV:-62.897608874574,time:1.1000000000000008
mV:-62.902177024406434,time:1.1100000000000008
mV:-62.9067356776721,time:1.1200000000000008
mV:-62.91128193915551,time:1.1300000000000008
mV:-62.91581286620819,time:1.1400000000000008
mV:-62.920324618278705,time:1.1500000000000008
mV:-62.92481290721827,time:1.1600000000000008
mV:-62.92927215659422,time:1.1700000000000008
mV:-62.933695716388954,time:1.1800000000000008
mV:-62.938075240511886,time:1.1900000000000008
mV:-62.94240033317906,time:1.2000000000000008
mV:-62.94665750775271,time:1.2100000000000009
mV:-62.95082972495221,time:1.2200000000000009
mV:-62.954894756874694,time:1.2300000000000009
mV:-62.95882320701313,time:1.2400000000000009
mV:-62.96257555119266,time:1.2500000000000009
mV:-62.96609863009189,time:1.260000000000001
mV:-62.96931937246964,time:1.270000000000001
mV:-62.97213703980905,time:1.280000000000001
mV:-62.97441244463429,time:1.290000000000001
mV:-62.97595555499618,time:1.300000000000001
mV:-62.97651620079594,time:1.310000000000001
mV:-62.97578575715806,time:1.320000000000001
mV:-62.973429437578154,time:1.330000000000001
mV:-62.96915485384918,time:1.340000000000001
mV:-62.95120726564034,time:1.350000000000001
mV:-62.93307536958639,time:1.360000000000001
mV:-62.914974856152945,time:1.370000000000001
mV:-62.89690557286867,time:1.380000000000001
mV:-62.878867364831706,time:1.390000000000001
mV:-62.86086007482083,time:1.400000000000001
mV:-62.84288354340221,time:1.410000000000001
mV:-62.824937609031885,time:1.420000000000001
mV:-62.80702210815413,time:1.430000000000001
mV:-62.789136875295824,time:1.440000000000001
mV:-62.771281743157026,time:1.450000000000001
mV:-62.75345654269782,time:1.460000000000001
mV:-62.7356611032216,time:1.470000000000001
mV:-62.71789525245494,time:1.480000000000001
mV:-62.70015881662408,time:1.490000000000001
mV:-62.68245162052832,time:1.500000000000001
mV:-62.664773487610205,time:1.5100000000000011
mV:-62.64712424002284,time:1.5200000000000011
mV:-62.62950369869428,time:1.5300000000000011
mV:-62.61191168338916,time:1.5400000000000011
mV:-62.59434801276768,time:1.5500000000000012
mV:-62.576812504442024,time:1.5600000000000012
mV:-62.55930497503026,time:1.5700000000000012
mV:-62.541825240207906,time:1.5800000000000012
mV:-62.52437311475716,time:1.5900000000000012
mV:-62.50694841261393,time:1.6000000000000012
mV:-62.48955094691272,time:1.6100000000000012
mV:-62.472180530029455,time:1.6200000000000012
mV:-62.454836973622314,time:1.6300000000000012
mV:-62.43752008867066,time:1.6400000000000012
mV:-62.42022968551214,time:1.6500000000000012
mV:-62.40296557387796,time:1.6600000000000013
mV:-62.38572756292648,time:1.6700000000000013
mV:-62.36851546127519,time:1.6800000000000013
mV:-62.35132907703098,time:1.6900000000000013
mV:-62.33416821781904,time:1.7000000000000013
mV:-62.317032690810116,time:1.7100000000000013
mV:-62.29992230274646,time:1.7200000000000013
mV:-62.28283685996633,time:1.7300000000000013
mV:-62.26577616842722,time:1.7400000000000013
mV:-62.248740033727785,time:1.7500000000000013
mV:-62.23172826112849,time:1.7600000000000013
mV:-62.21474065557116,time:1.7700000000000014
mV:-62.19777702169734,time:1.7800000000000014
mV:-62.18083716386551,time:1.7900000000000014
mV:-62.1639208861673,time:1.8000000000000014
mV:-62.147027992442624,time:1.8100000000000014
mV:-62.13015828629387,time:1.8200000000000014
mV:-62.113311571099096,time:1.8300000000000014
mV:-62.0964876500243,time:1.8400000000000014
mV:-62.079686326034825,time:1.8500000000000014
mV:-62.062907401905875,time:1.8600000000000014
mV:-62.04615068023222,time:1.8700000000000014
mV:-62.029415963437096,time:1.8800000000000014
mV:-62.0127030537803,time:1.8900000000000015
mV:-61.99601175336558,time:1.9000000000000015
mV:-61.97934186414728,time:1.9100000000000015
mV:-61.96269318793628,time:1.9200000000000015
mV:-61.94606552640528,time:1.9300000000000015
mV:-61.92945868109337,time:1.9400000000000015
mV:-61.91287245341009,time:1.9500000000000015
mV:-61.89630664463872,time:1.9600000000000015
mV:-61.87976105593914,time:1.9700000000000015
mV:-61.86323548834998,time:1.9800000000000015
mV:-61.846729742790295,time:1.9900000000000015
mV:-61.830243620060685,time:2.0000000000000013
mV:-61.8137769208439,time:2.010000000000001
mV:-61.7973294457049,time:2.020000000000001
mV:-61.78090099509049,time:2.0300000000000007
mV:-61.76449136932845,time:2.0400000000000005
mV:-61.74810036862616,time:2.0500000000000003
mV:-61.7317277930689,time:2.06
mV:-61.7317277930689,time:2.07
mV:-61.71537344261756,time:2.0799999999999996
mV:-61.699037117106066,time:2.0899999999999994
mV:-61.6827186162383,time:2.099999999999999
mV:-61.66641773958468,time:2.109999999999999
mV:-61.65013428657834,time:2.1199999999999988
mV:-61.633868056510906,time:2.1299999999999986
mV:-61.617618848527925,time:2.1399999999999983
mV:-61.601386461623946,time:2.149999999999998
mV:-61.585170694637235,time:2.159999999999998
mV:-61.568971346244155,time:2.1699999999999977
mV:-61.55278821495322,time:2.1799999999999975
mV:-61.536621099098795,time:2.1899999999999973
mV:-61.52046979683453,time:2.199999999999997
mV:-61.50433410612643,time:2.209999999999997
mV:-61.48821382474565,time:2.2199999999999966
mV:-61.472108750260986,time:2.2299999999999964
mV:-61.45601868003108,time:2.239999999999996
mV:-61.43994341119632,time:2.249999999999996
mV:-61.423882740670464,time:2.259999999999996
mV:-61.40783646513203,time:2.2699999999999956
mV:-61.391804381015326,time:2.2799999999999954
mV:-61.37578628450129,time:2.289999999999995
mV:-61.35978197150804,time:2.299999999999995
mV:-61.34379123768116,time:2.3099999999999947
mV:-61.327813878383715,time:2.3199999999999945
mV:-61.31184968868606,time:2.3299999999999943
mV:-61.29589846335534,time:2.339999999999994
mV:-61.2799599968448,time:2.349999999999994
mV:-61.264034083282795,time:2.3599999999999937
mV:-61.24812051646159,time:2.3699999999999934
mV:-61.232219089825925,time:2.3799999999999932
mV:-61.21632959646131,time:2.389999999999993
mV:-61.20045182908211,time:2.399999999999993
mV:-61.184585580019395,time:2.4099999999999926
mV:-61.168730641208526,time:2.4199999999999924
mV:-61.15288680417654,time:2.429999999999992
mV:-61.13705386002929,time:2.439999999999992
mV:-61.12123159943835,time:2.4499999999999917
mV:-61.1054198126277,time:2.4599999999999915
mV:-61.089618289360146,time:2.4699999999999913
mV:-61.07382681892356,time:2.479999999999991
mV:-61.05804519011684,time:2.489999999999991
mV:-61.042273191235715,time:2.4999999999999907
mV:-61.02651061005818,time:2.5099999999999905
mV:-61.01075723382986,time:2.5199999999999902
mV:-60.99501284924901,time:2.52999999999999
mV:-60.979277242451374,time:2.53999999999999
mV:-60.96355019899476,time:2.5499999999999896
mV:-60.94783150384338,time:2.5599999999999894
mV:-60.932120941351975,time:2.569999999999989
mV:-60.91641829524968,time:2.579999999999989
mV:-60.900723348623664,time:2.5899999999999888
mV:-60.885035883902525,time:2.5999999999999885
mV:-60.869355682839426,time:2.6099999999999883
mV:-60.853682526495014,time:2.619999999999988
mV:-60.83801619522006,time:2.629999999999988
mV:-60.82235646863786,time:2.6399999999999877
mV:-60.806703125626406,time:2.6499999999999875
mV:-60.791055944300254,time:2.6599999999999873
mV:-60.77541470199219,time:2.669999999999987
mV:-60.75977917523457,time:2.679999999999987
mV:-60.744149139740465,time:2.6899999999999866
mV:-60.72852437038448,time:2.6999999999999864
mV:-60.71290464118334,time:2.709999999999986
mV:-60.69728972527621,time:2.719999999999986
mV:-60.681679394904656,time:2.7299999999999858
mV:-60.666073421392454,time:2.7399999999999856
mV:-60.650471575124996,time:2.7499999999999853
mV:-60.63487362552849,time:2.759999999999985
mV:-60.61927934104881,time:2.769999999999985
mV:-60.603688489130086,time:2.7799999999999847
mV:-60.588100836192964,time:2.7899999999999845
mV:-60.572516147612596,time:2.7999999999999843
mV:-60.55693418769627,time:2.809999999999984
mV:-60.54135471966077,time:2.819999999999984
mV:-60.525777505609376,time:2.8299999999999836
mV:-60.51020230650859,time:2.8399999999999834
mV:-60.49462888216446,time:2.849999999999983
mV:-60.47905699119865,time:2.859999999999983
mV:-60.463486391024055,time:2.869999999999983
mV:-60.44791683782022,time:2.8799999999999826
mV:-60.43234808650828,time:2.8899999999999824
mV:-60.41677989072554,time:2.899999999999982
mV:-60.401212002799824,time:2.909999999999982
mV:-60.38564417372327,time:2.9199999999999817
mV:-60.3700761531259,time:2.9299999999999815
mV:-60.35450768924869,time:2.9399999999999813
mV:-60.33893852891632,time:2.949999999999981
mV:-60.323368417509506,time:2.959999999999981
mV:-60.307797098936895,time:2.9699999999999807
mV:-60.292224315606596,time:2.9799999999999804
mV:-60.276649808397245,time:2.9899999999999802
mV:-60.26107331662867,time:2.99999999999998
mV:-60.24549457803209,time:3.00999999999998
mV:-60.22991332871991,time:3.0199999999999796
mV:-60.214329303155026,time:3.0299999999999794
mV:-60.19874223411966,time:3.039999999999979
mV:-60.183151852683785,time:3.049999999999979
mV:-60.16755788817298,time:3.0599999999999787
mV:-60.151960068135864,time:3.0699999999999785
mV:-60.13635811831102,time:3.0799999999999783
mV:-60.120751762593386,time:3.089999999999978
mV:-60.105140723000126,time:3.099999999999978
mV:-60.08952471963602,time:3.1099999999999777
mV:-60.07390347065826,time:3.1199999999999775
mV:-60.058276692240725,time:3.1299999999999772
mV:-60.04264409853769,time:3.139999999999977
mV:-60.02700540164697,time:3.149999999999977
mV:-60.011360311572446,time:3.1599999999999766
mV:-59.99570853618607,time:3.1699999999999764
mV:-59.98004978118919,time:3.179999999999976
mV:-59.964383750073274,time:3.189999999999976
mV:-59.94871014408005,time:3.1999999999999758
mV:-59.93302866216094,time:3.2099999999999755
mV:-59.91733900093587,time:3.2199999999999753
mV:-59.901640854651404,time:3.229999999999975
mV:-59.8859339151382,time:3.239999999999975
mV:-59.870217871767764,time:3.2499999999999747
mV:-59.85449241140847,time:3.2599999999999745
mV:-59.83875721838091,time:3.2699999999999743
mV:-59.82301197441243,time:3.279999999999974
mV:-59.80725635859097,time:3.289999999999974
mV:-59.791490047318085,time:3.2999999999999736
mV:-59.775712714261225,time:3.3099999999999734
mV:-59.759924030305164,time:3.319999999999973
mV:-59.74412366350263,time:3.329999999999973
mV:-59.728311279024076,time:3.3399999999999728
mV:-59.71248653910665,time:3.3499999999999726
mV:-59.6966491030022,time:3.3599999999999723
mV:-59.68079862692447,time:3.369999999999972
mV:-59.66493476399532,time:3.379999999999972
mV:-59.64905716419005,time:3.3899999999999717
mV:-59.63316547428175,time:3.3999999999999715
mV:-59.61725933778472,time:3.4099999999999713
mV:-59.60133839489682,time:3.419999999999971
mV:-59.585402282440874,time:3.429999999999971
mV:-59.569450633805005,time:3.4399999999999706
mV:-59.55348307888191,time:3.4499999999999704
mV:-59.537499244007066,time:3.45999999999997
mV:-59.52149875189581,time:3.46999999999997
mV:-59.50548122157931,time:3.47999999999997
mV:-59.48944626833935,time:3.4899999999999696
mV:-59.47339350364197,time:3.4999999999999694
mV:-59.45732253506988,time:3.509999999999969
mV:-59.441232966253615,time:3.519999999999969
mV:-59.42512439680148,time:3.5299999999999687
mV:-59.408996422228164,time:3.5399999999999685
mV:-59.39284863388205,time:3.5499999999999683
mV:-59.3766806188712,time:3.559999999999968
mV:-59.360491959987876,time:3.569999999999968
mV:-59.34428223563177,time:3.5799999999999677
mV:-59.32805101973173,time:3.5899999999999674
mV:-59.311797881665974,time:3.5999999999999672
mV:-59.29552238618087,time:3.609999999999967
mV:-59.279224093308144,time:3.619999999999967
mV:-59.26290255828048,time:3.6299999999999666
mV:-59.24655733144555,time:3.6399999999999664
mV:-59.23018795817838,time:3.649999999999966
mV:-59.213793978792,time:3.659999999999966
mV:-59.19737492844641,time:3.6699999999999657
mV:-59.180930337055734,time:3.6799999999999655
mV:-59.1644597291936,time:3.6899999999999653
mV:-59.14796262399663,time:3.699999999999965
mV:-59.13143853506604,time:3.709999999999965
mV:-59.11488697036737,time:3.7199999999999647
mV:-59.098307432128124,time:3.7299999999999645
mV:-59.08169941673341,time:3.7399999999999642
mV:-59.065062414619526,time:3.749999999999964
mV:-59.048395910165425,time:3.759999999999964
mV:-59.03169938158191,time:3.7699999999999636
mV:-59.014972300798696,time:3.7799999999999634
mV:-58.99821413334911,time:3.789999999999963
mV:-58.98142433825249,time:3.799999999999963
mV:-58.96460236789415,time:3.8099999999999627
mV:-58.947747667902924,time:3.8199999999999625
mV:-58.93085967702613,time:3.8299999999999623
mV:-58.91393782700201,time:3.839999999999962
mV:-58.8969815424295,time:3.849999999999962
mV:-58.87999024063529,time:3.8599999999999617
mV:-58.86296333153809,time:3.8699999999999615
mV:-58.8459002175101,time:3.8799999999999613
mV:-58.828800293235474,time:3.889999999999961
mV:-58.81166294556589,time:3.899999999999961
mV:-58.794487553372996,time:3.9099999999999606
mV:-58.777273487397714,time:3.9199999999999604
mV:-58.76002011009635,time:3.92999999999996
mV:-58.742726775483376,time:3.93999999999996
mV:-58.72539282897082,time:3.9499999999999598
mV:-58.708017607204205,time:3.9599999999999596
mV:-58.690600437894915,time:3.9699999999999593
mV:-58.67314063964887,time:3.979999999999959
mV:-58.65563752179151,time:3.989999999999959
mV:-58.63809038418891,time:3.9999999999999587
mV:-58.62049851706488,time:4.009999999999959
mV:-58.60286120081417,time:4.019999999999959
mV:-58.585177705811326,time:4.0299999999999585
mV:-58.567447292215455,time:4.039999999999958
mV:-58.54966920977049,time:4.049999999999958
mV:-58.53184269760103,time:4.059999999999958
mV:-58.51396698400352,time:4.069999999999958
mV:-58.4933974069612,time:4.079999999999957
mV:-58.471206894653264,time:4.089999999999957
mV:-58.44874074436085,time:4.099999999999957
mV:-58.42598883140643,time:4.109999999999957
mV:-58.40293762609748,time:4.119999999999957
mV:-58.379584420185644,time:4.129999999999956
mV:-58.35591872457195,time:4.139999999999956
mV:-58.33192889861104,time:4.149999999999956
mV:-58.30759886505219,time:4.159999999999956
mV:-58.28291148638362,time:4.1699999999999555
mV:-58.2578585672369,time:4.179999999999955
mV:-58.23242385748219,time:4.189999999999955
mV:-58.20658977859693,time:4.199999999999955
mV:-58.18033736975431,time:4.209999999999955
mV:-58.15364622655189,time:4.2199999999999545
mV:-58.126494431951194,time:4.229999999999954
mV:-58.09885847893256,time:4.239999999999954
mV:-58.070713184293105,time:4.249999999999954
mV:-58.042031592931764,time:4.259999999999954
mV:-58.01278487187252,time:4.269999999999953
mV:-57.982942193173706,time:4.279999999999953
mV:-57.95245835797766,time:4.289999999999953
mV:-57.92129862341164,time:4.299999999999953
mV:-57.889431902827425,time:4.3099999999999525
mV:-57.85678529775882,time:4.319999999999952
mV:-57.823335058169015,time:4.329999999999952
mV:-57.78899651216995,time:4.339999999999952
mV:-57.75371966957861,time:4.349999999999952
mV:-57.71743076141037,time:4.3599999999999515
mV:-57.68004507211489,time:4.369999999999951
mV:-57.641469988135576,time:4.379999999999951
mV:-57.601604205253686,time:4.389999999999951
mV:-57.56032305329298,time:4.399999999999951
mV:-57.517488433705424,time:4.40999999999995
mV:-57.472941129746474,time:4.41999999999995
mV:-57.42649979313697,time:4.42999999999995
mV:-57.37794580167415,time:4.43999999999995
mV:-57.32701483889413,time:4.4499999999999496
mV:-57.27340398368527,time:4.459999999999949
mV:-57.216718653632945,time:4.469999999999949
mV:-57.15650472820026,time:4.479999999999949
mV:-57.0921795706533,time:4.489999999999949
mV:-57.02299496693093,time:4.4999999999999485
mV:-56.94797544822849,time:4.509999999999948
mV:-56.86581869508196,time:4.519999999999948
mV:-56.77470927538715,time:4.529999999999948
mV:-56.672020045946915,time:4.539999999999948
mV:-56.55371339261887,time:4.549999999999947
mV:-56.413149702029045,time:4.559999999999947
mV:-56.23804398807342,time:4.569999999999947
mV:-56.001357299589664,time:4.579999999999947
mV:-55.61877299319158,time:4.589999999999947
mV:38.1147563459064,time:4.599999999999946
6000
1.8
currents = np.arange(0,70,0.2)
I_and_freq_list = []
def find_firing_rate(driving_current):
I_list = create_I_list(driving_current, 0.01, 120, 120)
Vm, Im = HodHux_ELEC380(I_list, 0.01, 0)
peaks, _ = find_peaks(Vm, height=0)
if len(peaks) == 0:
frequency = 0
else:
frequency = (len(peaks) / 60) * 1000 #convert to Hz
return frequency
for driving_current in currents:
I_and_freq_list.append((driving_current, find_firing_rate(driving_current)))
driving_currents = [i[0] for i in I_and_freq_list]
frequencies = [i[1] for i in I_and_freq_list]
plt.plot(driving_currents, frequencies)
plt.xlabel('current (mA)')
plt.ylabel('firing frequency (Hz)')
I_A = create_I_list(15, 0.01, 80, 80)
time = np.arange(0, 80, 0.01)
V_mem_A, I_mem_A = HodHux_ELEC380(I_A, 0.01, plot_activation = 0)
I_B = (V_mem_A / 0.15) / 1000 #units are weird here...
V_mem_B, I_mem_B = HodHux_ELEC380(I_B, 0.01, plot_activation = 0)
plt.plot(time, V_mem_A)
plt.plot(time, V_mem_B)
plt.title('2.1 Part 1')
plt.ylabel('Membrane Potential (mV)')
plt.xlabel('time (ms)')
plt.legend(['V_mem_A', 'V_mem_B'])
avmin, avmax = min(V_mem_A), max(V_mem_A)
for i, val in enumerate(V_mem_A):
V_mem_A[i] = (val-avmin) / (avmax-avmin)
bvmin, bvmax = min(V_mem_B), max(V_mem_B)
for i, val in enumerate(V_mem_B):
V_mem_B[i] = (val-bvmin) / (bvmax-bvmin)
plt.plot(time, V_mem_A)
plt.plot(time, V_mem_B)
plt.title('2.1 Part 2')
plt.ylabel('Normalized Membrane Potential (mV)')
plt.xlabel('time (ms)')
plt.legend(['norm_V_mem_A', 'norm_V_mem_B'])
I_A = create_I_list(15, 0.01, 80, 80)
time = np.arange(0, 80, 0.01)
V_mem_A, I_mem_A = HodHux_ELEC380(I_A, 0.01, plot_activation = 0)
old_I_B = (V_mem_A / 0.15) / 1000 #units are weird here...
new_I_B = (V_mem_A / 0.3) / 1000 #units are weird here...
old_V_mem_B, old_I_mem_B = HodHux_ELEC380(old_I_B, 0.01, plot_activation = 0)
new_V_mem_B, new_I_mem_B = HodHux_ELEC380(new_I_B, 0.01, plot_activation = 0)
plt.plot(time, old_V_mem_B)
plt.plot(time, new_V_mem_B)
plt.title('2.3 Proof of Concept')
plt.ylabel('Membrane Potential (mV)')
plt.xlabel('time (ms)')
plt.legend(['old_V_mem_B', 'new_V_mem_B'])
#wtf????????