# Gradients

A most fundamental feature of this framework is its ability to rapidly compute the gradients of physical properties with respect to the force field parameters used to estimate them.

Note

Prior to v0.3.0 of this framework a combination of re-weighting and the central finite difference was employed to estimate the gradients of observables. From v0.3.0 onwards the fluctuation method [1] is instead used. The change was made to, in future, enable better integration with automatic differentiation libraries such as jax, and differentiable simulation engines such as timemachine.

## Theory

The framework currently employs the fluctuation approach [1] to compute gradients of observables with respect to the force field parameters used to estimate them.

This approach may be derived by direct differentiation of the ensemble average an observable \(X\):

where

is the isothermal-isobaric partion function, \(\theta\) are the force field parameters being used to estimate the observable, \(U\) the systems potential energy, \(\beta \equiv k_b T\), \(k_b\) the Boltzmann constant, \(T\) the temperature, \(p\) the pressure and \(V\) the volume.

The derivative of the ensemble average defined above with respect to a particular force field parameter of interest \(\theta\) is given by:

## Computing \(\mathrm{d} U / \mathrm{d} \theta_i\)

While future integrations with differentiable simulation engines such as timemachine will allow \(\mathrm{d} U / \mathrm{d} \theta_i\) to be computed directly from molecular simulation runs, currently most common simulation engines do not directly support computing this quantity.

Until such an integration is complete, the framework currently employs a central finite difference approach, whereby

Although more expensive than computing either the forward or backwards derivative, the central difference method should give a more accurate estimate of the gradient at the minima, maxima and transition points. By default a value of \(h = \theta_i \times 10^{-4}\) is used. This has been found to yield finite differences which do not suffer from precision issues, while being sufficiently small so as to yield an accurate estimate.

In practice the derivatives obtained by re-evaluating the energies of each configuration in a trajectory generated by a molecular simulation (either after a simulation or after loading one from disk) at each of the perturbed parameters.

While there is an expense associated with extra evaluations of the potential energy function for each configuration, this is mitigated by only computing those terms which depend upon (or may depend upon) \(\theta_i\). As an example, when computing derivatives with respect to a bond length the electrostatic and van der Waal contributions are not computed. This significantly speeds up the computation of these derivatives.

The final derivatives are stored in `ObservableArray`

objects for convenience and for easy propagation of gradients
through workflows. See the observables documentation for more information.