def run_plugin_mp2(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that mollerplesset2 can be called via :py:func:`~driver.energy`. >>> energy('mollerplesset2') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) # Your plugin's psi4 run sequence goes here psi4.set_local_option('MOLLERPLESSET2', 'PRINT', 1) scf_wfn = scf_helper(lowername) # Need to semicanonicalize the ROHF orbitals if psi4.get_global_option('REFERENCE') == 'ROHF': scf_wfn.semicanonicalize() # Ensure IWL files have been written when not using DF/CD proc_util.check_iwl_file_from_scf_type(psi4.get_option('SCF', 'SCF_TYPE'), scf_wfn) #psi4.set_legacy_wavefunction(scf_wfn) returnvalue = psi4.plugin('mollerplesset2.so', scf_wfn) return returnvalue
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_paralleldf(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that paralleldf can be called via :py:func:`~driver.energy`. For post-scf plugins. >>> energy('paralleldf') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) # Your plugin's psi4 run sequence goes here #psi4.set_global_option('BASIS', 'sto-3g') psi4.set_local_option('MYPLUGIN', 'PRINT', 1) # Compute a SCF reference, a wavefunction is return which holds the molecule used, orbitals # Fock matrices, and more ref_wfn = kwargs.get('ref_wfn', None) if ref_wfn is None: ref_wfn = driver.scf_helper(name, **kwargs) # Call the Psi4 plugin # Please note that setting the reference wavefunction in this way is ONLY for plugins paralleldf_wfn = psi4.plugin('paralleldf.so', ref_wfn) return paralleldf_wfn
def run_v2rdm_casscf(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that v2rdm_casscf can be called via :py:func:`~driver.energy`. For post-scf plugins. >>> energy('v2rdm_casscf') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) optstash = p4util.OptionsState( ['SCF', 'DF_INTS_IO']) psi4.set_local_option('SCF', 'DF_INTS_IO', 'SAVE') # Your plugin's psi4 run sequence goes here scf_wfn = scf_helper(name, **kwargs) # if restarting from a checkpoint file, this file # needs to be in scratch with the correct name filename = psi4.get_option("V2RDM_CASSCF","RESTART_FROM_CHECKPOINT_FILE") # todo PSIF_V2RDM_CHECKPOINT should be definied in psifiles.h if ( filename != "" ): molname = psi4.wavefunction().molecule().name() p4util.copy_file_to_scratch(filename,'psi',molname,269,False) returnvalue = psi4.plugin('v2rdm_casscf.so',scf_wfn) #psi4.set_variable('CURRENT ENERGY', returnvalue) return psi4.get_variable('CURRENT ENERGY')
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_v2rdm_casscf(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that v2rdm_casscf can be called via :py:func:`~driver.energy`. For post-scf plugins. >>> energy('v2rdm_casscf') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) optstash = p4util.OptionsState(['SCF', 'DF_INTS_IO']) psi4.set_local_option('SCF', 'DF_INTS_IO', 'SAVE') # Your plugin's psi4 run sequence goes here scf_wfn = scf_helper(name, **kwargs) # if restarting from a checkpoint file, this file # needs to be in scratch with the correct name filename = psi4.get_option("V2RDM_CASSCF", "RESTART_FROM_CHECKPOINT_FILE") # todo PSIF_V2RDM_CHECKPOINT should be definied in psifiles.h if (filename != ""): molname = psi4.wavefunction().molecule().name() p4util.copy_file_to_scratch(filename, 'psi', molname, 269, False) returnvalue = psi4.plugin('v2rdm_casscf.so', scf_wfn) #psi4.set_variable('CURRENT ENERGY', returnvalue) return psi4.get_variable('CURRENT ENERGY')
def restore(self): psi4.set_global_option(self.option, self.value_global) if not self.haschanged_global: psi4.revoke_global_option_changed(self.option) if self.module: psi4.set_local_option(self.module, self.option, self.value_local) if not self.haschanged_local: psi4.revoke_local_option_changed(self.module, self.option)
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 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 run_cis(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that cis can be called via :py:func:`~driver.energy`. For post-scf plugins. >>> energy('cis') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) # Your plugin's psi4 run sequence goes here psi4.set_local_option('CIS', 'PRINT', 1) scf_helper(name, **kwargs) returnvalue = psi4.plugin('cis.so') psi4.set_variable('CURRENT ENERGY', returnvalue)
def run_fasnocis(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that OCDFT can be called via :py:func:`~driver.energy`. >>> energy('fasnocis') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) # Run OCDFT psi4.set_local_option('CDFT','METHOD','FASNOCIS') returnvalue = psi4.plugin('cdft.so') return returnvalue
def run_dpd_unit_test(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that dpd_unit_test can be called via :py:func:`~driver.energy`. For post-scf plugins. >>> energy('dpd_unit_test') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) # Your plugin's psi4 run sequence goes here psi4.set_global_option('BASIS', 'sto-3g') psi4.set_local_option('DPD_UNIT_TEST', 'PRINT', 1) scf_helper(name, **kwargs) returnvalue = psi4.plugin('dpd_unit_test.so') psi4.set_variable('CURRENT ENERGY', returnvalue)
def run_plugin_mp2(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that mollerplesset2 can be called via :py:func:`~driver.energy`. >>> energy('mollerplesset2') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) # Your plugin's psi4 run sequence goes here psi4.set_local_option('MOLLERPLESSET2', 'PRINT', 1) psi4.scf() returnvalue = psi4.plugin('mollerplesset2.so') return returnvalue
def run_myplugin1(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that myplugin1 can be called via :py:func:`~driver.energy`. >>> energy('myplugin1') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) # Your plugin's psi4 run sequence goes here psi4.set_global_option('BASIS', 'sto-3g') psi4.set_local_option('MYPLUGIN1', 'PRINT', 1) energy('scf', **kwargs) returnvalue = psi4.plugin('myplugin1.so') return returnvalue
def run_v2rdm_casscf(name, **kwargs): r"""Function encoding sequence of PSI module and plugin calls so that v2rdm_casscf can be called via :py:func:`~driver.energy`. For post-scf plugins. >>> energy('v2rdm_casscf') """ lowername = name.lower() kwargs = p4util.kwargs_lower(kwargs) optstash = p4util.OptionsState( ['SCF', 'DF_INTS_IO']) psi4.set_local_option('SCF', 'DF_INTS_IO', 'SAVE') # Your plugin's psi4 run sequence goes here ref_wfn = kwargs.get('ref_wfn', None) if ref_wfn is None: ref_wfn = driver.scf_helper(name, **kwargs) # if restarting from a checkpoint file, this file # needs to be in scratch with the correct name filename = psi4.get_option("V2RDM_CASSCF","RESTART_FROM_CHECKPOINT_FILE") # todo PSIF_V2RDM_CHECKPOINT should be definied in psifiles.h if ( filename != "" ): molname = ref_wfn.molecule().name() p4util.copy_file_to_scratch(filename,'psi',molname,269,False) # Ensure IWL files have been written when not using DF/CD scf_type = psi4.get_option('SCF', 'SCF_TYPE') if ( scf_type == 'PK' or scf_type == 'DIRECT' ): proc_util.check_iwl_file_from_scf_type(psi4.get_option('SCF', 'SCF_TYPE'), ref_wfn) returnvalue = psi4.plugin('v2rdm_casscf.so', ref_wfn) #psi4.set_variable('CURRENT ENERGY', returnvalue) #return psi4.get_variable('CURRENT ENERGY') return returnvalue
def run_gaussian_2(name, **kwargs): # throw an exception for open-shells if (psi4.get_option('SCF', 'REFERENCE') != 'RHF'): raise ValidationError("""g2 computations require "reference rhf".""") # stash user options: optstash = p4util.OptionsState(['FNOCC', 'COMPUTE_TRIPLES'], ['FNOCC', 'COMPUTE_MP4_TRIPLES'], ['FREEZE_CORE'], ['MP2_TYPE'], ['SCF', 'SCF_TYPE']) # override default scf_type psi4.set_local_option('SCF', 'SCF_TYPE', 'PK') # optimize geometry at scf level psi4.clean() psi4.set_global_option('BASIS', "6-31G(D)") driver.optimize('scf') psi4.clean() # scf frequencies for zpe # NOTE This line should not be needed, but without it there's a seg fault scf_e, ref = driver.frequency('scf', return_wfn=True) # thermodynamic properties du = psi4.get_variable('INTERNAL ENERGY CORRECTION') dh = psi4.get_variable('ENTHALPY CORRECTION') dg = psi4.get_variable('GIBBS FREE ENERGY CORRECTION') freqs = ref.frequencies() nfreq = freqs.dim(0) freqsum = 0.0 for i in range(0, nfreq): freqsum += freqs.get(i) zpe = freqsum / p4const.psi_hartree2wavenumbers * 0.8929 * 0.5 psi4.clean() # optimize geometry at mp2 (no frozen core) level # note: freeze_core isn't an option in MP2 psi4.set_global_option('FREEZE_CORE', "FALSE") psi4.set_global_option('MP2_TYPE', 'CONV') driver.optimize('mp2') psi4.clean() # qcisd(t) psi4.set_local_option('FNOCC', 'COMPUTE_MP4_TRIPLES', "TRUE") psi4.set_global_option('FREEZE_CORE', "TRUE") psi4.set_global_option('BASIS', "6-311G(D_P)") ref = driver.proc.run_fnocc('qcisd(t)', return_wfn=True, **kwargs) # HLC: high-level correction based on number of valence electrons nirrep = ref.nirrep() frzcpi = ref.frzcpi() nfzc = 0 for i in range(0, nirrep): nfzc += frzcpi[i] nalpha = ref.nalpha() - nfzc nbeta = ref.nbeta() - nfzc # hlc of gaussian-2 hlc = -0.00481 * nalpha - 0.00019 * nbeta # hlc of gaussian-1 hlc1 = -0.00614 * nalpha eqci_6311gdp = psi4.get_variable("QCISD(T) TOTAL ENERGY") emp4_6311gd = psi4.get_variable("MP4 TOTAL ENERGY") emp2_6311gd = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() # correction for diffuse functions psi4.set_global_option('BASIS', "6-311+G(D_P)") driver.energy('mp4') emp4_6311pg_dp = psi4.get_variable("MP4 TOTAL ENERGY") emp2_6311pg_dp = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() # correction for polarization functions psi4.set_global_option('BASIS', "6-311G(2DF_P)") driver.energy('mp4') emp4_6311g2dfp = psi4.get_variable("MP4 TOTAL ENERGY") emp2_6311g2dfp = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() # big basis mp2 psi4.set_global_option('BASIS', "6-311+G(3DF_2P)") #run_fnocc('_mp2',**kwargs) driver.energy('mp2') emp2_big = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() eqci = eqci_6311gdp e_delta_g2 = emp2_big + emp2_6311gd - emp2_6311g2dfp - emp2_6311pg_dp e_plus = emp4_6311pg_dp - emp4_6311gd e_2df = emp4_6311g2dfp - emp4_6311gd eg2 = eqci + e_delta_g2 + e_plus + e_2df eg2_mp2_0k = eqci + (emp2_big - emp2_6311gd) + hlc + zpe psi4.print_out('\n') psi4.print_out(' ==> G1/G2 Energy Components <==\n') psi4.print_out('\n') psi4.print_out(' QCISD(T): %20.12lf\n' % eqci) psi4.print_out(' E(Delta): %20.12lf\n' % e_delta_g2) psi4.print_out(' E(2DF): %20.12lf\n' % e_2df) psi4.print_out(' E(+): %20.12lf\n' % e_plus) psi4.print_out(' E(G1 HLC): %20.12lf\n' % hlc1) psi4.print_out(' E(G2 HLC): %20.12lf\n' % hlc) psi4.print_out(' E(ZPE): %20.12lf\n' % zpe) psi4.print_out('\n') psi4.print_out(' ==> 0 Kelvin Results <==\n') psi4.print_out('\n') eg2_0k = eg2 + zpe + hlc psi4.print_out(' G1: %20.12lf\n' % (eqci + e_plus + e_2df + hlc1 + zpe)) psi4.print_out(' G2(MP2): %20.12lf\n' % eg2_mp2_0k) psi4.print_out(' G2: %20.12lf\n' % eg2_0k) psi4.set_variable("G1 TOTAL ENERGY", eqci + e_plus + e_2df + hlc1 + zpe) psi4.set_variable("G2 TOTAL ENERGY", eg2_0k) psi4.set_variable("G2(MP2) TOTAL ENERGY", eg2_mp2_0k) psi4.print_out('\n') T = psi4.get_global_option('T') psi4.print_out(' ==> %3.0lf Kelvin Results <==\n' % T) psi4.print_out('\n') internal_energy = eg2_mp2_0k + du - zpe / 0.8929 enthalpy = eg2_mp2_0k + dh - zpe / 0.8929 gibbs = eg2_mp2_0k + dg - zpe / 0.8929 psi4.print_out(' G2(MP2) energy: %20.12lf\n' % internal_energy) psi4.print_out(' G2(MP2) enthalpy: %20.12lf\n' % enthalpy) psi4.print_out(' G2(MP2) free energy: %20.12lf\n' % gibbs) psi4.print_out('\n') psi4.set_variable("G2(MP2) INTERNAL ENERGY", internal_energy) psi4.set_variable("G2(MP2) ENTHALPY", enthalpy) psi4.set_variable("G2(MP2) FREE ENERGY", gibbs) internal_energy = eg2_0k + du - zpe / 0.8929 enthalpy = eg2_0k + dh - zpe / 0.8929 gibbs = eg2_0k + dg - zpe / 0.8929 psi4.print_out(' G2 energy: %20.12lf\n' % internal_energy) psi4.print_out(' G2 enthalpy: %20.12lf\n' % enthalpy) psi4.print_out(' G2 free energy: %20.12lf\n' % gibbs) psi4.set_variable("CURRENT ENERGY", eg2_0k) psi4.set_variable("G2 INTERNAL ENERGY", internal_energy) psi4.set_variable("G2 ENTHALPY", enthalpy) psi4.set_variable("G2 FREE ENERGY", gibbs) psi4.clean() optstash.restore() # return 0K g2 results return eg2_0k
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 run_gaussian_2(name, **kwargs): # throw an exception for open-shells if (psi4.get_option('SCF','REFERENCE') != 'RHF' ): raise ValidationError("""g2 computations require "reference rhf".""") # stash user options: optstash = p4util.OptionsState( ['FNOCC','COMPUTE_TRIPLES'], ['FNOCC','COMPUTE_MP4_TRIPLES'], ['FREEZE_CORE'], ['MP2_TYPE'], ['SCF','SCF_TYPE']) # override default scf_type psi4.set_local_option('SCF','SCF_TYPE','PK') # optimize geometry at scf level psi4.clean() psi4.set_global_option('BASIS',"6-31G(D)") driver.optimize('scf') psi4.clean() # scf frequencies for zpe # NOTE This line should not be needed, but without it there's a seg fault scf_e, ref = driver.frequency('scf', return_wfn=True) # thermodynamic properties du = psi4.get_variable('INTERNAL ENERGY CORRECTION') dh = psi4.get_variable('ENTHALPY CORRECTION') dg = psi4.get_variable('GIBBS FREE ENERGY CORRECTION') freqs = ref.frequencies() nfreq = freqs.dim(0) freqsum = 0.0 for i in range(0, nfreq): freqsum += freqs.get(i) zpe = freqsum / p4const.psi_hartree2wavenumbers * 0.8929 * 0.5 psi4.clean() # optimize geometry at mp2 (no frozen core) level # note: freeze_core isn't an option in MP2 psi4.set_global_option('FREEZE_CORE',"FALSE") psi4.set_global_option('MP2_TYPE', 'CONV') driver.optimize('mp2') psi4.clean() # qcisd(t) psi4.set_local_option('FNOCC','COMPUTE_MP4_TRIPLES',"TRUE") psi4.set_global_option('FREEZE_CORE',"TRUE") psi4.set_global_option('BASIS',"6-311G(D_P)") ref = driver.proc.run_fnocc('qcisd(t)', return_wfn=True, **kwargs) # HLC: high-level correction based on number of valence electrons nirrep = ref.nirrep() frzcpi = ref.frzcpi() nfzc = 0 for i in range (0,nirrep): nfzc += frzcpi[i] nalpha = ref.nalpha() - nfzc nbeta = ref.nbeta() - nfzc # hlc of gaussian-2 hlc = -0.00481 * nalpha -0.00019 * nbeta # hlc of gaussian-1 hlc1 = -0.00614 * nalpha eqci_6311gdp = psi4.get_variable("QCISD(T) TOTAL ENERGY") emp4_6311gd = psi4.get_variable("MP4 TOTAL ENERGY") emp2_6311gd = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() # correction for diffuse functions psi4.set_global_option('BASIS',"6-311+G(D_P)") driver.energy('mp4') emp4_6311pg_dp = psi4.get_variable("MP4 TOTAL ENERGY") emp2_6311pg_dp = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() # correction for polarization functions psi4.set_global_option('BASIS',"6-311G(2DF_P)") driver.energy('mp4') emp4_6311g2dfp = psi4.get_variable("MP4 TOTAL ENERGY") emp2_6311g2dfp = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() # big basis mp2 psi4.set_global_option('BASIS',"6-311+G(3DF_2P)") #run_fnocc('_mp2',**kwargs) driver.energy('mp2') emp2_big = psi4.get_variable("MP2 TOTAL ENERGY") psi4.clean() eqci = eqci_6311gdp e_delta_g2 = emp2_big + emp2_6311gd - emp2_6311g2dfp - emp2_6311pg_dp e_plus = emp4_6311pg_dp - emp4_6311gd e_2df = emp4_6311g2dfp - emp4_6311gd eg2 = eqci + e_delta_g2 + e_plus + e_2df eg2_mp2_0k = eqci + (emp2_big - emp2_6311gd) + hlc + zpe psi4.print_out('\n') psi4.print_out(' ==> G1/G2 Energy Components <==\n') psi4.print_out('\n') psi4.print_out(' QCISD(T): %20.12lf\n' % eqci) psi4.print_out(' E(Delta): %20.12lf\n' % e_delta_g2) psi4.print_out(' E(2DF): %20.12lf\n' % e_2df) psi4.print_out(' E(+): %20.12lf\n' % e_plus) psi4.print_out(' E(G1 HLC): %20.12lf\n' % hlc1) psi4.print_out(' E(G2 HLC): %20.12lf\n' % hlc) psi4.print_out(' E(ZPE): %20.12lf\n' % zpe) psi4.print_out('\n') psi4.print_out(' ==> 0 Kelvin Results <==\n') psi4.print_out('\n') eg2_0k = eg2 + zpe + hlc psi4.print_out(' G1: %20.12lf\n' % (eqci + e_plus + e_2df + hlc1 + zpe)) psi4.print_out(' G2(MP2): %20.12lf\n' % eg2_mp2_0k) psi4.print_out(' G2: %20.12lf\n' % eg2_0k) psi4.set_variable("G1 TOTAL ENERGY",eqci + e_plus + e_2df + hlc1 + zpe) psi4.set_variable("G2 TOTAL ENERGY",eg2_0k) psi4.set_variable("G2(MP2) TOTAL ENERGY",eg2_mp2_0k) psi4.print_out('\n') T = psi4.get_global_option('T') psi4.print_out(' ==> %3.0lf Kelvin Results <==\n'% T) psi4.print_out('\n') internal_energy = eg2_mp2_0k + du - zpe / 0.8929 enthalpy = eg2_mp2_0k + dh - zpe / 0.8929 gibbs = eg2_mp2_0k + dg - zpe / 0.8929 psi4.print_out(' G2(MP2) energy: %20.12lf\n' % internal_energy ) psi4.print_out(' G2(MP2) enthalpy: %20.12lf\n' % enthalpy) psi4.print_out(' G2(MP2) free energy: %20.12lf\n' % gibbs) psi4.print_out('\n') psi4.set_variable("G2(MP2) INTERNAL ENERGY",internal_energy) psi4.set_variable("G2(MP2) ENTHALPY",enthalpy) psi4.set_variable("G2(MP2) FREE ENERGY",gibbs) internal_energy = eg2_0k + du - zpe / 0.8929 enthalpy = eg2_0k + dh - zpe / 0.8929 gibbs = eg2_0k + dg - zpe / 0.8929 psi4.print_out(' G2 energy: %20.12lf\n' % internal_energy ) psi4.print_out(' G2 enthalpy: %20.12lf\n' % enthalpy) psi4.print_out(' G2 free energy: %20.12lf\n' % gibbs) psi4.set_variable("CURRENT ENERGY",eg2_0k) psi4.set_variable("G2 INTERNAL ENERGY",internal_energy) psi4.set_variable("G2 ENTHALPY",enthalpy) psi4.set_variable("G2 FREE ENERGY",gibbs) psi4.clean() optstash.restore() # return 0K g2 results return eg2_0k
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