From e4547b0339dc1cc89ecec1769d3e9dcabb177760 Mon Sep 17 00:00:00 2001 From: Greg Jones Date: Sun, 3 Mar 2024 16:22:29 -0500 Subject: [PATCH] Prevent using guesses with QCSCF, as it is unsupported and can cause errors in cases of frozen-core gradients. --- pysisyphus/calculators/CFOUR.py | 67 ++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/pysisyphus/calculators/CFOUR.py b/pysisyphus/calculators/CFOUR.py index 4e27cb4cd..508aabcb6 100644 --- a/pysisyphus/calculators/CFOUR.py +++ b/pysisyphus/calculators/CFOUR.py @@ -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) @@ -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") @@ -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) @@ -254,7 +278,6 @@ 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, @@ -262,15 +285,17 @@ def get_chkfiles(self): 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):