%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Weber AM, Wong FK, Tufford AR, Schlichter LC, Matveev V, Stanley EF
%        N-type Ca2+ channels carry the largest current: 
%    implications for nanodomains and transmitter release.
%
%              Nature Neuroscience 13: 1348-1350.
%
% This script plots data summarized in Fig. 2(d) based on data produced
%               by CalC script GenerateData.par
%
%               Victor Matveev, August 8, 2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(2);
hold off;
XM = 100;

prefix={'L', 'N'};

TT     = 0.5;
kappa  = 50;
D      = 0.05;
PWR    = 5;

cls = [ [0.5 0.5 0.5]; [0 0 0] ];
lst = {':', '--', '-'};
iPanel = 1;

for V = [65 40]
    subplot(2,1,iPanel); 
    iPanel = iPanel + 1;
    lgnd   = {};
    for i = 1 : length(prefix)
            fname = ['1Dr_V', num2str(V), '_Ca_', prefix{i}, '_kappa_', num2str(kappa), '_BD_', num2str(D), '_300x300.dat'];
            A     = process(fname);
            I     = find(A(1,1,:) > TT);
            it    = I(1) - 1;
            ind   = 0;
            for Aff = [5 10 100];
                hill     = @(x,K,n) x.^n ./ (x + K).^n;
                ind      = ind + 1;
                lgnd     = [ lgnd, ['I_{Ca,', prefix{i}, '} D_B=', num2str(D), '\mum^2/ms, K=', num2str(Aff), '\muM '] ];
                plot(A(2,:,it)*1000, hill(A(3,:,it),Aff,PWR), 'color', cls(i,:), 'linestyle', lst{ind}, 'linewidth', 2 ); 
                hold on;
            end
    end
    axis([0 XM 0 1 ]);
    plot([0 XM], [0.5 0.5], 'k:', 'linewidth', 2);
    grid on;
    legend(lgnd); 

    set(gca, 'XTick', [0:10:XM]);
    xlabel('Distance (nm)');
    ylabel(['[Ca^{2+}]^', num2str(PWR), '/ ([Ca^{2+}]+ K)^', num2str(PWR) ]);
    tstr = ['Fig. 2d: V = -', num2str(V), 'ms, time=', num2str(A(1,1,it)),' ms, Buffer capacity=', num2str(kappa)];
    title(tstr);

end