Location: BG_ns_Ca @ 6da40f865c78 / matlab_parameter_fitting / PSO_GHK_fitting_curve.asv

Author:
Shelley Fong <s.fong@auckland.ac.nz>
Date:
2022-03-17 11:11:36+13:00
Desc:
Updated parameter finding and cellml script
Permanent Source URI:
https://models.physiomeproject.org/workspace/83b/rawfile/6da40f865c787757867dbc173c29f385f7a3bf29/matlab_parameter_fitting/PSO_GHK_fitting_curve.asv

clear;
% clc;
% close all;

%% Options
run_optimisation = true;

%% Set up directories
current_dir = pwd;
Idx_backslash = find(current_dir == filesep);
main_dir = current_dir; %(1:Idx_backslash(end));
output_dir = [main_dir '\output' filesep];
storage_dir = current_dir; %[main_dir '\storage' filesep];

%% Define constants - coonsistent with VOLTS.
R = 8.314;
T = 310;
F = 96485;

%% Plot I-V curves
% UNITS:
%     I = G_GHK * [K] [=] mA
%     G_GHK = I/[K] [=] Amp.litre/mol
%     G_lin [=] mS [=] mA/V
    
V = (-110:1:65)/1000;
V(find(V == 0,1)) = [];
V = V';

cCao = 1.8;
cCai = 6e-5; %millimolar
cNao = 140;
cNai = 10;
cKo = 5.4;
cKi = 145;
z = 2;
Cm = 153400e-9; % Unit microF
SA = 11400e-6; % [=] mm2, using SA(um2) = 0.3*vol (in um3) (Bers)
P_ns_Ca = 1.75e-7; % [=] cm_per_second
K_m_ns_Ca = 0.0012; % [=] mM
gamma = 0.75; % [=] dimensionless

% the following currents in units [=] uA_per_mm2
I_ns_Na = P_ns_Ca*V*(F^2)/(R*T).*(gamma*cNai*exp(1*V*F/(R*T))-gamma*cNao)./(exp(V*F/(R*T))-1);
I_ns_K = P_ns_Ca*V*(F^2)/(R*T).*(gamma*cKi*exp(1*V*F/(R*T))-gamma*cKo)./(exp(V*F/(R*T))-1);
i_ns_Na = I_ns_Na./(1+(K_m_ns_Ca/cCai ^ 3));
i_ns_K = I_ns_K./(1+(K_m_ns_Ca/cCai ^ 3));
i_ns_Ca = i_ns_Na+i_ns_K;

% convert uA/mm2 to unit mA
i_ns_Ca_lrd = 1e-3*SA*i_ns_Ca; 

Vstart = 1;
Vend =  length(V);
error_func = @(G_GHK) square_error(i_ns_Ca_lrd(Vstart:Vend) - calc_IGHK(G_GHK,V(Vstart:Vend),cCai,cCao, z));

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

options_ps = optimoptions('particleswarm','UseParallel',false,'HybridFcn',@fminunc,'SwarmSize',1000, ...
    'FunctionTolerance', 1e-9);

if run_optimisation
    [G_GHK,fval,exitflag,output] = particleswarm(error_func,1,lb,ub,options_ps);
    save([storage_dir '\nsCa_G_GHK.mat'],'G_GHK');
else
    load([storage_dir '\nsCa_G_GHK.mat']);
end

I_GHK = calc_IGHK(G_GHK,V,cCai,cCao,z);

h = figure;
% subplot(1,2,1)
plot(1000*V,1e6*I_lin,'k--',1000*V,1e6*I_GHK);
legend('linear','GHK fit','Location','southeast');
ylabel('Current (nA)');
xlabel('Voltage (mV)');
set(gca,'FontSize',16);

% subplot(1,2,2)
% plot(1000*V,1e6*I_lin,'k--',1000*V, 1e6*I_GHK2);
% legend('LRd','BG_test','Location','southeast');
% ylabel('Current (nA)');
% xlabel('Voltage (mV)');
% set(gca,'FontSize',16);

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