21.3. Example Python scripts
Several complete examples can be found in the directory data/examples/geometry.
21.3.1. RHF geometry optimization of the water molecule
This is a basic example of how to perform a restricted Hartree–Fock geometry optimization for the water molecule using dense integrals.
from pybest import context
from pybest.gbasis import (
compute_eri,
compute_kinetic,
compute_nuclear,
compute_nuclear_repulsion,
compute_overlap,
get_gobasis,
)
from pybest.geometry import RHFGeometryOptimizer
from pybest.linalg import DenseLinalgFactory
from pybest.occ_model import AufbauOccModel
# Hartree-Fock calculation
# ------------------------
# Load the coordinates from file.
# Use the XYZ file from PyBEST's test data directory.
fn_xyz = context.get_fn("test/water.xyz")
# Create a Gaussian basis set
basis = get_gobasis("cc-pvtz", fn_xyz)
# Create a linalg factory
lf = DenseLinalgFactory(basis.nbasis)
# Compute integrals
olp = compute_overlap(basis)
kin = compute_kinetic(basis)
ne = compute_nuclear(basis)
eri = compute_eri(basis)
external = compute_nuclear_repulsion(basis)
# Create alpha orbitals
orb_a = lf.create_orbital()
# Decide how to occupy the orbitals (5 alpha electrons)
occ_model = AufbauOccModel(basis)
# Relax molecular geometry within RHF
hf = RHFGeometryOptimizer(lf, occ_model)
# The order of the arguments does not matter
hf_output = hf(kin, ne, eri, olp, orb_a, external)
21.3.2. ROOpCCD geometry optimization of the water molecule
This is a basic example of how to perform a restricted orbital-optimized pCCD geometry optimization for the water molecule using dense integrals.
from pybest import context
from pybest.gbasis import (
compute_eri,
compute_kinetic,
compute_nuclear,
compute_overlap,
get_gobasis,
)
from pybest.geometry import ROOpCCDGeometryOptimizer
from pybest.linalg import DenseLinalgFactory
from pybest.occ_model import AufbauOccModel
# Hartree-Fock calculation
# ------------------------
# Load the coordinates from file.
# Use the XYZ file from PyBEST's test data directory.
fn_xyz = context.get_fn("test/water.xyz")
# Create a Gaussian basis set
basis = get_gobasis("cc-pvdz", fn_xyz)
# Create a linalg factory
lf = DenseLinalgFactory(basis.nbasis)
# Compute integrals
olp = compute_overlap(basis)
kin = compute_kinetic(basis)
ne = compute_nuclear(basis)
eri = compute_eri(basis)
# Decide how to occupy the orbitals (5 alpha electrons)
occ_model = AufbauOccModel(basis, ncore=0)
# Converge pCCD
pccd = ROOpCCDGeometryOptimizer(lf, occ_model)
pccd_output = pccd(
kin,
ne,
eri,
hf_kwargs={"threshold": 1e-4},
pccd_kwargs={
"thresh": {"energy": 1e-5, "gradientnorm": 5e-3, "gradientmax": 5e-3}
},
)