%plot dynamics
clear

IP3Rconc = 0.26667
filelong = 100001
filenum  = 11
set(0,'DefaultLineLineWidth',1);
CaIPlow               = zeros(filelong, filenum);
IP3RinactIPlow        = zeros(filelong, filenum);
CaIPmid               = zeros(filelong, filenum);
IP3RinactIPmid        = zeros(filelong, filenum);
CaIPhi                = zeros(filelong, filenum);
IP3RinactIPhi         = zeros(filelong, filenum);
tempload              = zeros(filelong, 2);

linecolor = [0,   0,   0;    %black
             0.5, 0,   0.5;  %violet
             0,   0,   1;    %blue
             0,   1,   1;    %cyan
             0,   0.5, 0;    %dark green
             0,   1,   0;    %light green
             1,   1,   0;    %yellow
             1,   0.5, 0;    %orange
             1,   0,   0;    %red
             1,   0,   1;    %magenta
             1,   0.5, 1];   %pink

%CaInflux = [0,  2008,  5218,  8181, 10406, 12054, 13324, 14351, 15222, 15990, 16694; % [IP3] = 0.1 uM
%            0,  1749,  4775,  7674,  9870, 11503, 12762, 13780, 14643, 15404, 16100; % [IP3] = 2.5 uM
%            0,  1414,  4359,  7261,  9461, 11096, 12357, 13377, 14241, 15004, 15702];% [IP3] =  10 uM
         
%load Ca transient
for i = 1:11
    tempload = load(strcat('trajectory_IP30.1Ca', num2str(i-1), '_Ca.plot'));
    CaIPlow(:, i) = tempload(:,2);
end
%load IP3Rinact transient
for i = 1:11
    tempload = load(strcat('trajectory_IP30.1Ca', num2str(i-1), '_IP3Rinact.plot'));
    IP3RinactIPlow(:, i) = tempload(:,2) / IP3Rconc * 100;
end

%load Ca transient
for i = 1:11
    tempload = load(strcat('trajectory_IP32.5Ca', num2str(i-1), '_Ca.plot'));
    CaIPmid(:, i) = tempload(:,2);
end
%load IP3Rinact transient
for i = 1:11
    tempload = load(strcat('trajectory_IP32.5Ca', num2str(i-1), '_IP3Rinact.plot'));
    IP3RinactIPmid(:, i) = tempload(:,2) / IP3Rconc * 100;
end

%load Ca transient
for i = 1:11
    tempload = load(strcat('trajectory_IP310Ca', num2str(i-1), '_Ca.plot'));
    CaIPhi(:, i) = tempload(:,2);
end
%load IP3Rinact transient
for i = 1:11
    tempload = load(strcat('trajectory_IP310Ca', num2str(i-1), '_IP3Rinact.plot'));
    IP3RinactIPhi(:, i) = tempload(:,2) / IP3Rconc * 100;
end


subplot(1,3,1)
for i = 11:-1:1
semilogx(CaIPlow(5001:5021,   i), IP3RinactIPlow(5001:5021,   i), 'Color',linecolor(i,:))
hold on
semilogx(CaIPlow(5021:100001, i), IP3RinactIPlow(5021:100001, i), 'Color',linecolor(i,:))           
end
axis([0.05 50 0 100]);
axis square
set(gca,'xtick',[0.05 0.1 1 10 50]);
set(gca,'ytick',[0 20 40 60 80 100]);
set(gca,'XTickLabel','0.05|0.1|1|10|50')
xlabel('[Ca2+]i (\muM)')
ylabel('IP3R inactivated (%)')
title('[IP3] = 0.1 \muM')

subplot(1,3,2)
for i = 11:-1:1
semilogx(CaIPmid(5001:5021,   i), IP3RinactIPmid(5001:5021,   i), 'Color',linecolor(i,:))
hold on
semilogx(CaIPmid(5021:100001, i), IP3RinactIPmid(5021:100001, i), 'Color',linecolor(i,:))           
end
axis([0.05 50 0 100]);
axis square
set(gca,'xtick',[0.05 0.1 1 10 50]);
set(gca,'ytick',[0 20 40 60 80 100]);
set(gca,'XTickLabel','0.05|0.1|1|10|50')
xlabel('[Ca2+]i (\muM)')
ylabel('IP3R inactivated (%)')
title('[IP3] = 2.5 \muM')

subplot(1,3,3)
for i = 11:-1:1
semilogx(CaIPhi(5001:5021,   i), IP3RinactIPhi(5001:5021,   i), 'Color',linecolor(i,:))
hold on
semilogx(CaIPhi(5021:100001, i), IP3RinactIPhi(5021:100001, i), 'Color',linecolor(i,:))           
end
axis([0.05 50 0 100]);
axis square
set(gca,'xtick',[0.05 0.1 1 10 50]);
set(gca,'ytick',[0 20 40 60 80 100]);
set(gca,'XTickLabel','0.05|0.1|1|10|50')
xlabel('[Ca2+]i (\muM)')
ylabel('IP3R inactivated (%)')
title('[IP3] = 10 \muM')