Refinement. During refinement in x-ray diffraction analysis, the initial model of the protein structure is used to calculate the theoretical diffraction pattern it would produce, using a Fourier series. The phases are then adjusted to obtain a pattern close to the observed diffraction pattern. The adjusted phases generate a more detailed electron density map, thus allowing more precise positioning of amino acid residues in the model. The process is repeated several times until the residual error (R factor) between observed and calculated diffraction patterns is reduced to an acceptable value.