# 9.2. geomopt — Geometry optimization¶

The geomopt module implements geometry optimization via interfaces to geomeTRIC and PyBerny. The following example shows how to optimize the structure of N2 molecule with PyBerny:

from pyscf import gto, scf
from pyscf.geomopt.berny_solver import optimize
mol = gto.M(atom='N 0 0 0; N 0 0 1.2', basis='ccpvdz')
mf = scf.RHF(mol)
mol_eq = optimize(mf)
print(mol_eq.atom_coords())


## 9.2.2. Program reference¶

Interface to geomeTRIC library https://github.com/leeping/geomeTRIC

class pyscf.geomopt.geometric_solver.GeometryOptimizer(method)[source]

Optimize the molecular geometry for the input method.

Note the method.mol will be changed after calling .kernel() method.

kernel(params=None)[source]

Kernel function is the main driver of a method. Every method should define the kernel function as the entry of the calculation. Note the return value of kernel function is not strictly defined. It can be anything related to the method (such as the energy, the wave-function, the DFT mesh grids etc.).

optimize(params=None)

Kernel function is the main driver of a method. Every method should define the kernel function as the entry of the calculation. Note the return value of kernel function is not strictly defined. It can be anything related to the method (such as the energy, the wave-function, the DFT mesh grids etc.).

exception pyscf.geomopt.geometric_solver.NotConvergedError[source]
pyscf.geomopt.geometric_solver.kernel(method, assert_convergence=True, include_ghost=True, constraints=None, callback=None, maxsteps=100, **kwargs)[source]

Optimize geometry with geomeTRIC library for the given method.

To adjust the convergence threshold, parameters can be set in kwargs as below:

pyscf.geomopt.geometric_solver.optimize(method, assert_convergence=True, include_ghost=True, constraints=None, callback=None, maxsteps=100, **kwargs)[source]

Optimize geometry with geomeTRIC library for the given method.

To adjust the convergence threshold, parameters can be set in kwargs as below:

Helper functions for geometry optimizer

pyscf.geomopt.addons.as_pyscf_method(mol, scan_function)[source]

Creat an wrapper for the given scan_function, to make it work as a pyscf gradients scanner. The wrapper can be passed to optimize().

Args:

scan_function : [mol] => (e_tot, grad)

Examples:: >>> mol = gto.M(atom=’H; H 1 1.2’, basis=’ccpvdz’) >>> scan_fn = scf.RHF(mol).nuc_grad_method().as_scanner() >>> m = as_pyscf_method(mol, scan_fn) >>> pyscf.geomopt.berny_solver.kernel(m)

pyscf.geomopt.addons.dump_mol_geometry(mol, new_coords, log=None)[source]

Dump the molecular geometry (new_coords) and the displacement wrt old geometry.

Args:

new_coords (ndarray) : Cartesian coordinates in Angstrom

pyscf.geomopt.addons.symmetrize(mol, coords)[source]

Symmetrize the structure of a molecule.