Code covered by the BSD License  

Highlights from
PES Fitting

image thumbnail

PES Fitting

by

 

One dimensional potential energy surface fitting

PES_Fitting(varargin)
function varargout = PES_Fitting(varargin)
% PES_FITTING MATLAB code for PES_Fitting.fig
%      PES_FITTING, by itself, creates a new PES_FITTING or raises the existing
%      singleton*.
%
%      H = PES_FITTING returns the handle to a new PES_FITTING or the handle to
%      the existing singleton*.
%
%      PES_FITTING('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PES_FITTING.M with the given input arguments.
%
%      PES_FITTING('Property','Value',...) creates a new PES_FITTING or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before PES_Fitting_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to PES_Fitting_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 PES_Fitting

% Last Modified by GUIDE v2.5 13-Dec-2012 14:22:59

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @PES_Fitting_OpeningFcn, ...
                   'gui_OutputFcn',  @PES_Fitting_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 PES_Fitting is made visible.
function PES_Fitting_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 PES_Fitting (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
    plot((-5:0.1:5),(-5:0.1:5).^2);
end
% UIWAIT makes PES_Fitting wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = PES_Fitting_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 xeqedit_Callback(hObject, eventdata, handles)
% hObject    handle to xeqedit (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 xeqedit as text
%        str2double(get(hObject,'String')) returns contents of xeqedit as a double


% --- Executes during object creation, after setting all properties.
function xeqedit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xeqedit (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 Kedit_Callback(hObject, eventdata, handles)
% hObject    handle to Kedit (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 Kedit as text
%        str2double(get(hObject,'String')) returns contents of Kedit as a double


% --- Executes during object creation, after setting all properties.
function Kedit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Kedit (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 E0edit_Callback(hObject, eventdata, handles)
% hObject    handle to E0edit (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 E0edit as text
%        str2double(get(hObject,'String')) returns contents of E0edit as a double


% --- Executes during object creation, after setting all properties.
function E0edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to E0edit (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 Cedit_Callback(hObject, eventdata, handles)
% hObject    handle to Cedit (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 Cedit as text
%        str2double(get(hObject,'String')) returns contents of Cedit as a double


% --- Executes during object creation, after setting all properties.
function Cedit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Cedit (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 plotbutton.
function plotbutton_Callback(hObject, eventdata, handles)
% hObject    handle to plotbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;


try   
    xstringvar=get(handles.xvaredit,'String');
    %# Make an attempt to...
    xValue = evalin('base',xstringvar);  %#   get the value from the base workspace
catch exception                       %# Catch the exception if the above fails
  error(['Variable ''' xstringvar ...    %# Throw an error
         ''' doesn''t exist in workspace.']);
        %# Get the string value from the uicontrol
end                                 %#   object with handle hEditText
try       
    %# Make an attempt to..
  potvarName=get(handles.yvaredit,'String');
  potValue = evalin('base',potvarName);  %#   get the value from the base workspace
catch exception                       %# Catch the exception if the above fails
  error(['Variable ''' potvarName ...    %# Throw an error
         ''' doesn''t exist in workspace.']);
     
end
xmin=get(handles.xmintextedit,'String');
xmax=get(handles.xmaxtextedit,'String');
if (~strcmp(xmin,'Set Xmin'))
     
    dxmin = str2double(xmin);
    
    for nx=1:length(xValue),
        
        if (xValue(nx)>dxmin) 
            if (nx == 1)
                nx=nx+1;
            end
            
                min=nx-1;
                break;%break the for loop if it's true the condition
        end
        
    end
else
    
        min=1;
end
if (~strcmp(xmax,'Set Xmax')) 
    
    dxmax=str2double(xmax);
    
    for nx=1:length(xValue),
        
        if (xValue(nx)>dxmax || nx==length(xValue) ) 
            
            max=nx;
            break;%break the for loop if it's true the condition
        end
            
    end
else
    
        max=length(xValue);
end
global XFIT;
global YFIT;
XFIT=xValue(min:max);
YFIT=potValue(min:max);
popup_sel_index = get(handles.PEStypemenu, 'Value');
switch popup_sel_index
    case 1
        plot(XFIT,YFIT)
    case 2
        XEQ=str2double(get(handles.xeqedit,'String'));
        K=str2double(get(handles.Kedit,'String'));
        E0=str2double(get(handles.E0edit,'String'));
        plot(XFIT,K/2*(XFIT-XEQ).^2+E0,XFIT,YFIT);
    case 3
        XEQ=str2double(get(handles.xeqedit,'String'));
        K=str2double(get(handles.Kedit,'String'));
        E0=str2double(get(handles.E0edit,'String'));
        C=str2double(get(handles.Cedit,'String'));
        plot(XFIT,K/2*(XFIT-XEQ).^2+C*(XFIT-XEQ).^3+E0,XFIT,YFIT);
    case 4
        XEQ=str2double(get(handles.xeqedit,'String'));
        K=str2double(get(handles.Kedit,'String'));
        E0=str2double(get(handles.E0edit,'String'));
        C=str2double(get(handles.Cedit,'String'));
        plot(XFIT,K*(exp(-2*C*(XFIT-XEQ))-2*exp(-C*(XFIT-XEQ)))+E0,XFIT,YFIT);
        %legend('Morse Fit','DATA');
        
end


test1=get(handles.xmintextedit,'String');
if (strcmp(test1,'Set Xmin')) 
    set(handles.xmintextedit,'String',XFIT(1));
end
test2=get(handles.xmaxtextedit,'String');
if (strcmp(test2,'Set Xmax'))   
    set(handles.xmaxtextedit,'String',XFIT(length(XFIT)));
end








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




% --- Executes on selection change in PEStypemenu.
function PEStypemenu_Callback(hObject, eventdata, handles)
% hObject    handle to PEStypemenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns PEStypemenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from PEStypemenu
popup_sel_index = get(handles.PEStypemenu, 'Value');
global XFIT;
global YFIT;
switch popup_sel_index
    case 1
        plot(XFIT,YFIT)
    case 2
        XEQ=str2double(get(handles.xeqedit,'String'));
        K=str2double(get(handles.Kedit,'String'));
        E0=str2double(get(handles.E0edit,'String'));
        f=fittype('a*(x-b)^2+c');
        g=fit(XFIT,YFIT,f,'StartPoint', [K, XEQ, E0]);
        result=coeffvalues(g);
        K=2*result(1);
        
        XEQ=result(2);
        set(handles.xeqedit,'String',XEQ);
        set(handles.Kedit,'String',K);
        E0=result(3);
        set(handles.E0edit,'String',E0);
        
        plot(XFIT,K/2*(XFIT-XEQ).^2+E0,XFIT,YFIT);
    case 3
        XEQ=str2double(get(handles.xeqedit,'String'));
        K=str2double(get(handles.Kedit,'String'));
        E0=str2double(get(handles.E0edit,'String'));
        C=str2double(get(handles.Cedit,'String'));
        f=fittype('a*(x-b)^2+d*(x-b)^3+c');
        g=fit(XFIT,YFIT,f,'StartPoint', [K, XEQ, E0,C]);
        result=coeffvalues(g);
        K=2*result(1);
        
        XEQ=result(2);
        set(handles.xeqedit,'String',XEQ);
        set(handles.Kedit,'String',K);
        E0=result(3);
        set(handles.E0edit,'String',E0);
        C=result(4);
        set(handles.Cedit,'String',C);
        plot(XFIT,K/2*(XFIT-XEQ).^2+C*(XFIT-XEQ).^3+E0,XFIT,YFIT);
   %     plot(sin(1:0.01:25.99));
    case 4
        XEQ=str2double(get(handles.xeqedit,'String'));
        K=str2double(get(handles.Kedit,'String'));
        E0=str2double(get(handles.E0edit,'String'));
        C=str2double(get(handles.Cedit,'String'));
        f=fittype('a*(exp(-2*b*(x-c))-2*exp(-b*(x-c)))+d');
        g=fit(XFIT,YFIT,f,'StartPoint', [K, C, XEQ,E0]);
        result=coeffvalues(g);
        K=2*result(1);
        C=result(2);
        XEQ=result(3);
        E0=result(4);
        set(handles.xeqedit,'String',XEQ);
        set(handles.Kedit,'String',K);
        set(handles.E0edit,'String',E0);
        set(handles.Cedit,'String',C);
        plot(XFIT,K*(exp(-2*C*(XFIT-XEQ))-2*exp(-C*(XFIT-XEQ)))+E0,XFIT,YFIT);
        %legend('Morse Fit','DATA');
        %     bar(1:.5:10);                ,'StartPoint', [K, XEQ, E0,C]
   % case 4
   %     plot(membrane);
   % case 5
   %     surf(peaks);
end

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

% Hint: popupmenu 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
set(hObject, 'String', {'No Fit','Harmonic', 'Anharmonic', 'Morse'});%,, 'Lennard-Jonne'});



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to xmintextedit (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 xmintextedit as text
%        str2double(get(hObject,'String')) returns contents of xmintextedit as a double


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over xmintextedit.
function xmintextedit_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to xmintextedit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes during object creation, after setting all properties.
function xmintextedit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xmintextedit (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 xmaxtextedit_Callback(hObject, eventdata, handles)
% hObject    handle to xmaxtextedit (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 xmaxtextedit as text
%        str2double(get(hObject,'String')) returns contents of xmaxtextedit as a double


% --- Executes during object creation, after setting all properties.
function xmaxtextedit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xmaxtextedit (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 xvaredit_Callback(hObject, eventdata, handles)
% hObject    handle to xvaredit (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 xvaredit as text
%        str2double(get(hObject,'String')) returns contents of xvaredit as a double


% --- Executes during object creation, after setting all properties.
function xvaredit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xvaredit (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 xvaredit_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to xvaredit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

function yvaredit_Callback(hObject, eventdata, handles)
% hObject    handle to yvaredit (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 yvaredit as text
%        str2double(get(hObject,'String')) returns contents of yvaredit as a double


% --- Executes during object creation, after setting all properties.
function yvaredit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yvaredit (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


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over yvaredit.
function yvaredit_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to yvaredit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over xvaredit.


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over PEStypemenu.
function PEStypemenu_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to PEStypemenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over xeqedit.
function xeqedit_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to xeqedit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


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


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



Contact us