%------------------- LineShapeKin MODEL_SETUP -----------------------------
%-- version 3.0 
%
% 3/11/08
% Written by Evgenii Kovrigin, Medical College of Wisconsin

%  Here I additionally fit w0_B - to compensate for incomplete titrations

%  This is the model where I  fit Kd, Koff and w0_B - but not scale factor! I
%  assume you already fit your data in a 'single' mode and adjusted the
%  scaling of the data in 'scale_factor.txt' for every peak.

% NOTE: I cannot do GLOBAL fitting in this mode because I need DIFFERENT
%            w0_B values. The way is to do this fitting individually,
%            determine w0_B and the put them in into 'manual_w0.txt'. After
%            that I will return to Koff - only or Kd/Koff fitting models.


%
% This file contains model-specific parameters. You edit this file if you
%   want to change your fitting model. 
%
%  X_columns is a structure that
%      specifies column positions of protein concentration, ligand/protein
%      ratio, relaxation rates, peak positions, temperature etc.
%
%  B_vector
%      is a structure that specifies positions of variable for fitting such
%      as Koff, scale_factor, Kd, activation energy etc.
%
%  Model_description
%     is a structure that contains additional information on the fitting
%     model
%
%  This file sets these variables global so for fitting functions to access
%  them.

% 3/29/08 - Dataset ID column added
%               - switcheable Scale Factor fitting


global YES NO X_columns B_vector Model;

%% Definition of the 'Xcomposite' array of experimental data

X_columns.number= 9;  %-- Enter here total number of columns used in 
                                        %    'Xcomposite' matrix of
                                        %    experimental conditions (see
                                        %    prepare_residue_data.m)

%-- Enter here positions the specific data columns appear in the 'Xcomposite' vector                                        
X_columns.Ptotal  =1;
X_columns.LPratio=2;
X_columns.Xtotal = 3;
X_columns.R2A    = 4;
X_columns.R2B    = 5;
X_columns.wA     = 6;
X_columns.wB     = 7;
X_columns.Temp= 8;
X_columns.DataID= 9;   

%% Model description
Model.name = 'Two-site exchange: fitted Kd, Koff and w0_B';


% Starting and fixed parameters of the fitting model

%-- list corresponding Kds here If the model does fitting of Kd then
%     this number is used as a starting parameter. If the grid search
%     (below) is requested for the parameter then its value here is
%     disregarded and taken from B_vector.grid_values

Model.Kd  = 1.40e-6 ;  %-- [M]
%- if Kd is variable set these
Model.Kd_min=0; 
Model.Kd_max=10e10;

%-- list corresponding koffs here to be used as a starting parameter.
Model.Koff    =     100 ;  %-- /s 
Model.Koff_min=0; 
Model.Koff_max=10e10;

%--- correction factor for intensity of spectra (to compensate for
%      imprecise normalization) - 
%Model.w0_B = 8040;     <-- value of this parameter is specific to a
%     dataset so will be entered new per each dataset 
Model.w0_B_min = Model.w0_B*0.995;  
Model.w0_B_max = Model.w0_B*1.005;  




%% Definition of the 'beta' vector:   variable parameters in the model to
%    fit.

%--  Generate starting 'beta' vector
B_vector.starting_values = [ Model.Kd, Model.Koff Model.w0_B];
B_vector.min = [ Model.Kd_min, Model.Koff_min Model.w0_B_min];
B_vector.max = [ Model.Kd_max, Model.Koff_max Model.w0_B_max];
B_vector.parameter_names= { 'Kd' , 'Koff', 'w0_B'};


%--  Assign here the positions of the fitting parameters in the 'beta'
%     vector to use in when addressing the vector
B_vector.Kd = 1;
B_vector.Koff = 2;
B_vector.w0_B = 3;

%-- model.m needs to know if Scale Factor is one of the parameters
B_vector.fit_scale_factor=NO;  


%---- Setting the grid values to start fitting from when searching for global
%        minimum
%B_vector.grid_search_parameter=B_vector.w0_B;
%B_vector.grid_values=[ Model.w0_B_min Model.w0_B Model.w0_B_max ];
B_vector.grid_search_parameter=B_vector.Koff;
%B_vector.grid_values=[  10 100 1000  ];
B_vector.grid_values=[   100  ];

