def test_no_ion_selective_setter(self): protocol = protocols.SingleActionPotentialProtocol() paci_baseline = paci_2018.PaciModel() ion_selective_scales = {'I_CaL': .4, 'I_NaCa': .4} paci_no_ion = paci_2018.PaciModel() baseline_trace = paci_baseline.generate_response(protocol) paci_baseline.no_ion_selective = ion_selective_scales baseline_no_ion_trace = paci_baseline.generate_response( protocol, is_no_ion_selective=True) tst.assert_raises(AssertionError, tst.assert_array_equal, baseline_trace.y, baseline_no_ion_trace.y, 'generate_no_ion_trace() does not update trace')
def test_no_ion_selective_IK1_no_effect(self): protocol = protocols.SingleActionPotentialProtocol() paci_k1_increase = paci_2018.PaciModel( updated_parameters={'G_K1': 1.4}) ion_selective_scales = {'I_K1': .4} paci_k1_no_ion = paci_2018.PaciModel( no_ion_selective_dict=ion_selective_scales) trace_ion_selective = paci_k1_increase.generate_response(protocol) trace_no_ion_selective = paci_k1_no_ion.generate_response( protocol, is_no_ion_selective=True) tst.assert_raises(AssertionError, tst.assert_array_equal, trace_ion_selective.y, trace_no_ion_selective.y, 'generate_no_ion_trace() does not update trace')
def plot_baseline_irregular_pacing_trace(): model = paci_2018.PaciModel() trace = model.generate_response( protocol=protocols.IrregularPacingProtocol( duration=10, stimulation_offsets=[0.6, 0.4, 1., 0.1, 0.2, 0.0, 0.8, 0.9])) trace.plot() trace.pacing_info.plot_peaks_and_apd_ends(trace=trace) plt.savefig( 'figures/Irregular Pacing Figure/baseline_irregular_pacing_trace.svg')
def plot_all_in_system_of_equations(duration=10): model = paci_2018.PaciModel() model.generate_response( protocol=protocols.SingleActionPotentialProtocol(duration=duration)) for i in range(len(model.y_names)): plt.figure() plt.plot([timestamp[i] for timestamp in model.full_y]) plt.savefig('figures/before_hold_i_na_480/{}.png'.format( model.y_names[i]))
def test_generate_trace_SAP(self): protocol = protocols.SingleActionPotentialProtocol() baseline_model = paci_2018.PaciModel() baseline_model.generate_response(protocol) self.assertTrue( len(baseline_model.t) > 100, 'Paci errored in less than .4s') self.assertTrue( min(baseline_model.y_voltage) < -.01, 'baseline Paci min is greater than .01') self.assertTrue( max(baseline_model.y_voltage) < .06, 'baseline Paci max is greater than .06')
def plot_baseline_voltage_clamp_trace(): model = paci_2018.PaciModel() steps = [ protocols.VoltageClampStep(duration=0.9, voltage=-0.08), protocols.VoltageClampStep(duration=0.7, voltage=-0.12), protocols.VoltageClampStep(duration=0.5, voltage=-0.06), protocols.VoltageClampStep(duration=0.9, voltage=-0.04), protocols.VoltageClampStep(duration=0.95, voltage=0.02), protocols.VoltageClampStep(duration=0.9, voltage=0.04), ] trace = model.generate_response( protocol=protocols.VoltageClampProtocol(steps=steps)) trace.plot_with_currents() plt.savefig( 'figures/Voltage Protocol Figure/baseline_voltage_clamp_trace.svg')
def main(): """Run parameter tuning or voltage clamp protocol experiments here """ paci_model = paci_2018.PaciModel() paci_model.generate_response(protocol=VC_PROTOCOL_ZERO) fig = plt.figure(figsize=(10, 5)) ax_1 = fig.add_subplot(511) ax_1.plot([1000 * i for i in paci_model.t], [i * 1000 for i in paci_model.y_voltage], 'b', label='Voltage') plt.xlabel('Time (ms)') plt.ylabel(r'$V_m$ (mV)') I_NaCa = [] I_CaL = [] Cai = [] CaSR = [] i = 0 for currents in paci_model.current_response_info.currents: I_CaL.append(currents[4].value) I_NaCa.append(currents[8].value) Cai.append(paci_model.full_y[i][2]) CaSR.append(paci_model.full_y[i][1]) i = i + 1 ax_2 = fig.add_subplot(512) ax_2.plot([1000 * i for i in paci_model.t], I_CaL, 'r--', label='I_CaL') plt.ylabel(r'$I_{CaL}$ (nA/nF)') ax_3 = fig.add_subplot(513) ax_3.plot([1000 * i for i in paci_model.t], I_NaCa, 'r--', label='I_NaCa') plt.ylabel(r'$I_{NaCa}$ (nA/nF)') ax_4 = fig.add_subplot(514) ax_4.plot([1000 * i for i in paci_model.t], Cai, 'r--', label='Ca_i') plt.ylabel(r'$Cai$ (nA/nF)') ax_5 = fig.add_subplot(515) ax_5.plot([1000 * i for i in paci_model.t], CaSR, 'r--', label='CaSR') plt.ylabel(r'$Ca_{SR}$ (nA/nF)') plt.show()
def generate_restitution_curve(): max_pacing_rate = 1.1 model = paci_2018.PaciModel() cycle_lengths = [] pacing_rates = np.arange(0.1, max_pacing_rate, 0.1) for i in pacing_rates: print('Generating trace at pacing rate: {}'.format(i)) stimulation_count = 8 curr_trace = model.generate_response( protocol=protocols.IrregularPacingProtocol( duration=20, stimulation_offsets=[i for _ in range(stimulation_count)])) plt.figure() curr_trace.plot() curr_trace.pacing_info.plot_peaks_and_apd_ends(trace=curr_trace) plt.savefig('figures/Restitution Curve/{}_PacingRate.svg'.format(i)) relevant_peaks = curr_trace.pacing_info.peaks[1:1+stimulation_count] curr_cycle_lengths = [] for j in range(1, len(relevant_peaks)): curr_cycle_lengths.append(relevant_peaks[j] - relevant_peaks[j-1]) print('Curr cycle lengths: {}'.format(curr_cycle_lengths)) # Remove outliers if i == 0.5: median = 0.871659106127219 else: median = np.median(np.array(curr_cycle_lengths)) print('Median: {}'.format(median)) cycle_lengths.append(median) print('Pacing rates') print(pacing_rates) print('Cycle lengths') print(cycle_lengths) plt.figure() plt.plot(pacing_rates, cycle_lengths) plt.xlabel('Pacing Rate (s)') plt.ylabel('Cycle Length (s)') plt.savefig('figures/Restitution Curve/Restitution Curve.svg')