-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate-mc3nocomp.py
141 lines (125 loc) · 3.92 KB
/
simulate-mc3nocomp.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
#!/usr/bin/env python3
from __future__ import print_function
import sys
sys.path.append('../lib/')
import os
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import pints
import model as m; m.vhold = 0
"""
Simulation for single model cell experiment data with amplifier settings.
"""
sim_list = ['staircase', 'sinewave', 'ap-beattie', 'ap-lei']
data_idx = {'staircase': 1, 'sinewave': 0, 'ap-beattie': 2, 'ap-lei': 3}
protocol_list = {
'staircase': 'staircase-ramp.csv',
'sinewave': 'sinewave-ramp.csv',
'ap-beattie': 'ap-beattie.csv',
'ap-lei': 'ap-lei.csv'}
legend_ncol = {
'staircase': (2, 1),
'sinewave': (1, 1),
'ap-beattie': (4, 2),
'ap-lei': (4, 2)}
try:
which_sim = sys.argv[1]
except:
print('Usage: python %s [str:which_sim]' % os.path.basename(__file__))
sys.exit()
if which_sim not in sim_list:
raise ValueError('Input data %s is not available in the predict list' \
% which_sim)
savedir = './figs'
if not os.path.isdir(savedir):
os.makedirs(savedir)
# Load data
import util
idx = [0, data_idx[which_sim], 0]
f = 'data/20191011_mc3re_nocomp.dat'
whole_data, times = util.load(f, idx, vccc=True)
times = times * 1e3 # s -> ms
data_cc = whole_data[2] * 1e3 # V -> mV
data_vc = whole_data[1] * 1e3 # V -> mV
data = (whole_data[0] + whole_data[3]) * 1e12 # A -> pA
#out = np.array([times * 1e-3, data_vc]).T
#np.savetxt('recorded-voltage.csv', out, delimiter=',', comments='',
# header='\"time\",\"voltage\"')
saveas = 'mc3nocomp'
# Model
model = m.Model('../mmt-model-files/full2-voltage-clamp-mc3.mmt',
protocol_def=protocol_list[which_sim],
temperature=273.15 + 23.0, # K
transform=None,
readout='voltageclamp.Iout',
useFilterCap=False)
parameters = [
'mc.gk',
'mc.ck',
'mc.gm',
'voltageclamp.cprs',
'membrane.cm',
'voltageclamp.rseries',
'voltageclamp.voffset_eff',
'voltageclamp.cprs_est',
'voltageclamp.cm_est',
'voltageclamp.rseries_est',
]
model.set_parameters(parameters)
# Set parameters
#''' What we have in the circuit
p = [
1. / 0.1, # pA/mV = 1/GOhm; g_kinetics
1000., # pF; C_kinetics
1. / 0.5, # pA/mV = 1/GOhm; g_membrane
4.7, # pF; Cprs
22, # pF; Cm
30e-3, # GOhm; Rs
0, # mV; Voffset+
0., # pF; Cprs*
0., # pF; Cm*
0., # GOhm; Rs*
]
''' What the machine thought
p = [
1. / 0.1, # pA/mV = 1/GOhm; g_kinetics
1000., # pF; C_kinetics
1. / 0.5, # pA/mV = 1/GOhm; g_membrane
8.88, # pF; Cprs
41.19, # pF; Cm
33.6e-3, # GOhm; Rs
-1.2, # mV; Voffset+
0., # pF; Cprs*
0., # pF; Cm*
0., # GOhm; Rs*
]
#'''
# Simulate
extra_log = ['voltageclamp.Vc', 'membrane.V']
simulation = model.simulate(p, times, extra_log=extra_log)
Iout = simulation['voltageclamp.Iout']
Vc = simulation['voltageclamp.Vc']
Vm = simulation['membrane.V']
# Plot
fig, axes = plt.subplots(2, 1, sharex=True, figsize=(7, 5))
axes[0].plot(times, data_vc, c='#a6bddb', label=r'Measured $V_{cmd}$')
axes[0].plot(times, data_cc, c='#feb24c', label=r'Measured $V_{m}$')
axes[0].plot(times, Vc, ls='--', c='#045a8d', label=r'Input $V_{cmd}$')
axes[0].plot(times, Vm, ls='--', c='#bd0026', label=r'Simulated $V_{m}$')
axes[0].set_ylabel('Voltage (mV)', fontsize=14)
#axes[0].set_xticks([])
axes[0].legend(ncol=legend_ncol[which_sim][0])
axes[1].plot(times, data, alpha=0.5, label='Measurement')
axes[1].plot(times, Iout, ls='--', label='Simulation')
axes[1].set_ylim([-800, 1200]) # TODO?
axes[1].legend(ncol=legend_ncol[which_sim][1])
axes[1].set_ylabel('Current (pA)', fontsize=14)
axes[1].set_xlabel('Time (ms)', fontsize=14)
plt.subplots_adjust(hspace=0)
plt.savefig('%s/simulate-%s-%s.pdf' % (savedir, saveas, which_sim),
format='pdf', bbox_inches='tight')
plt.savefig('%s/simulate-%s-%s' % (savedir, saveas, which_sim), dpi=300,
bbox_inches='tight')
plt.close()