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_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.variable("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_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.1890645313, -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", "df_basis_elst": "cc-pvdz-ri", "guess": "sad", "scf_type": "df", "sad_print": 2, "d_convergence": 11, "puream": True, "print": 1 }) psi4.energy('sapt0', molecule=ethene_ethyne) Eelst = psi4.variable("SAPT ELST ENERGY") Eexch = psi4.variable("SAPT EXCH ENERGY") Eind = psi4.variable("SAPT IND ENERGY") Edisp = psi4.variable("SAPT DISP ENERGY") ET = psi4.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_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_cancelled_qcvars(): err_substr = "no direct replacement" with pytest.raises(psi4.UpgradeHelper) as e: psi4.variable("scsn-mp2 same-spin correlation energy") assert err_substr in str(e.value)
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_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.1890645313, -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.variable("SAPT ELST ENERGY") Eexch = psi4.variable("SAPT EXCH ENERGY") Eind = psi4.variable("SAPT IND ENERGY") Edisp = psi4.variable("SAPT DISP ENERGY") ET = psi4.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_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', { '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 * 0.52917721067 / 0.52917720859 refscf = -103.04337420425350 refv2rdm = -103.086205379481 psi4.energy('v2rdm-casscf', molecule=n2) assert psi4.compare_values(refscf, psi4.variable("SCF TOTAL ENERGY"), 8, "SCF total energy") assert psi4.compare_values(refv2rdm, psi4.variable("CURRENT ENERGY"), 5, "v2RDM-CASSCF total 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', { '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 * 0.52917721067 / 0.52917720859 refscf = -103.04337420425350 refv2rdm = -103.086205379481 psi4.energy('v2rdm-casscf', molecule=n2) assert psi4.compare_values(refscf, psi4.variable("SCF TOTAL ENERGY"), 8, "SCF total energy") assert psi4.compare_values(refv2rdm, psi4.variable("CURRENT ENERGY"), 5, "v2RDM-CASSCF total energy")
def test_renamed_qcvars(): psi4.set_variable("SCS(N)-MP2 TOTAL ENERGY", 3.3) with pytest.warns(FutureWarning) as e: ans = psi4.variable("SCSN-MP2 TOTAL ENERGY") assert ans == 3.3
def test_dft_block_scheme_distantpoints(): """Test removal of distant grid points. all DFT_BLOCK_SCHEME should give same results and number of grid points.""" mol = psi4.geometry( """ 0 1 O -1.551007 -0.114520 0.000000 H -1.934259 0.762503 0.000000 H -0.599677 0.040712 0.000000 no_com no_reorient symmetry c1 """ ) psi4.set_options( { "BASIS": "sto-3g", "maxiter": 1, "FAIL_ON_MAXITER": False, "DFT_PRUNING_SCHEME": "ROBUST", "DFT_WEIGHTS_TOLERANCE": -1.0, } ) ref = {"True": 45929, "False": 46890} YESNO = [True,False] SCHEMES = ["OCTREE", "NAIVE", "ATOMIC"] for YN in YESNO: psi4.set_options({"DFT_REMOVE_DISTANT_POINTS":YN}) for S in SCHEMES: psi4.set_options({"DFT_BLOCK_SCHEME": S}) e, wfn = psi4.energy("pbe", return_wfn=True) P = psi4.variable("XC GRID TOTAL POINTS") XC = wfn.variable("DFT XC ENERGY") assert psi4.compare_integers(ref[f"{YN}"], P, f" scheme={S}; distant points={YN} ")
def test_dft_block_schemes(scheme): """all DFT_BLOCK_SCHEME should give same results and number of grid points. Water dimer with ghost atoms""" mol = psi4.geometry( """ 0 1 O -1.490196515110 -0.043256842172 0.000000000000 H -1.845932568294 0.844902886698 0.000000000000 H -0.533258283804 0.073267064698 0.000000000000 @O 1.416663724802 0.038738966977 0.000000000000 @H 1.773104797767 -0.423233996755 0.760023878024 @H 1.773104797767 -0.423233996755 -0.760023878024 no_com no_reorient symmetry c1 """ ) psi4.set_options( { "BASIS": "def2-SVPD", "DFT_SPHERICAL_POINTS": 590, "DFT_RADIAL_POINTS": 85, "D_convergence": 1e-8, "DFT_WEIGHTS_TOLERANCE": -1.0, } ) ref = {"XC GRID TOTAL POINTS": 300900, "DFT XC ENERGY": -9.218561399189895} psi4.set_options({"DFT_BLOCK_SCHEME": scheme}) e, wfn = psi4.energy("pbe/def2-SVPD", return_wfn=True) P = psi4.variable("XC GRID TOTAL POINTS") XC = wfn.variable("DFT XC ENERGY") assert psi4.compare_integers(ref["XC GRID TOTAL POINTS"], P, f" {scheme} GRID POINTS:") assert psi4.compare_values(ref["DFT XC ENERGY"], XC, f" {scheme} XC ENERGY:")
def test_v2rdm6(): #! cc-pvdz N2 (6,6) active space Test DQG print(' N2 / cc-pVDZ / DQG(6,6), geometry optimization') import psi4 n2 = psi4.geometry(""" 0 1 n n 1 1.1 """) psi4.set_options({ 'basis': 'cc-pvdz', 'scf_type': 'pk', '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', { 'positivity': 'dqg', #'r_convergence': 1e-7, 'r_convergence': 1e-6, 'e_convergence': 1e-5, 'orbopt_gradient_convergence': 1e-8, 'maxiter': 20000, }) psi4.activate(n2) psi4.optimize('v2rdm-casscf') refnuc = 23.1968666562054260 refscf = -108.95016246035139 refv2rdm = -109.095505119442 assert psi4.compare_values(refnuc, n2.nuclear_repulsion_energy(), 4, "Nuclear repulsion energy") assert psi4.compare_values(refscf, psi4.variable("SCF TOTAL ENERGY"), 5, "SCF total energy") assert psi4.compare_values(refv2rdm, psi4.variable("CURRENT ENERGY"), 4, "v2RDM-CASSCF total energy")
def test_v2rdm(): #! cc-pvdz N2 (6,6) active space Test DQG print(' N2 / cc-pVDZ / DQG(6,6), scf_type = DF, rNN = 1.1 A') import psi4 import sys sys.path.insert(0, '../..') import hilbert n2 = psi4.geometry(""" 0 1 n n 1 r """) psi4.set_options({ 'basis': 'cc-pvdz', 'scf_type': 'df', '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( 'hilbert', { 'positivity': 'dqg', 'r_convergence': 1e-5, 'e_convergence': 1e-6, 'maxiter': 20000, }) psi4.activate(n2) n2.r = 1.1 refscf = -108.95348837831371 refv2rdm = -109.094404909477 psi4.energy('v2rdm-casscf') assert psi4.compare_values(refscf, psi4.variable("SCF TOTAL ENERGY"), 8, "SCF total energy") assert psi4.compare_values(refv2rdm, psi4.variable("CURRENT ENERGY"), 5, "v2RDM-CASSCF total energy")
def test_deprecated_component_dipole(): #with pytest.warns(FutureWarning) as e: psi4.set_variable("current dipole x", 5) with pytest.warns(FutureWarning) as e: ans = psi4.variable("current dipole x") assert ans == 5
def test_v2rdm5(): #! cc-pvdz N2 (6,6) active space Test DQG print(' N2 / cc-pVDZ / DQG+T2(6,6), scf_type = PK, rNN = 1.1 A') import psi4 n2 = psi4.geometry(""" 0 1 n n 1 r """) psi4.set_options({ 'basis': 'cc-pvdz', 'scf_type': 'pk', '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', { 'positivity': 'dqgt2', 'r_convergence': 1e-4, 'e_convergence': 5e-4, 'maxiter': 20000, }) psi4.activate(n2) n2.r = 1.1 refscf = -108.95379624015767 refv2rdm = -109.091487394061 psi4.energy('v2rdm-casscf') assert psi4.compare_values(refscf, psi4.variable("SCF TOTAL ENERGY"), 8, "SCF total energy") assert psi4.compare_values(refv2rdm, psi4.variable("CURRENT ENERGY"), 4, "v2RDM-CASSCF total energy")
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_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_allen_focal_point(): be = psi4.geometry("Be") psi4.energy("allen_focal_point", scf_basis="cc-pV[TQ5]Z", corl_basis="cc-pV[Q5]Z", delta_basis="cc-pV[Q5]Z", delta2_basis="cc-pV[Q5]Z") psi4.core.print_variables() assert compare_values(-14.57305004, psi4.variable("CBS REFERENCE ENERGY"), 7, "scf tq5") #ADD VAR assert compare_values(-0.06148737, psi4.variable("CBS CORL ENERGY"), 7, "corl mp2 q5") assert compare_values(-0.01767880, psi4.variable("CBS DELTA1 TOTAL ENERGY"), 7, "delta1 ccsd q5") assert compare_values(-0.00063008, psi4.variable("CBS DELTA2 TOTAL ENERGY"), 7, "delta2 (t) q5") assert compare_values(-0.00001090, psi4.variable("CBS DELTA3 TOTAL ENERGY"), 7, "delta3 t 3") assert compare_values(-0.00000205, psi4.variable("CBS DELTA4 TOTAL ENERGY"), 7, "delta4 (q) 2") assert compare_values(-14.65285924, psi4.variable("CBS TOTAL ENERGY"), 7, "cbs") assert compare_values(-14.65285924, psi4.variable("CURRENT ENERGY"), 7, "current") assert compare(5, psi4.variable("CBS NUMBER"), "cbs no")
def test_spacious_option(): """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.variable('SCF TOTAL ENERGY'), 6, 'SCF energy')
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.variable('SCF TOTAL ENERGY'), 6, 'SCF energy')
def test_restart_scf_orbital_file(): """wfn serialization""" h2o = psi4.geometry(""" O H 1 0.96 H 1 0.96 2 104.5 """) psi4.set_options({'basis': "cc-pVDZ"}) _, scf_wfn = psi4.energy('scf', return_wfn=True, write_orbitals='my_mos') psi4.core.clean() psi4.set_options({'maxiter': 1}) scf_wfn = psi4.energy('scf', restart_file='my_mos') assert psi4.compare_values(-76.0266327341067125, psi4.variable('SCF TOTAL ENERGY'), 6, 'SCF 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.variable("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 callback(self, pos, **kwargs): """Initialize psi with new positions and calculate force. Arguments: - pos: positions of the atoms as array. """ self.initial_molecule.set_geometry(psi4.core.Matrix.from_array(pos)) self.calculate_gradient(self.LOT, pos=pos, **kwargs) self._potential = psi4.variable('CURRENT ENERGY') self._force = -np.array(self.grd) self._vir = np.array([[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]]) return self._force, np.float64(self._potential)
def test_restart_scf_serial_wfn(): """scf restart from wfn file""" h2o = psi4.geometry(""" O H 1 0.96 H 1 0.96 2 104.5 """) psi4.set_options({'basis': "cc-pVDZ"}) _, scf_wfn = psi4.energy('scf', return_wfn=True) scf_wfn.to_file('pytest_wfn') psi4.core.clean() psi4.set_options({'maxiter': 1}) psi4.energy('scf', restart_file='pytest_wfn') psi4.core.clean() assert psi4.compare_values(-76.0266327341067125, psi4.variable('SCF TOTAL ENERGY'), 6, 'SCF energy')
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 get_grad(self, mol): self.update_coor(mol) g, wfn = psi4.gradient(self.met, return_wfn=True) mol.func += psi4.variable('CURRENT ENERGY') * self._ce g = sum(g.to_array().tolist(), []) qm3.engines.LA_gradient(self.vla, g) for i in range(len(self.sel)): i3 = i * 3 for j in [0, 1, 2]: mol.grad[3 * self.sel[i] + j] += g[i3 + j] * self._cg if (len(self.nbn) > 0): ef = psi4.core.OEProp(wfn) ef.add("GRID_FIELD") ef.compute() efx = ef.Exvals() efy = ef.Eyvals() efz = ef.Ezvals() for i in range(len(self.nbn)): mol.grad[3 * self.nbn[i]] -= self._cg * mol.chrg[ self.nbn[i]] * efx[i] mol.grad[3 * self.nbn[i] + 1] -= self._cg * mol.chrg[self.nbn[i]] * efy[i] mol.grad[3 * self.nbn[i] + 2] -= self._cg * mol.chrg[self.nbn[i]] * efz[i]
_, wfn = psi4.energy('ccsd', return_wfn=True, molecule=Ne) amps = wfn.get_amplitudes() TIjAb = amps['tIjAb'].to_array() TIA = amps['tIA'].to_array() tau_IjAb = TIjAb + np.einsum("ia,jb->ijab", TIA, TIA) mints = psi4.core.MintsHelper(wfn.basisset()) D = mints.mo_eri( wfn.Ca_subset("AO", "OCC"), wfn.Ca_subset("AO", "VIR"), wfn.Ca_subset("AO", "OCC"), wfn.Ca_subset("AO", "VIR")).to_array() D = D.swapaxes(1, 2) RHF_ccsd_corr_e = 2 * np.einsum("ijab,ijab->", tau_IjAb, D) - np.einsum("ijab,ijba->", tau_IjAb, D) psi4.compare_values(RHF_ccsd_corr_e, psi4.variable('CCSD CORRELATION ENERGY'), 8, "RHF CCSD CORRELATION ENERGY") # END RHF psi4.core.clean() # UHF psi4.set_options({ 'basis': 'cc-pvdz', 'freeze_core': 'false', 'reference': 'UHF', }) _, wfn = psi4.energy('ccsd', return_wfn=True, molecule=Ne) amps = wfn.get_amplitudes()
def test_deprecated_component_dipole(): with pytest.raises(psi4.UpgradeHelper) as e: psi4.variable("current dipole x")
R["vv"], t2, optimize=True) r2 += temp + temp.transpose((1, 0, 3, 2)) - temp.transpose( (0, 1, 3, 2)) - temp.transpose((1, 0, 2, 3)) ### One Electron Terms. For canonical orbitals, this will reduce to -t2, after dividing by D temp = -np.einsum("Ii, iJAB -> IJAB", F["oo"], t2, optimize=True) r2 += temp - temp.transpose((1, 0, 2, 3)) temp = +np.einsum("aA, IJaB -> IJAB", F["vv"], t2, optimize=True) r2 += temp - temp.transpose((0, 1, 3, 2)) ### Step t2 += r2 / D t2 = dsd.diis(r2, t2) r_norm = np.linalg.norm(r2) Elccd = 0.5 * np.einsum( "iaq, jbq, ijab", R["ov"], R["ov"], t2, optimize=True) print(f"{i:3d} E={Elccd:3.10f} R = {r_norm:0.8f}") if r_norm < float(f"1e-{target_convergence}"): break else: raise Exception("Equations did not converge.") if compare_psi4: wfn = psi4.energy("lccd", return_wfn=True)[1] # Change to wfn.variable when DFOCC variables are available on the wfn. psi4.compare_values(psi4.variable("CURRENT CORRELATION ENERGY"), Elccd, target_convergence, "LCCD Energy")
AllChem.EmbedMolecule(mol, AllChem.ETKDGv2()) AllChem.UFFOptimizeMolecule(mol) conf = mol.GetConformer(-1) xyz = '0 1' for atom, (x, y, z) in zip(mol.GetAtoms(), conf.GetPositions()): xyz += '\n' xyz += '{}\t{}\t{}\t{}'.format(atom.GetSymbol(), x, y, z) return xyz # 入力する分子(thiacloprid) smiles = 'C1CSC(=NC#N)N1CC2=CN=C(C=C2)Cl' psi4.set_output_file('04_thiacloprid.txt') dinotefuran = psi4.geometry(smi2xyz(smiles)) _, wfn_dtf = psi4.optimize('B3LYP/6-31G*', molecule=dinotefuran, return_wfn=True) rdkit_dinotefuran = Chem.AddHs(Chem.MolFromSmiles(smiles)) ## 双極子モーメントの計算 psi4.oeprop(wfn_dtf, 'DIPOLE', titile='dipole') dipole_x, dipole_y, dipole_z = psi4.variable('SCF DIPOLE X'), psi4.variable( 'SCF DIPOLE Y'), psi4.variable('SCF DIPOLE Z') dipole_moment = np.sqrt(dipole_x**2 + dipole_y**2 + dipole_z**2) #print(round(dipole_moment,3),'D')
def test_psi4_scfproperty(): """scf-property""" #! UFH and B3LYP cc-pVQZ properties for the CH2 molecule. ref_hf_di_au = np.array([0.0, 0.0, 0.22531665104559076]) ref_hf_quad_au = np.array([[-5.69804565317, 0.0, 0.0], [0.0, -4.53353128969, 0.0], [0.0, 0.0, -5.25978856037]]) ref_b3lyp_di_au = np.array([0.0, 0.0, 0.252480541747]) ref_b3lyp_quad_au = np.array([[-5.66266837697, 0.0, 0.0], [0.0, -4.46523692003, 0.0], [0.0, 0.0, -5.22054902407]]) 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.6484189450, 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(-38.91591819679808, psi4.variable("CURRENT ENERGY"), 6, "SCF energy") assert psi4.compare_values(ref_hf_di_au, psi4.variable('SCF DIPOLE'), 4, "SCF DIPOLE") assert psi4.compare_values(ref_hf_quad_au, psi4.variable('SCF QUADRUPOLE'), 4, "SCF QUADRUPOLE") psi4.properties('B3LYP', properties=props) assert psi4.compare_values(psi4.variable('CURRENT ENERGY'), -39.14134740550916, 6, "B3LYP energy") assert psi4.compare_values(ref_b3lyp_di_au, psi4.variable('B3LYP DIPOLE'), 4, "B3LYP DIPOLE") assert psi4.compare_values(ref_b3lyp_quad_au, psi4.variable('B3LYP QUADRUPOLE'), 4, "B3LYP QUADRUPOLE")
1.0042710000 1.0000000000 S 1 1.00 0.3006860000 1.0000000000 S 1 1.00 0.0900300000 1.0000000000 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(ref_di_au, psi4.variable('(OEPROP)CC DIPOLE'), 4, "CC DIPOLE") #TEST psi4.compare_values(ref_quad_au, psi4.variable('(OEPROP)CC QUADRUPOLE'), 4, "CC QUADRUPOLE") #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.6484189450, 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.variable("CURRENT ENERGY"), -38.91591819679808, 6, "SCF energy") assert psi4.compare_values(psi4.variable('SCF DIPOLE X'), 0.000000000000, 4, "SCF DIPOLE X") assert psi4.compare_values(psi4.variable('SCF DIPOLE Y'), 0.000000000000, 4, "SCF DIPOLE Y") assert psi4.compare_values(psi4.variable('SCF DIPOLE Z'), 0.572697798348, 4, "SCF DIPOLE Z") assert psi4.compare_values(psi4.variable('SCF QUADRUPOLE XX'), -7.664066833060, 4, "SCF QUADRUPOLE XX") assert psi4.compare_values(psi4.variable('SCF QUADRUPOLE YY'), -6.097755074075, 4, "SCF QUADRUPOLE YY") assert psi4.compare_values(psi4.variable('SCF QUADRUPOLE ZZ'), -7.074596012050, 4, "SCF QUADRUPOLE ZZ") assert psi4.compare_values(psi4.variable('SCF QUADRUPOLE XY'), 0.000000000000, 4, "SCF QUADRUPOLE XY") assert psi4.compare_values(psi4.variable('SCF QUADRUPOLE XZ'), 0.000000000000, 4, "SCF QUADRUPOLE XZ") assert psi4.compare_values(psi4.variable('SCF QUADRUPOLE YZ'), 0.000000000000, 4, "SCF QUADRUPOLE YZ") psi4.properties('B3LYP', properties=props) assert psi4.compare_values(psi4.variable('CURRENT ENERGY'), -39.14134740550916, 6, "B3LYP energy") assert psi4.compare_values(psi4.variable('B3LYP DIPOLE X'), 0.000000000000, 4, "B3LYP DIPOLE X") assert psi4.compare_values(psi4.variable('B3LYP DIPOLE Y'), -0.000000000000, 4, "B3LYP DIPOLE Y") assert psi4.compare_values(psi4.variable('B3LYP DIPOLE Z'), 0.641741521158, 4, "B3LYP DIPOLE Z") assert psi4.compare_values(psi4.variable('B3LYP QUADRUPOLE XX'), -7.616483183211, 4, "B3LYP QUADRUPOLE XX") assert psi4.compare_values(psi4.variable('B3LYP QUADRUPOLE YY'), -6.005896804551, 4, "B3LYP QUADRUPOLE YY") assert psi4.compare_values(psi4.variable('B3LYP QUADRUPOLE ZZ'), -7.021817489904, 4, "B3LYP QUADRUPOLE ZZ") assert psi4.compare_values(psi4.variable('B3LYP QUADRUPOLE XY'), 0.000000000000, 4, "B3LYP QUADRUPOLE XY") assert psi4.compare_values(psi4.variable('B3LYP QUADRUPOLE XZ'), 0.000000000000, 4, "B3LYP QUADRUPOLE XZ") assert psi4.compare_values(psi4.variable('B3LYP QUADRUPOLE YZ'), -0.000000000000, 4, "B3LYP QUADRUPOLE YZ")
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.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.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.variable("PCM POLARIZATION ENERGY"), 6, "Polarization energy (PCM, separate algorithm)") psi4.set_options({'pcm_scf_type': 'total', 'reference': 'rohf'}) print('ROHF-PCM, total algorithm') energy_scf4 = psi4.energy('scf') assert psi4.compare_values(totalenergy, energy_scf4, 10, "Total energy (PCM, separate algorithm)") #TEST assert psi4.compare_values( polenergy, psi4.variable("PCM POLARIZATION ENERGY"), 6, "Polarization energy (PCM, separate algorithm)") #TEST
def test_dftd3(): """dftd3/energy""" #! Exercises the various DFT-D corrections, both through python directly and through c++ ref_d2 = [-0.00390110, -0.00165271, -0.00058118] ref_d3zero = [-0.00285088, -0.00084340, -0.00031923] ref_d3bj = [-0.00784595, -0.00394347, -0.00226683] ref_pbe_d2 = [-0.00278650, -0.00118051, -0.00041513] ref_pbe_d3zero = [-0.00175474, -0.00045421, -0.00016839] ref_pbe_d3bj = [-0.00475937, -0.00235265, -0.00131239] 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 """) print(' -D correction from Py-side') eneyne.update_geometry() E, G = eneyne.run_dftd3('b3lyp', 'd2') assert psi4.compare_values(ref_d2[0], E, 7, 'Ethene-Ethyne -D2') mA = eneyne.extract_subsets(1) E, G = mA.run_dftd3('b3lyp', 'd2') assert psi4.compare_values(ref_d2[1], E, 7, 'Ethene -D2') mB = eneyne.extract_subsets(2) E, G = mB.run_dftd3('b3lyp', 'd2') assert psi4.compare_values(ref_d2[2], E, 7, 'Ethyne -D2') #mBcp = eneyne.extract_subsets(2,1) #E, G = mBcp.run_dftd3('b3lyp', 'd2') #compare_values(ref_d2[2], E, 7, 'Ethyne(CP) -D2') E, G = eneyne.run_dftd3('b3lyp', 'd3zero') assert psi4.compare_values(ref_d3zero[0], E, 7, 'Ethene-Ethyne -D3 (zero)') mA = eneyne.extract_subsets(1) E, G = mA.run_dftd3('b3lyp', 'd3zero') assert psi4.compare_values(ref_d3zero[1], E, 7, 'Ethene -D3 (zero)') mB = eneyne.extract_subsets(2) E, G = mB.run_dftd3('b3lyp', 'd3zero') assert psi4.compare_values(ref_d3zero[2], E, 7, 'Ethyne -D3 (zero)') E, G = eneyne.run_dftd3('b3lyp', 'd3bj') assert psi4.compare_values(ref_d3bj[0], E, 7, 'Ethene-Ethyne -D3 (bj)') mA = eneyne.extract_subsets(1) E, G = mA.run_dftd3('b3lyp', 'd3bj') assert psi4.compare_values(ref_d3bj[1], E, 7, 'Ethene -D3 (bj)') mB = eneyne.extract_subsets(2) E, G = mB.run_dftd3('b3lyp', 'd3bj') assert psi4.compare_values(ref_d3bj[2], E, 7, 'Ethyne -D3 (bj)') E, G = eneyne.run_dftd3('b3lyp', 'd3') assert psi4.compare_values(ref_d3zero[0], E, 7, 'Ethene-Ethyne -D3 (alias)') E, G = eneyne.run_dftd3('b3lyp', 'd') assert psi4.compare_values(ref_d2[0], E, 7, 'Ethene-Ethyne -D (alias)') E, G = eneyne.run_dftd3('b3lyp', 'd2') assert psi4.compare_values(ref_d2[0], E, 7, 'Ethene-Ethyne -D2 (alias)') psi4.set_options({'basis': 'sto-3g', 'scf_type': 'df', 'dft_radial_points': 50, # use really bad grid for speed since all we want is the -D value 'dft_spherical_points': 110, #'scf print': 3, # will print dftd3 program output to psi4 output file }) print(' -D correction from C-side') psi4.activate(mA) #psi4.energy('b3lyp-d2', engine='libdisp') #assert psi4.compare_values(ref_d2[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D2 (calling psi4 Disp class)') #psi4.energy('b3lyp-d2') #assert psi4.compare_values(ref_d2[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D2 (calling dftd3 -old)') #psi4.energy('b3lyp-d3zero') #assert psi4.compare_values(ref_d3zero[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (calling dftd3 -zero)') psi4.energy('b3lyp-d3bj') assert psi4.compare_values(ref_d3bj[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (calling dftd3 -bj)') psi4.energy('b3lyp-d2', engine='libdisp') assert psi4.compare_values(ref_d2[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D2 (alias)') #psi4.energy('b3lyp-d3') #assert psi4.compare_values(ref_d3zero[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (alias)') #psi4.energy('b3lyp-d') #assert psi4.compare_values(ref_d2[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D (alias)') psi4.energy('wb97x-d') assert psi4.compare_values(-0.000834247063, psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene wb97x-d (chg)') print(' non-default -D correction from C-side') psi4.activate(mB) #psi4.set_options({'dft_dispersion_parameters': [0.75]}) #psi4.energy('b3lyp-d2', engine='libdisp') #assert psi4.compare_values(ref_pbe_d2[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D2 (calling psi4 Disp class)') #psi4.set_options({'dft_dispersion_parameters': [0.75, 20.0]}) #psi4.energy('b3lyp-d2') #assert psi4.compare_values(ref_pbe_d2[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D2 (calling dftd3 -old)') #psi4.set_options({'dft_dispersion_parameters': [1.0, 0.722, 1.217, 14.0]}) #psi4.energy('b3lyp-d3zero') #assert psi4.compare_values(ref_pbe_d3zero[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (calling dftd3 -zero)') psi4.set_options({'dft_dispersion_parameters': [1.000, 0.7875, 0.4289, 4.4407]}) psi4.energy('b3lyp-d3bj') assert psi4.compare_values(ref_pbe_d3bj[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (calling dftd3 -bj)') psi4.set_options({'dft_dispersion_parameters': [0.75]}) psi4.energy('b3lyp-d2', engine='dftd3') assert psi4.compare_values(ref_pbe_d2[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D2 (alias)') psi4.set_options({'dft_dispersion_parameters': [1.0, 0.722, 1.217, 14.0]}) psi4.energy('b3lyp-d3') assert psi4.compare_values(ref_pbe_d3zero[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (alias)') psi4.set_options({'dft_dispersion_parameters': [0.75]}) psi4.energy('b3lyp-d') assert psi4.compare_values(ref_pbe_d2[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D (alias)') psi4.activate(mA) psi4.set_options({'dft_dispersion_parameters': [1.0]}) psi4.energy('wb97x-d') assert psi4.compare_values(-0.000834247063, psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene wb97x-d (chg)') print(' non-default -D correction from Py-side') eneyne.update_geometry() eneyne.run_dftd3('b3lyp', 'd2', {'s6': 0.75}) assert psi4.compare_values(ref_pbe_d2[0], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene-Ethyne -D2') mA = eneyne.extract_subsets(1) mA.run_dftd3('b3lyp', 'd2', {'s6': 0.75}) assert psi4.compare_values(ref_pbe_d2[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D2') mB = eneyne.extract_subsets(2) mB.run_dftd3('b3lyp', 'd2', {'s6': 0.75}) assert psi4.compare_values(ref_pbe_d2[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethyne -D2') eneyne.run_dftd3('b3lyp', 'd3zero', {'s6': 1.0, 's8': 0.722, 'sr6': 1.217, 'alpha6': 14.0}) assert psi4.compare_values(ref_pbe_d3zero[0], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene-Ethyne -D3 (zero)') mA = eneyne.extract_subsets(1) mA.run_dftd3('b3lyp', 'd3zero', {'s6': 1.0, 's8': 0.722, 'sr6': 1.217, 'alpha6': 14.0}) assert psi4.compare_values(ref_pbe_d3zero[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (zero)') mB = eneyne.extract_subsets(2) mB.run_dftd3('b3lyp', 'd3zero', {'s6': 1.0, 's8': 0.722, 'sr6': 1.217, 'alpha6': 14.0}) assert psi4.compare_values(ref_pbe_d3zero[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethyne -D3 (zero)') eneyne.run_dftd3('b3lyp', 'd3bj', {'s6': 1.000, 's8': 0.7875, 'a1': 0.4289, 'a2': 4.4407}) assert psi4.compare_values(ref_pbe_d3bj[0], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene-Ethyne -D3 (bj)') mA = eneyne.extract_subsets(1) mA.run_dftd3('b3lyp', 'd3bj', {'s6': 1.000, 's8': 0.7875, 'a1': 0.4289, 'a2': 4.4407}) assert psi4.compare_values(ref_pbe_d3bj[1], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene -D3 (bj)') mB = eneyne.extract_subsets(2) mB.run_dftd3('b3lyp', 'd3bj', {'s6': 1.000, 's8': 0.7875, 'a1': 0.4289, 'a2': 4.4407}) assert psi4.compare_values(ref_pbe_d3bj[2], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethyne -D3 (bj)') eneyne.run_dftd3('b3lyp', 'd3', {'s6': 1.0, 's8': 0.722, 'sr6': 1.217, 'alpha6': 14.0}) assert psi4.compare_values(ref_pbe_d3zero[0], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene-Ethyne -D3 (alias)') eneyne.run_dftd3('b3lyp', 'd', {'s6': 0.75}) assert psi4.compare_values(ref_pbe_d2[0], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene-Ethyne -D (alias)') eneyne.run_dftd3('b3lyp', 'd2', {'s6': 0.75}) assert psi4.compare_values(ref_pbe_d2[0], psi4.variable('DISPERSION CORRECTION ENERGY'), 7, 'Ethene-Ethyne -D2 (alias)')
def test_libefp(): """libefp/qchem-qmefp-sp""" #! EFP on mixed QM (water) and EFP (water + 2 * ammonia) system. #! An EFP-only calc performed first to test vales against q-chem. qmefp = psi4.geometry(""" # QM fragment 0 1 units bohr O1 0.000000000000 0.000000000000 0.224348285559 H2 -1.423528800232 0.000000000000 -0.897393142237 H3 1.423528800232 0.000000000000 -0.897393142237 # EFP as EFP fragments -- efp h2o -4.014110144291 2.316749370493 -1.801514729931 -2.902133 1.734999 -1.953647 -- efp NH3,1.972094713645,,3.599497221584 , 5.447701074734 -1.105309 2.033306 -1.488582 -- efp NH3 -7.876296399270 -1.854372164887 -2.414804197762 2.526442 1.658262 -2.742084 """) # <<< EFP calc >>> psi4.set_options({ 'basis': '6-31g*', 'scf_type': 'pk', 'guess': 'core', 'df_scf_guess': False}) psi4.energy('efp') assert psi4.compare_values( 9.1793879214, qmefp.nuclear_repulsion_energy(), 6, 'QM NRE') assert psi4.compare_values(-0.0004901368, psi4.variable('efp elst energy'), 6, 'EFP-EFP Elst') # from q-chem assert psi4.compare_values(-0.0003168768, psi4.variable('efp ind energy'), 6, 'EFP-EFP Indc') assert psi4.compare_values(-0.0021985285, psi4.variable('efp disp energy'), 6, 'EFP-EFP Disp') # from q-chem assert psi4.compare_values( 0.0056859871, psi4.variable('efp exch energy'), 6, 'EFP-EFP Exch') # from q-chem assert psi4.compare_values( 0.0026804450, psi4.variable('efp total energy'), 6, 'EFP-EFP Totl') assert psi4.compare_values( 0.0026804450, psi4.variable('current energy'), 6, 'Current') psi4.core.print_variables() psi4.core.clean() psi4.core.clean_variables() # <<< QM + EFP calc >>> psi4.set_options({ 'e_convergence': 12, 'd_convergence': 12}) psi4.energy('scf') assert psi4.compare_values( 9.1793879214, qmefp.nuclear_repulsion_energy(), 6, 'QM NRE') assert psi4.compare_values( 0.2622598847, psi4.variable('efp total energy') - psi4.variable('efp ind energy'), 6, 'EFP corr to SCF') # from q-chem assert psi4.compare_values(-0.0117694790, psi4.variable('efp ind energy'), 6, 'QM-EFP Indc') # from q-chem assert psi4.compare_values(-0.0021985285, psi4.variable('efp disp energy'), 6, 'EFP-EFP Disp') # from q-chem assert psi4.compare_values( 0.0056859871, psi4.variable('efp exch energy'), 6, 'EFP-EFP Exch') # from q-chem assert psi4.compare_values( 0.2504904057, psi4.variable('efp total energy'), 6, 'EFP-EFP Totl') # from q-chem assert psi4.compare_values(-76.0139362744, psi4.variable('scf total energy'), 6, 'SCF') # from q-chem psi4.core.print_variables()
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.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.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.variable("PCM POLARIZATION ENERGY"), 6, "Polarization energy (PCM, separate algorithm)") psi4.set_options({'pcm_scf_type': 'total', 'reference': 'rohf'}) print('ROHF-PCM, total algorithm') energy_scf4 = psi4.energy('scf') assert psi4.compare_values(totalenergy, energy_scf4, 10, "Total energy (PCM, separate algorithm)") #TEST assert psi4.compare_values(polenergy, psi4.variable("PCM POLARIZATION ENERGY"), 6, "Polarization energy (PCM, separate algorithm)") #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()