Exemple #1
0
def test_aci_1():
    """Test FCI on Li2/STO-3G. Reproduces the test aci-1"""

    ref_hf_energy = -14.839846512738
    ref_aci_energy = -14.889166993726

    # setup job
    xyz = """
    Li
    Li 1 2.0
    """
    input = solver_factory(molecule=xyz, basis='DZ')
    state = input.state(charge=0, multiplicity=1, sym='ag')
    hf = HF(input, state=state)
    options = {
        'sigma': 0.001,
        'sci_enforce_spin_complete': False,
        'sci_project_out_spin_contaminants': False,
        'active_ref_type': 'hf'
    }
    aci = ActiveSpaceSolver(hf, type='ACI', states=state, options=options)
    aci.run()

    # check results
    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)
    assert aci.value('active space energy')[state] == pytest.approx(
        [ref_aci_energy], 1.0e-10)
Exemple #2
0
def test_uhf():
    """Test UHF computation of the B1 state of methylene."""

    ref_energy = -38.92655952236967

    # create a molecule from a string
    mol = Molecule.from_geom("""
    C
    H 1 1.085
    H 1 1.085 2 135.5
    """)

    # create a basis object
    basis = Basis('cc-pVDZ')

    # create a molecular model
    input = solver_factory(molecule=mol, basis=basis)

    # specify the electronic state
    state = input.state(charge=0, multiplicity=3, sym='b1')

    # define a HF object
    hf = HF(input, state=state, restricted=False)
    hf.run()

    assert hf.value('hf energy') == pytest.approx(ref_energy, 1.0e-10)
Exemple #3
0
def test_uhf_wrong_sym():
    """Test UHF computation that lands on the wrong symmetry state."""

    # create a molecule from a string
    mol = Molecule.from_geom("""
    C
    H 1 1.085
    H 1 1.085 2 135.5
    """)

    # create a basis object
    basis = Basis('cc-pVDZ')

    # create a molecular model
    input = solver_factory(molecule=mol, basis=basis)

    # specify the electronic state
    state = input.state(charge=0, multiplicity=3, sym='a1')

    # define a HF object
    hf = HF(input, state=state, docc=[2, 0, 0, 1], socc=[1, 0, 1, 0], restricted=False)

    # should raise an error since we get a state with different symmetry
    with pytest.raises(RuntimeError):
        hf.run()
Exemple #4
0
def test_rhf_docc():
    """Test RHF on LiH using an occupation pattern that is not optimal.
    This example shows an alternative way to build the molecule/basis."""

    ref_energy = -7.40425598707951

    # create a molecule from a string
    mol = Molecule.from_geom("""
    Li 0.0 0.0 0.0
    H  0.0 0.0 1.6
    """)

    # create a basis object
    basis = Basis('cc-pVDZ')

    # create a molecular model
    input = solver_factory(molecule=mol, basis=basis)

    # specify the electronic state
    state = input.state(charge=0, multiplicity=1, sym='a1')

    hf = HF(input, state=state, docc=[1, 0, 1, 0])
    hf.run()

    assert hf.value('hf energy') == pytest.approx(ref_energy, 1.0e-10)
Exemple #5
0
def test_detci_4():
    """CASCI test of Forte DETCI using the SparseList algorithm to build the sigma vector"""

    ref_hf_energy = -99.977636678461636
    ref_fci_energy = -100.113732484560970

    xyz = """
    F
    H 1 1.0
    """
    input = solver_factory(molecule=xyz, basis='6-31g')
    state = input.state(charge=0, multiplicity=1, sym='a1')
    hf = HF(input, state=state, e_convergence=1.0e-12, d_convergence=1.0e-8)
    # create a detci solver
    fci = ActiveSpaceSolver(
        hf,
        type='detci',
        states=state,
        mo_spaces=input.mo_spaces(frozen_docc=[1, 0, 0, 0]),
        options={'active_ref_type': 'cas'})
    fci.run()

    # check results
    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)
    assert fci.value('active space energy')[state] == pytest.approx(
        [ref_fci_energy], 1.0e-10)
Exemple #6
0
def test_detci_2():
    """Test GAS CI calculation with multi-gas algorithm"""

    ref_hf_energy = -76.0172965561
    ref_gas1_energy = -76.029945793736
    ref_gas2_energy = -55.841944166803

    # setup job
    xyz = """
    O
    H 1 1.00
    H 1 1.00 2 103.1
    """
    input = solver_factory(molecule=xyz, basis='6-31g**')
    state = input.state(charge=0, multiplicity=1, sym='a1')
    hf = HF(input, state=state, d_convergence=1.0e-10)
    hf.run()

    # define two states with different number of GAS constraints
    gas_state_1 = input.state(charge=0, multiplicity=1, sym='a1', gasmin=[0], gasmax=[2])
    gas_state_2 = input.state(charge=0, multiplicity=1, sym='a1', gasmin=[0], gasmax=[1])

    # define the active space
    mo_spaces = input.mo_spaces(gas1=[1, 0, 0, 0], gas2=[3, 0, 1, 2])
    # create a detci solver
    fci = ActiveSpaceSolver(
        hf, type='detci', states=[gas_state_1, gas_state_2], mo_spaces=mo_spaces, options={'active_ref_type': 'gas'}
    )
    fci.run()

    # check results
    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)
    assert fci.value('active space energy')[gas_state_1] == pytest.approx([ref_gas1_energy], 1.0e-10)
    assert fci.value('active space energy')[gas_state_2] == pytest.approx([ref_gas2_energy], 1.0e-10)
Exemple #7
0
def test_hf_callback():
    """Example of using a callback to localize HF MOs."""

    xyz = """
    H 0.0 0.0 0.0
    H 0.0 0.0 1.0
    H 0.0 0.0 2.0
    H 0.0 0.0 3.0
    symmetry c1
    """
    input = solver_factory(molecule=xyz, basis='sto-3g')
    state = input.state(charge=0, multiplicity=1)

    cbh = CallbackHandler()

    def localize(cb, state):
        """Localize the orbitals after a HF computation"""
        import psi4
        wfn = state.data.psi_wfn
        basis_ = wfn.basisset()
        C = wfn.Ca_subset("AO", "ALL")
        Local = psi4.core.Localizer.build("PIPEK_MEZEY", basis_, C)
        Local.localize()
        new_C = Local.L
        wfn.Ca().copy(new_C)
        wfn.Cb().copy(new_C)

    cbh.add_callback('post hf', localize)
    hf = HF(input, state=state, restricted=False, cbh=cbh)
    hf.run()
Exemple #8
0
def test_fci_one_electron():
    """Test FCI on a one-electron system"""

    ref_hf_energy = -0.600480545551890
    ref_fci_energy = -0.600480545551890

    xyz = """
    H
    H 1 1.0
    """
    input = solver_factory(molecule=xyz, basis='aug-cc-pVDZ')
    state = input.state(charge=1, multiplicity=2, sym='ag')
    hf = HF(input, state=state, e_convergence=1.0e-12)
    # define an active space
    mo_spaces = input.mo_spaces(frozen_docc=[0, 0, 0, 0, 0, 0, 0, 0],
                                restricted_docc=[0, 0, 0, 0, 0, 0, 0, 0],
                                active=[1, 0, 0, 0, 0, 0, 0, 0])
    fci = ActiveSpaceSolver(hf,
                            type='FCI',
                            states=state,
                            e_convergence=1.0e-12,
                            mo_spaces=mo_spaces)
    fci.run()

    # check results
    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)
    assert fci.value('active space energy')[state] == pytest.approx(
        [ref_fci_energy], 1.0e-10)
Exemple #9
0
def test_fci_rdms_1():
    """Test the FCI 2- and 3-RDMs on LiH/STO-3G"""

    # setup job
    xyz = """
    Li
    H 1 3.0
    units bohr
    """
    input = solver_factory(molecule=xyz, basis='sto-3g')
    state = input.state(charge=0, multiplicity=1, sym='a1')
    hf = HF(input, state=state)
    fci = ActiveSpaceSolver(hf, type='FCI', states=state, options={'fci_test_rdms': True})
    fci.run()

    # check results
    print("Testing AAAA 2-RDM")
    assert psi4.core.variable("AAAA 2-RDM ERROR") == pytest.approx(0.0, 1.0e-10)
    print("Testing BBBB 2-RDM")
    assert psi4.core.variable("BBBB 2-RDM ERROR") == pytest.approx(0.0, 1.0e-10)
    print("Testing ABAB 2-RDM")
    assert psi4.core.variable("ABAB 2-RDM ERROR") == pytest.approx(0.0, 1.0e-10)

    print("Testing AAAAAA 3-RDM")
    assert psi4.core.variable("AAAAAA 3-RDM ERROR") == pytest.approx(0.0, 1.0e-10)
    print("Testing AABAAB 3-RDM")
    assert psi4.core.variable("AABAAB 3-RDM ERROR") == pytest.approx(0.0, 1.0e-10)
    print("Testing ABBABB 3-RDM")
    assert psi4.core.variable("ABBABB 3-RDM ERROR") == pytest.approx(0.0, 1.0e-10)
    print("Testing BBBBBB 3-RDM")
    assert psi4.core.variable("BBBBBB 3-RDM ERROR") == pytest.approx(0.0, 1.0e-10)
Exemple #10
0
def test_solver_2():
    """Test RHF on H2."""

    # define a molecule
    xyz = """
    H 0.0 0.0 0.0
    H 0.0 0.0 1.0
    """

    # create a molecular model
    input = solver_factory(molecule=xyz, basis='cc-pVDZ')

    # specify the electronic state
    state = input.state(charge=0, multiplicity=1, sym='ag')

    # create a HF object and run
    hf = HF(input, state=state)
    fci = ActiveSpaceSolver(hf, state, 'FCI')
    spin = SpinAnalysis(fci)
    test_graph = """SpinAnalysis
 |
ActiveSpaceSolver
 |
HF
 |
Input"""
    assert spin.computational_graph() == test_graph
Exemple #11
0
def test_aci_3():
    """Test FCI on H4/STO-3G. Reproduces the test aci-1"""

    ref_hf_energy = -2.0310813811962456
    ref_aci_energy = -2.115455548674
    ref_acipt2_energy = -2.116454734743
    spin_val = 1.02027340

    # setup job
    xyz = """
    H -0.4  0.0 0.0
    H  0.4  0.0 0.0
    H  0.1 -0.3 1.0
    H -0.1  0.5 1.0
    """
    input = solver_factory(molecule=xyz, basis='cc-pVDZ')
    state = input.state(charge=0, multiplicity=1, sym='a')
    hf = HF(input, state=state, e_convergence=1.0e-12, d_convergence=1.0e-6)
    options = {
        'sigma': 0.001,
        'active_ref_type': 'hf',
        'diag_algorithm': 'SPARSE',
        'active_guess_size': 300,
        'aci_screen_alg': 'BATCH_HASH',
        'aci_nbatch': 2
    }
    aci = ActiveSpaceSolver(hf,
                            type='ACI',
                            states=state,
                            e_convergence=1.0e-11,
                            r_convergence=1.0e-7,
                            options=options)
    spin = SpinAnalysis(aci, options={'SPIN_TEST': True})
    spin.run()

    # check results
    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)
    assert aci.value('active space energy')[state] == pytest.approx(
        [ref_aci_energy], 1.0e-9)
    assert psi4.core.variable("ACI+PT2 ENERGY") == pytest.approx(
        ref_acipt2_energy, 1.0e-8)
    assert psi4.core.variable("SPIN CORRELATION TEST") == pytest.approx(
        spin_val, 1.0e-7)
Exemple #12
0
def test_fci_ex_1():
    """Test FCI on the ground and first singlet A1 states of acetone"""

    ref_hf_energy = -190.88631411404435
    ref_fci_energies = [-190.903043353477869, -190.460579059045074]

    # setup job
    xyz = """
    H   0.000000   2.136732  -0.112445
    H   0.000000  -2.136732  -0.112445
    H  -0.881334   1.333733  -1.443842
    H   0.881334  -1.333733  -1.443842
    H  -0.881334  -1.333733  -1.443842
    H   0.881334   1.333733  -1.443842
    C   0.000000   0.000000   0.000000
    C   0.000000   1.287253  -0.795902
    C   0.000000  -1.287253  -0.795902
    O   0.000000   0.000000   1.227600
    units angstrom
    """
    input = solver_factory(molecule=xyz, basis='3-21g')
    state = input.state(charge=0, multiplicity=1, sym='a1')

    hf = HF(input, state=state, docc=[8, 1, 2, 5])
    hf.run()
    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)

    # define an active space
    mo_spaces = input.mo_spaces(frozen_docc=[3, 0, 0, 1],
                                restricted_docc=[4, 1, 1, 3],
                                active=[2, 0, 2, 1])
    # compute the FCI energy for the double B1 (M_S =  1/2) solution
    fci = ActiveSpaceSolver(hf,
                            type='FCI',
                            states={state: 2},
                            mo_spaces=mo_spaces)
    fci.run()

    # check results
    assert fci.value('active space energy')[state] == pytest.approx(
        ref_fci_energies, 1.0e-10)
Exemple #13
0
def test_rhf():
    """Test RHF on H2."""

    ref_energy = -1.10015376479352

    # define a molecule
    xyz = """
    H 0.0 0.0 0.0
    H 0.0 0.0 1.0
    """

    # create a molecular model
    input = solver_factory(molecule=xyz, basis='cc-pVDZ')

    # specify the electronic state
    state = input.state(charge=0, multiplicity=1, sym='ag')

    # create a HF object and run
    hf = HF(input, state=state)
    hf.run()

    assert hf.value('hf energy') == pytest.approx(ref_energy, 1.0e-10)
Exemple #14
0
def test_fci_1():
    """Test FCI on Li2/STO-3G"""

    ref_hf_energy = -14.54873910108353
    ref_fci_energy = -14.595808852754054

    # setup job
    xyz = """
    Li
    Li 1 3.0
    units bohr
    """
    input = solver_factory(molecule=xyz, basis='sto-3g')
    state = input.state(charge=0, multiplicity=1, sym='ag')
    hf = HF(input, state=state)
    fci = ActiveSpaceSolver(hf, type='FCI', states=state)
    fci.run()

    # check results
    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)
    assert fci.value('active space energy')[state] == pytest.approx(
        [ref_fci_energy], 1.0e-10)
Exemple #15
0
def test_df_rhf():
    """Test DF-RHF on HF."""

    ref_energy = -100.04775218911111

    # define a molecule
    xyz = """
    H 0.0 0.0 0.0
    F 0.0 0.0 1.0
    """

    # create a molecular model
    input = solver_factory(molecule=xyz, basis='cc-pVTZ', int_type='df')

    # specify the electronic state
    state = input.state(charge=0, multiplicity=1, sym='a1')

    # create a HF object and run
    hf = HF(input, state=state)
    hf.run()

    assert hf.value('hf energy') == pytest.approx(ref_energy, 1.0e-10)
Exemple #16
0
def test_fci_7():
    """
    Test FCI on the doublet state of CH and triplet state of CH+.
    It also verifies that computations with different values of M_S yield the same energy
    """

    ref_hf_energy = -37.43945401822133
    ref_fci_energy = -37.49081328115731

    # setup job
    xyz = """
    C
    H 1 1.0
    units bohr
    """
    input = solver_factory(molecule=xyz, basis='6-31G')
    state = input.state(charge=0, multiplicity=2, sym='b1')

    hf_doublet = HF(input, state=state, docc=[3, 0, 0, 0], socc=[0, 0, 1, 0])
    hf_doublet.run()

    # compute the FCI energy for the double B1 (M_S =  1/2) solution
    state_doublet_1 = input.state(charge=0, multiplicity=2, ms=0.5, sym='b1')
    fci_doublet_1 = ActiveSpaceSolver(hf_doublet,
                                      type='FCI',
                                      states=state_doublet_1)
    fci_doublet_1.run()

    # check results
    assert hf_doublet.value('hf energy') == pytest.approx(
        ref_hf_energy, 1.0e-10)
    assert fci_doublet_1.value(
        'active space energy')[state_doublet_1] == pytest.approx(
            [ref_fci_energy], 1.0e-10)

    # compute the FCI energy for the double B1 (M_S =  1/2) solution
    state_doublet_2 = input.state(charge=0, multiplicity=2, ms=-0.5, sym='b1')
    fci_doublet_2 = ActiveSpaceSolver(hf_doublet,
                                      type='FCI',
                                      states=state_doublet_2)
    fci_doublet_2.run()
    assert fci_doublet_2.value(
        'active space energy')[state_doublet_2] == pytest.approx(
            [ref_fci_energy], 1.0e-10)

    state = input.state(charge=1, multiplicity=3, sym='b1')

    ref_hf_triplet = -37.066693498042760
    ref_fci_triplet = -37.088876452204509

    hf_triplet = HF(input, state=state, docc=[2, 0, 0, 0], socc=[1, 0, 1, 0])
    hf_triplet.run()

    # compute the FCI energy for the triplet B1 (M_S =  1) solution
    state_triplet_1 = input.state(charge=1, multiplicity=3, ms=1.0, sym='b1')
    fci_triplet_1 = ActiveSpaceSolver(hf_triplet,
                                      type='FCI',
                                      states=state_triplet_1)
    fci_triplet_1.run()

    # check results
    assert hf_triplet.value('hf energy') == pytest.approx(
        ref_hf_triplet, 1.0e-10)
    assert fci_triplet_1.value(
        'active space energy')[state_triplet_1] == pytest.approx(
            [ref_fci_triplet], 1.0e-10)

    # compute the FCI energy for the triplet B1 (M_S =  0) solution
    state_triplet_2 = input.state(charge=1, multiplicity=3, ms=0.0, sym='b1')
    fci_triplet_2 = ActiveSpaceSolver(hf_triplet,
                                      type='FCI',
                                      states=state_triplet_2)
    fci_triplet_2.run()
    assert fci_triplet_2.value(
        'active space energy')[state_triplet_2] == pytest.approx(
            [ref_fci_triplet], 1.0e-10)

    # compute the FCI energy for the triplet B1 (M_S =  0) solution
    state_triplet_3 = input.state(charge=1, multiplicity=3, ms=-1.0, sym='b1')
    fci_triplet_3 = ActiveSpaceSolver(hf_triplet,
                                      type='FCI',
                                      states=state_triplet_3)
    fci_triplet_3.run()
    assert fci_triplet_3.value(
        'active space energy')[state_triplet_3] == pytest.approx(
            [ref_fci_triplet], 1.0e-10)
Exemple #17
0
def test_detci_3():
    """Test DETCI transition dipole and oscillator strengths"""

    ref_hf_energy = -154.80914322697598

    ref_ag_energies = [
        -154.84695193645672, -154.59019912152513, -154.45363253270600
    ]
    ref_bu_energies = [-154.54629332287075]
    ref_osc_0ag_0bu = 1.086716030595
    ref_osc_1ag_0bu = 0.013542791095
    ref_osc_2ag_0bu = 0.041762051475

    # setup job
    butadiene = """
    H  1.080977 -2.558832  0.000000
    H -1.080977  2.558832  0.000000
    H  2.103773 -1.017723  0.000000
    H -2.103773  1.017723  0.000000
    H -0.973565 -1.219040  0.000000
    H  0.973565  1.219040  0.000000
    C  0.000000  0.728881  0.000000
    C  0.000000 -0.728881  0.000000
    C  1.117962 -1.474815  0.000000
    C -1.117962  1.474815  0.000000
    """
    input = solver_factory(molecule=butadiene,
                           basis='def2-svp',
                           scf_aux_basis='def2-universal-jkfit',
                           corr_aux_basis='def2-universal-jkfit',
                           int_type='df')

    state = input.state(charge=0, multiplicity=1, sym='ag')
    hf = HF(input, state=state, d_convergence=1.0e-12)
    hf.run()

    assert hf.value('hf energy') == pytest.approx(ref_hf_energy, 1.0e-10)

    # define two states with different number of GAS constraints
    ag_state = input.state(charge=0, multiplicity=1, sym='ag')
    bu_state = input.state(charge=0, multiplicity=1, sym='bu')

    # define the active space
    mo_spaces = input.mo_spaces(frozen_docc=[2, 0, 0, 2],
                                restricted_docc=[5, 0, 0, 4],
                                active=[0, 2, 2, 0])
    # create a detci solver
    fci = ActiveSpaceSolver(hf,
                            type='detci',
                            states={
                                ag_state: 3,
                                bu_state: 1
                            },
                            mo_spaces=mo_spaces,
                            options={'transition_dipoles': True})
    fci.run()

    # check results
    assert fci.value('active space energy')[ag_state] == pytest.approx(
        ref_ag_energies, 1.0e-10)
    assert fci.value('active space energy')[bu_state] == pytest.approx(
        ref_bu_energies, 1.0e-10)
    print("Oscillator strength singlet 0Ag -> 0Bu")
    assert psi4.core.variable("OSC. SINGLET 0AG -> 0BU") == pytest.approx(
        ref_osc_0ag_0bu, 1.0e-8)
    print("Oscillator strength singlet 1Ag -> 0Bu")
    assert psi4.core.variable("OSC. SINGLET 1AG -> 0BU") == pytest.approx(
        ref_osc_1ag_0bu, 1.0e-8)
    print("Oscillator strength singlet 2Ag -> 0Bu")
    assert psi4.core.variable("OSC. SINGLET 2AG -> 0BU") == pytest.approx(
        ref_osc_2ag_0bu, 1.0e-8)