Energy evaluation
Introduction
It is possible to call individual energy methods through the Python API for integration in other workflows. In addition to single-point energies, gradients can be computed, as well as hessian for some methods. For geometry optimization, see the separate tutorial on that topic.
The Python object that describes a calculation at a single molecular geometry is SingleInput
. We can try a simple example by constructing then evaluating a SingleInput
for a B97-3c energy calculation on the water molecule as follows:
import sierra
from sierra.inputs import *
water = Molecule(pubchem="water")
inp = SingleInput(molecule=water, method=DFTMethod(xc="b97-3c"))
result = sierra.run(inp)
print(result.energy)
Evaluating gradients and hessians
The same API is used for a single gradient or hessian evaluation. For example the gradients of the energy with respect to geometrical coordinates for the above example can be computed through:
import sierra
from sierra.inputs import *
water = Molecule(pubchem="water")
inp = SingleInput(molecule=water, method=DFTMethod(xc="b97-3c"), result_type="gradient")
result = sierra.run(inp)
print(result.gradient)
In the same way, the hessian can be evaluated (result_type="hessian"
) where available, and printed as print(result.hessian)
. Lower derivatives are always computed, so for example the result
object is populated by the energy and gradient in a hessian calculation.
Using SingleInput
for OrbNet energy evaluations
Here we will compute the reaction energy for conversion of ethyne to benzene using both OrbNet and the (much more computationally expensive) DFT method on which the OrbNet Fuji model was trained.
The reaction_energy
function below calculates the (0K) reaction energy for a given Sierra method.
import sierra
from sierra.inputs import *
benzene = Molecule(pubchem="benzene")
ethyne = Molecule(pubchem="ethyne")
def reaction_energy(method):
e_benzene = sierra.run(SingleInput(molecule=benzene, method=method)).energy
e_ethyne = sierra.run(SingleInput(molecule=ethyne, method=method)).energy
delta_e = e_benzene - 3 * e_ethyne
return delta_e * sierra.constants.cf("hartree", "kJ / mol")
reference_dft = DFTMethod(xc="wb97xd3", ao="def2-tzvp")
orbnet = OrbNetMethod(model="fuji")
for method in [reference_dft, orbnet]:
delta_e = reaction_energy(method)
print(f"{str(method):48} {delta_e:10.3f} kJ / mol")
Running the script produces the table
DFTMethod(xc='WB97XD3', ao='def2-tzvp') -689.166 kJ / mol
OrbNetMethod(model='fuji', version='3.1') -692.228 kJ / mol