
clear all

% Create a qualitative energy vs reaction coordinate plot with and without
% the presence of a catalyst.
%
% Executes properly on MATLAB version 9.4.0.813654 (R2018a).
% Executes with arriw Annotation errors on OCTAVE version 4.2.1.
% Joshua C. Vaughan 5/8/2020


x = linspace(-0.9,1,2^10);

y_offsets = 20;
scale = 10;
peak_amp = 1;
k =0.7;
red_fac = 0.6;
y1 = y_offsets + scale*( peak_amp*cos(2*pi*k*x) - x );
y2 = y_offsets + scale*( red_fac*peak_amp*cos(2*pi*k*(x+0.035)) - x - (1-red_fac) );

ch = 2;

if ch==1
    % do nothing
elseif ch==2
    % keep only inds from a specified range
    keep_inds = x>-0.8 & x<0.9;
    x = x(keep_inds);
    y1 = y1(keep_inds);
    y2 = y2(keep_inds);
end

figure(1); clf
ax_lw = 2;
pl_lw = 2;
ax_fs = 24;
la_fs = 24;
lg_fs = 20;
fontname = 'Arial';

plot(x,y1,'k',x,y2-0.2,'b','linewidth',pl_lw)
xlabel('reaction coordinate','fontsize',la_fs)
ylabel('energy','fontsize',la_fs)
set(gca,'fontsize',la_fs)
set(gca,'linewidth',ax_lw)
set(gca,'tickdir','out')
set(gcf,'color',[1 1 1])
set(gca,'fontname',fontname)
dy = diff(minmax([y1 y2]));
xlim([-0.85 0.95])
ylim([min([y1 y2])-dy*0.25 max([y1 y2])+dy*0.1])
set(gca,'xtick',[-0.664 0.76])
set(gca,'yticklabel',{'','','',''})
set(gca,'xtick',[-0.664 0.76])
set(gca,'xticklabel',{'reactants','products'})
set(gca,'yticklabel',{'','','',''})

% Annotate. Use package from link below.
% https://www.mathworks.com/matlabcentral/fileexchange/63760-annotate?s_tid=mwa_osa_a
ypeak1 = 30.26;
ypeak2 = 22.6;
ytrough1 = 16.9;
ytrough2 = 2.6;

an_lw = 1.5;
dtx = 0.25;
dty = 2.75;
tx_fs = 24;

hold on
plot([-0.5 0.57],ypeak1*[1 1],'--','color',0.5*[1 1 1],'linewidth',an_lw)
plot([-0.5 0.57],ypeak2*[1 1],'--','color',0.5*[1 1 1],'linewidth',an_lw)
plot([-0.8 0.1],ytrough1*[1 1],'--','color',0.5*[1 1 1],'linewidth',an_lw)
plot([0.2 0.9],ytrough2*[1 1],'--','color',0.5*[1 1 1],'linewidth',an_lw)
hold off

h=legend('uncatalyzed','catalyzed');
set(h,'box','off')
set(h,'fontsize',lg_fs)
set(h,'position',[0.1770 0.2672 0.3527 0.1458])


a1_xp = [-0.43 -0.43];
a1_yp = [ytrough1 ypeak1];
obj1 = Annotate(gca,'doublearrow',a1_xp,a1_yp,'color','r','linewidth',an_lw);
text(a1_xp(1),min(a1_yp)-dty,'{\itE}_a^f','fontsize',tx_fs,'color','r','HorizontalAlignment','center')

a2_xp = a1_xp + dtx + 0.0;
a2_yp =[ytrough1 ypeak2];
obj2 = Annotate(gca,'doublearrow',a2_xp,a2_yp,'color','r','linewidth',an_lw);
text(a2_xp(1),min(a1_yp)-dty,'{\itE}^f_{a,cat}','fontsize',tx_fs,'color','r','HorizontalAlignment','center')

a3_xp = [0.24 0.24]+0.02;
a3_yp =[ytrough2 ypeak1];
obj2 = Annotate(gca,'doublearrow',a3_xp,a3_yp,'color','r','linewidth',an_lw);
text(a3_xp(1),min(a3_yp)-dty,'{\itE}_a^r','fontsize',tx_fs,'color','r','HorizontalAlignment','center')

a4_xp = a3_xp + dtx;
a4_yp =[ytrough2 ypeak2];
obj2 = Annotate(gca,'doublearrow',a4_xp,a4_yp,'color','r','linewidth',an_lw);
text(a4_xp(1),min(a4_yp)-dty,'{\itE}_{a,cat}^r','fontsize',tx_fs,'color','r','HorizontalAlignment','center')

a5_xp = [0 0]-0.075;
a5_yp =[ypeak1 ypeak2];
obj2 = Annotate(gca,'doublearrow',a5_xp,a5_yp,'color','r','linewidth',an_lw);
text(a5_xp(1)+0.075,mean(a5_yp),'\Delta','fontsize',tx_fs,'color','r','HorizontalAlignment','center')

set(gca,'LooseInset',get(gca,'TightInset'));






%
