Пример #1
0
def test_guess_mix_for_broken_symmetry(inp):

    refENuc = 0.17639240356
    refSCF = -0.82648407827446
    refBSSCF = -0.99872135103903

    h2 = psi4.geometry("""
        0 1
        H
        H 1 3.0
        symmetry c1
        """)

    psi4.set_options({
        "reference": "uhf",
        "e_convergence": 12,
        "basis": "cc-pvdz"
    })
    psi4.set_options(inp.get("options", {}))

    thisSCF = psi4.energy("scf")
    psi4.set_options(inp.get("late_options", {}))
    psi4.set_options({"guess_mix": True})
    thisBSSCF = psi4.energy("scf")

    assert compare_values(refENuc, h2.nuclear_repulsion_energy(), 10,
                          "Nuclear repulsion energy")
    assert compare_values(refSCF, thisSCF, 10, "Reference energy")
    assert compare_values(refBSSCF, thisBSSCF, 10,
                          "Reference broken-symmetry energy")
Пример #2
0
def test_schwarz_vs_density_energy():
    """Checks difference in Hartree-Fock energy between Schwarz and Density screening (with and without IFB), 
    which should be insignificant.
    """

    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
        O   1.350625   0.111469   0.000000
        H   1.680398  -0.373741  -0.758561
        H   1.680398  -0.373741   0.758561
        symmetry c1
        no_reorient
        no_com
    """)

    psi4.set_options({
        'scf_type': 'direct',
        'd_convergence': 1e-6,
        'df_scf_guess': False,
        'screening': 'schwarz',
        'ints_tolerance': 1.0e-12
    })
    e_schwarz = psi4.energy('hf/DZ')

    psi4.core.clean()

    psi4.set_options({
        'scf_type': 'direct',
        'd_convergence': 1e-6,
        'df_scf_guess': False,
        'screening': 'density',
        'incfock': False,
        'ints_tolerance': 1.0e-12
    })
    e_density = psi4.energy('hf/DZ')

    psi4.core.clean()

    psi4.set_options({
        'scf_type': 'direct',
        'd_convergence': 1e-6,
        'df_scf_guess': False,
        'screening': 'density',
        'incfock': True,
        'ints_tolerance': 1.0e-12
    })

    e_incfock = psi4.energy('hf/DZ')

    assert compare_values(e_schwarz, e_density, 10,
                          'Schwarz vs Density Screening, Cutoff 1.0e-12')
    assert compare_values(e_schwarz, e_incfock, 10,
                          'Schwarz vs Density Screening, Cutoff 1.0e-12')
Пример #3
0
def test_RU_TDA_C1():
    h2o = psi4.geometry("""0 1
    O          0.000000    0.000000    0.135446
    H         -0.000000    0.866812   -0.541782
    H         -0.000000   -0.866812   -0.541782
    symmetry c1
    no_reorient
    no_com
    """)
    psi4.set_options({"scf_type": "pk", 'save_jk': True})
    e, wfn = psi4.energy("hf/sto-3g", molecule=h2o, return_wfn=True)
    A_ref, _ = build_UHF_AB_C1(wfn)
    ni, na, _, _ = A_ref['IAJB'].shape
    nia = ni * na
    A_sing_ref = A_ref['IAJB'] + A_ref['IAjb']
    A_sing_ref = A_sing_ref.reshape(nia, nia)
    A_trip_ref = A_ref['IAJB'] - A_ref['IAjb']
    A_trip_ref = A_trip_ref.reshape(nia, nia)
    sing_vals, _ = np.linalg.eigh(A_sing_ref)
    trip_vals, _ = np.linalg.eigh(A_trip_ref)

    trip_eng = TDRSCFEngine(wfn, ptype='tda', triplet=True)
    sing_eng = TDRSCFEngine(wfn, ptype='tda', triplet=False)
    ID = [
        psi4.core.Matrix.from_array(v.reshape((ni, na)))
        for v in tuple(np.eye(nia).T)
    ]
    psi4.core.print_out("\nA sing:\n" + str(A_sing_ref) + "\n\n")
    psi4.core.print_out("\nA trip:\n" + str(A_trip_ref) + "\n\n")
    A_trip_test = np.column_stack(
        [x.to_array().flatten() for x in trip_eng.compute_products(ID)[0]])
    assert compare_arrays(A_trip_ref, A_trip_test, 8, "Triplet Ax C1 products")
    A_sing_test = np.column_stack(
        [x.to_array().flatten() for x in sing_eng.compute_products(ID)[0]])
    assert compare_arrays(A_sing_ref, A_sing_test, 8, "Singlet Ax C1 products")

    sing_vals_2, _ = np.linalg.eigh(A_sing_test)
    trip_vals_2, _ = np.linalg.eigh(A_trip_test)

    psi4.core.print_out("\n\n SINGLET EIGENVALUES\n")
    for x, y in zip(sing_vals, sing_vals_2):
        psi4.core.print_out("{:10.6f}  {:10.6f}\n".format(x, y))
        # assert compare_values(x, y, 4, "Singlet ROOT")
    psi4.core.print_out("\n\n Triplet EIGENVALUES\n")
    for x, y in zip(trip_vals, trip_vals_2):
        psi4.core.print_out("{:10.6f}  {:10.6f}\n".format(x, y))
        # assert compare_values(x, y, 4, "Triplet Root")

    for x, y in zip(sing_vals, sing_vals_2):
        assert compare_values(x, y, 4, "Singlet ROOT")
    for x, y in zip(trip_vals, trip_vals_2):
        assert compare_values(x, y, 4, "Triplet Root")
Пример #4
0
def test_schwarz_vs_csam_energy():
    """Checks difference in Hartree-Fock energy between no screening and CSAM screening, which should be
    insignificant. """

    psi4.geometry("""
        Ne 0.0 0.0 0.0
        Ne 4.0 0.0 0.0
        Ne 8.0 0.0 0.0
    """)

    psi4.set_options({
        'scf_type': 'direct',
        'd_convergence': 1e-12,
        'screening': 'schwarz',
        'ints_tolerance': 1.0e-12
    })
    e_schwarz = psi4.energy('hf/DZ')

    psi4.core.clean()

    psi4.set_options({
        'scf_type': 'direct',
        'd_convergence': 1e-12,
        'screening': 'csam',
        'ints_tolerance': 1.0e-12
    })
    e_csam = psi4.energy('hf/DZ')

    assert compare_values(e_schwarz, e_csam, 11,
                          'Schwarz vs CSAM Screening, Cutoff 1.0e-12')
Пример #5
0
def test_dipole(inp):
    h2o = psi4.geometry("""
        O
        H 1 1.0
        H 1 1.0 2 101.5
    """)

    psi4.set_options({
        'perturb_h': True,
        'perturb_with': 'dipole',
        'basis': 'cc-pvdz'
    })
    psi4.set_options(inp['options'])
    energies = dict()
    for l in [1, -1, 2, -2]:
        psi4.set_options({'perturb_dipole': [0, 0, l * perturbation_strength]})
        energies[l] = psi4.energy(inp['name'])
    findif_dipole = [
        0, 0,
        (8 * energies[1] - 8 * energies[-1] - energies[2] + energies[-2]) /
        (12 * perturbation_strength)
    ]

    psi4.set_options({'perturb_h': False})
    wfn = psi4.properties(inp['name'], properties=['dipole'],
                          return_wfn=True)[1]
    analytic_dipole = wfn.variable(inp['varname'] + " DIPOLE")

    assert compare_values(findif_dipole, analytic_dipole, 5,
                          "findif vs. analytic dipole")
Пример #6
0
def test_RU_TDA_C1():
    h2o = psi4.geometry("""0 1
    O          0.000000    0.000000    0.135446
    H         -0.000000    0.866812   -0.541782
    H         -0.000000   -0.866812   -0.541782
    symmetry c1
    no_reorient
    no_com
    """)
    psi4.set_options({"scf_type": "pk", 'save_jk': True})
    e, wfn = psi4.energy("hf/sto-3g", molecule=h2o, return_wfn=True)
    A_ref, _ = build_UHF_AB_C1(wfn)
    ni, na, _, _ = A_ref['IAJB'].shape
    nia = ni * na
    A_sing_ref = A_ref['IAJB'] + A_ref['IAjb']
    A_sing_ref = A_sing_ref.reshape(nia, nia)
    A_trip_ref = A_ref['IAJB'] - A_ref['IAjb']
    A_trip_ref = A_trip_ref.reshape(nia, nia)
    sing_vals, _ = np.linalg.eigh(A_sing_ref)
    trip_vals, _ = np.linalg.eigh(A_trip_ref)

    trip_eng = TDRSCFEngine(wfn, ptype='tda', triplet=True)
    sing_eng = TDRSCFEngine(wfn, ptype='tda', triplet=False)
    ID = [psi4.core.Matrix.from_array(v.reshape((ni, na))) for v in tuple(np.eye(nia).T)]
    psi4.core.print_out("\nA sing:\n" + str(A_sing_ref) + "\n\n")
    psi4.core.print_out("\nA trip:\n" + str(A_trip_ref) + "\n\n")
    A_trip_test = np.column_stack([x.to_array().flatten() for x in trip_eng.compute_products(ID)[0]])
    assert compare_arrays(A_trip_ref, A_trip_test, 8, "Triplet Ax C1 products")
    A_sing_test = np.column_stack([x.to_array().flatten() for x in sing_eng.compute_products(ID)[0]])
    assert compare_arrays(A_sing_ref, A_sing_test, 8, "Singlet Ax C1 products")

    sing_vals_2, _ = np.linalg.eigh(A_sing_test)
    trip_vals_2, _ = np.linalg.eigh(A_trip_test)

    psi4.core.print_out("\n\n SINGLET EIGENVALUES\n")
    for x, y in zip(sing_vals, sing_vals_2):
        psi4.core.print_out("{:10.6f}  {:10.6f}\n".format(x, y))
        # assert compare_values(x, y, 4, "Singlet ROOT")
    psi4.core.print_out("\n\n Triplet EIGENVALUES\n")
    for x, y in zip(trip_vals, trip_vals_2):
        psi4.core.print_out("{:10.6f}  {:10.6f}\n".format(x, y))
        # assert compare_values(x, y, 4, "Triplet Root")

    for x, y in zip(sing_vals, sing_vals_2):
        assert compare_values(x, y, 4, "Singlet ROOT")
    for x, y in zip(trip_vals, trip_vals_2):
        assert compare_values(x, y, 4, "Triplet Root")
Пример #7
0
def test_gradient(inp):
    h2o = psi4.geometry("""
        O
        H 1 0.958
        H 1 0.958 2 104.5
    """)

    psi4.set_options({'basis': 'aug-cc-pvdz', 'points': 5})
    psi4.set_options(inp['options'])

    analytic_gradient = psi4.gradient(inp['name'], dertype=1)
    print(analytic_gradient)
    findif_gradient = psi4.gradient(inp['name'], dertype=0)
    reference_gradient = inp["ref"]

    assert compare_values(findif_gradient, analytic_gradient, 5,
                          "analytic vs. findif gradient")
    assert compare_values(reference_gradient, analytic_gradient.np, 5,
                          "analytic vs. reference gradient")
Пример #8
0
def test_dfjcosk(inp, mols):
    """Test the DFJCOSK JK object via SCF calculations"""

    molecule = mols[inp["molecule"]]
    psi4.set_options({"scf_type": "cosx", "basis": "cc-pvdz"})
    psi4.set_options(inp["options"])

    # does the DFJCOSK SCF energy match a pre-computed reference?
    energy_dfjcosk = psi4.energy(inp["method"],
                                 molecule=molecule,
                                 bsse_type=inp["bsse_type"])
    assert compare_values(inp["ref"], energy_dfjcosk, atol=1e-6)

    # is the DFJCOSK SCF energy reasonably close to a conventional SCF?
    psi4.set_options({"scf_type": "pk"})
    energy_pk = psi4.energy(inp["method"],
                            molecule=molecule,
                            bsse_type=inp["bsse_type"])
    assert compare_values(energy_pk, energy_dfjcosk, atol=1e-4)
Пример #9
0
def test_weird_basis(subject, bas, ans, mols, request):
    """non-consecutive angular momentum basis set patterns"""

    mol = mols[subject]
    ref = "rhf" if mol.multiplicity() == 1 else "uhf"
    psi4.set_options({
        "reference": ref,
        "guess": "core",
        "scf_type": "pk",
        "df_scf_guess": "false",
        "basis": "anonymous1234",
    })

    def basisspec_psi4_yo__anonymous1234(mol, role):
        mol.set_basis_all_atoms("test", role=role)
        return {"test": bas}

    psi4.driver.qcdb.libmintsbasisset.basishorde[
        "ANONYMOUS1234"] = basisspec_psi4_yo__anonymous1234

    ene = psi4.energy("scf", molecule=mol)
    assert compare_values(ans, ene, 6, request.node.name)