Gradient() returns none but it should return a matrix object


#1

Hi. Again I’m new with these stuff so pleas help.
I need to obtain the gradient of a wavefuntion so I was trying to use de method gradient() that according with documentation should return a psi4.core.matrix object but insted it is returning me a none. Can somebody tell me what is wrong?
import psi4
import numpy as np

psi4.set_options({‘basis’: ‘cc-pvdz’,
‘e_convergence’: 1e-8})
molecule= psi4.geometry("""
0 1
O
H 1 1.0
H 1 1.0 2 104.5"""
)
wfn= psi4.core.Wavefunction.build(molecule, psi4.core.get_global_option(“basis”))
A=wfn.gradient()
print(type(A))


#2

The documentation could be clearer on this point, but the problem is straightforward.

There is no such thing as the gradient. There is only the gradient that you computed under such-and-such conditions.wfn.gradient() returns the last computed gradient, and in your case, there is none, so the function returns None.

If you need to compute a gradient, it’s better not to construct a Wavefunction manually in the first place. But just to use the gradient function. You’ll need to pass in your molecule explicitly.


#3

Hi, thanks for your answer. But I still having problems. If first I use the function compute_gradient() I got this: Fatal Error: Analytic gradients are not available for this wavefunction.
What do you mean with “Pass in your molecule explicitly”?


#4

I suspect you misunderstood what I said. Post your new input file. This time, enclose the input file in triple backticks (`) so the formatting doesn’t get distorted.


#5

instead of your last three lines, do

G = psi4.gradient("HF/cc-pvdz")
print(type(G))

or

G, wfn = psi4.gradient("HF/cc-pvdz")
print(type(wfn.gradient()))

returned gradient and gradient from the wfn will be the same. Note the extra input of the method/basis, so it knows what calc to do the gradient for.