Example #1
0
def test_scf_conv(program, keywords):
    prefix = qcdb.util.program_prefix(program)

    qcdb.set_keywords(keywords)

    hcn2 = qcdb.Molecule(
        """
H 0.000000 0.000000 3.409664
C 0.000000 0.000000 2.340950
N 0.000000 0.000000 1.185959
--
H 0.000000 0.000000 -0.148222
C 0.000000 0.000000 -1.222546
N 0.000000 0.000000 -2.379698
"""
    )

    ene, wfn = qcdb.energy(prefix + "hf/6-311G*", molecule=hcn2, return_wfn=True)
    pprint.pprint(wfn)

    assert wfn["success"] is True
    assert compare_values(-185.74334367736, ene, 6, "ene")

    ans = _harvest_scf_convergence(wfn["stdout"])
    print(ans)
Example #2
0
def test_tu2_uhf_nwchem():
    ch2 = qcdb.set_molecule("""
        0 3
        C
        H 1 R
        H 1 R 2 A

        R = 2.05
        A = 133.93
        units au
    """)

    qcdb.set_keywords({
        "basis": "6-31g**",
        "reference": "uhf",
    })
    print(ch2)
    print(qcdb.get_active_options().print_changed())

    ene, wfn = qcdb.energy("nwc-scf", return_wfn=True)
    pprint.pprint(wfn, width=200)  # debug printing

    assert compare_values(tu2_scf_ene, qcdb.variable("hf total energy"), 6,
                          "energy")
    assert compare("NWChem", wfn["provenance"]["creator"], "harness")
Example #3
0
def test_fig2cd_api(qcprog, part, request):
    """
    Execution (c, d; api)

                       c4
    ene = qcdb.energy('gms-ccsd/aug-cc-pvdz')
                       nwc
                       p4

    """
    if part == "c":
        datin = _fig2_ins[qcprog]["c"]
        mo = {"mode": "sandwich"}
    elif part == "d":
        datin = _fig2_ins["all"]["d"]
        mo = {"mode": "unified"}

    qcskmol = qcel.models.Molecule(**datin["molecule"])
    qcdbmol = qcdb.Molecule.from_schema(qcskmol.dict())
    qcdb.set_keywords(datin["keywords"])
    driver = {
        "energy": qcdb.energy,
        "gradient": qcdb.gradient,
    }[datin["driver"]]
    call = qcdb.util.program_prefix(
        qcprog) + datin["model"]["method"] + "/" + datin["model"]["basis"]

    ene = driver(call, molecule=qcdbmol, mode_options=mo)
    assert compare_values(_the_fig2_energy,
                          ene,
                          atol=1.0e-6,
                          label=request.node.name)
Example #4
0
def test_tu1_ene_psi4():

    # memory 600 mb
    #
    # molecule h2o {
    #  O
    #  H 1 0.96
    #  H 1 0.96 2 104.5
    # }
    #
    # set basis cc-pVDZ
    # energy('scf')

    # compare_values(-76.0266327341067125, variable('SCF TOTAL ENERGY'), 6, 'SCF energy')  #TEST

    h2o = qcdb.set_molecule("""
  O 
  H 1 0.96
  H 1 0.96 2 104.5
""")

    qcdb.set_keywords({"scf_type": "pk"})

    ene = qcdb.energy("p4-hf/cc-pVDZ")

    assert compare_values(tu1_scf_ene, ene, 6, "energy")
Example #5
0
def test_mode_psi_hf_details(mode_options, keywords, xptd):
    h2o = qcdb.set_molecule(_sh2o)
    #qcdb.set_keywords({"scf_type": "pk"})
    qcdb.set_keywords(keywords)

    ene, wfn = qcdb.energy("p4-hf/cc-pVDZ",
                           mode_options=mode_options,
                           return_wfn=True)
    pprint.pprint(wfn, width=200)

    assert compare_values(xptd, ene, 6, "energy")
Example #6
0
def test_diatomic(qcp):

    h2 = qcdb.set_molecule("""
    H
    H 1 R
    """)

    energies = []
    rvals = [0.65, 0.7, 0.75, 0.8, 0.85]
    qcdb.set_keywords({
        "basis": "cc-pvtz",
        "d_convergence": 12,
        "e_convergence": 12,
        # "r_convergence": 12,
    })

    for r in rvals:
        h2.R = r
        energies.append(qcdb.energy(qcp + "fci"))

    # Since h2 is the active molecule it will be used by default in diatomic.anharmonicity
    # However, if you need to provide the routine a molecule pass it as the third parameter:
    #   phys_const = diatomic.anharmonicity(rvals, energies, h2)

    # phys_consts = diatomic.anharmonicity(rvals, energies)
    phys_consts = qcdb.diatomic(rvals, energies, molecule=h2)
    ref_we = 4412.731844941288
    ref_ae = 3.280703358397913
    ref_wexe = 144.6025772908216
    ref_Be = 60.66938330300022
    ref_r0 = 0.752814273047763
    ref_De = 0.045872631987045
    ref_re = 0.742567407914979
    ref_B0 = 59.02903162380126
    ref_nu = 4123.526690359645
    assert compare_values(ref_re, phys_consts["re"], 5,
                          "Equilibrium bond length")
    assert compare_values(ref_r0, phys_consts["r0"], 5,
                          "Zero-point corrected bond length")
    assert compare_values(ref_Be, phys_consts["Be"], 5,
                          "Equilibrium rotational constant")
    assert compare_values(ref_B0, phys_consts["B0"], 5,
                          "Zero-point corrected rotational constant")
    assert compare_values(ref_we, phys_consts["we"], 4,
                          "Harmonic vibrational frequency")
    assert compare_values(ref_wexe, phys_consts["wexe"], 4, "Anharmonicity")
    assert compare_values(ref_nu, phys_consts["nu"], 4,
                          "Anharmonic vibrational frequency")
    assert compare_values(ref_ae, phys_consts["ae"], 5,
                          "Vibration-rotation interaction constant")
    assert compare_values(ref_De, phys_consts["De"], 5,
                          "Quartic centrifugal distortion constant")
Example #7
0
def test_mode_fcae_mp2(program, mode_options, keywords, xptd):

    mode_options = {"translate_method_algorithm": True, **mode_options}
    prefix = qcdb.util.program_prefix(program)

    h2o = qcdb.set_molecule(_sh2o)
    qcdb.set_keywords(keywords)

    ene, wfn = qcdb.energy(prefix + "mp2/cc-pVDZ",
                           mode_options=mode_options,
                           return_wfn=True)
    pprint.pprint(wfn, width=200)

    assert compare_values(xptd, ene, atol=1.e-6, label="energy")
Example #8
0
def test_snippet4d():
    qcdb.set_molecule("""
     H
     H 1 0.74
    """)

    qcdb.set_keywords({
        "basis": "6-31g",  # ok, new info
        "cfour_memory_size": 9000000,  # clash w/1 gib below
    })

    with pytest.raises(qcdb.exceptions.KeywordReconciliationError) as e:
        qcdb.energy("c4-hf", local_options={"memory": 1})

    assert "Conflicting option requirements btwn user (9000000) and driver (134217728) for MEMORY_SIZE" in str(
        e)
Example #9
0
def test_snippet4a():
    qcdb.set_molecule("""
     H
     H 1 0.74
    """)

    qcdb.set_keywords({
        "basis": "6-31g",  # ok, new info
        "cfour_calc_level": "ccsd",  # clash w/"c4-hf" below
    })

    with pytest.raises(qcdb.exceptions.KeywordReconciliationError) as e:
        qcdb.energy("c4-hf")

    assert "Conflicting option requirements btwn user (CCSD) and driver (SCF) for CALC_LEVEL" in str(
        e)
Example #10
0
def test_snippet4c():
    qcdb.set_molecule("""
     H
     H 1 0.74
    """)

    qcdb.set_keywords({
        "basis": "6-31g",  # ok, new info
        "cfour_multiplicity": 3,  # clash w/implicit singlet of mol above
        "cfour_units": "angstrom",  # ok, consistent w/mol above
    })

    with pytest.raises(qcdb.exceptions.KeywordReconciliationError) as e:
        qcdb.energy("c4-hf")

    assert "Conflicting option requirements btwn user (3) and driver (1) for MULTIPLICITY" in str(
        e)
Example #11
0
def test_snippet4b():
    qcdb.set_molecule("""
     H
     H 1 0.74
    """)

    qcdb.set_keywords({
        "basis": "6-31g",  # ok, new info
        "cfour_deriv_level":
        "first",  # clash w/energy() below (use gradient())
    })

    with pytest.raises(qcdb.exceptions.KeywordReconciliationError) as e:
        qcdb.energy("c4-hf")

    assert "Conflicting option requirements btwn user (FIRST) and driver (ZERO) for DERIV_LEVEL" in str(
        e)
Example #12
0
def test_tu4_freq_gamess():
    h2o = qcdb.set_molecule("""
      O
      H 1    0.9462932382
      H 1    0.9462932382      2  104.6566705798
    """)

    qcdb.set_keywords({"basis": "cc-pvdz"})
    ene, wfn = qcdb.frequency("gms-scf/cc-pvdz", return_wfn=True)
    freqs = wfn["frequency_analysis"]["omega"].data
    pprint.pprint(wfn, width=200)  # debug printing

    assert compare_values(tu3_nre_opt, h2o.nuclear_repulsion_energy(), 3,
                          "Nuclear repulsion energy")
    assert compare_values(tu3_scf_ene, qcdb.variable("CURRENT ENERGY"), 6,
                          "opt energy")
    assert compare_values(tu4_scf_freqs,
                          freqs[-3:],
                          atol=0.1,
                          label="freq omegas")
    assert compare("GAMESS", wfn["provenance"]["creator"], "harness")
Example #13
0
def test_mode_dfconv_hf(program, mode_options, keywords, xptd):

    mode_options = {"translate_method_algorithm": True, **mode_options}
    prefix = qcdb.util.program_prefix(program)

    h2o = qcdb.set_molecule(_sh2o)
    qcdb.set_keywords(keywords)

    if xptd == "raise":
        with pytest.raises(qcdb.ValidationError) as e:
            qcdb.energy(prefix + "hf/cc-pVDZ",
                        mode_options=mode_options,
                        return_wfn=True)

        assert "SCF_TYPE 'DF' is not available" in str(e)

    else:
        ene, wfn = qcdb.energy(prefix + "hf/cc-pVDZ",
                               mode_options=mode_options,
                               return_wfn=True)
        pprint.pprint(wfn, width=200)

        assert compare_values(xptd, ene, atol=1.e-6, label="energy")
Example #14
0
def test_scf4(program, keywords):
    #! RHF cc-pVDZ energy for water, automatically scanning the symmetric stretch and bending coordinates
    #! using Python's built-in loop mechanisms.  The geometry is apecified using a Z-matrix with variables
    #! that are updated during the potential energy surface scan, and then the same procedure is performed
    #! using polar coordinates, converted to Cartesian coordinates.
    import math

    refENuc = [
        9.785885838936569,
        9.780670106434425,
        8.807297255042920,
        8.802603095790996,
        8.006633868220828,
        8.002366450719077,
    ]
    refSCF = [
        -76.02132544702374,
        -76.02170973231352,
        -76.02148196912412,
        -76.0214579633461369,
        -75.99010402473729,
        -75.98979578728871,
    ]

    # Define the points on the potential energy surface using standard Python list functions
    Rvals = [0.9, 1.0, 1.1]
    Avals = range(102, 106, 2)

    # Start with a potentital energy scan in Z-matrix coordinates

    h2o = qcdb.Molecule("""
        O
        H 1 R
        H 1 R 2 A
    """)

    print("\n Testing Z-matrix coordinates\n")

    qcdb.set_keywords(keywords)
    model = qcdb.util.program_prefix(program) + "scf/cc-pvdz"

    count = 0
    for R in Rvals:
        h2o.set_variable("R", R)  # alternately, h2o.R = R
        for A in Avals:
            h2o.A = A  # alternately, h2o.set_variable('A', A)
            h2o.update_geometry()

            ene, jrec = qcdb.energy(model, molecule=h2o, return_wfn=True)
            assert compare_values(refSCF[count], ene, 6,
                                  f"Reference energy {count}")
            assert compare_values(refENuc[count] * a2a,
                                  h2o.nuclear_repulsion_energy(), 10,
                                  f"Nuclear repulsion energy {count}")
            assert program == jrec["provenance"]["creator"].lower(
            ), "zmat prov"
            count += 1

    # And now the same thing, using Python's trigonometry functions, and Cartesian input.  This time
    # we want to reset the Cartesian positions every time the angles and bond lengths change, so we
    # define the geometry inside the loops.  N.B. this requires the basis set to be re-specified after
    # every change of geometry

    print("\n Testing polar coordinates\n")

    count = 0
    for R in Rvals:
        for A in Avals:
            h2o = qcdb.Molecule("""
                O   0.0    0.0    0.0
                H   0.0      R    0.0
                H   0.0  RCosA  RSinA
            """)
            # The non-numeric entries above just define placeholders with names.  They still need
            # to be set, which we do below.
            h2o.R = R
            h2o.set_variable("RCosA", R * math.cos(math.radians(A)))
            h2o.RSinA = R * math.sin(math.radians(A))
            h2o.update_geometry()

            ene, jrec = qcdb.energy(model, molecule=h2o, return_wfn=True)
            assert compare_values(refSCF[count], ene, 6,
                                  f"Reference energy {count}")
            assert compare_values(refENuc[count] * a2a,
                                  h2o.nuclear_repulsion_energy(), 10,
                                  f"Nuclear repulsion energy {count}")
            assert program == jrec["provenance"]["creator"].lower(
            ), "polar prov"
            count += 1