Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Optimization methods

The first class of special points on the PES that we will discuss are local energy minima. These correspond to equilibrium molecular structures and are characterized by a vanishing first order energy derivative combined with a Hessian matrix which has only positive eigenvalues. The procedure to determine a local minimum (i.e. finding the coordinates that minimize the energy) is called a structure optimization.

In practical terms, the ingredients to perform a geometry optimization include: (1) the initial molecular coordinates, (2) a choice of coordinate system, (3) the energy at a specific geometry E(x)E(\mathbf{x}), (4) the gradient g(x)=∇E(x)\mathbf{g}(\mathbf{x})=\nabla E(\mathbf{x}), (5) the Hessian, and (6) a procedure to update the coordinates and Hessian and move on the potential energy surface towards lower energy.

Having addressed the issue of coordinate system, the remaining question is what procedure to use to move along the potential energy surface and arrive at a local energy minimum. There are several iterative methods to do this, some of which need only information on the energy gradient (e.g. gradient-descent, conjugate gradient), while others take into account also the Hessian (Newton–Raphson, quasi-Newton). For a detailed review of minimization techniques, see Snyman (2005).

In the following, we will illustrate the performance of different optimization methods using a mathematical 2D function for which we can visualize the surface and calculate the gradient and Hessian analytically.

Let us define a function and represent it graphically.

Source
<Figure size 700x700 with 1 Axes>

Gradient descent

The simplest optimization procedure is to repeatedly take a step in the direction opposite to the local gradient

xi+1=xi−kig(xi)\mathbf{x}_{i+1} = \mathbf{x}_i - k_i\mathbf{g}(\mathbf{x}_i) \nonumber

where by xi+1\mathbf{x}_{i+1} we denote the new coordinates (in a generic coordinate system -- either Cartesian or internal coordinates), xi\mathbf{x}_i are the coordinates at the previous step ii, ∇E\nabla E is the energy gradient and kik_i is the step size. The step size can either be kept constant, or adjusted at each iteration, e.g. by the line search procedure.

The gradient-descent method is simple to implement and is guaranteed to converge, but has the disadvantage that it requires many steps and becomes slow when close to the minimum where the gradient is small. It always converges to a local minimum, given enough steps.

Implementation

Let’s implement the gradient descent method. We will need to set prepare a routine which determines the gradient of our function f(x,y)f(x, y).

Now, we can write the routine to run the gradient descent algorithm:

Converged in 69 iterations!

Let us represent the trajectory graphically.

Source
<Figure size 700x700 with 1 Axes>

Conjugate gradient

An improved method over the gradient-descent approach is to use the “gradient history” (steps ii and i−1i-1) to determine the coordinates at step i+1i+1

xi+1=xi−kihi\mathbf{x}_{i+1} = \mathbf{x}_i - k_i \mathbf{h}_i \nonumber

with hi=g(xi)+γihi−1\mathbf{h}_i = \mathbf{g}(\mathbf{x}_i)+\gamma_i\mathbf{h}_{i-1}. The function γi\gamma_i contains gradient information from steps ii and i−1i-1 and can be defined in different ways. For example, in the Fletcher-Reeves conjugate gradient method

γi=∣g(xi)∣2∣g(xi−1)∣2\gamma_i = \frac{|\mathbf{g}(\mathbf{x}_i)|^2}{|\mathbf{g}(\mathbf{x}_{i-1})|^2} \nonumber

Another option, is the Polak-Ribiere method,

γi=[g(xi)−g(xi−1)]Tg(xi)∣g(xi−1)∣2\gamma_i = \frac{\left[\mathbf{g}(\mathbf{x}_i)-\mathbf{g}(\mathbf{x}_{i-1})\right]^\mathrm{T}\mathbf{g}(\mathbf{x}_i)}{|\mathbf{g}(\mathbf{x}_{i-1})|^2} \nonumber

Implementation

Let us now implement the conjugate gradient optimization algorithm and compare its performance to the gradient descent method.

Fletcher-Reeves converged in 118 iterations!
Polak-Ribiere converged in 81 iterations!

Let’s plot the conjugate gradient results in comparison to gradient descent.

<Figure size 700x700 with 1 Axes>

Newton–Raphson

The next step in the hierarchy of minimization methods is to use both the first and second order energy derivatives (i.e. gradient g\mathbf{g} and Hessian H\mathbf{H}) in determining the next step in conformation space. This is based on a quadratic approximation for the local shape of the PES

E(x+Δx)≈E(x)+g(x)Δx+12ΔxTHΔxE(\mathbf{x}+\Delta\mathbf{x}) \approx E(\mathbf{x}) + \mathbf{g}(\mathbf{x})\Delta\mathbf{x} + \frac{1}{2}\Delta\mathbf{x}^\mathrm{T}\mathbf{H}\Delta\mathbf{x}

Here, Δx\Delta \mathbf{x} is the Newton step used to update the coordinates

Δx=−H−1g(x)xi+1=xi+Δx\begin{align} \Delta \mathbf{x} &= -\mathbf{H}^{-1}\mathbf{g}(\mathbf{x})\\ \mathbf{x}_\mathrm{i+1} &= \mathbf{x}_\mathrm{i}+\Delta \mathbf{x} \end{align}

Implementation

In the following, we will implement the Newton-Raphson optimization algorithm. For this, we need to write a routine which computes the Hessian of our mathematical function.

Using the Hessian, we can now implement the Newton-Raphson algorithm:

Converged in 7 iterations!

Let’s plot the trajectory followed by the Newton-Raphson optimization and compare it with gradient descent and conjugate gradient.

Source
<Figure size 700x700 with 1 Axes>

The Newton-Raphson algorithm converges very fast, but it converges to the nearest stationary point. This can be a transition state, rather than a local minimum, as shown by the graph above. For this reason, one must always make sure that the coordinates found by Newton-Raphson correspond to a minimum, e.g. by checking that the Hessian has no imaginary eigenvalues.

Quasi-Newton

The methods illustrated here can easily be adapted to use the molecular energy gradient and molecular coordinates and obtain optimized molecular structures. However, in the case of the Newton-Raphson method, the second order derivatives of the energy with respect to nuclear displacements are required to generate the Newton step. The direct computation of these derivatives (which compose the Hessian matrix) is quite expensive, but good approximations for the Hessian can be constructed using the gradient history. For example, the Broyden-Fletcher-Goldfarb-Shanno (BFGS, used by geomeTRIC) approach uses the relation:

Hi+1=Hi+hihiThiTsi−Hisi(Hisi)TsiTHisi ,\begin{align} \mathbf{H}_{i+1} &= \mathbf{H}_i + \frac{\mathbf{h}^{}_i\mathbf{h}_i^\mathrm{T}}{\mathbf{h}_i^\mathrm{T}\mathbf{s}^{}_i} - \frac{\mathbf{H}_i\mathbf{s}_i\left(\mathbf{H}_i\mathbf{s}_i\right)_{}^\mathrm{T}}{\mathbf{s}_i^\mathrm{T}\mathbf{H}_i^{}\mathbf{s}_i^{}} \, ,\nonumber \end{align}

with,

hi=g(xi+1)−g(xi) si=xi+1−xi ,\begin{align} \mathbf{h}_i &= \mathbf{g}(\mathbf{x}_{i+1}) - \mathbf{g}(\mathbf{x}_i) \, \nonumber \\ \mathbf{s}_i &= \mathbf{x}_{i+1} - \mathbf{x}_{i} \nonumber \,, \end{align}

to update the Hessian at step i+1i+1 using the Hessian at step ii and information about the gradient at the current and previous step.

This method is the typical one used in molecular geometry optimization because it achieves a very quick convergence at the same computational cost as gradient-descent. The steps of a molecular geometry optimization are illustrated in the figure below.

References
  1. Snyman, J. A. (2005). Practical mathematical optimization. Springer.
  2. Neese et al., F. (2009). Orca. An Ab Initio, DFT and Semiempirical Electronic Structure Package, 3.