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([[-7.38964445e-10, -7.03437308e-10, 3.19229776e-01],
[ 7.03437308e-10, 7.53175300e-10, -3.19229776e-01]])
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 13:23:47 -113.101204 0.319230
new radius 0.012247
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.02
Abs Gbar estimate 0.042646422466296546
GoodOldQuasiNewton: 1 13:24:34 -113.098913 0.319230
energies -113.09891342922442 -113.10120446793493
reject step
new radius 0.006124
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.02
Abs Gbar estimate 0.10823086218962535
GoodOldQuasiNewton: 2 13:25:22 -113.100204 0.248237
energies -113.10020359454646 -113.10120446793493
reject step
new radius 0.003062
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.02
Abs Gbar estimate 0.1522730802910769
GoodOldQuasiNewton: 3 13:26:10 -113.100741 0.282892
energies -113.10074132944385 -113.10120446793493
reject step
new radius 0.001531
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.02
Abs Gbar estimate 0.17710669005277638
GoodOldQuasiNewton: 4 13:26:58 -113.100982 0.300816
energies -113.10098236796145 -113.10120446793493
reject step
new radius 0.000765
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.02
Abs Gbar estimate 0.19022661981615946
GoodOldQuasiNewton: 5 13:27:45 -113.101096 0.310054
energies -113.10109580258063 -113.10120446793493
reject step
new radius 0.000383
eigenvalues 20.00 20.00 20.00
Corrected Newton step: abs(D) = 0.02
Abs Gbar estimate 0.19696236595622885
GoodOldQuasiNewton: 6 13:28:32 -113.101151 0.314829
energies -113.10115073498847 -113.10120446793493
energy change; actual: 0.000054 estimated: -0.000171
Energy prediction factor 1.313634710499241
Force prediction factor -1.625081318846672
Scale factors 0.364431 0.364431
new radius 0.000139
eigenvalues 7.62 20.00 20.00
Corrected Newton step: abs(D) = 0.06
Abs Gbar estimate 0.20023874309014142
GoodOldQuasiNewton: 7 13:29:19 -113.101131 0.317168
energies -113.10113085428142 -113.10115073498847
energy change; actual: 0.000020 estimated: -0.000062
Energy prediction factor 1.3181492133464323
Force prediction factor 0.12838671352944372
Scale factors 0.364431 0.510204
new radius 0.000100
eigenvalues 8.74 20.00 20.00
Corrected Newton step: abs(D) = 0.05
Abs Gbar estimate 0.1993174285015904
GoodOldQuasiNewton: 8 13:30:06 -113.101117 0.316306
energies -113.10111650360768 -113.10113085428142
energy change; actual: 0.000014 estimated: -0.000045
Energy prediction factor 1.3211254369770389
Force prediction factor 0.2542237315486981
Scale factors 0.364431 0.510204
new radius 0.000100
eigenvalues 11.72 20.00 20.00
Corrected Newton step: abs(D) = 0.04
Abs Gbar estimate 0.19800698928286098
GoodOldQuasiNewton: 9 13:30:53 -113.101102 0.315477
energies -113.10110207138132 -113.10111650360768
energy change; actual: 0.000014 estimated: -0.000045
Energy prediction factor 1.3239078578269774
Force prediction factor -0.9962332832498628
Scale factors 0.364431 0.364431
new radius 0.000100
eigenvalues 5.87 20.00 20.00
Corrected Newton step: abs(D) = 0.08
Abs Gbar estimate 0.19800502105371318
GoodOldQuasiNewton: 10 13:31:40 -113.101088 0.315062