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 energyenergy='singlets': BSE singlet energyenergy='triplets': BSE triplet energyenergy='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([[-6.13908924e-09, -8.41282599e-09, 8.69231590e+00],
[-4.32009983e-09, 6.36646291e-09, -8.69231588e+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 21:40:39 -3077.640560 8.692316
new radius 0.012247
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 145.15049778030925
GoodOldQuasiNewton: 1 21:40:45 -3077.578217 8.692316
energies -3077.5782173233865 -3077.6405596626664
reject step
new radius 0.006124
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 148.11660432385406
GoodOldQuasiNewton: 2 21:40:52 -3077.613325 6.758169
energies -3077.613324510289 -3077.6405596626664
reject step
new radius 0.003062
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 149.61090759911588
GoodOldQuasiNewton: 3 21:40:59 -3077.627957 7.693924
energies -3077.627957022293 -3077.6405596626664
reject step
new radius 0.001531
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.36087173647138
GoodOldQuasiNewton: 4 21:41:05 -3077.634516 8.185343
energies -3077.6345160145324 -3077.6405596626664
reject step
new radius 0.000765
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.73655693025802
GoodOldQuasiNewton: 5 21:41:12 -3077.637603 8.436918
energies -3077.6376027276624 -3077.6405596626664
reject step
new radius 0.000383
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.92457530833462
GoodOldQuasiNewton: 6 21:41:18 -3077.639098 8.564132
energies -3077.639097514813 -3077.6405596626664
reject step
new radius 0.000191
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.01862844268933
GoodOldQuasiNewton: 7 21:41:25 -3077.639833 8.628125
energies -3077.639832642549 -3077.6405596626664
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.0635437098752
GoodOldQuasiNewton: 8 21:41:32 -3077.640181 8.660190
energies -3077.6401807853035 -3077.6405596626664
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.0635437098752
GoodOldQuasiNewton: 9 21:41:38 -3077.640181 8.675513
energies -3077.6401807853035 -3077.6405596626664
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.0635437098752
GoodOldQuasiNewton: 10 21:41:38 -3077.640181 8.675513