Skip to content

Geometry optimization

Introduction

Geometry optimization calculations are represented by the Python object OptimizationInput. The initial geometry is specified through the initial_molecule argument, and the underlying energy method through method.

Energy minimization

A first example

A short script to optimize the geometry of water using GFN1-xTB is shown below.

import sierra
from sierra.inputs import *

water = Molecule(pubchem="water")
inp = OptimizationInput(
    initial_molecule=water, 
    method=XTBMethod(model="gfn1")
)
result = sierra.run(inp)
for i, e in enumerate(result.energies):
    print(f"  {i+1} {e:15.9f}")

This example also prints out the table of energies computed during the optimization. The optimized molecular structure is found in result.final_molecule, along with a host of other data.

Energy minimization with OrbNet

In this second example, we will use OrbNet to determine the O-H bond length in phenol.

import sierra
from sierra.inputs import *

inp = OptimizationInput(
    initial_molecule=Molecule(pubchem="phenol"), 
    method=OrbNetMethod()
)
result = sierra.run(inp)
phenol = result.final_molecule
# find index of the oxygen atom in the structure
o_index = list(phenol.symbols).index('O')
# find the distances between oxygen and each hydrogen, and take the smallest
rOH = min([phenol.measure([o_index,i]) for i, s in enumerate(phenol.symbols) if s == 'H'])
print(f"OH bond length = {rOH * sierra.constants.cf('bohr', 'pm'):.2f} pm")

This should print out the OrbNet-optimized bond-length as:

OH bond length = 95.94 pm