Geometry Optimisation with arbitrary wavefunction

This is something I’ve needed for my own research! I’m going to warn you that this part of the interface is going to be changing soon as part of a larger change to the driver logic and the optimizer.

Here’s what you can do for now:
Call psi4.optimize(your-function-here, dertype=1, molecule=your-molecule-here). The signature Psi expects of your function is shown here. gradient is Psi’s own gradient method, which is passed as the first argument for historical reasons. Your function must return a Psi4 Matrix object as the first argument and a second argument. Although Psi expects this to be a wavefunction, nothing bad will happen if you have something else as your second argument, as long as you don’t pass return_wfn=True to your psi4.optimize call.

In your case, your gradient function will probably be a regular Psi4 gradient call, a call to your dispersion function, and then returning the sum of the two.