function sigmaData = stereoAndQ2HFun(sigmaData, pdbNumCode, conditions)

user                                        = sigmaData(1).user;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if user.stereoAvg              == 1

selectStereo
    
%single methylene stereopartners
fprintf('\nDetermining stereopartners\n')
for j = 1:length(sigmaData)
    
    for s = 1:length(conditions.methylene) - 2 %minus two, because the last two methylene conditons are not relevant here!
        if sigmaData(j).numcode.stAssi == 0
            if ismember(sigmaData(j).numcode.ATOMi, conditions.methylene(s).atoms)
                sigmaData(j).numcode.ATOMi_H            = conditions.methylene(s).atoms;
                if sigmaData(j).numcode.ATOMi == sigmaData(j).numcode.ATOMi_H(2)
                ATOMi_H1                            = sigmaData(j).numcode.ATOMi_H(1);
                sigmaData(j).numcode.ATOMi_H(1)     = sigmaData(j).numcode.ATOMi_H(2);
                sigmaData(j).numcode.ATOMi_H(2)     = ATOMi_H1;
                end
                sigmaData(j).numcode.split(1)           = length(sigmaData(j).numcode.ATOMi_H);
                sigmaData(j).numcode.stereo(1)          = 1;
            end
        end
        if sigmaData(j).numcode.stAssj == 0  
            if ismember(sigmaData(j).numcode.ATOMj, conditions.methylene(s).atoms)
                sigmaData(j).numcode.ATOMj_H            = conditions.methylene(s).atoms;
                if sigmaData(j).numcode.ATOMj == sigmaData(j).numcode.ATOMj_H(2)
                ATOMj_H1                            = sigmaData(j).numcode.ATOMj_H(1);
                sigmaData(j).numcode.ATOMj_H(1)     = sigmaData(j).numcode.ATOMj_H(2);
                sigmaData(j).numcode.ATOMj_H(2)     = ATOMj_H1;
                end
                sigmaData(j).numcode.split(2)           = length(sigmaData(j).numcode.ATOMj_H);
                sigmaData(j).numcode.stereo(2)          = 1;
            end
        end
    end
end


%Methyl stereo partners: val(101/102)/leu(104/105)
for j = 1:length(sigmaData)
        if sigmaData(j).numcode.stAssi == 0 
            if ismember(sigmaData(j).numcode.ATOMi, conditions.methyl(9).atoms)             
                sigmaData(j).numcode.split(1)           = 2;
                sigmaData(j).numcode.stereo(1)          = 1;
            end
            if ismember(sigmaData(j).numcode.ATOMi, conditions.methyl(10).atoms)
                sigmaData(j).numcode.split(1)           = 2;
                sigmaData(j).numcode.stereo(1)          = 1;    
            end
        end
        if sigmaData(j).numcode.stAssj == 0 
            if ismember(sigmaData(j).numcode.ATOMj, conditions.methyl(9).atoms)
                sigmaData(j).numcode.split(2)           = 2;
                sigmaData(j).numcode.stereo(2)          = 1;
            end
            if ismember(sigmaData(j).numcode.ATOMj, conditions.methyl(10).atoms)
                sigmaData(j).numcode.split(2)           = 2;
                sigmaData(j).numcode.stereo(2)          = 1;
            end
        end
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pseudo methylene split
fprintf('\nSplitting methylene pseudo atoms\n')
for j = 1:length(sigmaData)
    for s = 1:length(conditions.methylene)
    
        if ismember(sigmaData(j).numcode.ATOMi, conditions.methylene(s).grpNum)
            sigmaData(j).numcode.ATOMi_H            = conditions.methylene(s).atoms;
            sigmaData(j).numcode.split(1)           = length(sigmaData(j).numcode.ATOMi_H);
            sigmaData(j).numcode.pseudo(1)          = 1;
        end
          
        if ismember(sigmaData(j).numcode.ATOMj, conditions.methylene(s).grpNum)
            sigmaData(j).numcode.ATOMj_H            = conditions.methylene(s).atoms;
            sigmaData(j).numcode.split(2)           = length(sigmaData(j).numcode.ATOMj_H);
            sigmaData(j).numcode.pseudo(2)          = 1;
        end
        
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if user.pseudoMethyl  == 0 
    %pseudo methyl split
    fprintf('\nSplitting methyl pseudo atoms\n')
    for j = 1:length(sigmaData)
    
        for s = 1:length(conditions.methyl) - 2
            if sigmaData(j).numcode.stereo(1) == 0
                if ismember(sigmaData(j).numcode.ATOMi, conditions.methyl(s).grpNum)
              
                sigmaData(j).numcode.ATOMi_H        = conditions.methyl(s).atoms;
                sigmaData(j).numcode.split(1)       = length(sigmaData(j).numcode.ATOMi_H);
                sigmaData(j).numcode.pseudo(1)      = 1;
    
                end
            end
            
            if sigmaData(j).numcode.stereo(2) == 0
                if ismember(sigmaData(j).numcode.ATOMj, conditions.methyl(s).grpNum)
            
                sigmaData(j).numcode.ATOMj_H        = conditions.methyl(s).atoms;
                sigmaData(j).numcode.split(2)       = length(sigmaData(j).numcode.ATOMj_H);
                sigmaData(j).numcode.pseudo(2)      = 1;
    
                end
            end
        end
    end

    %pseudo methyl split
    for j = 1:length(sigmaData)
            
            if sigmaData(j).numcode.stereo(1) == 0
                if ismember(sigmaData(j).numcode.ATOMi, conditions.methyl(9).grpNum)
              
                sigmaData(j).numcode.ATOMi_H        = [conditions.methyl(2).atoms, conditions.methyl(3).atoms];
                sigmaData(j).numcode.split(1)       = length(sigmaData(j).numcode.ATOMi_H);
                sigmaData(j).numcode.pseudo(1)      = 1;
                
                end
          
                if ismember(sigmaData(j).numcode.ATOMi, conditions.methyl(10).grpNum)
            
                sigmaData(j).numcode.ATOMi_H        = [conditions.methyl(5).atoms, conditions.methyl(6).atoms];
                sigmaData(j).numcode.split(1)       = length(sigmaData(j).numcode.ATOMi_H);
                sigmaData(j).numcode.pseudo(2)      = 1;
                
                end
            end
            
            if sigmaData(j).numcode.stereo(2) == 0
                if ismember(sigmaData(j).numcode.ATOMj, conditions.methyl(9).grpNum)
              
                sigmaData(j).numcode.ATOMj_H        = [conditions.methyl(2).atoms, conditions.methyl(3).atoms];
                sigmaData(j).numcode.split(1)       = length(sigmaData(j).numcode.ATOMj_H);
                sigmaData(j).numcode.pseudo(1)      = 1;
                
                end
            
                if ismember(sigmaData(j).numcode.ATOMj, conditions.methyl(10).grpNum)
            
                sigmaData(j).numcode.ATOMj_H        = [conditions.methyl(5).atoms, conditions.methyl(6).atoms];
                sigmaData(j).numcode.split(1)       = length(sigmaData(j).numcode.ATOMj_H);
                sigmaData(j).numcode.pseudo(2)      = 1;
                
                end
            end
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% asssign pdb serial number to split atoms

sigmaData                                           = HpdbSerNoFunMaster(sigmaData, pdbNumCode);
    

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