Dispersion gradients

Hello Psi4,

I have been looking into separating the pure DFT gradients from the D3BJ ones when doing a DFT+D3BJ type of calculation. Since by default, Psi4 prints the total DFT gradient in the output, I added a print 2 option, which produces the following block in the output (water molecule, input file at the bottom). Does the -New Matrix gradient corresponds to the D3BJ contribution?

   -Nuclear Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1        0.000000000000    -6.336322099982     0.000000000000
        2       -3.448189570284     3.168161049991     0.000000000000
        3        3.448189570284     3.168161049991     0.000000000000
 
 
   -Core Hamiltonian Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1        0.000000160115    12.737735589129     0.000000000001
        2        4.092406412677    -6.368867633716     0.000000000002
        3       -4.092406572792    -6.368867955413    -0.000000000003
 
 
   -Overlap Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1       -0.000000011174    -0.295078004165    -0.000000000000
        2        0.153305204487     0.147538988769    -0.000000000000
        3       -0.153305193312     0.147539015396     0.000000000000
 
 
   -Coulomb Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1       -0.000000168165    -7.904292166484    -0.000000000001
        2       -1.494681166562     3.952145917090    -0.000000000002
        3        1.494681334728     3.952146249393     0.000000000003
 
 
   -Exchange Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1        0.000000003308     0.159890000972     0.000000000000
        2        0.026222382135    -0.079944997243     0.000000000000
        3       -0.026222385443    -0.079945003729    -0.000000000000
 
 
   -Exchange,LR Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1        0.000000009225     0.173102081587     0.000000000000
        2       -0.012825039710    -0.086551030917     0.000000000000
        3        0.012825030484    -0.086551050670    -0.000000000000
 
 
   -XC Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1        0.000000007258     0.596457152410     0.000000000000
        2        0.147060333410    -0.298231449131     0.000000000000
        3       -0.147060340668    -0.298231460464    -0.000000000000
 
 
   -New Matrix:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1        0.000000000000     0.000000347250     0.000000000000
        2       -0.000019266865    -0.000000173625     0.000000000000
        3        0.000019266865    -0.000000173625     0.000000000000
 
 
   -Total Gradient:
      Atom            X                  Y                   Z
     ------   -----------------  -----------------  -----------------
        1        0.000000000567    -0.868507099283     0.000000000000
        2       -0.536720710712     0.434250671219    -0.000000000000
        3        0.536720710146     0.434250670879     0.000000000000

Psi4 version: 1.8 (from conda)

Psi4 input:

 molecule lig {
 0 1
 O   0.0  0.5  0.0
 H   0.5  0.0  0.0
 H  -0.5  0.0  0.0
 
 no_reorient
 symmetry c1
 }
 
 set basis aug-cc-pvtz
 set print 2
 
 grad, wfn = gradient('wb97m-d3bj', return_wfn=True)

That’s correct. I’ll open a PR to fix the printing.

You can also grab the dispersion correction contribution with the “-D Gradient” variable:

disp_grad = wfn.variable("-D Gradient")

Thanks for the quick reply! Indeed, the -D Gradient prints the same value as in the output.
I tried to also print -Total Gradient or -XC Gradient (since they are called that way in the Psi4 output produced with print 2) but no success - I get the following error:

KeyError: “psi4.core.Wavefunction.variable: Requested variable ‘-XC Gradient’ was not set!”

However, I get the corrent total gradient by using CURRENT GRADIENT key for wfn. Does it mean that separate contributions of the DFT gradient are not available via the wfn object? Just curios.

That’s correct, the other individual gradient contributions are not currently accessible through the wfn object.

Just a small remark:
I did some additional tests and turns out that the dispersion gradient is stored multiple times under different names in Psi4 Wavefunction object. Here is a sample code to demonstrate:

molecule lig {
0 1
O   0.0  0.5  0.0
H   0.5  0.0  0.0
H  -0.5  0.0  0.0
 
no_reorient
symmetry c1
}
 
set basis 6-31G
 
# Test gradients
grad, wfn = gradient('wb97m-d3bj', return_wfn=True)

disp_grad_1 = wfn.variable("-D Gradient").to_array()
disp_grad_2 = wfn.variable("WB97M-D3BJ DISPERSION CORRECTION GRADIENT").to_array()
disp_grad_3 = wfn.variable("DISPERSION CORRECTION GRADIENT").to_array()
disp_grad_4 = wfn.variable("2-BODY DISPERSION CORRECTION GRADIENT").to_array()
 
import numpy as np
assert np.allclose(disp_grad_1, disp_grad_2)
assert np.allclose(disp_grad_1, disp_grad_3)
assert np.allclose(disp_grad_1, disp_grad_4)