While the calculation of the gradient and curvature usually is not too difficult for many restraint types when diffraction gets involved these calculations can become difficult to code in an efficient manner. TNT contains tools which can be used to speed these calculations and lessen the amount of work you have to do to implement your ideas.
The Agarwal method of calculating gradients of the usual least-squares restraint is generalizable to any restraints which are a function of amplitudes and phases. In this method the gradient of a residual function is calculated by generating Fourier coefficients which depend upon the form of the residual, and processing the corresponding map in a general fashion. For the calculation of the gradient the coefficients are given to the AGARWAL command in Rfactor. The diagonal of the Normal matrix is calculated in a similar fashion by passing different coefficients to the NORMAL_MATRIX command.
The Fourier coefficients required to calculate the gradient of a residual of the form
The coefficients required to calculate the curvature of a residual is much more complicated. The principle component can be calculated by passing
to the NORMAL_MATRIX command.