Atomic Forces and Geometry Optimizaiton

What this tutorial is about

In this tutorial we will learn how to compute the excited state atomic forces of a molecular structure and how to use these to perform geometry optimization. Let’s start by importing the relevant modules

[1]:
from pyxtp import xtp
from ase.io import write
from ase.build import molecule
from ase.optimize import GoodOldQuasiNewton

Define the molecular structure

We define here a CO molecule in its ground state geometry.

[2]:
atoms = molecule('CO')

Configure the xtp calculator

We now define the xtp calculator and configure it to target particular forces. We can select which forces we want to compute with the method .select_force() of the calculator. We can choose to target different forces :

  • energy='energy' : DFT total energy

  • energy='singlets': BSE singlet energy

  • energy='triplets': BSE triplet energy

  • energy='qp': Quasi particile energy

For singlets, triplets and qp one can also specify which particular level to target to compute the forces. For example energy='singlets', level=0 will target the lowest lying singlet state.

[3]:
# instantiate the calculator
calc = xtp(nthreads=2)

# select the force we want to use
calc.select_force(energy='singlets', level=0, dynamic=False)

# this allows to change all options
# calc.options.dftpackage.functional = 'PBE'
calc.options.dftpackage.basisset = 'def2-svp'
calc.options.dftpackage.auxbasisset = 'aux-def2-svp'
calc.options.gwbse.gw.qp_grid_search_mode = 'dense'
calc.options.gwbse.gw.qp_grid_spacing = 0.001
calc.options.gwbse.gw.qp_grid_steps = 1001

# set up the logger
calc.options.logging_file = 'CO_forces.log'

# set the calculator
atoms.calc = calc

Compute the forces

If you are simply interested in computing the forces, they can easily be accessed through the .get_forces() method

[4]:
atoms.get_forces()
[4]:
array([[-1.79625204e-08, -2.13731255e-08,  8.68668465e+00],
       [ 2.13731255e-08,  1.77351467e-08, -8.68668466e+00]])

Geometry optimization

Geometry optimization can be run by leveraging the intrinsic ASE capabilities. We can for example use the QuasiNewton method implemented in ASE to relax the molecular structre in the excited states we have just specified. We here fix the number of steps to 10 to limit the computational cost.

[5]:
dyn = GoodOldQuasiNewton(atoms, trajectory='test.traj')
dyn.run(fmax=0.05, steps=10)
write('final.xyz', atoms)
                    Step     Time          Energy          fmax
GoodOldQuasiNewton:    0 20:47:02    -3077.640560        8.686685
new radius 0.012247
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 144.95866869843604
GoodOldQuasiNewton:    1 20:47:29    -3077.578217        8.686685
energies -3077.5782173233915 -3077.640559662651
reject step
new radius 0.006124
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 147.9228245334587
GoodOldQuasiNewton:    2 20:47:56    -3077.613325        6.754864
energies -3077.6133245102924 -3077.640559662651
reject step
new radius 0.003062
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 149.41615244998093
GoodOldQuasiNewton:    3 20:48:23    -3077.627957        7.697872
energies -3077.6279570222846 -3077.640559662651
reject step
new radius 0.001531
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.16562890770035
GoodOldQuasiNewton:    4 20:48:51    -3077.634516        8.185633
energies -3077.634516014483 -3077.640559662651
reject step
new radius 0.000765
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.54107026178866
GoodOldQuasiNewton:    5 20:49:16    -3077.637603        8.436988
energies -3077.637602727723 -3077.640559662651
reject step
new radius 0.000383
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.72896672003952
GoodOldQuasiNewton:    6 20:49:43    -3077.639098        8.566944
energies -3077.6390975146887 -3077.640559662651
reject step
new radius 0.000191
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.82295889447602
GoodOldQuasiNewton:    7 20:50:09    -3077.639833        8.630578
energies -3077.639832642476 -3077.640559662651
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.86784505682374
GoodOldQuasiNewton:    8 20:50:36    -3077.640181        8.657054
energies -3077.6401807853117 -3077.640559662651
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.86784505682374
GoodOldQuasiNewton:    9 20:51:00    -3077.640181        8.677949
energies -3077.6401807853117 -3077.640559662651
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.86784505682374
GoodOldQuasiNewton:   10 20:51:00    -3077.640181        8.677949