function varargout = ssp2_kolb(varargin)
% SSP2_KOLB MATLAB code for ssp2_kolb.fig
%      SSP2_KOLB, by itself, creates a new SSP2_KOLB or raises the existing
%      singleton*.
%
%      H = SSP2_KOLB returns the handle to a new SSP2_KOLB or the handle to
%      the existing singleton*.
%
%      SSP2_KOLB('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SSP2_KOLB.M with the given input arguments.
%
%      SSP2_KOLB('Property','Value',...) creates a new SSP2_KOLB or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ssp2_kolb_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ssp2_kolb_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ssp2_kolb

% Last Modified by GUIDE v2.5 27-Nov-2012 13:51:52

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ssp2_kolb_OpeningFcn, ...
                   'gui_OutputFcn',  @ssp2_kolb_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before ssp2_kolb is made visible.
function ssp2_kolb_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to ssp2_kolb (see VARARGIN)

% Choose default command line output for ssp2_kolb
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ssp2_kolb wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ssp2_kolb_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit_eps1_Callback(hObject, eventdata, handles)
% hObject    handle to edit_eps1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_eps1 as text
%        str2double(get(hObject,'String')) returns contents of edit_eps1 as a double


% --- Executes during object creation, after setting all properties.
function edit_eps1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_eps1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_eps2_Callback(hObject, eventdata, handles)
% hObject    handle to edit_eps2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_eps2 as text
%        str2double(get(hObject,'String')) returns contents of edit_eps2 as a double


% --- Executes during object creation, after setting all properties.
function edit_eps2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_eps2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_t_Callback(hObject, eventdata, handles)
% hObject    handle to edit_t (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_t as text
%        str2double(get(hObject,'String')) returns contents of edit_t as a double


% --- Executes during object creation, after setting all properties.
function edit_t_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_t (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton_calc.
function pushbutton_calc_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_calc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%-------General parameters--------
t=str2double(get(handles.edit_t,'string'));
lattice=str2double(get(handles.edit_lattice,'String'));
eps_en1=str2double(get(handles.edit_eps1,'String'));
eps_en2=str2double(get(handles.edit_eps2,'String'));


%Starting with the 3D-presentation of the energy dispersion relation....

%Creating the necessary k-vectors for this part of the calculation
k_vec_x = linspace(-2*pi/(lattice),2*pi/(lattice),100);
k_vec_y = linspace(-2*pi/lattice,2*pi/lattice,100);
[k_meshx,k_meshy]=meshgrid(k_vec_x,k_vec_y);


%Energy values with the preset parameters in the 3D presentation
energy_mesh=NaN([size(k_meshx,1),size(k_meshx,2),2]);
for a = 1 : size(k_meshx,1)
    energy_mesh(:,a,1) = ((eps_en1+eps_en2))/2 + sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_meshy(:,a)/2*lattice).^2)+cos(sqrt(3)/2*k_meshx(:,a)*lattice).*cos(k_meshy(:,a)/2*lattice))+1/4);
    energy_mesh(:,a,2) = ((eps_en1+eps_en2))/2 - sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_meshy(:,a)/2*lattice).^2)+cos(sqrt(3)/2*k_meshx(:,a)*lattice).*cos(k_meshy(:,a)/2*lattice))+1/4);
end


%Graphic presentation (3D)
set(handles.axes_mesh,'Color','w')
set(handles.axes_mesh,'NextPlot','replace')
surf(k_meshx,k_meshy,real(energy_mesh(:,:,1)),'parent',handles.axes_mesh,'FaceAlpha',0.6)
set(handles.axes_mesh,'NextPlot','add')
hold on
surf(k_meshx,k_meshy,real(energy_mesh(:,:,2)),'parent',handles.axes_mesh,'FaceAlpha',0.6)
colormap('jet')
shading interp
%Plot of the brillouin zone (black) and the triangular path (red) of the
%dispersion plot
plot3(2*pi/(sqrt(3)*lattice)*[1,0,-1,-1,0,1,1],2*pi/(3*lattice)*[1,2,1,-1,-2,-1,1],(eps_en1+eps_en2)/2*ones(1,7),'k-','LineWidth',2,'parent',handles.axes_mesh)
plot3(2*pi/(lattice*sqrt(3))*[0,1,1,0],2*pi/(3*lattice)*[0,0,1,0],(eps_en1+eps_en2)/2*ones(1,4),'r-','LineWidth',2,'parent',handles.axes_mesh)
hx = xlabel('k_x','parent',handles.axes_mesh);
hy = ylabel('k_y','parent',handles.axes_mesh);
hz = zlabel('E(k)','parent',handles.axes_mesh);
axis equal
grid off
hold off

%2nd main part of the program code....2D presentation
%k-values along the red coloured triangle
k_vec_k=nan(2,1000);
ener_k=k_vec_k;
k_vec_m=nan(2,ceil(1000/sqrt(3)));
ener_m=k_vec_m;
k_vec_g=k_vec_k;
ener_g=k_vec_g;

k_vec_k(1,:)=linspace(0,2*pi/(lattice*sqrt(3)),1000);
k_vec_k(2,:)=0;

k_vec_m(1,:)=k_vec_k(1,end);
k_vec_m(2,:)=linspace(0,2*pi/(lattice*3),ceil(1000/sqrt(3)));

k_vec_g(1,:)=linspace(2*pi/(lattice*sqrt(3)),0,1000);
k_vec_g(2,:)=linspace(2*pi/(lattice*3),0,1000);

%Energy values with the preset parameters and the k-values along the red
%triangle in the 2D presentation (3 energy vectors of the 3 different sides
%of the triangle)
ener_k(1,:)=((eps_en1+eps_en2))/2 + sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_vec_k(2,:)/2*lattice).^2)+cos(sqrt(3)/2*k_vec_k(1,:)*lattice).*cos(k_vec_k(2,:)/2*lattice))+1/4);
ener_k(2,:)=((eps_en1+eps_en2))/2 - sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_vec_k(2,:)/2*lattice).^2)+cos(sqrt(3)/2*k_vec_k(1,:)*lattice).*cos(k_vec_k(2,:)/2*lattice))+1/4);

ener_m(1,:)=((eps_en1+eps_en2))/2 + sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_vec_m(2,:)/2*lattice).^2)+cos(sqrt(3)/2*k_vec_m(1,:)*lattice).*cos(k_vec_m(2,:)/2*lattice))+1/4);
ener_m(2,:)=((eps_en1+eps_en2))/2 - sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_vec_m(2,:)/2*lattice).^2)+cos(sqrt(3)/2*k_vec_m(1,:)*lattice).*cos(k_vec_m(2,:)/2*lattice))+1/4);

ener_g(1,:)=((eps_en1+eps_en2))/2 + sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_vec_g(2,:)/2*lattice).^2)+cos(sqrt(3)/2*k_vec_g(1,:)*lattice).*cos(k_vec_g(2,:)/2*lattice))+1/4);
ener_g(2,:)=((eps_en1+eps_en2))/2 - sqrt(((eps_en1-eps_en2)^2)/4 + 4*t^2*((cos(k_vec_g(2,:)/2*lattice).^2)+cos(sqrt(3)/2*k_vec_g(1,:)*lattice).*cos(k_vec_g(2,:)/2*lattice))+1/4);


%Graphic presentation 2D energy disperion relation (3 different plots for
%every 3 sides of the triangle) 
plot_ind=(1:(length(k_vec_m)+length(k_vec_k)+length(k_vec_g)))/(length(k_vec_m)+length(k_vec_k)+length(k_vec_g));%x-axes of the dispersion plot
plot(plot_ind,real([ener_k(1,:),ener_m(1,:),ener_g(1,:)]),'r-','parent',handles.axes_enerDisp)
hold on
plot(plot_ind,real([ener_k(2,:),ener_m(2,:),ener_g(2,:)]),'b-','parent',handles.axes_enerDisp)
xlabel('k')
ylabel('E(k)')
hold off
set(handles.axes_enerDisp,'XGrid','on')
set(handles.axes_enerDisp,'XTickMode','manual')
set(handles.axes_enerDisp,'XTickLabelMode','manual')
set(handles.axes_enerDisp,'XTick',[0;0.3878;0.6121;1])
set(handles.axes_enerDisp,'XTickLabel',['G';'M';'K';'G'])
guidata(hObject,handles)

function edit_lattice_Callback(hObject, eventdata, handles)
% hObject    handle to edit_lattice (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_lattice as text
%        str2double(get(hObject,'String')) returns contents of edit_lattice as a double


% --- Executes during object creation, after setting all properties.
function edit_lattice_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_lattice (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton_cancel.
function pushbutton_cancel_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_cancel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
delete(handles.figure1)
