def dft_set_reference_local(name): """ Figures out the correct DFT reference to set locally """ optstash = p4util.OptionsState(['SCF', 'DFT_FUNCTIONAL'], ['SCF', 'REFERENCE'], ['SCF', 'SCF_TYPE'], ['DF_BASIS_MP2'], ['DFMP2', 'MP2_OS_SCALE'], ['DFMP2', 'MP2_SS_SCALE']) # Alter default algorithm if not psi4.has_option_changed('SCF', 'SCF_TYPE'): psi4.set_local_option('SCF', 'SCF_TYPE', 'DF') psi4.set_local_option('SCF', 'DFT_FUNCTIONAL', name) user_ref = psi4.get_option('SCF', 'REFERENCE') if (user_ref == 'RHF'): psi4.set_local_option('SCF', 'REFERENCE', 'RKS') elif (user_ref == 'UHF'): psi4.set_local_option('SCF', 'REFERENCE', 'UKS') elif (user_ref == 'ROHF'): raise ValidationError('ROHF reference for DFT is not available.') elif (user_ref == 'CUHF'): raise ValidationError('CUHF reference for DFT is not available.') return optstash
def dft_set_reference_local(name): """ Figures out the correct DFT reference to set locally """ optstash = p4util.OptionsState( ['SCF', 'DFT_FUNCTIONAL'], ['SCF', 'REFERENCE'], ['SCF', 'SCF_TYPE'], ['DF_BASIS_MP2'], ['DFMP2', 'MP2_OS_SCALE'], ['DFMP2', 'MP2_SS_SCALE']) # Alter default algorithm if not psi4.has_option_changed('SCF', 'SCF_TYPE'): psi4.set_local_option('SCF', 'SCF_TYPE', 'DF') psi4.set_local_option('SCF', 'DFT_FUNCTIONAL', name) user_ref = psi4.get_option('SCF', 'REFERENCE') if (user_ref == 'RHF'): psi4.set_local_option('SCF', 'REFERENCE', 'RKS') elif (user_ref == 'UHF'): psi4.set_local_option('SCF', 'REFERENCE', 'UKS') elif (user_ref == 'ROHF'): raise ValidationError('ROHF reference for DFT is not available.') elif (user_ref == 'CUHF'): raise ValidationError('CUHF reference for DFT is not available.') return optstash
def scf_set_reference_local(name): """ Figures out the correct SCF reference to set locally """ optstash = p4util.OptionsState(['SCF', 'DFT_FUNCTIONAL'], ['SCF', 'SCF_TYPE'], ['SCF', 'REFERENCE']) # Alter default algorithm if not psi4.has_option_changed('SCF', 'SCF_TYPE'): psi4.set_local_option('SCF', 'SCF_TYPE', 'DF') if name == 'hf': if psi4.get_option('SCF', 'REFERENCE') == 'RKS': psi4.set_local_option('SCF', 'REFERENCE', 'RHF') elif psi4.get_option('SCF', 'REFERENCE') == 'UKS': psi4.set_local_option('SCF', 'REFERENCE', 'UHF') elif name == 'scf': if psi4.get_option('SCF', 'REFERENCE') == 'RKS': if (len(psi4.get_option( 'SCF', 'DFT_FUNCTIONAL')) > 0) or psi4.get_option( 'SCF', 'DFT_CUSTOM_FUNCTIONAL') is not None: pass else: psi4.set_local_option('SCF', 'REFERENCE', 'RHF') elif psi4.get_option('SCF', 'REFERENCE') == 'UKS': if (len(psi4.get_option( 'SCF', 'DFT_FUNCTIONAL')) > 0) or psi4.get_option( 'SCF', 'DFT_CUSTOM_FUNCTIONAL') is not None: pass else: psi4.set_local_option('SCF', 'REFERENCE', 'UHF') return optstash
def scf_set_reference_local(name): """ Figures out the correct SCF reference to set locally """ optstash = p4util.OptionsState( ['SCF', 'DFT_FUNCTIONAL'], ['SCF', 'SCF_TYPE'], ['SCF', 'REFERENCE']) # Alter default algorithm if not psi4.has_option_changed('SCF', 'SCF_TYPE'): psi4.set_local_option('SCF', 'SCF_TYPE', 'DF') if name == 'hf': if psi4.get_option('SCF','REFERENCE') == 'RKS': psi4.set_local_option('SCF','REFERENCE','RHF') elif psi4.get_option('SCF','REFERENCE') == 'UKS': psi4.set_local_option('SCF','REFERENCE','UHF') elif name == 'scf': if psi4.get_option('SCF','REFERENCE') == 'RKS': if (len(psi4.get_option('SCF', 'DFT_FUNCTIONAL')) > 0) or psi4.get_option('SCF', 'DFT_CUSTOM_FUNCTIONAL') is not None: pass else: psi4.set_local_option('SCF','REFERENCE','RHF') elif psi4.get_option('SCF','REFERENCE') == 'UKS': if (len(psi4.get_option('SCF', 'DFT_FUNCTIONAL')) > 0) or psi4.get_option('SCF', 'DFT_CUSTOM_FUNCTIONAL') is not None: pass else: psi4.set_local_option('SCF','REFERENCE','UHF') return optstash
def run_gpu_dfcc(name, **kwargs): """Function encoding sequence of PSI module calls for a GPU-accelerated DF-CCSD(T) computation. >>> energy('df-ccsd(t)') """ lowername = name.lower() kwargs = kwargs_lower(kwargs) # stash user options optstash = OptionsState( ['GPU_DFCC','COMPUTE_TRIPLES'], ['GPU_DFCC','DFCC'], ['GPU_DFCC','NAT_ORBS'], ['SCF','DF_INTS_IO'], ['SCF','SCF_TYPE']) psi4.set_local_option('SCF','DF_INTS_IO', 'SAVE') psi4.set_local_option('GPU_DFCC','DFCC', True) # throw an exception for open-shells if (psi4.get_option('SCF','REFERENCE') != 'RHF' ): raise ValidationError("Error: %s requires \"reference rhf\"." % lowername) # override symmetry: molecule = psi4.get_active_molecule() molecule.update_geometry() molecule.reset_point_group('c1') molecule.fix_orientation(1) molecule.update_geometry() # triples? if (lowername == 'gpu-df-ccsd'): psi4.set_local_option('GPU_DFCC','COMPUTE_TRIPLES', False) if (lowername == 'gpu-df-ccsd(t)'): psi4.set_local_option('GPU_DFCC','COMPUTE_TRIPLES', True) #if (lowername == 'fno-df-ccsd'): # psi4.set_local_option('GPU_DFCC','COMPUTE_TRIPLES', False) # psi4.set_local_option('GPU_DFCC','NAT_ORBS', True) #if (lowername == 'fno-df-ccsd(t)'): # psi4.set_local_option('GPU_DFCC','COMPUTE_TRIPLES', True) # psi4.set_local_option('GPU_DFCC','NAT_ORBS', True) # set scf-type to df unless the user wants something else if psi4.has_option_changed('SCF','SCF_TYPE') == False: psi4.set_local_option('SCF','SCF_TYPE', 'DF') if psi4.get_option('GPU_DFCC','DF_BASIS_CC') == '': basis = psi4.get_global_option('BASIS') dfbasis = corresponding_rifit(basis) psi4.set_local_option('GPU_DFCC','DF_BASIS_CC',dfbasis) scf_helper(name,**kwargs) psi4.plugin('gpu_dfcc.so') # restore options optstash.restore() return psi4.get_variable("CURRENT ENERGY")
def dft_set_reference_local(name): """ Figures out the correct DFT reference to set locally """ optstash = p4util.OptionsState( ["SCF", "DFT_FUNCTIONAL"], ["SCF", "REFERENCE"], ["SCF", "SCF_TYPE"], ["DF_BASIS_MP2"], ["DFMP2", "MP2_OS_SCALE"], ["DFMP2", "MP2_SS_SCALE"], ) # Alter default algorithm if not psi4.has_option_changed("SCF", "SCF_TYPE"): psi4.set_local_option("SCF", "SCF_TYPE", "DF") psi4.set_local_option("SCF", "DFT_FUNCTIONAL", name) user_ref = psi4.get_option("SCF", "REFERENCE") if user_ref == "RHF": psi4.set_local_option("SCF", "REFERENCE", "RKS") elif user_ref == "UHF": psi4.set_local_option("SCF", "REFERENCE", "UKS") elif user_ref == "ROHF": raise ValidationError("ROHF reference for DFT is not available.") elif user_ref == "CUHF": raise ValidationError("CUHF reference for DFT is not available.") return optstash
def scf_set_reference_local(name): """ Figures out the correct SCF reference to set locally """ optstash = p4util.OptionsState(["SCF", "DFT_FUNCTIONAL"], ["SCF", "SCF_TYPE"], ["SCF", "REFERENCE"]) # Alter default algorithm if not psi4.has_option_changed("SCF", "SCF_TYPE"): psi4.set_local_option("SCF", "SCF_TYPE", "DF") if name == "hf": if psi4.get_option("SCF", "REFERENCE") == "RKS": psi4.set_local_option("SCF", "REFERENCE", "RHF") elif psi4.get_option("SCF", "REFERENCE") == "UKS": psi4.set_local_option("SCF", "REFERENCE", "UHF") elif name == "scf": if psi4.get_option("SCF", "REFERENCE") == "RKS": if (len(psi4.get_option("SCF", "DFT_FUNCTIONAL")) > 0) or psi4.get_option( "SCF", "DFT_CUSTOM_FUNCTIONAL" ) is not None: pass else: psi4.set_local_option("SCF", "REFERENCE", "RHF") elif psi4.get_option("SCF", "REFERENCE") == "UKS": if (len(psi4.get_option("SCF", "DFT_FUNCTIONAL")) > 0) or psi4.get_option( "SCF", "DFT_CUSTOM_FUNCTIONAL" ) is not None: pass else: psi4.set_local_option("SCF", "REFERENCE", "UHF") return optstash
def fitScf(self): """Function to run scf and fit a system of diffuse charges to resulting density. """ basisChanged = psi4.has_option_changed("BASIS") ribasisChanged = psi4.has_option_changed("DF_BASIS_SCF") scftypeChanged = psi4.has_option_changed("SCF_TYPE") basis = psi4.get_option("BASIS") ribasis = psi4.get_option("DF_BASIS_SCF") scftype = psi4.get_option("SCF_TYPE") psi4.print_out(" => Diffuse SCF (Determines Da) <=\n\n") activate(self.molecule) psi4.set_global_option("BASIS", self.basisname) psi4.set_global_option("DF_BASIS_SCF", self.ribasisname) psi4.set_global_option("SCF_TYPE", "DF") energy('scf') psi4.print_out("\n") self.fitGeneral() psi4.clean() psi4.set_global_option("BASIS", basis) psi4.set_global_option("DF_BASIS_SCF", ribasis) psi4.set_global_option("SCF_TYPE", scftype) if not basisChanged: psi4.revoke_option_changed("BASIS") if not ribasisChanged: psi4.revoke_option_changed("DF_BASIS_SCF") if not scftypeChanged: psi4.revoke_option_changed("SCF_TYPE")
def __init__(self, option, module=None): self.option = option.upper() if module: self.module = module.upper() else: self.module = None self.value_global = psi4.get_global_option(option) self.haschanged_global = psi4.has_global_option_changed(option) if self.module: self.value_local = psi4.get_local_option(self.module, option) self.haschanged_local = psi4.has_local_option_changed(self.module, option) self.value_used = psi4.get_option(self.module, option) self.haschanged_used = psi4.has_option_changed(self.module, option) else: self.value_local = None self.haschanged_local = None self.value_used = None self.haschanged_used = None
def _set_convergence_criterion(ptype, method_name, scf_Ec, pscf_Ec, scf_Dc, pscf_Dc, gen_Ec, verbose=1): r""" This function will set local SCF and global energy convergence criterion to the defaults listed at: http://www.psicode.org/psi4manual/master/scf.html#convergence-and- algorithm-defaults. SCF will be converged more tightly if a post-SCF method is select (pscf_Ec, and pscf_Dc) else the looser (scf_Ec, and scf_Dc convergence criterion will be used). ptype - Procedure type (energy, gradient, etc). Nearly always test on procedures['energy'] since that's guaranteed to exist for a method. method_name - Name of the method scf_Ec - E convergence criterion for scf target method pscf_Ec - E convergence criterion for scf of post-scf target method scf_Dc - D convergence criterion for scf target method pscf_Dc - D convergence criterion for scf of post-scf target method gen_Ec - E convergence criterion for post-scf target method """ optstash = p4util.OptionsState( ['SCF', 'E_CONVERGENCE'], ['SCF', 'D_CONVERGENCE'], ['E_CONVERGENCE']) # Kind of want to move this out of here _method_exists(ptype, method_name) if verbose >= 2: print(' Setting convergence', end=' ') # Set method-dependent scf convergence criteria, check against energy routines if not psi4.has_option_changed('SCF', 'E_CONVERGENCE'): if procedures['energy'][method_name] in [proc.run_scf, proc.run_dft]: psi4.set_local_option('SCF', 'E_CONVERGENCE', scf_Ec) if verbose >= 2: print(scf_Ec, end=' ') else: psi4.set_local_option('SCF', 'E_CONVERGENCE', pscf_Ec) if verbose >= 2: print(pscf_Ec, end=' ') else: if verbose >= 2: print('CUSTOM', psi4.get_option('SCF', 'E_CONVERGENCE'), end=' ') if not psi4.has_option_changed('SCF', 'D_CONVERGENCE'): if procedures['energy'][method_name] in [proc.run_scf, proc.run_dft]: psi4.set_local_option('SCF', 'D_CONVERGENCE', scf_Dc) if verbose >= 2: print(scf_Dc, end=' ') else: psi4.set_local_option('SCF', 'D_CONVERGENCE', pscf_Dc) if verbose >= 2: print(pscf_Dc, end=' ') else: if verbose >= 2: print('CUSTOM', psi4.get_option('SCF', 'D_CONVERGENCE'), end=' ') # Set post-scf convergence criteria (global will cover all correlated modules) if not psi4.has_global_option_changed('E_CONVERGENCE'): if procedures['energy'][method_name] not in [proc.run_scf, proc.run_dft]: psi4.set_global_option('E_CONVERGENCE', gen_Ec) if verbose >= 2: print(gen_Ec, end=' ') else: if procedures['energy'][method_name] not in [proc.run_scf, proc.run_dft]: if verbose >= 2: print('CUSTOM', psi4.get_global_option('E_CONVERGENCE'), end=' ') if verbose >= 2: print('') return optstash