%------------------- LineshapeKin Simulation -----------------------------
%-- version 4.0 
%
% 5/8/09
% Written by Evgenii Kovrigin
% Medical College of Wisconsin
%
% 
function figure1 = PopulationsFigure(LRrange, smooth_p, real_p, Model, conditions, modes)
% Plot populations for the model

% Create figure
figure1 = figure('XVisual',...
    '0x22 (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)',...
    'Color',[1 1 1]);

% Create axes
TicksRange=0:0.2:max(LRrange);
axes1 = axes('Parent',figure1,'YGrid','on',...
    'XTick',TicksRange,...
    'XGrid','on',...
    'FontSize',16);

ylim([0 1]);
xlim([0 max(conditions.LRratio)*modes.extend_factor ]);
box('on');
hold('all');


% Check if enough colors were defined for the species display
Nspecies_total=length(Model.NMR_invisible_species_names)+length(Model.species_names);
if length(conditions.Colors) < Nspecies_total
   error('Not enough colors defined to display all species! Add more RGB colors to setup file!');
end

% Plot smooth lines
% NMR visible species
plot1 = plot(LRrange,smooth_p,'Parent',axes1,'LineWidth',2);
for species_counter=1:Model.species
    set(plot1(species_counter),'DisplayName',Model.species_names{species_counter});
    set(plot1(species_counter),'Color',conditions.Colors(species_counter,:));
end
% for NMR invisible species
for species_counter=Model.species+1: length(smooth_p(1,:))
    set(plot1(species_counter),'DisplayName',Model.NMR_invisible_species_names{species_counter-Model.species});
    set(plot1(species_counter),'Color',conditions.Colors(species_counter,:));
end

% Plot real values
% NMR visible species
plot2 = plot(conditions.LRratio, real_p, 'Parent',axes1,...
    'MarkerSize',8, 'Marker','o', 'LineStyle','none');
for species_counter=1:Model.species
   set(plot2(species_counter),'DisplayName',Model.species_names{species_counter},...
       'MarkerFaceColor',conditions.Colors(species_counter,:),...
       'Color',conditions.Colors(species_counter,:));
end
% for NMR invisible species
for species_counter=Model.species+1: length(smooth_p(1,:))
   set(plot2(species_counter),'DisplayName',Model.NMR_invisible_species_names{species_counter-Model.species},...
       'MarkerFaceColor',conditions.Colors(species_counter,:),...
       'Color',conditions.Colors(species_counter,:));
end
   

% Create ylabel
ylabel('Populations','FontSize',18);

% Create title
title(Model.name,'FontSize',24,'Interpreter','none');

legend1 = legend(axes1,'show');
set(legend1,'Orientation','vertical','Location','EastOutside');

% Create xlabel
xlabel('L/R, mol/mol','FontSize',18);

