def compute_energy(self, molecule: 'psi4.core.Molecule', wfn: 'psi4.core.Wavefunction' = None) -> float: """Compute dispersion energy based on engine, dispersion level, and parameters in `self`. Parameters ---------- molecule : psi4.core.Molecule System for which to compute empirical dispersion correction. wfn : Location to set QCVariables Returns ------- float Dispersion energy [Eh]. Notes ----- DISPERSION CORRECTION ENERGY Disp always set. Overridden in SCF finalization, but that only changes for "-3C" methods. self.fctldash + DISPERSION CORRECTION ENERGY Set if `fctldash` nonempty. """ if self.engine in ['dftd3', 'mp2d']: resi = ResultInput( **{ 'driver': 'energy', 'model': { 'method': self.fctldash, 'basis': '(auto)', }, 'keywords': { 'level_hint': self.dashlevel, 'params_tweaks': self.dashparams, 'dashcoeff_supplement': self.dashcoeff_supplement, 'verbose': 1, }, 'molecule': molecule.to_schema(dtype=2), 'provenance': p4util.provenance_stamp(__name__), }) jobrec = qcng.compute(resi, self.engine, raise_error=True) dashd_part = float(jobrec.extras['qcvars']['DISPERSION CORRECTION ENERGY']) if wfn is not None: for k, qca in jobrec.extras['qcvars'].items(): if 'CURRENT' not in k: wfn.set_variable(k, p4util.plump_qcvar(qca, k)) if self.fctldash in ['hf3c', 'pbeh3c']: gcp_part = gcp.run_gcp(molecule, self.fctldash, verbose=False, dertype=0) dashd_part += gcp_part return dashd_part else: ene = self.disp.compute_energy(molecule) core.set_variable('DISPERSION CORRECTION ENERGY', ene) if self.fctldash: core.set_variable('{} DISPERSION CORRECTION ENERGY'.format(self.fctldash), ene) return ene
def compute_gradient(self, molecule: core.Molecule, wfn: core.Wavefunction = None) -> core.Matrix: """Compute dispersion gradient based on engine, dispersion level, and parameters in `self`. Parameters ---------- molecule System for which to compute empirical dispersion correction. wfn Location to set QCVariables Returns ------- Matrix (nat, 3) dispersion gradient [Eh/a0]. """ if self.engine in ['dftd3', 'mp2d']: resi = AtomicInput( **{ 'driver': 'gradient', 'model': { 'method': self.fctldash, 'basis': '(auto)', }, 'keywords': { 'level_hint': self.dashlevel, 'params_tweaks': self.dashparams, 'dashcoeff_supplement': self.dashcoeff_supplement, 'verbose': 1, }, 'molecule': molecule.to_schema(dtype=2), 'provenance': p4util.provenance_stamp(__name__), }) jobrec = qcng.compute( resi, self.engine, raise_error=True, local_options={"scratch_directory": core.IOManager.shared_object().get_default_path()}) dashd_part = core.Matrix.from_array(jobrec.extras['qcvars']['DISPERSION CORRECTION GRADIENT']) if wfn is not None: for k, qca in jobrec.extras['qcvars'].items(): if "CURRENT" not in k: wfn.set_variable(k, float(qca) if isinstance(qca, str) else qca) if self.fctldash in ['hf3c', 'pbeh3c']: jobrec = qcng.compute( resi, "gcp", raise_error=True, local_options={"scratch_directory": core.IOManager.shared_object().get_default_path()}) gcp_part = core.Matrix.from_array(jobrec.return_result) dashd_part.add(gcp_part) return dashd_part else: return self.disp.compute_gradient(molecule)
def compute_gradient(self, molecule: 'psi4.core.Molecule', wfn: 'psi4.core.Wavefunction' = None) -> 'psi4.core.Matrix': """Compute dispersion gradient based on engine, dispersion level, and parameters in `self`. Parameters ---------- molecule : psi4.core.Molecule System for which to compute empirical dispersion correction. wfn : Location to set QCVariables Returns ------- psi4.core.Matrix (nat, 3) dispersion gradient [Eh/a0]. """ if self.engine in ['dftd3', 'mp2d']: resi = ResultInput( **{ 'driver': 'gradient', 'model': { 'method': self.fctldash, 'basis': '(auto)', }, 'keywords': { 'level_hint': self.dashlevel, 'params_tweaks': self.dashparams, 'dashcoeff_supplement': self.dashcoeff_supplement, 'verbose': 1, }, 'molecule': molecule.to_schema(dtype=2), 'provenance': p4util.provenance_stamp(__name__), }) jobrec = qcng.compute(resi, self.engine, raise_error=True) dashd_part = core.Matrix.from_array( np.array(jobrec.extras['qcvars']['DISPERSION CORRECTION GRADIENT']).reshape(-1, 3)) if wfn is not None: for k, qca in jobrec.extras['qcvars'].items(): if 'CURRENT' not in k: wfn.set_variable(k, p4util.plump_qcvar(qca, k)) if self.fctldash in ['hf3c', 'pbeh3c']: gcp_part = gcp.run_gcp(molecule, self.fctldash, verbose=False, dertype=1) dashd_part.add(gcp_part) return dashd_part else: return self.disp.compute_gradient(molecule)
def compute_energy(self, molecule: 'psi4.core.Molecule', wfn: 'psi4.core.Wavefunction' = None) -> float: """Compute dispersion energy based on engine, dispersion level, and parameters in `self`. Parameters ---------- molecule : psi4.core.Molecule System for which to compute empirical dispersion correction. wfn : Location to set QCVariables Returns ------- float Dispersion energy [Eh]. Notes ----- DISPERSION CORRECTION ENERGY Disp always set. Overridden in SCF finalization, but that only changes for "-3C" methods. self.fctldash + DISPERSION CORRECTION ENERGY Set if `fctldash` nonempty. """ if self.engine in ['dftd3', 'mp2d']: resi = AtomicInput( **{ 'driver': 'energy', 'model': { 'method': self.fctldash, 'basis': '(auto)', }, 'keywords': { 'level_hint': self.dashlevel, 'params_tweaks': self.dashparams, 'dashcoeff_supplement': self.dashcoeff_supplement, 'save_pairwise_dispersion': self.save_pairwise_disp, 'verbose': 1, }, 'molecule': molecule.to_schema(dtype=2), 'provenance': p4util.provenance_stamp(__name__), }) jobrec = qcng.compute( resi, self.engine, raise_error=True, local_options={ "scratch_directory": core.IOManager.shared_object().get_default_path() }) dashd_part = float( jobrec.extras['qcvars']['DISPERSION CORRECTION ENERGY']) if wfn is not None: for k, qca in jobrec.extras['qcvars'].items(): # The pairwise dispersion analysis is already a nparray # Do we always want to save it? if ('CURRENT' not in k) and ('PAIRWISE' not in k): wfn.set_variable(k, p4util.plump_qcvar(qca, k)) # Pass along the pairwise dispersion decomposition if we need it if self.save_pairwise_disp is True: wfn.set_variable( "PAIRWISE DISPERSION CORRECTION ANALYSIS", jobrec.extras['qcvars'] ["PAIRWISE DISPERSION CORRECTION ANALYSIS"]) if self.fctldash in ['hf3c', 'pbeh3c']: gcp_part = gcp.run_gcp(molecule, self.fctldash, verbose=False, dertype=0) dashd_part += gcp_part return dashd_part else: ene = self.disp.compute_energy(molecule) core.set_variable('DISPERSION CORRECTION ENERGY', ene) if self.fctldash: core.set_variable( '{} DISPERSION CORRECTION ENERGY'.format(self.fctldash), ene) return ene
def compute_energy(self, molecule: core.Molecule, wfn: core.Wavefunction = None) -> float: """Compute dispersion energy based on engine, dispersion level, and parameters in `self`. Parameters ---------- molecule System for which to compute empirical dispersion correction. wfn Location to set QCVariables Returns ------- float Dispersion energy [Eh]. Notes ----- :psivar:`DISPERSION CORRECTION ENERGY` Disp always set. Overridden in SCF finalization, but that only changes for "-3C" methods. :psivar:`fctl DISPERSION CORRECTION ENERGY` Set if :py:attr:`fctldash` nonempty. """ if self.engine in ['dftd3', 'mp2d']: resi = AtomicInput( **{ 'driver': 'energy', 'model': { 'method': self.fctldash, 'basis': '(auto)', }, 'keywords': { 'level_hint': self.dashlevel, 'params_tweaks': self.dashparams, 'dashcoeff_supplement': self.dashcoeff_supplement, 'pair_resolved': self.save_pairwise_disp, 'verbose': 1, }, 'molecule': molecule.to_schema(dtype=2), 'provenance': p4util.provenance_stamp(__name__), }) jobrec = qcng.compute( resi, self.engine, raise_error=True, local_options={ "scratch_directory": core.IOManager.shared_object().get_default_path() }) dashd_part = float( jobrec.extras['qcvars']['DISPERSION CORRECTION ENERGY']) if wfn is not None: for k, qca in jobrec.extras['qcvars'].items(): wfn.set_variable( k, float(qca) if isinstance(qca, str) else qca) # Pass along the pairwise dispersion decomposition if we need it if self.save_pairwise_disp is True: wfn.set_variable( "PAIRWISE DISPERSION CORRECTION ANALYSIS", jobrec.extras['qcvars'] ["2-BODY PAIRWISE DISPERSION CORRECTION ANALYSIS"]) if self.fctldash in ['hf3c', 'pbeh3c']: jobrec = qcng.compute( resi, "gcp", raise_error=True, local_options={ "scratch_directory": core.IOManager.shared_object().get_default_path() }) gcp_part = jobrec.return_result dashd_part += gcp_part return dashd_part else: ene = self.disp.compute_energy(molecule) core.set_variable('DISPERSION CORRECTION ENERGY', ene) if self.fctldash: core.set_variable( f"{self.fctldash} DISPERSION CORRECTION ENERGY", ene) return ene