Location: BG_Ks @ 5bbfc4d00cc6 / matlab_parameter_fitting / xs1_gate_fitting.m

Author:
Shelley Fong <s.fong@auckland.ac.nz>
Date:
2022-04-01 15:08:17+13:00
Desc:
With new densities found from fitting Pan - K + Ks to Clancy model
Permanent Source URI:
https://models.physiomeproject.org/workspace/82d/rawfile/5bbfc4d00cc6a4f7e910d47b7fbae5b14c56ab15/matlab_parameter_fitting/xs1_gate_fitting.m

% based on markov model of Pan's Na m channel
% work in SECONDS not ms.

clear;
%clc;
% close all;

%% Options
run_optimisation = false;

%% Set directories
current_dir = pwd;
main_dir = current_dir; %
data_dir = [main_dir '\data' filesep];
output_dir = [main_dir '\output' filesep];
storage_dir = [main_dir '\storage' filesep];

%% Steady-state gating parameters and time constants

V = transpose(-120:1:60); % unit mV
V(91) = []; % remove discontinuity at V=-30 

%  gate : % units: millivolt, seconds
xs1_infinity = 1./(1+exp(-(V-1.5)/16.7));
tau_xs1 = 0.001./((7.19e-5*(V+30)./(1-exp(-0.148.*(V+30))))+(0.000131*(V+30)./(exp(0.0687.*(V+30))-1)));

alpha_xs1 = xs1_infinity./tau_xs1;
beta_xs1 = (1./tau_xs1) - alpha_xs1;

%% Fit bond graph parameters to model
% params: [kf, zf, kr, zr];
% Kf corresponds to k_zdv20: 1*alpha_xs1
error_func_alpha = @(params) square_error(alpha_xs1 - calc_alpha(params,V/1000)); % fit to alpha - k.exp(zFV/RT) : do lsqminerror.
error_func_beta = @(params) square_error(beta_xs1 - calc_beta(params,V/1000));
error_func_gss = @(params) square_error(xs1_infinity - p2gss(params,V));
error_func_tau = @(params) square_error(tau_xs1- p2tau(params,V));

error_func = @(params) error_func_alpha(params) + error_func_beta(params) + error_func_gss(params) + error_func_tau(params);

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

options_unc = optimoptions('fminunc','MaxFunEvals',10000);
options_ps = optimoptions('particleswarm','UseParallel',false,'HybridFcn',@fmincon,'SwarmSize',750);

if run_optimisation
    [params_vec,fval,exitflag,output] = particleswarm(error_func,4,lb,ub,options_ps);
    save([storage_dir 'ks_xs1_parameters.mat'],'params_vec');
else
    load([storage_dir 'ks_xs1_parameters.mat']);
end
% [params_vec,fval,exitflag,output,grad,hessian] = fminunc(error_func,params_vec,options_unc);


g_ss_fit = p2gss(params_vec,V);
h1 = figure;
plot(V,xs1_infinity,'k--','LineWidth',4);
hold on;
plot(V,g_ss_fit,'k','LineWidth',4);
xlabel('Voltage (mV)');
ylabel('m_{ss}');
set(gca,'FontSize',28);
xlim([-120 60]);
set(gca,'XTick',-120:30:60);
set(gca,'YTick',0:0.2:1);
xticklabels({-120,'',-60,'',0,'',60});
yticklabels({0,'','','','',1});
set(gca,'LineWidth',3);
grid on;

tau_fit = p2tau(params_vec,V);
h2 = figure;
plot(V,tau_xs1,'k--','LineWidth',4);
hold on;
plot(V,tau_fit,'k','LineWidth',4);
% legend('Luo and Rudy','Fitted');
xlabel('Voltage (mV)');
ylabel('\tau_xs1 (ms)');
set(gca,'FontSize',28);
xlim([-120 60]);
set(gca,'XTick',-120:30:60);
% set(gca,'YTick',0:0.2:1);
xticklabels({-120,'',-60,'',0,'',60});
% yticklabels({0,'','','','',1});
set(gca,'LineWidth',3);
set(gca,'xgrid','on');

alpha_fit = calc_alpha(params_vec,V/1000);
beta_fit = calc_beta(params_vec,V/1000);
figure,
subplot(1,2,1)
plot(V,alpha_xs1,V,alpha_fit);
legend('original','fit');
title('alpha');
subplot(1,2,2)
plot(V,beta_xs1,V,beta_fit);
legend('original','fit');
title('beta');

% print_figure(h1,output_dir,'xs1_infinity');
% print_figure(h2,output_dir,'tau_xs1');