Continuing after failed geometry optimization

Hi,
I am trying to continue with further calculations even if a geometry optimization fails.

Below is my input file. It does work in that it runs both geometry optimizations But I would like it to read the coordinates from the first optimization as a starting point for the second.
How do I make psi4 read the coordinates from file 1 ?

Thanks,
Alberto

memory 500 mb
molecule h2o {
 0 1
    O
    H 1 1.0
    H 1 1.0 2 104.5
}
set {
    basis sto-3g
    GEOM_MAXITER 2 }

core.IOManager.shared_object().set_specific_retention(1, True)
core.IOManager.shared_object().set_specific_path(1, './')

try:
   ############################ first
   optE, optWfn = optimize('hf', return_wfn=True)
   print("after %s" % ("start"))
except ConvergenceError as cError:
   print("Convergence error caught: {0}".format(cError))

############################# second
optE, optWfn = optimize('hf', return_wfn=True)

This is now possible thanks to a fix implemented by Lori. here is an example.

Thanks Lori!
Alberto


try:
    optE, optWfn = optimize(optMethod, return_wfn=True)
except OptimizationConvergenceError as e:
    optWfn = e.wfn
    optE = optWfn.energy()
    clean()
    print("Geom Optimization did not converge, we are still continuing with last geometry")


set basis finalBas
#set scf guess read
finalE = energy(finalMethod, molecule=optWfn.molecule())

Hey, sorry to bump an old topic, but I figure it’s best to keep the discussion in one place.

I’m attempting a geometry optimization and single point energy calculation. I want to handle optimization failures through exceptions to proceed with further computations. However, I’m unclear about certain aspects of Psithon syntax and the behavior of Psi4 during these exceptions. Here are my specific questions:

  1. Geometry Handling After Failed Optimization: What happens to the molecule’s geometry if optimize fails? I understand that subsequent calls to energy will use the geometry from optimize. But what if optimize fails? Do I need to explicitly set the geometry for further calculations?
  2. Catching Exceptions from optimize: How should I handle the different exceptions thrown by optimize? Here are some exceptions I’ve encountered:
  • Maximum geometry optimization steps exceeded: PsiException
  • Maximum dynamic level reached: optking.exceptions.OptError
  • ADIIS minimization error: Exception: ADIIS minimization failed
  • SCF convergence failure: psi4.driver.p4util.exceptions.SCFConvergenceError

This is my current setup in the .in file, which catches the maximum step exceptions but not others. Should I switch to a general except to cover all bases?

# Geometry optimization in vacuo
try:
    psi4.optimize('B97M-D3BJ')
except psi4.PsiException as e:
    print("Warning: Optimization did not converge", e)

# Single point energy calculation
set basis def2-TZVPD
energy('WB97M-D3BJ')
  1. Two-Stage Optimization Approach: I’m considering implementing a two-stage optimization where each stage has its own try-except block. The first stage would use aggressive settings, and if it fails, a second, more conservative optimization would be attempted. How should I structure the exceptions to determine when to abort completely versus when to try the second optimization?

I would greatly appreciate any insights or examples of handling such scenarios in Psi4. Thank you!