def test_mp2_h2o(): h2o = psi4.geometry(""" O H 1 1.0 H 1 1.0 2 106.0 """) psi4.core.clean_options() psi4_options = { "basis": "6-31G**", "reference": "rhf", "d_convergence": 9, "e_convergence": 9, "mp2_type": "conv", "max_energy_g_convergence": 7, } psi4.set_options(psi4_options) result = optking.optimize_psi4("mp2") this_nucenergy = result["trajectory"][-1]["properties"][ "nuclear_repulsion_energy"] # TEST this_mp2 = result["energies"][-1] # TEST REF_nucenergy = 9.1622581908184 # TEST REF_mp2 = -76.2224486598878 # TEST assert psi4.compare_values(REF_nucenergy, this_nucenergy, 3, "Nuclear repulsion energy") # TEST assert psi4.compare_values(REF_mp2, this_mp2, 6, "CONV MP2 energy") # TEST
def test_mp2(): bas_list = ['STO-3G','DZ'] mol_list = ['H2O'] for name in mol_list: geom = mesp.mollib[name] geom += '\nsymmetry c1' for bas in bas_list: psi4.core.clean() mol = mesp.Molecule(name,geom,bas) psi4.set_options({ 'basis':bas, 'scf_type':'pk', 'mp2_type':'conv', 'freeze_core':'false', 'e_convergence':1e-12, 'd_convergence':1e-12}) psi4.set_module_options('SCF', {'e_convergence': 1e-12, 'd_convergence': 1e-12, 'DIIS': True, 'scf_type':'pk'}) print("Results for {}/MP2/{}".format(name,bas)) mesp.mp2.do_mp2(mol) E_mesp = mol.E_MP2 E_psi4 = psi4.energy('MP2') print("mesp energy: {}".format(E_mesp)) print("Psi4 energy: {}".format(E_psi4)) psi4.compare_values(E_psi4,E_mesp,11,"MP2 Energy")
def test_linesearch(): Ar2 = psi4.geometry(""" Ar Ar 1 5.0 """) psi4.core.clean_options() psi4_options = { "basis": "cc-pvdz", "d_convergence": 10, "geom_maxiter": 20, "g_convergence": "gau_tight" } psi4.set_options(psi4_options) # "linesearch" is not currrently recognized by psi4 read_options. json_output = optking.optimize_psi4("mp2", **{"step_type": "linesearch"}) print(json_output) E = json_output["energies"][-1] nucenergy = json_output["trajectory"][-1]["properties"][ "nuclear_repulsion_energy"] assert psi4.compare_values(nucenergy, nucenergy, 3, "Nuclear repulsion energy") # TEST assert psi4.compare_values(refenergy, E, 1, "Reference energy") # TEST
def test_fci_ecp_2(): """Water-Argon complex with ECP present; CASCI(6,6).""" nucenergy = 23.253113522963400 refenergy = -96.68319147222 arwater = psi4.geometry(""" Ar 0.000000000000 0.000000000000 3.000000000000 O 0.000000000000 0.000000000000 -0.071143036192 H 0.000000000000 -0.758215806856 0.564545805801 H 0.000000000000 0.758215806856 0.564545805801 """) psi4.set_options({ 'scf_type': 'pk', 'basis': 'lanl2dz', 'df_scf_guess': False, 'd_convergence': 10, }) psi4.set_module_options("FORTE", { 'job_type': 'fci', 'restricted_docc': [4,0,1,1], 'active': [2,0,2,2], }) e = psi4.energy('forte') assert psi4.compare_values(nucenergy, arwater.nuclear_repulsion_energy(), 10, "Nuclear repulsion energy") assert psi4.compare_values(refenergy, e, 10, "FCI energy with ECP")
def test_uccsd_ch2(): ch2 = psi4.geometry( """ 0 3 C H 1 1.1 H 1 1.1 2 109.0 """ ) psi4.core.clean_options() psi4_options = { "reference": "uhf", "basis": "cc-pvdz", "max_disp_g_convergence": 1e-6, "max_force_g_convergence": 1.0e-6, "max_energy_g_convergence": 7, "e_convergence": 10, "r_convergence": 10, "scf_type": "pk", } psi4.set_options(psi4_options) result = optking.optimize_psi4("CCSD") this_scf = result["trajectory"][-1]["properties"]["scf_total_energy"] # TEST this_ccsd = result["trajectory"][-1]["properties"]["ccsd_correlation_energy"] # TEST this_total = result["trajectory"][-1]["properties"]["return_energy"] # TEST REF_scf = -38.9265869596 # TEST REF_ccsd = -0.1153361899 # TEST REF_total = -39.0419231495 # TEST assert psi4.compare_values(REF_scf, this_scf, 6, "UHF energy") # TEST assert psi4.compare_values(REF_ccsd, this_ccsd, 6, "UHF CCSD contribution") # TEST assert psi4.compare_values(REF_total, this_total, 6, "UCCSD Total energy") # TEST
def test_scsmp2_opt(): h2o = psi4.geometry(""" 0 1 o h 1 0.958 h 1 0.958 2 104.4776 """) psi4.core.clean_options() psi4_options = { 'basis': 'cc-pvdz', 'max_energy_g_convergence': 7 } psi4.set_options(psi4_options) result = optking.optimize_psi4('scs-omp2') this_nuc = result['trajectory'][-1]['properties']['nuclear_repulsion_energy'] #TEST this_scf = result['trajectory'][-1]['properties']['scf_total_energy'] #TEST this_energy = result['energies'][-1] #TEST REF_nuc = 9.1123208123 REF_scf = -76.0260868661 REF_scsomp2 = -76.2280452486 assert psi4.compare_values(REF_nuc, this_nuc, 3, "Nuclear Repulsion Energy (a.u.)"); #TEST assert psi4.compare_values(REF_scf, this_scf, 6, "SCF Energy (a.u.)"); #TEST assert psi4.compare_values(REF_scsomp2, this_energy, 6, "SCS-OMP2 Total Energy (a.u.)"); #TEST
def test_grimme_3c(): s16di = psi4.geometry(""" C 0.000000 -0.667578 -2.124659 C 0.000000 0.667578 -2.124659 H 0.923621 -1.232253 -2.126185 H -0.923621 -1.232253 -2.126185 H -0.923621 1.232253 -2.126185 H 0.923621 1.232253 -2.126185 -- C 0.000000 0.000000 2.900503 C 0.000000 0.000000 1.693240 H 0.000000 0.000000 0.627352 H 0.000000 0.000000 3.963929 symmetry c1 """) ene = psi4.energy('pbeh3c', bsse_type='nocp') assert psi4.compare_values(-2.153, ene * psi4.constants.hartree2kcalmol, 0.03, 'S22-16 PBEh-3c/def2-mSVP') psi4.set_options({'basis': 'cc-pvdz'}) # try to confuse method psi4.set_options({'scf_type': 'pk'}) ene = psi4.energy('hf3c/', bsse_type='nocp') assert psi4.compare_values(-0.00240232, ene, 6, 'S22-16 HF-3c/minix')
def test_mp2d(): eneyne = psi4.geometry(""" C 0.000000 -0.667578 -2.124659 C 0.000000 0.667578 -2.124659 H 0.923621 -1.232253 -2.126185 H -0.923621 -1.232253 -2.126185 H -0.923621 1.232253 -2.126185 H 0.923621 1.232253 -2.126185 -- C 0.000000 0.000000 2.900503 C 0.000000 0.000000 1.693240 H 0.000000 0.000000 0.627352 H 0.000000 0.000000 3.963929 """) mol = eneyne.to_schema(dtype=2) expected = 0.00632174635953 resinp = { 'schema_name': 'qcschema_input', 'schema_version': 1, 'molecule': mol, 'driver': 'energy', #gradient', 'model': { 'method': 'mp2d-mp2-dmp2' }, 'keywords': {}, } jrec = qcng.compute(resinp, 'mp2d', raise_error=True) jrec = jrec.dict() assert psi4.compare_values(expected, jrec['extras']['qcvars']['CURRENT ENERGY'], 7, 'E') assert psi4.compare_values(expected, jrec['extras']['qcvars']['DISPERSION CORRECTION ENERGY'], 7, 'disp E') assert psi4.compare_values(expected, jrec['extras']['qcvars']['MP2-DMP2 DISPERSION CORRECTION ENERGY'], 7, 'mp2d disp E')
def test_psi4_cc(datadir): """cc1""" #! RHF-CCSD 6-31G** all-electron optimization of the H2O molecule ref_file = datadir.join(f"jatin2.ref") with open(ref_file) as f: jatin = json.load(f) atres = psi4.schema_wrapper.run_qcschema(jatin) if "qcengine.exceptions.InputError" in atres.error.error_message: pytest.xfail("no AtomicInput optimization") # psi4.optimize('ccsd') refnuc = 9.1654609427539 refscf = -76.0229427274435 refccsd = -0.20823570806196 reftotal = -76.2311784355056 assert psi4.compare_values(refnuc, atres.properties.nuclear_repulsion_energy, 3, "Nuclear repulsion energy") assert psi4.compare_values(refscf, atres.extras["qcvars"]["SCF total energy"], 5, "SCF energy") assert psi4.compare_values(refccsd, psi4.variable("CCSD correlation energy"), 4, "CCSD contribution") assert psi4.compare_values(reftotal, psi4.variable("Current energy"), 7, "Total energy")
def test_sosmp2_opt(): h2o = psi4.geometry( """ 0 1 o h 1 0.958 h 1 0.958 2 104.4776 """ ) psi4.core.clean_options() psi4_options = {"basis": "cc-pvdz", "max_energy_g_convergence": 7} psi4.set_options(psi4_options) result = optking.optimize_psi4("sos-omp2") this_nuc = result["trajectory"][-1]["properties"]["nuclear_repulsion_energy"] # TEST this_scf = result["trajectory"][-1]["properties"]["scf_total_energy"] # TEST this_energy = result["energies"][-1] # TEST REF_nuc = 9.1236764248 # TEST REF_scf = -76.0262152850 # TEST REF_sosomp2 = -76.2106507336 # TEST assert psi4.compare_values(REF_nuc, this_nuc, 3, "Nuclear Repulsion Energy (a.u.)") # TEST assert psi4.compare_values(REF_scf, this_scf, 6, "SCF Energy (a.u.)") # TEST assert psi4.compare_values(REF_sosomp2, this_energy, 6, "SOS-OMP2 Total Energy (a.u.)")
def test_psi4_cas(): """casscf-sp""" #! CASSCF/6-31G** energy point geom = psi4.geometry(""" O H 1 1.00 H 1 1.00 2 103.1 """) psi4.set_options({ "basis" : '6-31G**', "reference" : 'rhf', "scf_type" : 'pk', "mcscf_algorithm" : 'ah', "qc_module" : 'detci', "nat_orbs" : True}) cisd_energy, cisd_wfn = psi4.energy("CISD", return_wfn=True) assert psi4.compare_values(-76.2198474477531, cisd_energy, 6, 'CISD Energy') psi4.set_options({ "restricted_docc": [1, 0, 0, 0], "active": [3, 0, 1, 2]}) casscf_energy = psi4.energy('casscf', ref_wfn=cisd_wfn) assert psi4.compare_values(-76.073865006902, casscf_energy, 6, 'CASSCF Energy')
def test_psi4_cc(): """cc1""" #! RHF-CCSD 6-31G** all-electron optimization of the H2O molecule jatin = """{"id": null, "schema_name": "qcschema_input", "schema_version": 1, "molecule": {"schema_name": "qcschema_molecule", "schema_version": 2, "validated": true, "symbols": ["O", "H", "H"], "geometry": [0.0, 0.0, -0.12770502190246294, 0.0, -1.4345476276003923, 1.013385685261514, 0.0, 1.4345476276003923, 1.013385685261514], "name": "H2O", "molecular_charge": 0.0, "molecular_multiplicity": 1, "masses": [15.99491461957, 1.00782503223, 1.00782503223], "real": [true, true, true], "atom_labels": ["", "", ""], "atomic_numbers": [8, 1, 1], "mass_numbers": [16, 1, 1], "fragments": [[0, 1, 2]], "fragment_charges": [0.0], "fragment_multiplicities": [1], "fix_com": false, "fix_orientation": false, "provenance": {"creator": "QCElemental", "version": "v0.17.0+7.gf55d5ac.dirty", "routine": "qcelemental.molparse.from_string"}}, "driver": "optimize", "model": {"method": "ccsd", "basis": "6-31G**"}, "keywords": {}, "protocols": {}, "extras": {"wfn_qcvars_only": true}, "provenance": {"creator": "Psi4", "version": "1.4a2.dev1087", "routine": "psi4.driver.p4util.procutil"}}""" atres = psi4.schema_wrapper.run_qcschema(json.loads(jatin)) if "qcengine.exceptions.InputError" in atres.error.error_message: pytest.xfail("no AtomicInput optimization") # psi4.optimize('ccsd') refnuc = 9.1654609427539 refscf = -76.0229427274435 refccsd = -0.20823570806196 reftotal = -76.2311784355056 assert psi4.compare_values(refnuc, atres.properties.nuclear_repulsion_energy, 3, "Nuclear repulsion energy") assert psi4.compare_values(refscf, atres.extras["qcvars"]["SCF total energy"], 5, "SCF energy") assert psi4.compare_values(refccsd, psi4.variable("CCSD correlation energy"), 4, "CCSD contribution") assert psi4.compare_values(reftotal, psi4.variable("Current energy"), 7, "Total energy")
def test_psi4_cc(): """cc1""" #! RHF-CCSD 6-31G** all-electron optimization of the H2O molecule psi4.core.clean() h2o = psi4.geometry(""" O H 1 0.97 H 1 0.97 2 103.0 """) psi4.set_options({"basis": '6-31G**'}) psi4.optimize('ccsd') refnuc = 9.1654609427539 refscf = -76.0229427274435 refccsd = -0.20823570806196 reftotal = -76.2311784355056 assert psi4.compare_values(refnuc, h2o.nuclear_repulsion_energy(), 3, "Nuclear repulsion energy") assert psi4.compare_values(refscf, psi4.get_variable("SCF total energy"), 5, "SCF energy") assert psi4.compare_values(refccsd, psi4.get_variable("CCSD correlation energy"), 4, "CCSD contribution") assert psi4.compare_values(reftotal, psi4.get_variable("Current energy"), 7, "Total energy")
def test_linesearch(): Ar2 = psi4.geometry(""" Ar Ar 1 5.0 """) psi4.core.clean_options() psi4_options = { 'basis': 'cc-pvdz', 'd_convergence': 10, 'geom_maxiter': 20, 'g_convergence': 'gau_tight' } psi4.set_options(psi4_options) # For some reason this works but setting it through set_options throws an error psi4.set_module_options("OPTKING", {"step_type": "linesearch"}) json_output = optking.optimize_psi4('mp2') E = json_output['energies'][-1] nucenergy = json_output['trajectory'][-1]['properties'][ 'nuclear_repulsion_energy'] assert psi4.compare_values(nucenergy, nucenergy, 3, "Nuclear repulsion energy") #TEST assert psi4.compare_values(refenergy, E, 1, "Reference energy") #TEST
def test_B_dB_matrices(): hooh = psi4.geometry(""" H O 1 0.9 O 2 1.4 1 100.0 H 3 0.9 2 100.0 1 114.0 """) psi4.core.clean_options() psi4_options = { "basis": "cc-pvdz", "g_convergence": "gau_tight", "scf_type": "pk", "TEST_B": True, "TEST_DERIVATIVE_B": True, "G_CONVERGENCE": "gau_tight", } psi4.set_options(psi4_options) json_output = optking.optimize_psi4("hf") # Uses default program (psi4) E = json_output["energies"][-1] # TEST nucenergy = json_output["trajectory"][-1]["properties"][ "nuclear_repulsion_energy"] # TEST refnucenergy = 38.06177 # TEST refenergy = -150.786766850 # TEST assert "test_b" in json_output["keywords"] # TEST assert "test_derivative_b" in json_output["keywords"] # TEST assert "g_convergence" in json_output["keywords"] # TEST assert psi4.compare_values(refnucenergy, nucenergy, 3, "Nuclear repulsion energy") # TEST assert psi4.compare_values(refenergy, E, 8, "Reference energy") # TEST
def test_psi4_cas(): """casscf-sp""" #! CASSCF/6-31G** energy point geom = psi4.geometry(""" O H 1 1.00 H 1 1.00 2 103.1 """) psi4.set_options({ "basis": '6-31G**', "reference": 'rhf', "scf_type": 'pk', "mcscf_algorithm": 'ah', "qc_module": 'detci', "nat_orbs": True }) cisd_energy, cisd_wfn = psi4.energy("CISD", return_wfn=True) assert psi4.compare_values(-76.2198474477531, cisd_energy, 6, 'CISD Energy') psi4.set_options({"restricted_docc": [1, 0, 0, 0], "active": [3, 0, 1, 2]}) casscf_energy = psi4.energy('casscf', ref_wfn=cisd_wfn) assert psi4.compare_values(-76.073865006902, casscf_energy, 6, 'CASSCF Energy')
def test_ch2_with_dummy_atoms(): ch2 = psi4.geometry(""" 0 3 c x 1 1.0 h 1 b1 2 a1 h 1 b1 2 a1 3 180.0 b1 = 1.0 a1 = 60.0 """) psi4.core.clean_options() psi4_options = { 'reference': 'uhf', 'basis': '6-31G(d,p)', 'docc': [2, 0, 0, 1], 'socc': [1, 0, 1, 0], 'scf_type': 'pk' } psi4.set_options(psi4_options) json_output = optking.optimize_psi4('hf') thisenergy = json_output['energies'][-1] nucenergy = json_output['trajectory'][-1]['properties'][ 'nuclear_repulsion_energy'] assert psi4.compare_values(nucrefenergy, nucenergy, 3, "Nuclear repulsion energy") #TEST assert psi4.compare_values(refenergy, thisenergy, 6, "Reference energy") #TEST
def test_frozen_cart_h2o(): h2o = psi4.geometry(""" O 1.000000 1.000000 1.000000 H 2.000000 1.000000 1.000000 H 1.000000 2.000000 1.000000 units angstrom no_com no_reorient """) psi4.core.clean_options() psi4_options = { 'basis': 'cc-pvdz', 'reference': 'rhf', 'scf_type': 'df', 'max_energy_g_convergence': 7 } psi4.set_options(psi4_options) psi4.set_module_options("OPTKING", {'frozen_cartesian': '''1 xyz'''}) json_output = optking.optimize_psi4('hf') thisenergy = json_output['energies'][-1] assert psi4.compare_values(-76.0270327834836, thisenergy, 6, "RHF Energy") assert psi4.compare_values(h2o.x(0), 1.88972613289, 6, "X Frozen coordinate") assert psi4.compare_values(h2o.y(0), 1.88972613289, 6, "Y Frozen coordinate") assert psi4.compare_values(h2o.z(0), 1.88972613289, 6, "Z Frozen coordinate")
def test_ccsd_h2o(): h2o = psi4.geometry( """ O H 1 0.97 H 1 0.97 2 103.0 """ ) psi4.core.clean_options() psi4_options = {"basis": "6-31G**", "scf_type": "pk"} psi4.set_options(psi4_options) result = optking.optimize_psi4("ccsd") print(result["trajectory"][-1].keys()) this_scf = result["trajectory"][-1]["properties"]["scf_total_energy"] # TEST this_ccsd = result["trajectory"][-1]["properties"]["ccsd_correlation_energy"] # TEST this_total = result["trajectory"][-1]["properties"]["return_energy"] # TEST REF_scf = -76.0229406477 # TEST REF_ccsd = -0.2082378354 # TEST REF_total = -76.2311784830 # TEST assert psi4.compare_values(REF_scf, this_scf, 4, "SCF energy") # TEST assert psi4.compare_values(REF_ccsd, this_ccsd, 4, "CCSD contribution") # TEST assert psi4.compare_values(REF_total, this_total, 4, "Total energy") # TEST
def test_frozen_cart_h2o(): h2o = psi4.geometry(""" O 1.000000 1.000000 1.000000 H 2.000000 1.000000 1.000000 H 1.000000 2.000000 1.000000 units angstrom no_com no_reorient """) psi4.core.clean_options() psi4_options = { "basis": "cc-pvdz", "reference": "rhf", "scf_type": "df", "max_energy_g_convergence": 7 } psi4.set_options(psi4_options) psi4.set_options({"optking__frozen_cartesian": """1 xyz"""}) json_output = optking.optimize_psi4("hf") thisenergy = json_output["energies"][-1] assert psi4.compare_values(-76.0270327834836, thisenergy, 6, "RHF Energy") assert psi4.compare_values(h2o.x(0), 1.88972613289, 6, "X Frozen coordinate") assert psi4.compare_values(h2o.y(0), 1.88972613289, 6, "Y Frozen coordinate") assert psi4.compare_values(h2o.z(0), 1.88972613289, 6, "Z Frozen coordinate")
def test_ch2_with_dummy_atoms(): ch2 = psi4.geometry(""" 0 3 c x 1 1.0 h 1 b1 2 a1 h 1 b1 2 a1 3 180.0 b1 = 1.0 a1 = 60.0 """) psi4.core.clean_options() psi4_options = { "reference": "uhf", "basis": "6-31G(d,p)", "docc": [2, 0, 0, 1], "socc": [1, 0, 1, 0], "scf_type": "pk", } psi4.set_options(psi4_options) json_output = optking.optimize_psi4("hf") thisenergy = json_output["energies"][-1] nucenergy = json_output["trajectory"][-1]["properties"][ "nuclear_repulsion_energy"] assert psi4.compare_values(nucrefenergy, nucenergy, 3, "Nuclear repulsion energy") # TEST assert psi4.compare_values(refenergy, thisenergy, 6, "Reference energy") # TEST
def test_scsmp3_opt(): h2o = psi4.geometry( """ 0 1 o h 1 0.958 h 1 0.958 2 104.4776 """ ) psi4.core.clean_options() psi4_options = {"basis": "cc-pvdz", "max_energy_g_convergence": 7} psi4.set_options(psi4_options) result = optking.optimize_psi4("scs-omp3") this_nuc = result["trajectory"][-1]["properties"]["nuclear_repulsion_energy"] # TEST this_scf = result["trajectory"][-1]["properties"]["scf_total_energy"] # TEST this_energy = result["energies"][-1] # TEST REF_nuc = 9.1193753755 # TEST REF_scf = -76.0261614278 # TEST REF_scsomp3 = -76.2296260036 # TEST assert psi4.compare_values(REF_nuc, this_nuc, 3, "Nuclear Repulsion Energy (a.u.)") # TEST assert psi4.compare_values(REF_scf, this_scf, 6, "SCF Energy (a.u.)") # TEST assert psi4.compare_values(REF_scsomp3, this_energy, 6, "SCS-OMP3 Total Energy (a.u.)")
def test_mrcc(): """mrcc/ccsdt""" #! CCSDT cc-pVDZ energy for the H2O molecule using MRCC h2o = psi4.geometry(""" o h 1 1.0 h 1 1.0 2 104.5 """) psi4.set_options({'basis': 'cc-pvdz', 'freeze_core': 'true'}) psi4.energy('mrccsdt') assert psi4.compare_values(8.801465529972, psi4.variable("NUCLEAR REPULSION ENERGY"), 6, 'NRE') assert psi4.compare_values(-76.021418445155, psi4.variable("SCF TOTAL ENERGY"), 6, 'SCF') assert psi4.compare_values(-0.204692406830, psi4.variable("MP2 CORRELATION ENERGY"), 6, 'MP2 correlation') assert psi4.compare_values(-0.217715210258, psi4.variable("CCSDT CORRELATION ENERGY"), 6, 'CCSDT correlation') assert psi4.compare_values(-76.239133655413, psi4.variable("CURRENT ENERGY"), 6, 'CCSDT')
def test_ccsd_h2o(): h2o = psi4.geometry(""" O H 1 0.97 H 1 0.97 2 103.0 """) psi4.core.clean_options() psi4_options = {'basis': '6-31G**', 'scf_type': 'pk'} psi4.set_options(psi4_options) result = optking.optimize_psi4('ccsd') this_scf = result['trajectory'][-1]['properties'][ 'scf_total_energy'] #TEST this_ccsd = result['trajectory'][-1]['properties'][ 'ccsd_correlation_energy'] #TEST this_total = result['trajectory'][-1]['properties']['return_energy'] #TEST REF_scf = -76.0229406477 #TEST REF_ccsd = -0.2082378354 #TEST REF_total = -76.2311784830 #TEST assert psi4.compare_values(REF_scf, this_scf, 4, "SCF energy") #TEST assert psi4.compare_values(REF_ccsd, this_ccsd, 4, "CCSD contribution") #TEST assert psi4.compare_values(REF_total, this_total, 4, "Total energy") #TEST
def test_hf_g_h2o(): h2o = psi4.geometry(""" O H 1 1.0 H 1 1.0 2 104.5 """) psi4.core.clean_options() psi4_options = { "diis": False, "basis": "sto-3g", "e_convergence": 10, "d_convergence": 10, "scf_type": "pk", } psi4.set_options(psi4_options) json_output = optking.optimize_psi4("hf") E = json_output["energies"][-1] # TEST nucenergy = json_output["trajectory"][-1]["properties"][ "nuclear_repulsion_energy"] # TEST refnucenergy = 8.9064983474 # TEST refenergy = -74.9659011923 # TEST assert psi4.compare_values(refnucenergy, nucenergy, 3, "Nuclear repulsion energy") # TEST assert psi4.compare_values(refenergy, E, 6, "Reference energy") # TEST
def test_sosmp3_opt(): h2o = psi4.geometry(""" 0 1 o h 1 0.958 h 1 0.958 2 104.4776 """) psi4.core.clean_options() psi4_options = { 'basis': 'cc-pvdz', 'max_energy_g_convergence': 7 } psi4.set_options(psi4_options) result = optking.optimize_psi4('sos-omp3') this_nuc = result['trajectory'][-1]['properties']['nuclear_repulsion_energy'] #TEST this_scf = result['trajectory'][-1]['properties']['scf_total_energy'] #TEST this_energy = result['energies'][-1] #TEST REF_nuc = 9.1134855397 #TEST REF_scf = -76.0261191302 #TEST REF_sosomp3 = -76.2277207554 #TEST assert psi4.compare_values(REF_nuc, this_nuc, 3, "Nuclear Repulsion Energy (a.u.)"); #TEST assert psi4.compare_values(REF_scf, this_scf, 6, "SCF Energy (a.u.)"); #TEST assert psi4.compare_values(REF_sosomp3, this_energy, 6, "SOS-OMP3 Total Energy (a.u.)"); #TEST
def test_scf(): bas_list = ['STO-3G','DZ','DZP'] mol_list = ['H2O', 'CO2', 'C2H4'] for name in mol_list: geom = mesp.mollib[name] geom += '\nsymmetry c1' for bas in bas_list: psi4.core.clean() mol = mesp.Molecule(name,geom,bas) psi4.set_options({ 'basis':bas, 'scf_type':'pk', 'freeze_core':'false', 'e_convergence':1e-12, 'd_convergence':1e-12}) psi4.set_module_options('SCF', {'e_convergence': 1e-12, 'd_convergence': 1e-12, 'DIIS': True, 'scf_type':'pk'}) print("Results for {}/SCF/{}".format(name,bas)) mesp.scf.do_scf(mol) E_mesp = mol.E_SCF E_psi4 = psi4.energy('SCF',molecule=mol.p4mol) print("mesp energy: {}".format(E_mesp)) print("Psi4 energy: {}\n\n".format(E_psi4)) psi4.compare_values(E_psi4,E_mesp,11,"RHF Energy")
def test_nonstationary_forces_h2o(): mol = psi4.geometry(""" 0 1 O 0.0 -0.00 0.00 H 0.0 -0.75 0.58 H 0.0 0.75 0.58 unit Angstrom """) psi4_options = {"basis": "cc-pvdz", "scf_type": "pk"} psi4.set_options(psi4_options) mol.update_geometry() Natom = mol.natom() xyz = mol.geometry().to_array() coords = [stre.Stre(0, 1), stre.Stre(0, 2), bend.Bend(0, 1, 2)] Z = [mol.Z(i) for i in range(0, Natom)] masses = [mol.mass(i) for i in range(0, Natom)] f1 = optking.frag.Frag(Z, xyz, masses, intcos=coords, frozen=False) OptMol = optking.molsys.Molsys([f1]) grad_x = psi4.gradient("hf").to_array() grad_q = OptMol.gradient_to_internals(grad_x.flatten(), useMasses=False) grad_x2 = OptMol.gradient_to_cartesians(grad_q).reshape(Natom, 3) grad_x2 = psi4.core.Matrix.from_array(grad_x2) assert psi4.compare_values(grad_x, grad_x2, 10, "Diff grad. CART->int->CART") grad_q = OptMol.gradient_to_internals(grad_x.flatten(), useMasses=True) grad_x2 = OptMol.gradient_to_cartesians(grad_q).reshape(Natom, 3) grad_x2 = psi4.core.Matrix.from_array(grad_x2) assert psi4.compare_values(grad_x, grad_x2, 10, "Diff grad. CART->int->CART with u=1/mass")
def test_B_dB_matrices(): hooh = psi4.geometry(""" H O 1 0.9 O 2 1.4 1 100.0 H 3 0.9 2 100.0 1 114.0 """) psi4.core.clean_options() psi4_options = { 'basis': 'cc-pvdz', 'g_convergence': 'gau_tight', 'scf_type': 'pk', 'TEST_B': True, 'TEST_DERIVATIVE_B': True, "G_CONVERGENCE": "gau_tight" } psi4.set_options(psi4_options) json_output = optking.optimize_psi4('hf') # Uses default program (psi4) E = json_output['energies'][-1] #TEST nucenergy = json_output['trajectory'][-1]['properties'][ 'nuclear_repulsion_energy'] #TEST refnucenergy = 38.06177 #TEST refenergy = -150.786766850 #TEST assert 'test_b' in json_output['keywords'] #TEST assert 'test_derivative_b' in json_output['keywords'] #TEST assert "g_convergence" in json_output['keywords'] #TEST assert psi4.compare_values(refnucenergy, nucenergy, 3, "Nuclear repulsion energy") #TEST assert psi4.compare_values(refenergy, E, 8, "Reference energy") #TEST
def disabled_test_forte(): """aci-10: Perform aci on benzyne""" import forte refscf = -229.20378006852584 refaci = -229.359450812283 refacipt2 = -229.360444943286 mbenzyne = psi4.geometry(""" 0 1 C 0.0000000000 -2.5451795941 0.0000000000 C 0.0000000000 2.5451795941 0.0000000000 C -2.2828001669 -1.3508352528 0.0000000000 C 2.2828001669 -1.3508352528 0.0000000000 C 2.2828001669 1.3508352528 0.0000000000 C -2.2828001669 1.3508352528 0.0000000000 H -4.0782187459 -2.3208602146 0.0000000000 H 4.0782187459 -2.3208602146 0.0000000000 H 4.0782187459 2.3208602146 0.0000000000 H -4.0782187459 2.3208602146 0.0000000000 units bohr """) psi4.set_options({ 'basis': 'DZ', 'df_basis_mp2': 'cc-pvdz-ri', 'reference': 'uhf', 'scf_type': 'pk', 'd_convergence': 10, 'e_convergence': 12, 'guess': 'gwh', }) psi4.set_module_options("FORTE", { 'root_sym': 0, 'frozen_docc': [2,1,0,0,0,0,2,1], 'restricted_docc': [3,2,0,0,0,0,2,3], 'active': [1,0,1,2,1,2,1,0], 'multiplicity': 1, 'aci_nroot': 1, 'job_type': 'aci', 'sigma': 0.001, 'aci_select_type': 'aimed_energy', 'aci_spin_projection': 1, 'aci_enforce_spin_complete': True, 'aci_add_aimed_degenerate': False, 'aci_project_out_spin_contaminants': False, 'diag_algorithm': 'full', 'aci_quiet_mode': True, }) scf = psi4.energy('scf') assert psi4.compare_values(refscf, scf,10,"SCF Energy") psi4.energy('forte') assert psi4.compare_values(refaci, psi4.variable("ACI ENERGY"),10,"ACI energy") assert psi4.compare_values(refacipt2, psi4.variable("ACI+PT2 ENERGY"),8,"ACI+PT2 energy")
def test_v2rdm_casscf(): """v2rdm_casscf/tests/v2rdm1""" #! cc-pvdz N2 (6,6) active space Test DQG print(' N2 / cc-pVDZ / DQG(6,6), scf_type = CD / 1e-12, rNN = 0.5 A') import v2rdm_casscf n2 = psi4.geometry(""" 0 1 n n 1 r """) interloper = psi4.geometry(""" 0 1 O H 1 1.0 H 1 1.0 2 90.0 """) psi4.set_options({ 'basis': 'cc-pvdz', 'scf_type': 'cd', 'cholesky_tolerance': 1e-12, 'd_convergence': 1e-10, 'maxiter': 500, 'restricted_docc': [ 2, 0, 0, 0, 0, 2, 0, 0 ], 'active': [ 1, 0, 1, 1, 0, 1, 1, 1 ], }) ##psi4.set_module_options('v2rdm_casscf', { psi4.set_options({ # 'positivity': 'dqg', 'r_convergence': 1e-5, 'e_convergence': 1e-6, 'maxiter': 20000, # #'orbopt_frequency': 1000, # #'mu_update_frequency': 1000, }) psi4.activate(n2) n2.r = 0.5 refscf = -103.04337420425350 refv2rdm = -103.086205379481 psi4.energy('v2rdm-casscf', molecule=n2) assert psi4.compare_values(refscf, psi4.get_variable("SCF TOTAL ENERGY"), 8, "SCF total energy") assert psi4.compare_values(refv2rdm, psi4.get_variable("CURRENT ENERGY"), 5, "v2RDM-CASSCF total energy")
def test_gpudfcc2(): """gpu_dfcc/tests/gpu_dfcc2""" #! aug-cc-pvdz (H2O) Test DF-CCSD(T) vs GPU-DF-CCSD(T) import psi4 H20 = psi4.geometry(""" O 0.000000000000 0.000000000000 -0.068516219310 H 0.000000000000 -0.790689573744 0.543701060724 H 0.000000000000 0.790689573744 0.543701060724 """) psi4.set_memory(32000000000) psi4.set_options({ 'cc_type': 'df', 'basis': 'aug-cc-pvdz', 'freeze_core': 'true', 'e_convergence': 1e-8, 'd_convergence': 1e-8, 'r_convergence': 1e-8, 'scf_type': 'df', 'maxiter': 30}) psi4.set_num_threads(2) en_dfcc = psi4.energy('ccsd(t)') en_gpu_dfcc = psi4.energy('gpu-df-ccsd(t)') assert psi4.compare_values(en_gpu_dfcc, en_dfcc, 8, "CCSD total energy")
def test_gpu_dfcc(): """gpu_dfcc/tests/gpu_dfcc1""" #! cc-pvdz (H2O)2 Test DF-CCSD vs GPU-DF-CCSD import gpu_dfcc H20 = psi4.geometry(""" O 0.000000000000 0.000000000000 -0.068516219310 H 0.000000000000 -0.790689573744 0.543701060724 H 0.000000000000 0.790689573744 0.543701060724 """) psi4.set_memory(32000000000) psi4.set_options({ 'cc_timings': False, 'num_gpus': 1, 'cc_type': 'df', 'df_basis_cc': 'aug-cc-pvdz-ri', 'df_basis_scf': 'aug-cc-pvdz-jkfit', 'basis': 'aug-cc-pvdz', 'freeze_core': 'true', 'e_convergence': 1e-8, 'd_convergence': 1e-8, 'r_convergence': 1e-8, 'scf_type': 'df', 'maxiter': 30}) psi4.set_num_threads(2) en_dfcc = psi4.energy('ccsd', molecule=H20) en_gpu_dfcc = psi4.energy('gpu-df-ccsd', molecule=H20) assert psi4.compare_values(en_gpu_dfcc, en_dfcc, 8, "CCSD total energy")
def test_json(): """json/energy""" import numpy as np # Generate JSON data json_input = { "schema_name": "qc_schema_input", "schema_version": 1, "molecule": { "symbols": ["He", "He"], "geometry": [0, 0, -1, 0, 0, 1] }, "driver": "gradient", "model": { "method": "SCF", "basis": "sto-3g" }, "keywords": {} } json_ret = psi4.json_wrapper.run_json(json_input) assert psi4.compare_integers(True, json_ret["success"], "Success") assert psi4.compare_values(-5.474227786274896, json_ret["properties"]["return_energy"], 4, "SCF ENERGY") bench_gradient = np.array([[ 0.0 , 0.0 , 0.32746933], [ 0.0 , 0.0 , -0.32746933]]) cgradient = np.array(json_ret["return_result"]).reshape(-1, 3) assert psi4.compare_arrays(bench_gradient, cgradient, 4, "SCF RETURN GRADIENT") with open("pytest_output.dat", "w") as f: json.dump(json_ret["raw_output"], f)
def test_pcmsolver(): """pcmsolver/scf""" #! pcm nucenergy = 12.0367196636183458 polenergy = -0.0053060443528559 totalenergy = -55.4559426361734040 NH3 = psi4.geometry(""" symmetry c1 N -0.0000000001 -0.1040380466 0.0000000000 H -0.9015844116 0.4818470201 -1.5615900098 H -0.9015844116 0.4818470201 1.5615900098 H 1.8031688251 0.4818470204 0.0000000000 units bohr no_reorient no_com """) psi4.set_options({ 'basis': 'STO-3G', 'scf_type': 'pk', 'pcm': True, 'pcm_scf_type': 'total', }) psi4.pcm_helper(""" Units = Angstrom Medium { SolverType = IEFPCM Solvent = Water } Cavity { RadiiSet = UFF Type = GePol Scaling = False Area = 0.3 Mode = Implicit } """) print('RHF-PCM, total algorithm') energy_scf1, wfn1 = psi4.energy('scf', return_wfn=True) assert psi4.compare_values(nucenergy, NH3.nuclear_repulsion_energy(), 10, "Nuclear repulsion energy (PCM, total algorithm)") #TEST assert psi4.compare_values(totalenergy, energy_scf1, 10, "Total energy (PCM, total algorithm)") #TEST assert psi4.compare_values(polenergy, wfn1.get_variable("PCM POLARIZATION ENERGY"), 6, "Polarization energy (PCM, total algorithm)") #TEST psi4.set_options({'pcm_scf_type': 'separate'}) print('RHF-PCM, separate algorithm') energy_scf2 = psi4.energy('scf') assert psi4.compare_values(totalenergy, energy_scf2, 10, "Total energy (PCM, separate algorithm)") assert psi4.compare_values(polenergy, psi4.get_variable("PCM POLARIZATION ENERGY"), 6, "Polarization energy (PCM, separate algorithm)") # Now force use of UHF on NH3 to check sanity of the algorithm with PCM psi4.set_options({'pcm_scf_type': 'total', 'reference': 'uhf'}) print('UHF-PCM, total algorithm') energy_scf3 = psi4.energy('scf') assert psi4.compare_values(totalenergy, energy_scf3, 10, "Total energy (PCM, separate algorithm)") assert psi4.compare_values(polenergy, psi4.get_variable("PCM POLARIZATION ENERGY"), 6, "Polarization energy (PCM, separate algorithm)")
def test_gdma(): """gdma1""" #! Water RHF/cc-pVTZ distributed multipole analysis ref_energy = -76.0571685433842219 ref_dma_mat = psi4.core.Matrix(3, 9) ref_dma_mat.name = 'Reference DMA values' ref_dma_arr = [ [ -0.43406697290168, -0.18762673939633, 0.00000000000000, 0.00000000000000, 0.03206686487531, 0.00000000000000, -0.00000000000000, -0.53123477172696, 0.00000000000000 ], [ 0.21703348903257, -0.06422316619952, 0.00000000000000, -0.11648289410022, 0.01844320206227, 0.00000000000000, 0.07409226544133, -0.07115302332866, 0.00000000000000 ], [ 0.21703348903257, -0.06422316619952, 0.00000000000000, 0.11648289410022, 0.01844320206227, 0.00000000000000, -0.07409226544133, -0.07115302332866, 0.00000000000000 ] ] for i in range(3): for j in range(9): ref_dma_mat.set(i, j, ref_dma_arr[i][j]) ref_tot_mat = psi4.core.Matrix(1, 9) ref_tot_mat.name = "Reference total values" ref_tot_arr = [ 0.00000000516346, -0.79665315928128, 0.00000000000000, 0.00000000000000, 0.10813259329390, 0.00000000000000, 0.00000000000000, -2.01989585894142, 0.00000000000000 ] for i in range(9): ref_tot_mat.set(0, i, ref_tot_arr[i]) # noreorient/nocom are not needed, but are used here to guarantee that the # GDMA origin placement defined below is at the O atom. water = psi4.geometry(""" O 0.000000 0.000000 0.117176 H -0.000000 -0.756950 -0.468706 H -0.000000 0.756950 -0.468706 noreorient nocom """) psi4.set_options({"scf_type": "pk", "basis": "cc-pvtz", "d_convergence": 10, "gdma_switch": 0, "gdma_radius": [ "H", 0.65 ], "gdma_limit": 2, "gdma_origin": [ 0.000000, 0.000000, 0.117176 ]}) energy, wfn = psi4.energy('scf', return_wfn=True) psi4.gdma(wfn) dmavals = psi4.core.variable("DMA DISTRIBUTED MULTIPOLES") totvals = psi4.core.variable("DMA TOTAL MULTIPOLES") assert psi4.compare_values(ref_energy, energy, 8, "SCF Energy") assert psi4.compare_matrices(dmavals, ref_dma_mat, 6, "DMA Distributed Multipoles") assert psi4.compare_matrices(totvals, ref_tot_mat, 6, "DMA Total Multipoles")
def test_mrcc(): """mrcc/ccsdt""" #! CCSDT cc-pVDZ energy for the H2O molecule using MRCC h2o = psi4.geometry(""" o h 1 1.0 h 1 1.0 2 104.5 """) psi4.set_options({ 'basis': 'cc-pvdz', 'freeze_core': 'true'}) psi4.energy('mrccsdt') assert psi4.compare_values( 8.801465529972, psi4.variable("NUCLEAR REPULSION ENERGY"), 6, 'NRE') assert psi4.compare_values(-76.021418445155, psi4.variable("SCF TOTAL ENERGY"), 6, 'SCF') assert psi4.compare_values( -0.204692406830, psi4.variable("MP2 CORRELATION ENERGY") , 6, 'MP2 correlation') assert psi4.compare_values( -0.217715210258, psi4.variable("CCSDT CORRELATION ENERGY"), 6, 'CCSDT correlation') assert psi4.compare_values(-76.239133655413, psi4.variable("CURRENT ENERGY"), 6, 'CCSDT')
def test_cfour(): """cfour/sp-rhf-ccsd_t_""" #! single-point CCSD(T)/qz2p on water print(' <<< Translation of ZMAT to Psi4 format to Cfour >>>') psi4.geometry(""" O H 1 R H 1 R 2 A R=0.958 A=104.5 """) psi4.set_options({ 'cfour_CALC_level': 'CCSD(T)', 'cfour_BASIS': 'qz2p', 'cfour_SCF_CONV': 12, 'cfour_CC_CONV': 12, }) psi4.energy('cfour') assert psi4.compare_values(-76.062748460117, psi4.variable('scf total energy'), 6, 'SCF') assert psi4.compare_values(-76.332940127333, psi4.variable('mp2 total energy'), 6, 'MP2') assert psi4.compare_values(-76.338453951890, psi4.variable('ccsd total energy'), 6, 'CCSD') assert psi4.compare_values(-0.275705491773, psi4.variable('ccsd correlation energy'), 6, 'CCSD corl') assert psi4.compare_values(-76.345717549886, psi4.variable('ccsd(t) total energy'), 6, 'CCSD(T)') assert psi4.compare_values(-0.282969089769, psi4.variable('ccsd(t) correlation energy'), 6, 'CCSD(T) corl')
def test_psi4_dfmp2(): """dfmp2-1""" #! Density fitted MP2 cc-PVDZ/cc-pVDZ-RI computation of formic acid dimer binding energy #! using automatic counterpoise correction. Monomers are specified using Cartesian coordinates. Enuc = 235.946620315069168 Ecp = -0.0224119246 formic_dim = psi4.geometry(""" 0 1 C -1.888896 -0.179692 0.000000 O -1.493280 1.073689 0.000000 O -1.170435 -1.166590 0.000000 H -2.979488 -0.258829 0.000000 H -0.498833 1.107195 0.000000 -- 0 1 C 1.888896 0.179692 0.000000 O 1.493280 -1.073689 0.000000 O 1.170435 1.166590 0.000000 H 2.979488 0.258829 0.000000 H 0.498833 -1.107195 0.000000 units angstrom no_reorient """) psi4.set_options({ 'basis': 'cc-pvdz', 'df_basis_scf': 'cc-pvdz-jkfit', 'df_basis_mp2': 'cc-pvdz-ri', # not necessary to specify df_basis* for most basis sets 'scf_type': 'df', 'guess': 'sad', 'd_convergence': 11, }) e_cp = psi4.energy('mp2', bsse_type='cp') assert psi4.compare_values(Enuc, formic_dim.nuclear_repulsion_energy(), 7, "Nuclear Repulsion Energy") assert psi4.compare_values(Ecp, e_cp, 5, "CP Corrected cc-pVDZ/cc-pVDZ-RI DFMP2")
def test_snsmp2(): """snsmp2/he-he""" HeHe = psi4.geometry(""" 0 1 He 0 0 0 -- He 2 0 0 """) e = psi4.energy('sns-mp2') assert psi4.compare_values(0.00176708227, psi4.variable('SNS-MP2 TOTAL ENERGY'), 5, "SNS-MP2 IE [Eh]")
def test_psi4_basic(): """tu1-h2o-energy""" #! Sample HF/cc-pVDZ H2O computation h2o = psi4.geometry(""" O H 1 0.96 H 1 0.96 2 104.5 """) psi4.set_options({'basis': "cc-pVDZ"}) psi4.energy('scf') assert psi4.compare_values(-76.0266327341067125, psi4.get_variable('SCF TOTAL ENERGY'), 6, 'SCF energy')
def test_psi4_sapt(): """sapt1""" #! SAPT0 cc-pVDZ computation of the ethene-ethyne interaction energy, using the cc-pVDZ-JKFIT RI basis for SCF #! and cc-pVDZ-RI for SAPT. Monomer geometries are specified using Cartesian coordinates. Eref = [ 85.189064196429101, -0.00359915058, 0.00362911158, -0.00083137117, -0.00150542374, -0.00230683391 ] ethene_ethyne = psi4.geometry(""" 0 1 C 0.000000 -0.667578 -2.124659 C 0.000000 0.667578 -2.124659 H 0.923621 -1.232253 -2.126185 H -0.923621 -1.232253 -2.126185 H -0.923621 1.232253 -2.126185 H 0.923621 1.232253 -2.126185 -- 0 1 C 0.000000 0.000000 2.900503 C 0.000000 0.000000 1.693240 H 0.000000 0.000000 0.627352 H 0.000000 0.000000 3.963929 units angstrom """) # this molecule will crash test if molecule passing broken barrier = psi4.geometry(""" 0 1 He """) psi4.set_options({ "basis": "cc-pvdz", "guess": "sad", "scf_type": "df", "sad_print": 2, "d_convergence": 11, "puream": True, "print": 1}) psi4.energy('sapt0', molecule=ethene_ethyne) Eelst = psi4.get_variable("SAPT ELST ENERGY") Eexch = psi4.get_variable("SAPT EXCH ENERGY") Eind = psi4.get_variable("SAPT IND ENERGY") Edisp = psi4.get_variable("SAPT DISP ENERGY") ET = psi4.get_variable("SAPT0 TOTAL ENERGY") assert psi4.compare_values(Eref[0], ethene_ethyne.nuclear_repulsion_energy(), 9, "Nuclear Repulsion Energy") assert psi4.compare_values(Eref[1], Eelst, 6, "SAPT0 Eelst") assert psi4.compare_values(Eref[2], Eexch, 6, "SAPT0 Eexch") assert psi4.compare_values(Eref[3], Eind, 6, "SAPT0 Eind") assert psi4.compare_values(Eref[4], Edisp, 6, "SAPT0 Edisp") assert psi4.compare_values(Eref[5], ET, 6, "SAPT0 Etotal")
def test_chemps2(): """chemps2/scf-n2""" #! dmrg-scf on N2 N2 = psi4.geometry(""" N 0.0000 0.0000 0.0000 N 0.0000 0.0000 2.1180 units au """) psi4.set_options({ 'basis': 'cc-pVDZ', 'reference': 'rhf', 'e_convergence': 1e-12, 'd_convergence': 1e-12, 'dmrg_irrep': 0, 'dmrg_multiplicity': 1, 'restricted_docc': [ 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 ], 'active': [ 2 , 0 , 1 , 1 , 0 , 2 , 1 , 1 ], 'dmrg_sweep_states': [ 500, 1000, 1000 ], 'dmrg_sweep_energy_conv': [ 1e-10, 1e-10, 1e-10 ], 'dmrg_sweep_dvdson_rtol': [ 1e-4, 1e-6, 1e-8 ], 'dmrg_sweep_max_sweeps': [ 5, 5, 10 ], 'dmrg_sweep_noise_prefac': [ 0.05, 0.05, 0.0 ], 'dmrg_print_corr': True, 'dmrg_mps_write': False, 'dmrg_unitary_write': True, 'dmrg_diis': True, 'dmrg_scf_diis_thr': 1e-2, 'dmrg_diis_write': True, 'dmrg_excitation': 0, # Ground state 'dmrg_scf_state_avg': False, 'dmrg_scf_active_space': 'NO', # INPUT; NO; LOC 'dmrg_local_init': False, }) psi4.energy("dmrg-scf") ref_energy = -109.1035023353 assert psi4.compare_values(ref_energy, psi4.variable("CURRENT ENERGY"), 6, "DMRG Energy")
def test_dkh(): """dkh/molpro-2order""" Ne = psi4.geometry(""" 0 1 Ne """) psi4.set_options({ 'reference': 'rhf', 'basis': 'cc-pvtz-dk', 'relativistic': 'dkh', 'dkh_order': 2, 'print': 2, 'scf_type': 'pk'}) e = psi4.energy('scf') assert psi4.compare_values(-128.66891610, e, 6, '2nd order vs Molpro')
def test_fcidump_scf_energy(): """Compare FCIDUMP computed SCF energy against call to energy()""" Ne = psi4.geometry(""" Ne 0 0 0 """) psi4.set_options({'basis': 'cc-pVDZ', 'scf_type': 'pk', 'reference': 'uhf', 'd_convergence': 1e-8, 'e_convergence': 1e-8 }) scf_e, scf_wfn = psi4.energy('scf', return_wfn=True) psi4.fcidump(scf_wfn, fname='FCIDUMP_SCF', oe_ints=['EIGENVALUES']) intdump = psi4.fcidump_from_file('FCIDUMP_SCF') e_dict = psi4.energies_from_fcidump(intdump) fcidump_e = e_dict['SCF TOTAL ENERGY'] assert psi4.compare_values(scf_e, fcidump_e, 5, 'SCF energy') #TEST
dRMS = 0.5 * (np.mean(diisa_e**2)**0.5 + np.mean(diisb_e**2)**0.5) print('SCF Iteration %3d: Energy = %4.16f dE = % 1.5E dRMS = %1.5E' % (SCF_ITER, SCF_E, (SCF_E - Eold), dRMS)) if (abs(SCF_E - Eold) < E_conv) and (dRMS < D_conv): break Eold = SCF_E Fa = diisa.extrapolate() Fb = diisb.extrapolate() # Diagonalize Fock matrix Ca, Da = diag_H(Fa, nalpha) Cb, Db = diag_H(Fb, nbeta) if SCF_ITER == maxiter: clean() raise Exception("Maximum number of SCF cycles exceeded.") print('Total time for SCF iterations: %.3f seconds \n' % (time.time() - t)) spin_mat = (Cb[:, :nbeta].T).dot(S).dot(Ca[:, :nalpha]) spin_contam = min(nalpha, nbeta) - np.vdot(spin_mat, spin_mat) print('Spin Contamination Metric: %1.5E\n' % spin_contam) print('Final SCF energy: %.8f hartree' % SCF_E) # Compare to Psi4 SCF_E_psi = psi4.energy('SCF') psi4.compare_values(SCF_E_psi, SCF_E, 6, 'SCF Energy')
0.0, -0.043039786289375104, 0.02979887048056895, 0.0, 0.043039786289375104, 0.02979887048056895 ] expected_properties = { "calcinfo_nbasis": 24, "calcinfo_nmo": 24, "calcinfo_nalpha": 5, "calcinfo_nbeta": 5, "calcinfo_natom": 3, "scf_one_electron_energy": -122.4452968291507, "scf_two_electron_energy": 37.62243738251799, "nuclear_repulsion_energy": 8.80146206062943, "scf_total_energy": -76.02139738600329, "return_energy": -76.02139738600329 } json_ret = psi4.json_wrapper.run_json(json_data) with open("output.json", "w") as ofile: json.dump(json_ret, ofile, indent=2) psi4.compare_integers(True, json_ret["success"], "JSON Success") #TEST psi4.compare_arrays(expected_return_result, json_ret["return_result"], 5, "Return Value") #TEST for k in expected_properties.keys(): #TEST psi4.compare_values(expected_properties[k], json_ret["properties"][k], 5, k.upper()) #TEST
psi4.set_options({"REFERENCE" : "RHF", "MAX_ENERGY_G_CONVERGENCE" : 8, "BASIS" : "STO-3G", "DF_BASIS_SCF" : "CC-PVDZ-RI"}) psi4.optimize('scf') psi4.set_options({"REFERENCE" : "RHF", "BASIS" : "CC-PVDZ", "DF_BASIS_SCF" : "CC-PVDZ-JKFIT"}) e_sing_rhf = psi4.energy('scf') benz.set_multiplicity(3) psi4.set_options({"REFERENCE" : "ROHF"}) e_trip_rohf = psi4.energy('scf') psi4.set_options({"REFERENCE" : "UHF"}) e_trip_uhf = psi4.energy('scf') vertical_uhf = hartree2ev * (e_trip_uhf - e_sing_rhf) vertical_rohf = hartree2ev * (e_trip_rohf - e_sing_rhf) psi4.core.print_out("\nSinglet-Triplet gap (vertical, UHF) = %8.2f eV\n" % vertical_uhf) psi4.core.print_out("\nSinglet-Triplet gap (vertical, ROHF) = %8.2f eV\n" % vertical_rohf) enuc = 204.531600152395043 #TEST erhf = -230.72190557842444 #TEST psi4.compare_values(enuc, benz.nuclear_repulsion_energy(), 3, "Nuclear repulsion energy") #TEST psi4.compare_values(erhf, e_sing_rhf, 6, "Singlet benzene RHF energy") #TEST
def test_psi4_scfproperty(): """scf-property""" #! UFH and B3LYP cc-pVQZ properties for the CH2 molecule. with open('grid.dat', 'w') as handle: handle.write("""\ 0.0 0.0 0.0 1.1 1.3 1.4 """) ch2 = psi4.geometry(""" 0 3 c h 1 b1 h 1 b1 2 a1 b1 = 1.0 a1 = 125.0 """) # Get a reasonable guess, to save some iterations psi4.set_options({ "scf_type": "pk", "basis": "6-31G**", "e_convergence": 8, "docc": [2, 0, 0, 1], "socc": [1, 0, 1, 0], "reference": "uhf"}) ch2.update_geometry() assert psi4.compare_values(6.648418918908746, ch2.nuclear_repulsion_energy(), 9, "Nuclear repulsion energy") props = ['DIPOLE', 'QUADRUPOLE', 'MULLIKEN_CHARGES', 'LOWDIN_CHARGES', 'WIBERG_LOWDIN_INDICES', 'MAYER_INDICES', 'MAYER_INDICES', 'MO_EXTENTS', 'GRID_FIELD', 'GRID_ESP', 'ESP_AT_NUCLEI', 'MULTIPOLE(5)', 'NO_OCCUPATIONS'] psi4.properties('scf', properties=props) assert psi4.compare_values(psi4.get_variable("CURRENT ENERGY"), -38.91591819679808, 6, "SCF energy") assert psi4.compare_values(psi4.get_variable('SCF DIPOLE X'), 0.000000000000, 4, "SCF DIPOLE X") assert psi4.compare_values(psi4.get_variable('SCF DIPOLE Y'), 0.000000000000, 4, "SCF DIPOLE Y") assert psi4.compare_values(psi4.get_variable('SCF DIPOLE Z'), 0.572697798348, 4, "SCF DIPOLE Z") assert psi4.compare_values(psi4.get_variable('SCF QUADRUPOLE XX'), -7.664066833060, 4, "SCF QUADRUPOLE XX") assert psi4.compare_values(psi4.get_variable('SCF QUADRUPOLE YY'), -6.097755074075, 4, "SCF QUADRUPOLE YY") assert psi4.compare_values(psi4.get_variable('SCF QUADRUPOLE ZZ'), -7.074596012050, 4, "SCF QUADRUPOLE ZZ") assert psi4.compare_values(psi4.get_variable('SCF QUADRUPOLE XY'), 0.000000000000, 4, "SCF QUADRUPOLE XY") assert psi4.compare_values(psi4.get_variable('SCF QUADRUPOLE XZ'), 0.000000000000, 4, "SCF QUADRUPOLE XZ") assert psi4.compare_values(psi4.get_variable('SCF QUADRUPOLE YZ'), 0.000000000000, 4, "SCF QUADRUPOLE YZ") psi4.properties('B3LYP', properties=props) assert psi4.compare_values(psi4.get_variable('CURRENT ENERGY'), -39.14134740550916, 6, "B3LYP energy") assert psi4.compare_values(psi4.get_variable('B3LYP DIPOLE X'), 0.000000000000, 4, "B3LYP DIPOLE X") assert psi4.compare_values(psi4.get_variable('B3LYP DIPOLE Y'), -0.000000000000, 4, "B3LYP DIPOLE Y") assert psi4.compare_values(psi4.get_variable('B3LYP DIPOLE Z'), 0.641741521158, 4, "B3LYP DIPOLE Z") assert psi4.compare_values(psi4.get_variable('B3LYP QUADRUPOLE XX'), -7.616483183211, 4, "B3LYP QUADRUPOLE XX") assert psi4.compare_values(psi4.get_variable('B3LYP QUADRUPOLE YY'), -6.005896804551, 4, "B3LYP QUADRUPOLE YY") assert psi4.compare_values(psi4.get_variable('B3LYP QUADRUPOLE ZZ'), -7.021817489904, 4, "B3LYP QUADRUPOLE ZZ") assert psi4.compare_values(psi4.get_variable('B3LYP QUADRUPOLE XY'), 0.000000000000, 4, "B3LYP QUADRUPOLE XY") assert psi4.compare_values(psi4.get_variable('B3LYP QUADRUPOLE XZ'), 0.000000000000, 4, "B3LYP QUADRUPOLE XZ") assert psi4.compare_values(psi4.get_variable('B3LYP QUADRUPOLE YZ'), -0.000000000000, 4, "B3LYP QUADRUPOLE YZ")
"mp2_same_spin_correlation_energy": -0.05202760538221721, "mp2_opposite_spin_correlation_energy": -0.1548891108392641, "mp2_singles_energy": 0.0, "mp2_doubles_energy": -0.20691671622148142, "mp2_total_correlation_energy": -0.20691671622148142, "mp2_total_energy": -76.22831410222477, "return_energy": expected_return_result } json_ret = psi4.json_wrapper.run_json(json_data) with open("output.json", "w") as ofile: #TEST json.dump(json_ret, ofile, indent=2) #TEST psi4.compare_integers(True, json_ret["success"], "JSON Success") #TEST psi4.compare_values(expected_return_result, json_ret["return_result"], 5, "Return Value") #TEST psi4.compare_integers(True, "MAYER_INDICES" in json_ret["psi4:qcvars"], "Mayer Indices Found") #TEST for k in expected_properties.keys(): #TEST psi4.compare_values(expected_properties[k], json_ret["properties"][k], 5, k.upper()) #TEST # Expected output with exact MP2 expected_return_result = -76.2283674281634 expected_properties = { "calcinfo_nbasis": 24, "calcinfo_nmo": 24, "calcinfo_nalpha": 5, "calcinfo_nbeta": 5, "calcinfo_natom": 3, "scf_one_electron_energy": -122.44534537436829, "scf_two_electron_energy": 37.62246494646352,
print("\t\t%s\t %s\t %s\n" % (cart[0], cart[1], cart[2])) for a in range(0, 3): print(" %s %20.10lf %20.10lf %20.10lf\n" % (cart[a], optrot_vg_0[3 * a + 0], optrot_vg_0[3 * a + 1], optrot_vg_0[3 * a + 2])) specific_rotation_mvg = prefactor * rmvg_au / Mass print( "Specific rotation @ %d nm (Modified Velocity Gauge): %10.5lf deg/[dm (g/cm^3)]" % (omega_nm, specific_rotation_mvg)) """# Comaprison with PSI4 (if you have near to latest version of psi4) psi4.set_options({'d_convergence': 1e-10, 'e_convergence': 1e-10, 'r_convergence': 1e-10, 'omega': [589, 'nm'], 'gauge': 'both'}) psi4.properties('ccsd', properties=['rotation']) psi4.compare_values(specific_rotation_lg, psi4.get_variable("CCSD SPECIFIC ROTATION (LEN) @ 589NM"), \ 5, "CCSD SPECIFIC ROTATION (LENGTH GAUGE) 589 nm") #TEST psi4.compare_values(specific_rotation_mvg, psi4.get_variable("CCSD SPECIFIC ROTATION (MVG) @ 589NM"), \ 5, "CCSD SPECIFIC ROTATION (MODIFIED VELOCITY GAUGE) 589 nm") #TEST """ psi4.compare_values(specific_rotation_lg, 7.03123, 5, "CCSD SPECIFIC ROTATION (LENGTH GAUGE) 589 nm") #TEST psi4.compare_values( specific_rotation_mvg, -81.44742, 5, "CCSD SPECIFIC ROTATION (MODIFIED VELOCITY GAUGE) 589 nm") #TEST
# SCF energy and update FH = F.clone() FH.add(H) SCF_E = FH.vector_dot(D) + Enuc dRMS = diis_e.rms() psi4.core.print_out('SCF Iteration %3d: Energy = %4.16f dE = % 1.5E dRMS = %1.5E\n' % (SCF_ITER, SCF_E, (SCF_E - Eold), dRMS)) if (abs(SCF_E - Eold) < E_conv) and (dRMS < D_conv): break Eold = SCF_E # DIIS extrapolate F = diis_obj.extrapolate() # Diagonalize Fock matrix C, Cocc, D = build_orbitals(F) if SCF_ITER == maxiter: psi4.clean() raise Exception("Maximum number of SCF cycles exceeded.\n") psi4.core.print_out('Total time for SCF iterations: %.3f seconds \n\n' % (time.time() - t)) #print(psi4.energy("SCF")) psi4.core.print_out('Final SCF energy: %.8f hartree\n' % SCF_E) psi4.compare_values(-76.0033389840197202, SCF_E, 6, 'SCF Energy')
eocc = eps[:nocc] evir = eps[nocc:] epsilon = 1/(eocc.reshape(-1, 1, 1, 1) + eocc.reshape(-1, 1, 1) - evir.reshape(-1, 1) - evir) # Create occupied and virtual slices o = slice(0, nocc) v = slice(nocc, MO.shape[0]) # MP2 Correlation: [Szabo:1996] pp. 352, Eqn 6.72 MP2corr_E = 0.25 * np.einsum('abrs,rsab,abrs', MO[o, o, v, v], MO[v, v, o, o], epsilon) MP2total_E = SCF_E + MP2corr_E print('MP2 correlation energy: %16.10f' % MP2corr_E) print('MP2 total energy: %16.10f' % MP2total_E) # Compare to Psi4 psi4.compare_values(psi4.energy('MP2'), MP2total_E, 6, 'MP2 Energy') # MP3 Correlation: [Szabo:1996] pp. 353, Eqn. 6.75 eqn1 = 0.125 * np.einsum('abrs,cdab,rscd,abrs,cdrs->', MO[o, o, v, v], MO[o, o, o, o], MO[v, v, o, o], epsilon, epsilon) eqn2 = 0.125 * np.einsum('abrs,rstu,tuab,abrs,abtu', MO[o, o, v, v], MO[v, v, v, v], MO[v, v, o, o], epsilon, epsilon) eqn3 = np.einsum('abrs,cstb,rtac,absr,acrt', MO[o, o, v, v], MO[o, v, v, o], MO[v, v, o, o], epsilon, epsilon) MP3corr_E = eqn1 + eqn2 + eqn3 MP3total_E = MP2total_E + MP3corr_E print('\nMP3 correlation energy: %16.10f' % MP3corr_E) print('MP3 total energy: %16.10f' % MP3total_E) # Compare to Psi4 psi4.compare_values(psi4.energy('MP3'), MP3total_E, 6, 'MP3 Energy')
ret = [] cnt = 0 for act, mat in zip(active_mask, matrices): if act: ret.append(Hx_vec[cnt]) cnt += 1 else: ret.append(False) return ret # Solve ret, resid = psi4.p4util.solvers.cg_solver(dipoles_xyz, wrap_Hx, precon_func, rcond=1.e-6) polar = np.empty((3, 3)) for numx in range(3): for numf in range(3): polar[numx, numf] = -1 * ret[numx].vector_dot(dipoles_xyz[numf]) psi4.core.print_out("\n " + "CPHF Dipole Polarizability:".center(44) + "\n"); tops = ("X", "Y", "Z") psi4.core.print_out(" %12s %12s %12s\n" % tops); for n, p in enumerate(tops): psi4.core.print_out(" %3s %12.4f %12.4f %12.4f\n" % (p, polar[n][0], polar[n][1], polar[n][2])); psi4.core.print_out("\n") psi4.compare_values(8.01554, polar[0][0], 3, 'Dipole XX Polarizability') # TEST psi4.compare_values(12.50363, polar[1][1], 3, 'Dipole YY Polarizability') # TEST psi4.compare_values(10.04161, polar[2][2], 3, 'Dipole ZZ Polarizability') # TEST
P 4 1.00 34.8564630000 0.0156480000 7.8431310000 0.0981970000 2.3062490000 0.3077680000 0.7231640000 0.4924700000 P 1 1.00 0.2148820000 1.0000000000 P 1 1.00 0.0638500000 1.0000000000 D 2 1.00 2.3062000000 0.2027000000 0.7232000000 0.5791000000 D 2 1.00 0.2149000000 0.7854500000 0.0639000000 0.5338700000 **** """) ccsd_e, wfn = psi4.properties('ccsd',properties=['dipole'],return_wfn=True) psi4.oeprop(wfn,"DIPOLE", "QUADRUPOLE", title="(OEPROP)CC") psi4.compare_values(psi4.variable("(OEPROP)CC DIPOLE X"), 0.000000000000,6,"CC DIPOLE X") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC DIPOLE Y"), 0.000000000000,6,"CC DIPOLE Y") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC DIPOLE Z"),-1.840334899884,6,"CC DIPOLE Z") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC QUADRUPOLE XX"),-7.864006962064,6,"CC QUADRUPOLE XX") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC QUADRUPOLE XY"), 0.000000000000,6,"CC QUADRUPOLE XY") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC QUADRUPOLE XZ"), 0.000000000000,6,"CC QUADRUPOLE XZ") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC QUADRUPOLE YY"),-4.537386915305,6,"CC QUADRUPOLE YY") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC QUADRUPOLE YZ"), 0.000000000000,6,"CC QUADRUPOLE YZ") #TEST psi4.compare_values(psi4.variable("(OEPROP)CC QUADRUPOLE ZZ"),-6.325836255265,6,"CC QUADRUPOLE ZZ") #TEST psi4.core.print_variables()