Integration, scaling, space-group assignment and post-refinement

The working principles of important steps in processing rotation data are described as employed by the program XDS.


Introduction
The key steps in the processing of diffraction data from single crystals involve (i) modelling of the observed reflection positions in the detector plane, (ii) integration of diffraction intensities, (iii) data correction, scaling and post-refinement and (iv) space-group assignment. Much of the theory and many of the methods for carrying out these steps were developed about three decades ago for processing rotation data recorded on film and were subsequently extended in order to fully exploit the capabilities of a variety of electronic area detectors; some CCD (charge-coupled device) and multiwire detectors as well as a new pixel detector specially developed for data collection at synchrotron beamlines allow the recording of finely sliced rotation data because of their fast data read-out. In this article, the principles of the methods are described as employed by the program XDS (Kabsch, 2010). These apply equally well to rotation images covering small or large oscillation ranges. A large number of other dataprocessing systems have been developed which differ in the details of the implementations. Some of these packages were described in chapter 25.2 of Volume F of International Tables for Crystallography (2001). The theory and practice of processing fine-sliced data have been discussed by Pflugrath (1997).

Modelling rotation images
The observed diffraction pattern, i.e. the positions of the reflections recorded on the rotation-data images, is controlled by a small set of parameters which must be accurately determined before integration can start. Approximate values for some of these parameters are given by the experimental setup, whereas others may be completely unknown and must be obtained from the rotation images. This is achieved by the automatic location of strong diffraction spots, the extraction of a primitive lattice basis that yields integer indices for the observed reflections and the subsequent refinement of all parameters to minimize the discrepancies between observed and calculated spot positions in the data images.

Coordinate systems and parameters
In the rotation method, the incident-beam wavevector S 0 of length 1/ (where is the wavelength) is fixed while the crystal is rotated around a fixed axis described by a unit vector m 2 . S 0 points from the X-ray source towards the crystal. It is assumed that the incident beam and the rotation axis intersect at one point at which the crystal must be located. This point is defined as the origin of a right-handed orthonormal laboratory coordinate system {l 1 , l 2 , l 3 }. This fixed but otherwise arbitrary system is used as a reference frame to specify the setup of the diffraction experiment.
Diffraction data are assumed to be recorded on a fixed planar detector. A right-handed orthonormal detector coordinate system {d 1 , d 2 , d 3 } is defined such that a point with coordinates X, Y in the detector plane is represented by the vector (X À X 0 )d 1 + (Y À Y 0 )d 2 + Fd 3 with respect to the laboratory coordinate system. The origin X 0 , Y 0 of the detector plane is found at a distance |F| from the crystal position. It is assumed that the diffraction data are recorded on adjacent non-overlapping rotation images, each covering a constant oscillation range Á ' , with image No. 1 starting at spindle angle ' 0 .
Diffraction geometry is conveniently expressed with respect to a right-handed orthonormal goniostat system {m 1 , m 2 , m 3 }. It is constructed from the rotation axis and the incident-beam direction such that m 1 = (m 2 Â S 0 )/|m 2 Â S 0 | and m 3 = m 1 Â m 2 . The origin of the goniostat system is defined to coincide with the origin of the laboratory system.
Finally, a right-handed crystal coordinate system {b 1 , b 2 , b 3 } and its reciprocal basis {b Ã 1 , b Ã 2 , b Ã 3 } are defined to represent the unrotated crystal, i.e. at rotation angle ' = 0 , such that any reciprocal-lattice vector can be expressed as p Ã 0 = hb Ã 1 + kb Ã 2 + lb Ã 3 , where h, k, l are integers. As shown in x2.2, the location of all diffraction peaks recorded in the data images can be computed from the parameters S 0 , m 2 , b 1 , b 2 , b 3 , X 0 , Y 0 , F, d 1 , d 2 , d 3 , ' 0 and Á ' . In addition, knowledge of the shape and extent of the diffraction spots is required for accurate estimations of their intensities. This can be achieved by a Gaussian model involving two parameters: the standard deviations of the reflecting range, M , and of the beam divergence, D (see x2.3). This leads to an integration region around the spot defined by the parameters M and D , which are typically chosen to be 6-10 times larger than M and D , respectively.

Spot prediction
Let p Ã 0 denote any arbitrary reciprocal-lattice vector if the crystal has not been rotated, i.e. at rotation angle ' = 0 . Depending on the diffraction geometry, p Ã 0 may be rotated into a position fulfilling the reflecting condition. The required rotation angle ' and the coordinates X, Y of the diffracted beam at its intersection with the detector plane can be found from p Ã 0 as follows.
p Ã 0 can be expressed by its components with respect to the orthonormal goniostat system as The incident-beam and diffracted-beam wavevectors, S 0 and S, have their termini on the Ewald sphere and satisfy the Laue equations denotes the distance of p Ã 0 from the rotation axis, solutions for p Ã and ' can be obtained in terms of In general there are two solutions according to the sign of p Ã Ám 1 . If 2 < (p Ã Ám 3 ) 2 or p Ã2 0 > 4S 2 0 the Laue equations have no solution and the reciprocal-lattice point p Ã 0 is in the 'blind' region.
If FSÁd 3 > 0 the diffracted beam intersects the detector plane at the point which leads to a diffraction spot recorded at detector coordinates

Standard spot shape
A reciprocal-lattice point crosses the Ewald sphere by the shortest route only if the crystal happens to be rotated about an axis perpendicular to both the diffracted-beam and incident-beam wavevectors, the ' axis' e 1 = S Â S 0 /|S Â S 0 |, as introduced by Schutt & Winkler (1977). Rotation around the fixed axis m 2 , as enforced by the rotation camera, thus leads to an increase in the length of the shortest path by the factor 1/|e 1 Ám 2 |. This motivated the introduction of a coordinate system {e 1 , e 2 , e 3 }, specific for each reflection, which has its origin on the surface of the Ewald sphere at the terminus of the diffracted beam wavevector S, research papers The unit vectors e 1 and e 2 are tangential to the Ewald sphere, while e 3 is perpendicular to e 1 and p Ã = S À S 0 . The shape of a reflection, as represented with respect to {e 1 , e 2 , e 3 }, then no longer contains geometrical distortions resulting from the fixed rotation axis of the camera and the oblique incidence of the diffracted beam on a flat detector. Instead, all reflections appear as if they had followed the shortest path through the Ewald sphere and had been recorded on the surface of the sphere.
A detector pixel at X 0 , Y 0 in the neighbourhood of the reflection centre X, Y, when the crystal is rotated by ' 0 instead of ', is mapped to the profile coordinates " 1 , " 2 , " 3 by the following procedure: corrects for the increased path length of the reflection through the Ewald sphere and is closely related to the reciprocal Lorentz correction factor Because of crystal mosaicity and beam divergence, the intensity of a reflection is smeared around the diffraction maximum. The fraction of total reflection intensity found in the volume element d" 1 d" 2 d" 3 at " 1 , " 2 , " 3 can be approximated by Gaussian functions:

Spot centroids and partiality
The intensity of a reflection can be completely recorded on one image or distributed among several adjacent images. The fraction R j of total intensity recorded on image j, the 'partiality' of the reflection, can be derived from the distribution function !(" 1 , " 2 , " 3 ) as The integral is evaluated by using a numerical approximation of the error function, erf (Abramowitz & Stegun, 1972). While the spot centroids in the detector plane are usually good estimates for the detector position of the diffraction maximum, the angular centroid about the rotation axis, can be a rather poor guess for the true ' angle of the maximum. Its accuracy depends strongly on the value of ' and the size of the oscillation range Á' relative to the mosaicity M of the crystal. For a reflection fully recorded on image j, the value Z = ' 0 + (j À 1 2 )ÁÁ ' will always be obtained, which is correct only if ' accidentally happens to be close to the centre of the rotation range of the image. In contrast, the ' angle of a partial reflection recorded on images j and j + 1 is closely approximated by Z = ' 0 + [j + (R j+1 À R j )/2]ÁÁ ' . If many images contribute to the spot intensity, Z(') is always an excellent approximation to the ideal angular position ' when the Laue equations are satisfied; in fact, in the limiting case of infinitely fine-sliced data it can be shown that lim Á'!0 Z(') = '.
Most refinement routines minimize the discrepancies between the predicted ' angles and their approximations obtained from the observed Z centroids and must therefore carefully distinguish between fully and partially recorded reflections. However, this distinction is unnecessary if the observed Z centroids are instead compared with their analytic forms, because the sensitivity of the centroid positions to the diffraction parameters is correctly weighted in either case (see x2.8).

Localizing diffraction spots
Often, some of the parameters controlling the diffraction experiment are either completely unknown or available only at a crude approximation. Accurate values for all parameters must be obtained from the recorded data, i.e. from a list of the coordinates of strong spots occurring in the images. As implemented in XDS, this list is obtained from all or a subset of the data images by the following procedure. Firstly, each pixel value is compared with the mean value and standard deviation of surrounding pixels in the same image and classified as a strong pixel if its value exceeds the mean by a given multiple (typically 3-5) of the standard deviation. Values of the strong pixels and their location addresses and image running numbers are saved in a file. After the scan, a hash table of sufficient size is allocated to accommodate the strong pixels from the file together with their addresses (for a discussion of the hash technique, see Wirth, 1976). As several strong pixels may belong to the same spot, they are labelled with a unique spot number so that any two such pixels which can be connected by direct strong neighbours in two or three dimensions (if there are adjacent images) belong to the same spot (equivalence class). The labelling is achieved by the highly efficient algorithm for the recording of equivalence classes developed by Rem (see Dijkstra, 1976). On termina-tion, a list X 0 i , Y 0 i , Z 0 i (i = 1, . . . , n) of the centroids of n strong spots is available.

Basis extraction
Any reciprocal-lattice vector can be written in the form where h, k, l are integers and b Ã 1 , b Ã 2 , b Ã 3 are reciprocal basis vectors of the lattice. The basis vectors which describe the orientation, metric and symmetry of the crystal, as well as the reflection indices h, k, l, have to be determined from the list of strong diffraction spots X 0 i , Y 0 i , Z 0 i (i = 1, . . . , n). Ideally, each spot corresponds to a reciprocal-lattice vector p Ã 0 which satisfies the Laue equations after a crystal rotation by '. Substituting the observed value Z 0 for the unknown ' angle (see x2.4), p Ã 0 is found from the observed spot coordinates as Unfortunately, the reciprocal-lattice vectors p Ã 0i (i = 1, . . . , n) derived from the above list of strong diffraction spots often contain a number of 'aliens' (spots arising from fluctuations in the background, from ice or from satellite crystals) and a robust method has to be used which is still capable of recognizing the dominant lattice. One approach, suggested by Bricogne (1986) and implemented in a number of variants (Otwinowski & Minor, 1997;Steller et al., 1997), is to identify a lattice basis as the three shortest linear independent vectors b 1 , b 2 , b 3 , each at a maximum of the Fourier transform P n i¼1 cosð2b Á p Ã 0i Þ. Alternatively, a reciprocal basis for the dominant lattice can be determined from short differences between the reciprocal-lattice vectors (Howard, 1986;Kabsch, 1988a). As implemented in XDS, a lattice basis is found by the following procedure.
The list of given reciprocal-lattice points p Ã 0i (i = 1, . . . , n) is first reduced to a small number m of low-resolution differencevector clusters v Ã ( = 1, . . . , m). f is the population of a difference-vector cluster v Ã ; that is, the number of times the difference between any two reciprocal-lattice vectors p Ã 0i À p Ã 0j is approximately equal to v Ã . In a second step, three linear independent vectors b Ã 1 , b Ã 2 , b Ã 3 are selected among all possible triplets of difference-vector clusters that maximize the function Q, The absolute maximum of Q is assumed if all difference vectors can be expressed as small integral multiples of the best triplet. Deviations from this ideal situation are quantified by the quality measure q. The value of q declines sharply if the expansion coefficients k deviate by more than " from their nearest integers h k or if the indices are absolutely larger than . The constraint on the allowed range of indices prevents the selection of a spurious triplet of very short difference-vector clusters which might be present in the set. Excellent results have been obtained using " = 0.05 and = 5. The best vector triplet thus found is refined against the observed difference-vector clusters. Finally, a reduced cell is derived from the refined reciprocal-base vector triplet (see x6).

Indexing
Once a basis b 1 , b 2 , b 3 of the lattice is available, integral indices h i , k i , l i must be assigned to each reciprocal-lattice vector p Ã 0i (i = 1, . . . , n). Using the integers nearest to p Ã 0i Áb k (k = 1, 2, 3) as indices of the reciprocal-lattice vectors p Ã 0i could easily lead to a misindexing of longer vectors because of inaccuracies in the basis vectors b k and the initial values of the parameters describing the instrumental setup. A more robust solution of the indexing problem is provided by the local indexing method, which assigns only small index differences h i À h j , k i À k j , l i À l j between pairs of neighbouring reciprocallattice vectors (Kabsch, 1993).
The reciprocal-lattice points can be considered as nodes of a tree. The tree connects the n points to each other with the connections as its branches. The length ' ij of a possible branch between nodes i and j is defined here as h k ij is the nearest integer of k ij and k = 1, 2, 3. Reliable index differences are indicated by short branches; in fact, ' ij is 0 if none of the indices h k ij is absolutely larger than and the k ij are integer values to within ". Typical values are " = 0.05 and = 5. Defining the length of a tree as the sum of the lengths of its branches, a shortest tree among all n nÀ2 possible trees is determined using the elegant algorithm described by Dijkstra (1976). Starting with arbitrary indices 0, 0, 0 for the root node, the local indexing method then consists of traversing the shortest tree and thereby assigning each node the indices of its predecessor plus the small index differences between the two nodes.
During traversal of the tree, each node is also given a subtree number. Starting with subtree number 1 for the root node, each successor node is given the same subtree number as its predecessor if the length of the connecting branch is below a minimal length ' min . Otherwise, its subtree number is incremented by 1. Thus, all nodes in the same subtree have internally consistent reflection indices. Defining the size of a research papers subtree by the number of its nodes, 'aliens' are usually found in small subtrees. Finally, a constant index offset is determined such that the centroids of the observed reciprocal-lattice points p Ã 0i belonging to the largest subtree and their corresponding grid vectors P 3 k¼1 h i k b Ã k are as close as possible. This offset is added to the indices of each reciprocal-lattice point.

Refinement
For a fixed detector, the diffraction pattern depends on the parameters S 0 , m 2 , b 1 , b 2 , b 3 , X 0 , Y 0 , F. Starting values for the parameters can be obtained by the procedures described above, which do not rely on prior knowledge of the crystal orientation, space-group symmetry or unit-cell metric. Better estimates of the parameter values, as required for the subsequent integration step, can be obtained by the method of least squares from the list of n observed indexed reflection In this method, the parameters are chosen to minimize a weighted sum of squares of the residuals The residuals between the calculated (X i , Y i , Z i ) and observed spot centroids are Let s ( = 1, . . . , k) denote the k independent parameters for which initial estimates are available. Expanding the residuals to first order in the parameter changes s gives Áðs þ s Þ ' Áðs Þ þ P k ¼1 @Á @s s : The parameters should be changed in such a way as to minimize Eðs Þ, which implies @E=@s = 0 for = 1, . . . , k. The s are found as the solution of the k normal equations The parameters are corrected by s and a new cycle of refinement is started until a minimum of E is reached. The weights are calculated with the current guess for s at the beginning of each cycle. The derivatives appearing in the normal equations can be worked out from the definitions given in xx2.2 and 2.4 and only the form of the gradient of the Z residuals is shown.
is constant for each reflection, the gradients of the Z residuals are obtained from the chain rule and the relation d erf(z)/dz = (2/ 1/2 ) exp(Àz 2 ).
Obviously, @Á i Z /@s is small for a fully recorded reflection because of the small values of all exponentials appearing in @Á i Z /@' i . In contrast, the gradient for a partial reflection that is equally recorded on two adjacent images is most sensitive to parameter variations because one of the exponentials assumes its maximum value. In the limiting case of infinitely fine-sliced data it can be shown that lim Á'!0 @Á i Z /@' i = 1. Thus, the refinement scheme based on observed Z centroids, as described here and implemented in XDS, is applicable to finesliced data and also to data recorded with a large oscillation range.

Integration
Assuming that the diffraction parameters have been refined successfully as described above, the intensity of a reflection is distributed in the neighbourhood of the predicted location of the diffraction peak among detector pixels of one or several adjacent rotation images. Accurate integration requires several steps: determination of a reflection mask, estimation of the background, generation of reference profiles and integration by profile fitting.
The intensity distribution of a reflection can be modelled analytically or derived from the observed profiles of neighbouring strong spots. For the rotation method, the profile shape depends strongly on the specific path of the reflection through the Ewald sphere and on variations in the angle of incidence of the diffracted beam on a flat detector. These geometrical distortions can be eliminated by mapping the reflections onto the coordinate system defined in x2.3, which simplifies the task of modelling the expected intensity distribution as all reflection profiles become similar.

Reflection mask
The parameters M and D of the Gaussian model (see x2.3) used to describe reflection shape can be determined automatically from one or more data images by the following procedure.
(i) Identify and mark strong pixels in the data image.
(ii) Assign the indices of the nearest reflection to each strong pixel.
(iii) Sort the strong pixels by the assigned reflection indices such that pixels with the same indices follow each other in the list.
(iv) For each strong reflection find the rectangular box that encloses all of the strong pixels belonging to the reflection.
(v) Increase the box slightly and use all pixels within the box that are not strong for background determination.
(vi) Subtract the background and determine the centroid and variance s 2 of the intensity-weighted diffracted-beam directions S 0 associated with each strong pixel belonging to the spot (see x2.3).
(vii) Reject the spot if the centroid position deviates too much from the calculated spot location.
(viii) Calculate ' and for the accepted reflection and save the three values ', and s 2 in a list. The standard deviation of the beam divergence is obtained directly from this list of n reflections as Determination of the standard deviation of the reflecting range, the mosaicity M , requires additional considerations. For each of the n reflections from the list above, let denote the angular difference between the rotation angle ' at its Bragg maximum and the centre of the oscillation angles covered by the image. The fraction of observed reflection intensity is (see x2.4) For a given M / the function R(; M /) assumes its maximum at = 0 and declines as || increases. The decline depends strongly on the mosaicity M and on the path length of the reflection through the Ewald sphere, which is accounted for by the factor 1/. For a large mosaicity R(; M /) declines slowly, which explains why for such crystals many reflections with large || values can be observed on a data image. Clearly, the list of strong spots located by the automatic procedure described above contains information about the mosaicity of the crystal. The problem of finding M from this list can be solved if one considers each value as a random variable drawn from a probability distribution R(; M /) with population parameter M /. The mosaicity M can then be estimated so that it maximizes the likelihood (joint probability) The parameters D and M are mainly used to specify the integration region around the spot defined by the parameters M and D , which are typically chosen to be 6-10 times larger than M and D , respectively (see x2.1). The reflection mask thus comprises all image pixels that satisfy when mapped to the profile coordinate system {e 1 , e 2 , e 3 } defined in x2.3. In addition, pixels are excluded from the mask if they are closer to the predicted Bragg peak of an intruding reflection from the neighbourhood.

Background
The region around a spot is assumed to have been chosen to be large enough to include a sufficient number of pixels which can be used for determination of the background. Background determination, as implemented in XDS, begins by sorting all pixels belonging to a reflection by increasing intensity. For weak or absent reflections, these values should represent a random sample drawn from a normal distribution. If this is not the case, the pixel with the largest intensity is removed until the sampling distribution of the remaining smaller items satisfies the expected distribution. This method will also exclude pixels with unexpected high values, such as ice reflections. The background, determined as the mean value of the accepted pixels, is systematically overestimated for strong spots because of some residual intensity extending into the accepted background pixels. This residual intensity is estimated from the expected distribution !(" 1 , " 2 , " 3 ) defined in x2.3 and removed from the final background value.

Standard profiles
Reflection profiles are represented on the Ewald sphere within a domain D 0 comprising 2n 1 + 1, 2n 2 + 1 and 2n 3 + 1 equidistant gridpoints along e 1 , e 2 and e 3 , respectively. The sampling distances between adjacent grid points are then Á 1 = D /(2n 1 + 1), Á 2 = D /(2n 2 + 1) and Á 3 = M /(2n 3 + 1). Thus, grid coordinate 3 ( 3 = Àn 3 , . . . , n 3 ) covers the set of rotation angles Contributions to the spot intensity come from one or several adjacent data images (j = j 1 , . . . , j 2 ), each covering the set of rotation angles Assuming Gaussian profiles along e 3 for all reflections (see x2.3), the fraction of counts (after subtraction of the background) contributed by data frame j to grid coordinate 3 is where = M /||. The integrals can be expressed in terms of the error function, for which efficient numerical approximations are available (Abramowitz & Stegun, 1972). Finally, each pixel in data image j belonging to the reflection is subdivided into 5 Â 5 areas of equal size and f 3 j =25 of the pixel signal is added to the profile value at grid coordinates 1 , 3 , 3 corresponding to each subdivision. This complicated procedure leads to more uniform intensity profiles for all reflections than using their untransformed shape. This simplifies the task of modelling the expected intensity distribution needed for integration by profile fitting. As implemented in XDS, reference profiles are learnt every 5 of crystal rotation at nine positions on the detector, each covering an equal area of the detector face. In the learning phase, profile boxes of the strong reflections are normalized and added to their nearest reference profile boxes. The contributions are weighted according to the distance from the location of the reference profile. Each grid point within the research papers average profile boxes is classified as signal if it is above 2% of the peak maximum. Finally, each profile is scaled such that the sum of its signal pixels normalizes to one. The analytical expression !(" 1 , " 2 , " 3 ) defined in x2.3 for the expected intensity distribution is only a rough initial approximation, which is now replaced by the empirical reference profiles.

Intensity estimation
If an expected intensity distribution {p i |i 2 D 0 } of the observed profile is given in a domain D 0 , the reflection intensity I can be estimated as which minimizes the function are the background, contents and variance of pixels observed in a subdomain D D 0 of the expected distribution. The background b i underneath a diffraction spot is often assumed to be a constant which is estimated from the neighbourhood around the reflection. Determination of reflection intensities by profile fitting has a long tradition (Diamond, 1969;Ford, 1974;Kabsch, 1988b;Otwinowski, 1993). Implementations of the method differ mainly in their assumptions about the variances v i . Ford used constant variances, which work well for films, which have a high intrinsic background. In XDS, which was originally designed for a multwire detector, v i / p i was assumed, which results in a straight summation of background-subtracted counts within the expected profile region, I = P i2D ðc i À b i Þ/ P i2D p i . This particular simple formula is very satisfactory for the low background typical of these detectors. For the general case, however, better results can be obtained by using v i = b i + Ip i for the pixel variances as shown by Otwinowski and implemented in DENZO and in later versions of XDS. Starting with v i = b i , the intensity is now found by an iterative process which is terminated if the new intensity estimate becomes negative or does not change within a small tolerance, which is usually reached after three cycles. It can be shown that the solution thus obtained is unique.

Scaling
The integrated intensities of the reflections need to be corrected by various factors arising from the following (i) changes in the intensity of the incident beam and variations in the illuminated crystal volume, (ii) absorption of incident and diffracted beams, (iii) radiation damage, (iv) variations in detector sensitivity within the detector plane and (v) different crystal sizes and crystalline order if the data are from several crystals.
The combined effect manifests itself in correlations of the intensity of a reflection with details of its measurement, such as time (or image number) and location in the detector plane. Usually, many statistically independent observations of symmetry-related reflections are recorded in the rotation images taken from one or several similar crystals of the same compound. The squared structure-factor amplitudes of equivalent reflections should be equal and many scaling procedures (see, for example Evans, 2006;Otwinowski et al., 2003;Kabsch, 1988b) exploit this a priori knowledge to determine a correction factor for each observed intensity. However, the scaling programs differ in the details of their scaling models, i.e. the parametrization and methods used for determination of the correction factors. Below, the approach is described as implemented recently in the programs XDS and XSCALE (Kabsch, 2010).
If more than one data set is included, these are first put on approximately the same scale by the factor KÁexp[BÁ(2sin/ 2 )] involving two parameters, K and B, for each data set. The parameter values are assigned so that the resulting correction factors fit best to the observed intensity ratios of common reflections in each pair of data sets.
For the more detailed corrections, three types of twodimensional functions are used in succession to remove correlations of the intensity of a reflection with (i) image number and resolution, (ii) location in the detector plane and (iii) image number and 13 detector surface regions. To correct for non-uniform detector response such as edge effects at the boundaries of multisegment detectors, the use of smooth analytical correction functions was avoided. Instead, the correction functions are sampled at a finite set of grid regions covering all of the function's definition range. The grid regions are chosen automatically to be as small as possible without overfitting the data so that each sampling region contains more than a specified minimum number of reflections (default 50). Thus, the correction function G is represented by a possibly large number of reciprocal factors G l , where the subscript l denotes the grid regions.
The correction factors G l are found in a cyclic prodedure starting with G l = 1. In each cycle, G l is updated by a factor g l . The target function for refinement is based on an observational equation for each reflection hl ¼ ðI hl À g l G l I h Þ= hl as introduced by Hamilton et al. (1965). The subscript h represents the unique reflection indices and hl denotes symmetry-related reflections to h that need to be corrected by the reciprocal scaling factor g l associated with grid point l; I hl and hl are their weighted mean and standard deviation, respectively. This standard deviation is considered to be infinitely large if no such reflection was measured, which amounts to omitting the observational equation altogether. The factors g l and the 'true' intensities I h are found at the minimum of the function research papers The first sum on the right side is a homogeneous function of g l of degree zero so that the g l would only be determined up to an arbitrary factor. The second sum on the right side is used to weakly restrain the scaling factors to one; a reasonable value is = 0.05. Minimization of É leads to updates g l in terms of the 'true' intensities I h which again depend on g l , The new update factors g l are obtained by using 'true' intensities I h o from the previous cycle instead of the current I h as defined above. At the end of the cycle, the old correction factors G l are updated by multiplication with the new g l . This cyclic procedure typically converges in less than six cycles.
The approach described here has been implemented in XDS and XSCALE and has been successfully used for more than two years. In contrast to the 'shortest path' eigenvector method of Fox & Holmes (1966), which is very efficient for a relatively small number of variables, the computations here require a time that is proportional to the number of reflections used for scaling and thus quickly lead to a solution even when a very large number of correction factors from many data sets are involved.

Post-refinement
The number of fully recorded reflections on each single image rapidly declines for small oscillation ranges and the complete intensities of the partially recorded reflections have to be estimated. This presented a serious obstacle in early structural work on virus crystals, as the crystal had to be replaced after each exposure on account of radiation damage. A solution to this problem, the 'post-refinement' technique, was found by Schutt, Winkler and Harrison and variants of this powerful method have been incorporated into most data-reduction programs (for a detailed discussion, see Harrison et al., 1985;Rossmann, 1985). The method derives complete intensities of reflections that are only partially recorded on an image from accurate estimates for the fractions of observed intensity: the 'partiality'. The partiality of each reflection can always be calculated as a function of orientation, unit-cell metric, mosaic spread of the crystal and model intensity distributions. The accuracy of the estimated full reflection intensity obviously then strongly depends on a precise knowledge of the parameters describing the diffraction experiment. Usually, symmetry-related fully recorded reflections can be found for many of the partial reflections and the list of such pairs of intensity observations can be used to refine the required parameters using a least-squares procedure. Clearly, this refinement is carried out after all images have been processed, which explains why the procedure is called 'post-refinement'.
Adjustments of the diffraction parameters s ( = 1, . . . , k) are determined by minimization of the function E, which is defined as the weighted sum of squared residuals between calculated and observed partial intensites.
hj Þg j 2 2 ðI h Þg: Here, I hj is the intensity recorded on image j of a partial reflection with indices summarized as hj, I h is the mean of the observed intensities of all fully recorded reflections symmetryequivalent to hj, g j is the inverse scaling factor of image j, ' hj is the calculated spindle angle of reflection hj at diffraction and R j is the computed fraction of total intensity recorded on image j. Expansion of the residuals Á hj to first order in the parameter changes s and minimization of E(s ) leads to the k normal equations P k 0 ¼1 P hj w hj @Á hj @s @Á hj @s 0 s 0 ¼ À P hj w hj Á hj @Á hj @s : Often, the normal matrix is ill-conditioned since changes in some unit-cell parameters or small rotations of the crystal about the incident X-ray beam do not significantly affect the calculated partiality R j . To take care of these difficulties, the system of equations is rescaled to yield unit diagonal elements for the normal matrix and the correction vector s is filtered by projection into a subspace defined by the eigenvectors of the normal matrix with sufficiently large eigenvalues (Diamond, 1966). The parameters are corrected by the filtered s and a new cycle of refinement is started until a minimum of E is reached. The weights, residuals and their gradients are calculated using the current values for s and g j at the beginning of each cycle. The derivatives @j hj j @s appearing in the normal equations can be worked out from the definitions given in xx2.2 and 2.4 (to simplify the following equations, the subscript hj is omitted). The fraction R j of total intensity can be expressed in terms of the error function (see x2.4) as Using the relation d erf(z)/dz = (2/ 1/2 )exp(Àz 2 ), the derivatives of R j are research papers The derivatives @'/@s , @ M /@s and @||/@s remain to be worked out (not shown here). As discussed in detail by Greenhough & Helliwell (1982), spectral dispersion and asymmetric beam cross-fire lead to some variation in M , which makes it necessary to include additional parameters in the list s . The effect of these parameters on the partiality is dealt with easily by the derivatives @ M /@s . The refinement scheme described above requires initial scaling factors g j . With the now improved estimates for the partialities R j , a new set of scaling factors can be obtained using the method outlined in x4. This alternating procedure of scaling and post-refinement usually converges within three cycles.
The use of error functions for modelling partiality, as implicated by a Gaussian model for describing spot shape, was chosen here for reasons of conceptual simplicity and coherence. This choice is unlikely to significantly alter the results of post-refinement that are based on other functions of similar form (see the discussion by Rossmann, 1985).

Space-group assignment
Identification of the correct space group is not always an easy task and should be postponed for as long as possible. Sometimes, the true space group only becomes known when the structure has been successfully solved and refined! However, one can expect to identify a small number of possibilities from the diffraction experiment.
Fortunately, all data processing as implemented in the program XDS can be carried out in the absence of any knowledge of the crystal symmetry and unit-cell parameters. In this case, a reduced cell is extracted from the observed diffraction pattern and processing of the data images continues to completion as if the crystal were triclinic. Clearly, the reflection indices then refer to the reduced cell and must be reindexed once the space group is known. For all space groups, the required reindexing transformation is linear and involves only whole numbers, as shown in Part 9 of Vol. A of International Tables for Crystallography (1989).
Automatic space-group assignment is carried out in two steps once integrated intensities of all reflections are available (see Kabsch, 2010). Firstly, the Bravais lattices are identified that are compatible with the reduced cell derived from the observed diffraction pattern. In the second step, all enantiomorphous space groups compatible with the observed lattice symmetry are rated by a redundancy-independent R factor. The group is selected that explains all integrated intensities in the data set at an acceptable R factor requiring a minimum number of unique reflections (Occam's principle). This approach deliberately avoids any test for the presence of screw axes as these tests would depend strongly on the completeness of the data. Fortunately, the presence or absence of screw axes is irrelevant for the determination of data correction/scaling factors (see x4).

Determination of the Bravais lattice
The determination of possible Bravais lattices is based upon the concept of the reduced cell whose metric parameters characterize 44 lattice types as described in Part 9 of Vol. A of International Tables for Crystallography (1989). A primitive basis b 1 , b 2 , b 3 of a given lattice is defined there as a reduced cell if it is right-handed and if the components of its metric tensor Kabsch Integration, scaling, space-group assignment and post-refinement 141 Table 1 Rating of lattice types implied by a given reduced cell. satisfy a number of conditions (inequalities). The main conditions state that the basis vectors are the shortest three linear independent lattice vectors with either all acute or all nonacute angles between them. As specified in International Tables for Crystallography, each of the 44 lattice types is characterized by additional equality relations among the six components of the reduced-cell metric tensor. As an example, for lattice character 11 (Bravais type tP) the components of the metric tensor of the reduced cell must satisfy (Note that the other tetragonal primitive lattice character 21 requires A B = C with the fourfold as the shortest axis.) Any primitive triclinic cell describing a given lattice can be converted into a reduced cell. It is well known, however, that the reduced cell thus derived is sensitive to experimental error. Hence, the direct approach of first deriving the correct reduced cell and then finding the lattice type is unstable and may in certain cases even prevent identification of the correct Bravais lattice.
A suitable solution of the problem has been found that avoids any decision as to what the 'true' reduced cell is (see Kabsch, 1993). The essential ingredients of this procedure are (i) a database of possible reduced cells and (ii) a backwardsearch strategy that finds the best-fitting cell in the database for each lattice type.
The database is derived from a seed cell which strictly satisfies the definitions for a reduced cell. All cells of the same volume as the seed cell whose basis vectors can be linearly expressed in terms of the seed vectors by indices À1, 0 or +1 are included in the database. Each unit cell in the database is considered as a potential reduced cell, although some of the defining conditions as given in Part 9 of Vol. A of International Tables for Crystallography (1989) may be violated. These violations are treated as arising from experimental error.
The backward-search strategy starts with the hypothesis that the lattice type is already known and identifies the bestfitting cell in the database of possible reduced cells. In contrast to a forward-directed search, it is now always possible to decide which conditions have to be satisfied by the components of the metric tensor of the reduced cell. The total amount by which all these equality and inequality conditions are violated is used as a quality index. For example, to find out how well a potential reduced cell b 1 , b 2 , b 3 from the database characterizes lattice character 11 (Bravais lattice tP), the quality index p 11 ðb 1 ; b 2 ; b 3 Þ ¼ jA À Bj þ maxð0; B À CÞ þ jDj þ jEj þ jFj is computed. Positive values of p 11 indicate that some conditions are not satisfied. All potential reduced cells in the data base are tested and the smallest value for p 11 is used for rating lattice type 11. A similar test is carried out for all 44 possible lattice types using quality indices based on their defining conditions as listed in Part 9 of Vol. A of International Tables for Crystallography (1989).
The results obtained using this method are shown in Table 1 for the example of a data set comprising 177 images with each exposure covering 0.5 of spindle rotation. The space group of the protein crystal was P4 3 2 1 2 (unit-cell parameters a = 159.4, b = 159.4, c = 160.3 Å ), but this knowledge was not used in the processing. Instead, the data were processed with respect to a triclinic reduced cell derived from the observed diffraction pattern as described above.  by their quality index. The table shows the possible lattice symmetries, their implied conventional unit-cell parameters and a reindexing transformation. The table entries are sorted by increasing quality index and reveal a nearly cubic lattice symmetry. A lattice symmetry is considered to be acceptable if it has a low quality index and its implied unit-cell parameters do not violate the ideal values by more than 3.0 in angles and 3% in cell axes. Thus, except for the last entry, all of the lattice symmetries in the table are acceptable; the correct lattice type 11 tP is highlighted. Lattice symmetries that are not accepted include all body-centred lattices or those that are centred on all faces; they are omitted from the table.
The reindexing transformation REIDX() consists of 12 integers that relate the original indices h, k, l used during the integration to the indices h 0 , k 0 , l 0 with respect to the new cell.
The value of the integer IDXV depends on the lattice type used for specifying reflection indices in the integration step. IDXV is 1 for a primitive lattice, 2 for a face-centred or bodycentred lattice, 3 for a rhombohedral lattice and 4 for a lattice centred on all faces. In the example case we have IDXV = 1 because integration was carried out in space group P1.
Note also that elements 4, 8 and 12 of the transformation are always 0 in this example. These three extra elements were introduced to provide a simple tool for correcting the indices if all reflections are misindexed by a constant.

Finding possible space groups
For protein crystals, the absence of parity-changing symmetry operators restricts the number of possible space groups to 65 instead of 230. Moreover, the determination of correction factors for the integrated intensities does not depend on the presence or absence of any screw axes so that data processing can be finished without this knowledge. This reduces the problem to the identification of an enantiomorphous space group without screw axes that is compatible with the observed lattice symmetry (see above).
For solution of the problem, a quality indicator of the mean variation in the intensities of symmetry-equivalent reflections (R meas ) is calculated for each possible group. The decision for a particular group is then based on Occam's principle: the selected group must explain all integrated intensities in the data set at acceptable quality, thereby requiring a minimum number of unique reflections.
A suitable redundancy-independent data quality indicator has been suggested by Diederichs & Karplus (1997) and Weiss (2001), R meas R r:i:m: ¼ P hl n h n h À 1 1=2 jI hl À I h j P hl I hl : The subscript h represents the unique reflection indices and hl denotes any of the n h symmetry-related reflections to h. The absolute differences between the observed intensities I hl and their mean intensity I h are weighted to remove any dependency on n h and compared with the intensities. Small values of R meas indicate accurate single observations I hl and the use of symmetry operators compatible with the intensity data set. For the above example data set, Table 2 lists all enantiomorphous groups which are in harmony with the observed lattice symmetry shown in Table 1. For each listed space group, UNIQUE is the number of unique reflections and COM-PARED is the number of reflections used to calculate the redundancy-independent R factor R meas . Two sets of groups can be distinguished clearly: those implying an acceptable R meas and a second set with R meas > 45%, which is totally unacceptable. Among the acceptable solutions a minimum number of unique reflections is needed if the crystal has the tetragonal space-group symmetry P422.