Location: BG_TCC @ 9013e062f457 / parameter_fitting / K_kappa.m

Author:
Shelley Fong <s.fong@auckland.ac.nz>
Date:
2022-02-25 14:06:24+13:00
Desc:
Init
Permanent Source URI:
https://models.cellml.org/workspace/831/rawfile/9013e062f4570d3150bcc4df8b75ce3f956bc17a/parameter_fitting/K_kappa.m

% 18 April: make it fit 6 state CC model

clear;

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


%% Define constants and volumes ( [=] pL)
R = 8.314; % unit J/mol/K
T = 310;
F = 96485;
W_i = 38;
W_e = 5.182;
N_A = 6.022e23;
x_tcc_channel = 50000/N_A*1e15; % channel density: unit fmol. Using Pan value for LCC

%% Load stoichiometric matrices  

N_f = [1	0	0	0	0	0	0	0; % includes GHK for Cai and Cao
0	0	0	0	0	0	0	0;
0	1	0	0	0	1	0	0;
0	0	0	1	0	0	1	0;
0	0	0	0	0	0	0	1;
0	0	1	0	0	0	0	0;
0	0	0	0	1	0	0	0;
0	0	0	0	0	0	0	0;
];

N_r = [0	0	0	0	0	0	0	0;
1	0	0	0	0	0	0	0;
0	0	0	0	0	0	0	0;
0	1	0	0	0	0	0	0;
0	0	0	1	0	0	0	0;
0	0	0	0	0	1	0	0;
0	0	1	0	0	0	1	0;
0	0	0	0	1	0	0	1;
];

N_fT = transpose(N_f);
N_rT = transpose(N_r);

N = N_r - N_f;
% N_T = N_rT - N_fT;

num_cols = size(N,2); % number of reactions
I = eye(num_cols); 

M = [I N_fT; I N_rT];
M_rref = rref(M);

% GHK permeability for K in Ks channel (see PSO_GHK_fitting_curve.m)
load([storage_dir 'tcc_G_GHK.mat']);
P_CaTCC = G_GHK/F * 1e12; % Unit pL/s

%% Set up the vectors
load([storage_dir 'TCC_b_parameters.mat']);
params_b = params_vec;

load([storage_dir 'TCC_g_parameters.mat']);
params_g = params_vec;

% unit s^-1
alpha_b = params_b(1); % unit s^-1
beta_b = params_b(3); % unit s^-1

alpha_g = params_g(1); % unit s^-1
beta_g = params_g(3); % unit s^-1

kf_Na = [P_CaTCC/x_tcc_channel; ... % R_GHK
    2*alpha_b; ... % Rb_00
    2*alpha_b; ... % Rb_01
    alpha_b; ... % Rb_10
    alpha_b; ... % Rb_11
    alpha_g; ... % Rg_00
    alpha_g; ... % Rg_10
    alpha_g];    % Rg_20

kr_Na = [P_CaTCC/x_tcc_channel; ... % R_GHK
    beta_b; ... % Rb_00
    beta_b; ... % Rb_01
    2*beta_b; ... % Rb_10
    2*beta_b; ... % Rb_11
    beta_g; ... % Rg_00
    beta_g; ... % Rg_10
    beta_g];    % Rg_20

% Overall
kf = kf_Na;
kr = kr_Na;

k = [kf;kr];
% don't need W: all ones. only use Wi and We for GHK permeabilities : but
% use the P value from Pan.
% W = [ones(size(N,2),1);W_i;W_e;ones(10,1);W_i;W_e;ones(16,1);W_i;W_e;ones(12,1);...
%     ones(15,1);W_i;W_i;W_i;W_i;ones(6,1);W_i;W_i;W_i;W_i];

lambdaW = exp(pinv(M)*log(k));
lambda = lambdaW; %./W;
kappa = lambda(1:size(N,2));   % [=] mol/s if corresponding v [=] mol/s
K = lambda(size(N,2)+1:end);   % [=] 1/mol if corresponding q [=] mol

save([output_dir 'K_kappa_1.mat'],'kappa','K');

%% Checks
N_rref = rref(N);
R_zdvat = null(N,'r');

K_eq = kf./kr;
zero_est = R_zdvat'*K_eq;

k_est = exp(M*log(lambdaW));
diff = sum(abs((k-k_est)./k));

kdiff = [k,k_est];

if diff > 1
    warning('lol DIFF is greater than 1, nublet.');
end

%% display text for cellml
rname = {'to','z00','z01','z10','z11','z20','z21','y00','y10','y20','y30'};
Kname = {'Ki','Ke','S00','S10','S20','S30','S01','S11','S21','S31'};
zname = {'z', 'y'};
for ik = 1:length(kappa)
    fprintf('var kappa_%s: fmol_per_sec {init: %g, pub: out};\n', rname{ik}, kappa(ik));
end
for ik = 1:length(K)
    fprintf('var K_%s: per_fmol {init: %g, pub: out};\n', Kname{ik}, K(ik));
end
for ik = 1:length(zf)
    fprintf('var z_%sf: dimensionless {init: %g, pub: out};\n', zname{ik}, zf(ik));
end
for ik = 1:length(zr)
    fprintf('var z_%sr: dimensionless {init: %g, pub: out};\n', zname{ik}, zr(ik));
end
if true
    % component import parameters
for ik = 1:length(kappa)
    fprintf('var kappa_%s: fmol_per_sec {pub: in};\n', rname{ik});
end
for ik = 1:length(K)
    fprintf('var K_%s: per_fmol {pub: in};\n', Kname{ik});
end
    for ik = 1:length(zf)
        fprintf('var z_%sf: dimensionless {pub: in};\n', zname{ik});
    end
    for ik = 1:length(zr)
        fprintf('var z_%sr: dimensionless {pub: in};\n', zname{ik});
    end
    
    % mapping
    for ik = 1:length(kappa)
        fprintf('vars kappa_%s and kappa_%s;\n', rname{ik}, rname{ik});
    end
    for ik = 1:length(K)
        fprintf('vars K_%s and K_%s;\n', Kname{ik}, Kname{ik});
    end    
    for ik = 1:length(zf)
        fprintf('vars z_%sf and z_%sf;\n', zname{ik}, zname{ik});
    end
    for ik = 1:length(zr)
        fprintf('vars z_%sr and z_%sr;\n', zname{ik}, zname{ik});
    end
end