Exemplo n.º 1
0
def test_not_available_qc_package(package, tmpdir):
    r"""Test that an error is raised if the input quantum chemistry package
    is neither Psi4 nor PySCF"""

    with pytest.raises(TypeError,
                       match="Integration with quantum chemistry package"):
        qchem.meanfield(name,
                        geometry,
                        package=package,
                        outpath=tmpdir.strpath)
Exemplo n.º 2
0
def test_not_available_qc_package(tmpdir):
    r"""Test that an error is raised if the input quantum chemistry package
    is neither Psi4 nor PySCF"""

    with pytest.raises(TypeError,
                       match="Integration with quantum chemistry package"):
        qchem.meanfield(symbols,
                        coordinates,
                        name=name,
                        package="not_available_package",
                        outpath=tmpdir.strpath)
Exemplo n.º 3
0
def test_dimension_consistency(tmpdir):
    r"""Test that an error is raised if the size of the 'coordinates' array is
    not equal to ``3*len(symbols)``"""

    extra_coordinate = np.array(
        [0.0, 0.0, -0.66140414, 0.0, 0.0, 0.66140414, -0.987])
    with pytest.raises(ValueError,
                       match="The size of the array 'coordinates' has to be"):
        qchem.meanfield(symbols,
                        extra_coordinate,
                        name=name,
                        outpath=tmpdir.strpath)
Exemplo n.º 4
0
def test_path_to_file(package, basis, tmpdir, psi4_support):
    r"""Test the correctness of the full path to the file containing the meanfield
    electronic structure"""

    if package == "Psi4" and not psi4_support:
        pytest.skip("Skipped, no Psi4 support")

    exp_path = os.path.join(tmpdir.strpath, package.lower(), basis.strip(),
                            name)

    res_path = qchem.meanfield(name,
                               geometry,
                               basis=basis,
                               package=package,
                               outpath=tmpdir.strpath)

    assert res_path == exp_path
Exemplo n.º 5
0
def test_hf_calculations(package, tmpdir, psi4_support, tol):
    r"""Test the correctness of the HF calculation"""

    if package == "Psi4" and not psi4_support:
        pytest.skip("Skipped, no Psi4 support")

    n_atoms = 2
    n_electrons = 2
    n_orbitals = 2
    hf_energy = -1.1173490350703152
    orbital_energies = np.array([-0.59546347, 0.71416528])

    one_body_integrals = np.array([[-1.27785300e00, 1.11022302e-16],
                                   [0.00000000e00, -4.48299698e-01]])

    two_body_integrals = np.array([
        [
            [[6.82389533e-01, 0.00000000e00], [6.93889390e-17,
                                               1.79000576e-01]],
            [[4.16333634e-17, 1.79000576e-01], [6.70732778e-01,
                                                0.00000000e00]],
        ],
        [
            [[5.55111512e-17, 6.70732778e-01],
             [1.79000576e-01, 1.11022302e-16]],
            [[1.79000576e-01, 0.00000000e00], [2.77555756e-17,
                                               7.05105632e-01]],
        ],
    ])

    fullpath = qchem.meanfield(symbols,
                               coordinates,
                               name=name,
                               package=package,
                               outpath=tmpdir.strpath)

    molecule = MolecularData(filename=fullpath)

    assert molecule.n_atoms == n_atoms
    assert molecule.n_electrons == n_electrons
    assert molecule.n_orbitals == n_orbitals
    assert np.allclose(molecule.hf_energy, hf_energy, **tol)
    assert np.allclose(molecule.orbital_energies, orbital_energies, **tol)
    assert np.allclose(molecule.one_body_integrals, one_body_integrals, **tol)
    assert np.allclose(molecule.two_body_integrals, two_body_integrals, **tol)
Exemplo n.º 6
0
# <https://en.wikipedia.org/wiki/Basis_set_(chemistry)#Minimal_basis_sets>`__ ``'sto-3g'`` of
# Slater-type orbitals (STO) which provides the minimum number of atomic orbitals required to
# accommodate the electrons of the neutral atoms.

basis_set = 'sto-3g'

##############################################################################
# Finally, we can call the function :func:`~.pennylane_qchem.qchem.meanfield` to launch
# the mean field calculation. At present, the quantum chemistry packages `PySCF
# <https://sunqm.github.io/pyscf/>`_ or `Psi4 <http://www.psicode.org/>`_ can be chosen to solve
# the Hartree-Fock equations. In this example, we choose ``'pyscf'``, which is the default option,
# but the same results can be obtained using ``'psi4'``.

hf_file = qchem.meanfield(name,
                          geometry,
                          charge=charge,
                          mult=multiplicity,
                          basis=basis_set,
                          package='pyscf')

##############################################################################
# Once the calculation is completed,
# the string variable ``hf_file`` returned by the function stores the absolute path to the
# the hdf5-formatted file ``'water'`` with the Hartree-Fock electronic structure
# of the water molecule.

print(hf_file)

##############################################################################
# At this stage, we have a basis set of molecular orbitals. Next, we can use the
# function :func:`~.pennylane_qchem.qchem.active_space` to define an *active space*.
# But, what is an active space?
Exemplo n.º 7
0
# Slater-type orbitals (STO) which provides the minimum number of atomic orbitals required to
# accommodate the electrons of the neutral atoms.

basis_set = 'sto-3g'

##############################################################################
# Finally, we can call the function :func:`~.pennylane_qchem.qchem.meanfield` to launch
# the mean field calculation. At present, the quantum chemistry packages `PySCF
# <https://sunqm.github.io/pyscf/>`_ or `Psi4 <http://www.psicode.org/>`_ can be chosen to solve
# the Hartree-Fock equations. In this example, we choose ``'pyscf'``, which is the default option,
# but the same results can be obtained using ``'psi4'``.

hf_file = qchem.meanfield(symbols,
                          coordinates,
                          name=name,
                          charge=charge,
                          mult=multiplicity,
                          basis=basis_set,
                          package='pyscf')

##############################################################################
# Once the calculation is completed,
# the string variable ``hf_file`` returned by the function stores the absolute path to the
# the hdf5-formatted file ``'water'`` with the Hartree-Fock electronic structure
# of the water molecule.

print(hf_file)

##############################################################################
# At this stage, we have a basis set of molecular orbitals. Next, we can use the
# function :func:`~.pennylane_qchem.qchem.active_space` to define an *active space*.