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([[-4.77484718e-09, -7.27595761e-09, 8.69231590e+00],
[-1.02318154e-08, -2.27373675e-10, -8.69231587e+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 19:01:24 -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.15049757587613
GoodOldQuasiNewton: 1 19:01:32 -3077.578217 8.692316
energies -3077.5782173233874 -3077.640559662662
reject step
new radius 0.006124
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 148.1166041235063
GoodOldQuasiNewton: 2 19:01:40 -3077.613325 6.758169
energies -3077.613324510286 -3077.640559662662
reject step
new radius 0.003062
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 149.61090739883085
GoodOldQuasiNewton: 3 19:01:48 -3077.627957 7.693924
energies -3077.6279570222896 -3077.640559662662
reject step
new radius 0.001531
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.36087153553177
GoodOldQuasiNewton: 4 19:01:57 -3077.634516 8.185343
energies -3077.6345160145315 -3077.640559662662
reject step
new radius 0.000765
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.7365567289044
GoodOldQuasiNewton: 5 19:02:05 -3077.637603 8.436918
energies -3077.637602727663 -3077.640559662662
reject step
new radius 0.000383
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 150.9245751068609
GoodOldQuasiNewton: 6 19:02:13 -3077.639098 8.564132
energies -3077.639097514813 -3077.640559662662
reject step
new radius 0.000191
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.01862824115864
GoodOldQuasiNewton: 7 19:02:21 -3077.639833 8.628125
energies -3077.639832642549 -3077.640559662662
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.0635435083147
GoodOldQuasiNewton: 8 19:02:30 -3077.640181 8.660190
energies -3077.640180785306 -3077.640559662662
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.0635435083147
GoodOldQuasiNewton: 9 19:02:37 -3077.640181 8.675513
energies -3077.640180785306 -3077.640559662662
reject step
new radius 0.000100
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.61
Abs Gbar estimate 151.0635435083147
GoodOldQuasiNewton: 10 19:02:37 -3077.640181 8.675513