Optimizing a P4 molecule causes error "local variable 'errors'..."

Hello,

I’m currently attempting to geometry optimize a P4 molecule using the following input file using Psi4 1.9 release:

memory 10000 mb

molecule {
0 1
P 1.105170325692 -0.000000093915 0.781479445672
P -1.105170127906 -0.000000111490 0.781479165960
P -0.000000090105 1.105170299335 -0.781479451060
P -0.000000107680 -1.105170093930 -0.781479160571
symmetry c1
}

set {
reference               rhf
basis                   def2-qzvppd
dft_radial_points       99
dft_spherical_points    590
geom_maxiter            100
fail_on_maxiter        false
}

optimize('pbe0')

I get an error as shown below. For reference, I’m running a similar geometry optimization on ~160 other molecules and this was the only one with the issue. The geometry I’m using is a reference geometry from a W4 database.

Traceback (most recent call last):
  File "/topdir/psi4-install/bin/psi4", line 387, in <module>
    exec(content)
  File "<string>", line 30, in <module>
  File "/topdir/psi4-install/lib/psi4/driver/driver.py", line 1212, in optimize
    opt_object = optking.opt_helper.CustomHelper(molecule, params=optimizer_params)
  File "/path/to/environment/lib/python3.10/site-packages/optking/opt_helper.py", line 400, in __init__
    self.build_coordinates()
  File "/path/to/environment/lib/python3.10/site-packages/optking/opt_helper.py", line 147, in build_coordinates
    make_internal_coords(self.molsys, self.params)
  File "/path/to/environment/lib/python3.10/site-packages/optking/optimize.py", line 664, in make_internal_coords
    o_molsys.fragments[0].add_intcos_from_connectivity(connectivity)
  File "/path/to/environment/lib/python3.10/site-packages/optking/frag.py", line 146, in add_intcos_from_connectivity
    addIntcos.add_intcos_from_connectivity(connectivity, self._intcos, self._geom)
  File "/path/to/environment/lib/python3.10/site-packages/optking/addIntcos.py", line 136, in add_intcos_from_connectivity
    add_oofp_from_connectivity(C, intcos, geom)
  File "/path/to/environment/lib/python3.10/site-packages/optking/addIntcos.py", line 409, in add_oofp_from_connectivity
    if errors:

UnboundLocalError: local variable 'errors' referenced before assignment


Printing out the relevant lines from the Psithon --> Python processed input file:
    core.set_global_option("BASIS", "def2-qzvppd")
    core.set_global_option("DFT_RADIAL_POINTS", 99)
    core.set_global_option("DFT_SPHERICAL_POINTS", 590)
    core.set_global_option("GEOM_MAXITER", 100)
    core.set_global_option("FAIL_ON_MAXITER", "false")
--> optimize('pbe0')

!-------------------------------------------------------!
!                                                       !
!  local variable 'errors' referenced before assignment !
!                                                       !
!-------------------------------------------------------!

I’d appreciate any help with this!

Hi! This is an interesting case where the optimizer detects a situation where an out of plane angle might be needed, but then decides not to add any out of plane angles.

I have a fix that should get merged in the near future. For a temporary solution to get your setup working, if you’re willing and have permission to modify the source code simply adding errors = [] at line 375 of /path/to/environment/lib/python3.10/site-packages/optking/addIntcos.py
like so:

     4  def·add_oofp_from_connectivity(C,·intcos,·geom):⏎
     3  ····#·Look·for:··(terminal·atom)-connected·to-(tertiary·atom)⏎
     2  ····Nneighbors·=·[sum(C[i])·for·i·in·range(len(C))]⏎
     1  ····terminal_atoms·=·[i·for·i·in·range(len(Nneighbors))·if·Nneighbors[i]·==·1]⏎
   375  ····errors·=·[]⏎
     1  ⏎
     2  ····#·Find·adjacent·atoms⏎
     3  ····vertex_atoms·=·[]⏎
     4  ····for·T·in·terminal_atoms:⏎
     5  ········vertex_atoms.append(np.where(C[T])[0][0])⏎

should work. The system should optimize in a handful of steps with no out of plane angles needed.

Hope that helps. Let me know if you have any further questions!