function AtomicModel = fit_toBuildModel_res_up2(k,xdata)

k0 = [0.53 0.53 1.7172 0.3888];
background = k(5);

% using fitting to find the Gaussian parameters of atoms in ORNL images 
f_posFinalAngstromFit = xdata(1:3,:); % in angstrom
f_att = xdata(4,:);

Widthar = ([k(1)]).^2; % use k1=k2 to make all atoms same probe

% Widthar = ([0.52 0.52]).^2; % use k1=k2 to make all atoms same probe

Magar = [ k(2)];  
% Magar = [   1.7136    0.3844 73]; %here don't fit the intensity

res = k(2) % fit to get resolution
x0 = -59.5:0.5:60;
[X,Y] = ndgrid(x0,x0);
sizeX = size(X);
X = X(:);
Y = Y(:);

finalvol = zeros(1,length(X));
for i=1:length(X)
    finalvol(i) = sum( Magar(f_att).*exp(-1*( (X(i)*res-f_posFinalAngstromFit(1,:)).^2 + (Y(i)*res-f_posFinalAngstromFit(2,:)).^2)./(2*Widthar(f_att))),2);
end

AtomicModel = reshape(finalvol,sizeX);

AtomicModel = My_stripzero(AtomicModel,[120 120])+background;