Location: BG_Kp @ 4e1d102e1319 / matlab_parameter_fitting / Kp_IV_curve.m

Author:
Shelley Fong <s.fong@auckland.ac.nz>
Date:
2022-04-26 08:59:38+12:00
Desc:
Adding matlab curve and gate fitting files from Pan
Permanent Source URI:
https://staging.physiomeproject.org/workspace/825/rawfile/4e1d102e131954573132c707b5f2e764fb008587/matlab_parameter_fitting/Kp_IV_curve.m

clear;
% clc;
% close all;

%% Options
run_optimisation = true;

%% Set up directories
current_dir = cd;
Idx_backslash = find(current_dir == filesep);
main_dir = current_dir(1:Idx_backslash(end));
data_dir = ['data' filesep];
code_dir = ['code' filesep];
output_dir = ['output' filesep];
storage_dir = ['storage' filesep];

%% Define constants
R = 8.314;
T = 310;
F = 96485;

%% Plot I-V curves
cKo_st = 5.4;
cKi_st = 145;

A_geo = 1.1e-5; %1.534e-4; % Unit cm^2
G_Kp = 0.0183*A_geo; % Unit mA/V

V = (-120:1:60)/1000;
E_K = R*T/F*log(cKo_st/cKi_st);
I_lin = G_Kp*(V-E_K);

error_func = @(G_GHK) square_error(I_lin(V>=0) - calc_IGHK(G_GHK,V(V>=0),cKi_st,cKo_st));

A = [];
b = [];
Aeq = [];
beq = [];
lb = [-Inf];
ub = [Inf];

options_ps = optimoptions('particleswarm','UseParallel',false,'HybridFcn',@fminunc,'SwarmSize',200);

if run_optimisation
    [G_GHK,fval,exitflag,output] = particleswarm(error_func,1,lb,ub,options_ps);
    save([storage_dir 'Kp_G_GHK.mat'],'G_GHK');
else
    load([storage_dir 'Kp_G_GHK.mat']);
end
I_GHK = calc_IGHK(G_GHK,V,cKi_st,cKo_st);

h = figure;
plot(1000*V,1e6*I_lin,'k--',1000*V,1e6*I_GHK,'k','LineWidth',2);
legend('LRd','BG','Location','southeast');
ylabel('Current (nA)');
xlabel('Voltage (mV)');
set(gca,'FontSize',16);
grid on

diff = sum(abs((I_lin-I_GHK)./I_lin))

% print_figure(h,output_dir,'Kp_IV_curve');