- Author:
- Shelley Fong <s.fong@auckland.ac.nz>
- Date:
- 2022-02-28 14:45:16+13:00
- Desc:
- Fix equation finding K Kappa and update parameters
- Permanent Source URI:
- https://models.fieldml.org/workspace/831/rawfile/e236e9ab05e6d6c68759cde94bf4d795dea6c1ff/parameter_fitting/PSO_GHK_fitting_curve.m
clear;
% clc;
% close all;
%% Options
run_optimisation = true;
%% Set up directories
current_dir = cd;
Idx_bactcclash = find(current_dir == filesep);
main_dir = current_dir; %(1:Idx_bactcclash(end));
data_dir = [main_dir '\data' filesep];
code_dir = [main_dir '\code' filesep];
output_dir = [main_dir '\output' filesep];
storage_dir = [main_dir '\storage' filesep];
%% Define constants
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_PMR [=] mS [=] mA/V
V = (-150:1:80)/1000;
cCao = 1.8;
cCai = 6e-5;
Cai = 6e-5; %millimolar
Cm = 0.001; % Unit microF
G_pmr = 0.05*Cm; %Cm*0.433*(1+0.6/(1+((3.8e-5/Cai)^1.4)));
E_K = R*T/F*log(cCao/cCai);
E_K_st = R*T/F*log(cCao/cCai);
I_lin = G_pmr*(V-E_K); % Unit mA don't consider gating variable: just finding conductance.
Vstart = 1; %31;
Vend = length(V); %101;
error_func = @(G_GHK) square_error(I_lin(Vstart:Vend) - calc_IGHK(G_GHK,V(Vstart:Vend),cCai,cCao));
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 'tcc_G_GHK.mat'],'G_GHK');
else
load([storage_dir 'tcc_G_GHK.mat']);
end
G_GHK2 = 0.00001;
I_GHK = calc_IGHK(G_GHK,V,cCai,cCao);
I_GHK2 = calc_IGHK(G_GHK2,V,cCai,cCao);
h = figure;
% subplot(1,2,1)
plot(1000*V,1e6*I_lin,'k--',1000*V,1e6*I_GHK);
legend('LRd','BG','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');