Browse files

Merge pull request #1130 from obrien951/SCF_exc_wfn

SCF: Add SCFConvergence Error
  • Loading branch information...
loriab committed Sep 6, 2018
2 parents 2f23252 + af5f59d commit f7c1a59bb6f579dea73bc50d228627dddcb2702e
Showing with 52 additions and 11 deletions.
  1. +33 −6 psi4/driver/p4util/
  2. +6 −5 psi4/driver/procrouting/scf_proc/
  3. +13 −0 tests/scf2/input.dat
@@ -78,22 +78,49 @@ def __init__(self, msg):
class ConvergenceError(PsiException):
"""Error called for problems with converging and iterative method. Prints
error message *msg* to standard output stream and output file.
"""Error called for problems with converging and iterative method.
eqn_description : str
Type of QC routine that has failed (e.g., SCF)
iteration : int
What iteration we failed on
def __init__(self, eqn_description, maxit):
msg = "Could not converge %s in %d iterations." % (eqn_description, maxit)
def __init__(self, eqn_description, iteration):
msg = "Could not converge %s in %d iterations." % (eqn_description, iteration)
PsiException.__init__(self, msg)
self.iteration = iteration
self.message = msg
core.print_out('\nPsiException: %s\n\n' % (msg))
class OptimizationConvergenceError(ConvergenceError):
"""Error called for problems with geometry optimizer."""
def __init__(self, eqn_description, maxit, wfn):
ConvergenceError.__init__(self, eqn_description, maxit)
def __init__(self, eqn_description, iteration, wfn):
ConvergenceError.__init__(self, eqn_description, iteration)
self.wfn = wfn
class SCFConvergenceError(ConvergenceError):
"""Error called for problems with SCF iterations.
wfn : psi4.core.Wavefunction
Wavefunction at time of exception
e_conv : float
Change in energy for last iteration
d_conv : float
RMS change in density for last iteration
def __init__(self, eqn_description, iteration, wfn, e_conv, d_conv):
ConvergenceError.__init__(self, eqn_description, iteration)
self.e_conv = e_conv
self.d_conv = d_conv
self.wfn = wfn
@@ -34,7 +34,7 @@
from psi4.driver import p4util
from psi4.driver import constants
from psi4.driver.p4util.exceptions import ConvergenceError, ValidationError
from psi4.driver.p4util.exceptions import SCFConvergenceError, ValidationError
from psi4 import core
from .efp import get_qm_atoms_opts, modify_Fock_permanent, modify_Fock_induced
@@ -71,8 +71,9 @@ def scf_compute_energy(self):
except ConvergenceError:
raise ConvergenceError("""SCF DF preiterations""", self.iteration_)
except SCFConvergenceError:
raise SCFConvergenceError("""SCF DF preiterations""", self.iteration_, self, 0, 0)
core.print_out("\n DF guess converged.\n\n")
# reset the DIIS & JK objects in prep for DIRECT
@@ -84,7 +85,7 @@ def scf_compute_energy(self):
except ConvergenceError as e:
except SCFConvergenceError as e:
if core.get_option("SCF", "FAIL_ON_MAXITER"):
core.print_out(" Failed to converge.\n")
# energy = 0.0
@@ -355,7 +356,7 @@ def scf_iterate(self, e_conv=None, d_conv=None):
if _converged(Ediff, Drms, e_conv=e_conv, d_conv=d_conv):
if self.iteration_ >= core.get_option('SCF', 'MAXITER'):
raise ConvergenceError("""SCF iterations""", self.iteration_)
raise SCFConvergenceError("""SCF iterations""", self.iteration_, self, Ediff, Drms)
def scf_finalize_energy(self):
@@ -13,8 +13,21 @@ set {
basis cc-pVTZ
scf_type df
e_convergence 10
maxiter 6
except psi4.SCFConvergenceError as ex:
SCF_iter_6 = ex.wfn.get_energies("Total Energy")
SCF_error_iter = ex.iteration
SCF_e_conv = ex.e_conv
SCF_d_conv = ex.d_conv
compare_values(-76.050986, SCF_iter_6, 5, "Energy at iter {}".format(SCF_error_iter))
set maxiter 24
thisenergy = energy('scf')
compare_values(nucenergy, h2o.nuclear_repulsion_energy(), 9, "Nuclear repulsion energy") #TEST

0 comments on commit f7c1a59

Please sign in to comment.