%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% AUTO SETUP OF USER VARIABLES %%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Projectname
if ~isfield(user, 'projectname')
    user.projectname            = 'notSpecified';
end

%input output directories
if ~isfield(user, 'inputDirectory')
    user.inputDirectory         = './input_files'; %default = './input_files'
end

if ~isfield(user, 'outputDirectory')
    user.outputDirectory        = './output_files'; %default = './output_files'
end

%Specify pdb file name
if ~isfield(user, 'pdbFileName')
    user.pdbFileName            = input('Enter the name of the pdb file (xxx.pdb): ','s');
end

%naming convention (MARKLEY,oldCyana,MolMol)
if ~isfield(user, 'pdbNameConvention')
    user.pdbNameConvention      = 'cyana.lib'; % MARKLEY Code
end

user.timeStamp                  = [];

%secondary structure
if ~isfield(user, 'bStrParallel')
    user.bStrParallel           = [];
end
if ~isfield(user, 'bStrAnti')
    user.bStrAnti               = [];
end
if ~isfield(user, 'loop')
    user.loop                   = [];
end
if ~isfield(user, 'helical')
    user.helical                = [];
end


%Check assigment for double assignment (1/0)
if ~isfield(user, 'checkIntegrity')
    user.checkIntegrity         = 1;
end

if strcmp(user.spinDiffApp, 'threeSpin') 
    user.checkIntegrity         = 1;
end

%break points (y/n)
if ~isfield(user, 'runThrough')
    user.runThrough             = 1;
end

if ~isfield(user, 'autoPlot')
    user.autoPlot               = 0;
end

%series.tab file or intensity file

if ~isfield(user, 'nmrDrawTabFileName') && ~isfield(user, 'intensityFileName')

    user.read_nmrDrawTabFile    = input('Specify if you need to read an nmrDraw.tab file (y/n): ','s');
    
    if strcmp(user.read_nmrDrawTabFile, 'n')
            
        user.intensityFileName  = input('Enter the intensity file name: ','s');
        
    elseif strcmp(user.read_nmrDrawTabFile, 'y')
            
        user.nmrDrawTabFileName = input('xxx.tab file name (xxxx.tab): ','s');
            
        if ~isfield(user,'specDimens')
            user.specDimens     = input('Enter the number of spectral dimensions of your NOESY (2/3):');
        
        end
    end
end

if ~isfield(user, 'nmrDrawTabFileName')
    user.nmrDrawTabFileName     = [];
elseif~isfield(user, 'intensityFileName')
    user.intensityFileName      = [];
end

if ~isfield(user, 'intensityFileNumLetter')
    user.intensityFileNumLetter = 'let';
end

if ~isfield(user,'assNameConvention')
    user.assNameConvention      = 'cyana.lib';
end

if ~isfield(user,'assFilter')
    user.assFilter              = [];
end

if ~isfield(user,'heightVolume')
    user.heightVolume           = 'h';
end

if ~isfield(user,'singleMixTime')
    user.singleMixTime          = 0;
end

if ~isfield(user,'absIntensities')
    user.absIntensities         = 1;
end

if ~isfield(user, 'magOriginSpin')

    user.startMag = input(['\n(origin Mag,   destination mag (cross peak)) i.e.  3 H  12 HG  == >> user.magOriginSpin = 1'...
                           '\n(destination mag (cross peak), origin Mag)   i.e. 12 HG  3 H   == >> user.magOriginSpin = 2\n'...
                           '\nSpecify with regards to your assignment where magnetization came from (1/2): ']);
end

if ~isfield(user, 'magNormSpin')

    user.startMag = input(['\n(origin mag,   destination mag) i.e.  3 H  12 HG  == >> user.magNormSpin = 1'...
                           '\n(destination mag, origin Mag)   i.e. 12 HG  3 H   == >> user.magNormSpin = 2\n'...
                           '\nSpecify with regards to your assignment to which spin you want to normalize to (1/2): ']);
end

if ~isfield(user, 'backboneFilter')
    user.backboneFilter         = 0;
end

if ~isfield(user, 'noIz0Filter')
    user.noIz0Filter            = 1;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% EXPERIMENTAL INPUT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Specifiy the mixing times used (seconds)
if ~isfield(user, 'mixing_times')
    user.mixing_times           = input('Enter the mixing times of your NOESY spectra (in seconds):');
end

user.mixing_times               = sort(user.mixing_times);


if ~isfield(user, 'scaleFactor')
    user.scaleFactor(1:length(user.mixing_times)) = 1;
end

if ~isfield(user, 'perCentD2O')
    user.perCentD2O             = input('Enter the amount of D2O used in your NMR sample (in %): ');
end

%The correlation time
if ~isfield(user, 'tauC') &&  user.isoAniso == 1;
    user.tauC                   = input('Enter your measured TauC: ');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% BUILDUPS SPECIFIC INPUT %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%for the buildup routine, default is Rho.out.txt
if ~isfield(user, 'buildupRhoFileName')
    user.buildupRhoFileName     = 'n';
end

%Set RhoA and RhoB to rho from diagonal fit with identical Res Nr
if ~isfield(user, 'rhoAverage')
    user.rhoAverage             = 11.00;  % average determined by user
end

if ~isfield(user, 'izeroHistogram')
    user.izeroHistogram         = 0;    % plot histogram for Izero calculated (1/0)
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% SPINDIFFUSION SPECIFIC INPUT   %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Execute threeSpinDiffusion routine (y/n)
if ~isfield(user, 'spinDiffSim')
%     user.spinDiff               = '1';
    user.spinDiffSim            = 1;
    if ~isfield(user, 'spinDiffApp')
        user.spinDiffApp            = 'fullMatrix';
    end
end


if ~isfield(user, 'labelingScheme')
    user.labelingScheme           = 'n';
end

% % if strcmp(user.spinDiffApp, 'fullMatrix')
    
    user.pseudoMethyl           = 0;
% %     fprintf('\nFor fullMatrix approach: user.pseudoMethyl is set to 0 by default\n')
% %     
% % elseif ~isfield(user, 'pseudoMethyl')
% %     user.pseudoMethyl           = 0;
% % end

if ~isfield(user, 'stereoAvg')
%To calculate avg for stereo atoms(1/0):
user.stereoAvg              = 1;
end

%Enter the polarizing field strength (1H; in MHz)
if ~isfield(user, 'B0field')
    user.B0field                = input('Enter the magnetic field strength (MHz): ');
end

%NOESY Type (1H, 13C)
if ~isfield(user, 'noesyType')
    user.noesyType              = '1H';
end

% Calculate isotropic Spindiffusion(1), anisotropic Spindiffusion(2)
% default isotropic
if ~isfield(user, 'isoAniso')
    user.isoAniso               = 1;
end

%Set upper distance limit? (A)
if ~isfield(user, 'upperlimit')
    user.upperlimit             = 6.5;
end

%%%%%%%%%%%%%%%%%%%%%%%     three specific setup     %%%%%%%%%%%%%%%%%%%%%%

%Enter the deuteration level of the alpha protons (in %)
if ~isfield(user, 'deut_HA')
    user.deut_HA                = 0;
end

%Enter the deuteration level of the methyl protons (LEU,VAL,ILE QD1) (in %)
if ~isfield(user, 'deut_Met')
    user.deut_Met               = 0;
end

%Enter the deuteration level of all other carbon-bound protons (in %)
if ~isfield(user, 'deut_Prot')
    user.deut_Prot              = 0;
end

if ~isfield(user, 'rhoSupValues')
    user.rhoSupValues = 1;
end

if ~isfield(user, 'spindiffChiNcutOff')
    user.spindiffChiNcutOff     = 'n';
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%% DISTANCE CALCULATION SPECIFIC INPUT %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isfield(user, 'temp1')
    user.temp1                  = 1;  %temp sigma A > B
end
if ~isfield(user, 'temp2')
    user.temp2                  = 1;  %temp sigma B > A
end

if ~isfield(user, 'Ssquare')
    user.Ssquare                = 1;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~isfield(user, 'IzeroMethyl') 
 user.IzeroMethyl       = [];
end
if ~isfield(user, 'IzeroMethylenePseudo') 
 user.IzeroMethylenePseudo    = [];
end
if ~isfield(user, 'IzeroSingle') 
 user.IzeroSingle       = [];
end
            
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%