Skip to content

Commit

Permalink
Prevent using guesses with QCSCF, as it is unsupported and can cause …
Browse files Browse the repository at this point in the history
…errors in cases of frozen-core gradients.
  • Loading branch information
greghjones committed Mar 3, 2024
1 parent ca4192b commit e4547b0
Showing 1 changed file with 46 additions and 21 deletions.
67 changes: 46 additions & 21 deletions pysisyphus/calculators/CFOUR.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def __init__(
Whether or not to keep ground state SCF orbitals for each geometry step.
initden_file: str, optional
Path to an input initden file for use as a guess SCF density.
oldmos_files: str, optional
Path to guess orbitals.
"""
super().__init__(**kwargs)

Expand All @@ -131,16 +133,36 @@ def __init__(
self.inp_fn = "ZMAT"
self.out_fn = "out.log"
self.gradient_fn = "GRD"
self.to_keep = ("out.log", "density:__den.dat", "mos:NEWMOS")

self.initden = None
self.mos = None
self.qcscf = False
self.wavefunction_dump = wavefunction_dump

if "qcscf" in [x.lower() for x in cfour_input.values()]:
self.qcscf = True

if self.wavefunction_dump:
self.to_keep = self.to_keep + ("MOLDEN*",)
self.to_keep = ("out.log", "density:__den.dat", "mos:NEWMOS", "MOLDEN*")
else:
if not self.qcscf:
self.to_keep = ("out.log", "density:__den.dat", "mos:NEWMOS")
else:
self.to_keep = ("out.log",)

if initden_file:
assert self.qcscf == False, (
"QCSCF does not support guess densities "
"or orbitals, and presence of a GUESS "
"file can cause unexpected behavior."
)
self.initden = initden_file
if oldmos_file:
assert self.qcscf == False, (
"QCSCF does not support guess densities "
"or orbitals, and presence of a GUESS "
"file can cause unexpected behavior."
)
self.mos = oldmos_file

self.base_cmd = self.get_cmd("cmd")
Expand All @@ -160,19 +182,21 @@ def __init__(

def prepare(self, inp):
path = super().prepare(inp)
if self.initden:
shutil.copy(self.initden, f"{path}/initden.dat")
if self.mos:
shutil.copy(self.mos, f"{path}/GUESS")
if not self.qcscf:
if self.initden:
shutil.copy(self.initden, f"{path}/initden.dat")
if self.mos:
shutil.copy(self.mos, f"{path}/GUESS")
return path

def keep(self, path):
kept_fns = super().keep(path)
try:
self.initden = kept_fns["density"]
self.mos = kept_fns["mos"]
except KeyError:
self.log("den.dat not found!")
if self.wavefunction_dump or not self.qcscf:
try:
self.initden = kept_fns["density"]
self.mos = kept_fns["mos"]
except KeyError:
self.log("NEWMOS or den.dat not found!")

def prepare_input(self, atoms, coords, calc_type):
xyz_string = self.prepare_coords(atoms, coords)
Expand Down Expand Up @@ -254,23 +278,24 @@ def run_calculation(self, atoms, coords, calc_type, **prepare_kwargs):
return results

def get_chkfiles(self):
self.log("Called get_chkfiles")
return {
"initden": self.initden,
"mos": self.mos,
}


def set_chkfiles(self, chkfiles):
self.log("Called set_chkfiles")
try:
initden = chkfiles["initden"]
mos = chkfiles["mos"]
self.initden = initden
self.mos = mos
self.log(f"Set chkfile '{initden}' as initden and {mos} as OLDMOS.")
except KeyError:
self.log("Missing either initden or OLDMOS in chkfiles")
if not self.qcscf:
try:
initden = chkfiles["initden"]
mos = chkfiles["mos"]
self.initden = initden
self.mos = mos
self.log(f"Set chkfile '{initden}' as initden and {mos} as OLDMOS.")
except KeyError:
self.log("Missing either initden or OLDMOS in chkfiles")
else:
self.log("Cannot set chkfiles on calculation using QCSCF.")


def __str__(self):
Expand Down

0 comments on commit e4547b0

Please sign in to comment.