Questions about usage of basis sets

Hi, as the title of this post say, I have some questions about the use of basis set and how to use to construct molecular hamiltonians. The first one is related about to obtaining the element’s constants that are calculated using that basis set. The below code is an example of the call.

import pennylane as qml
from pennylane import numpy as np

basis = 'sto-6g'
element = 'Na'
basis = qml.qchem.load_basisset(basis, element)

The error that I got from the above code is KeyError: ‘Na’, the problem is that basis set have the Na element, so it’s weird that I got that error. I don’t know what I’m doing wrong or if pennylane have a restriction about what elements I can call.

The second thing about of how to use some inputs of the molecular hamiltonian constructor. The below code is a scheme of the idea that I have, load the constants from the load_basiset and pass those values to the molecular hamiltonian (I’m following the ideas from qml.qchem — PennyLane 0.32.0 documentation)

import pennylane as qml
from pennylane import numpy as np

symbols = ["H", "H"]
geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 2.0]], requires_grad=True)

basis = 'sto-6g'
element = 'H'
basis = qml.qchem.load_basisset(basis, element)

coeff = np.array([basis["coefficients"][0],basis["coefficients"][0]], requires_grad = True)
alpha = np.array([basis["exponents"][0], basis["exponents"][0]], requires_grad = True)

args = [geometry, alpha, coeff]
hamiltonian, qubits = qml.qchem.molecular_hamiltonian(symbols, geometry, alpha=alpha, coeff=coeff, args=args)

The above code doesn’t give me errors, but I don’t understand how to change to other basis that have another structure, for example. Taking the hydrogen, the structure that I got from the below code is a list of exponents and coefficients, so there’s no problem, I just take that list and I used to construct the hamiltonian.

import pennylane as qml
from pennylane import numpy as np
basis = 'sto-6g'
element = 'H'
basis = qml.qchem.load_basisset(basis, element)
{'orbitals': ['S'],
 'exponents': [[35.52322122,
   6.513143725,
   1.822142904,
   0.6259552659,
   0.2430767471,
   0.100112428]],
 'coefficients': [[0.009163596281,
   0.04936149294,
   0.1685383049,
   0.3705627997,
   0.4164915298,
   0.1303340841]]}

If I change the basis to, for example, sapporo-dzp, I got a completely different structure, a list of lists of different sizes, so my question is how I should use it this data (the exponents and coefficients) to construct the molecular hamiltonian, because I feel that the procedure would be different from the exposed in qml.qchem — PennyLane 0.32.0 documentation.

import pennylane as qml
from pennylane import numpy as np

basis = 'sapporo-dzp'
element = 'H'
basis = qml.qchem.load_basisset(basis, element)
{'orbitals': ['S', 'S', 'P'],
 'exponents': [[13.0107003, 1.9622571, 0.444538],
  [0.1219496],
  [2.860673, 0.88819, 0.303776]],
 'coefficients': [[0.0334855, 0.2347219, 0.8137703],
  [1.0],
  [0.128856, 0.6197488, 0.3731129]]}

I’m not an expert working with basis set and quantum chemistry in general, so, I would thank a lot any kind of help, documentation and ideas that can give me to solve these problems.
Thanks in advance.

Hey @jnorambu! I’ll get back to you tomorrow — we haven’t forgotten about your question!

The error that I got from the above code is KeyError: ‘Na’

We don’t have support for sodium at this time with load_basisset. These are the list of elements that are currently supported:

atomic_numbers = {
    "H": 1,
    "He": 2,
    "Li": 3,
    "Be": 4,
    "B": 5,
    "C": 6,
    "N": 7,
    "O": 8,
    "F": 9,
    "Ne": 10,
}

If I change the basis to, for example, sapporo-dzp, I got a completely different structure, a list of lists …

Great question, and welcome to the wonderful world of quantum chemistry :grin:. All jokes aside, modelling the electronic structure of molecular orbitals is a seriously tough task. So, clever people invented clever ways of approximating their true functional form.

Long story short, given a basis set, certain basis functions are used to express molecular orbitals. Basis functions are typically a linear combination of Gaussian functions, where the coefficients in the linear combination and the exponents themselves are what is returned by qml.qchem.load_basisset. These values, and how many of them there are, change from basis set to basis set.

As far as the output data structure of qml.qchem.load_basisset goes, the i^{th} entry of orbitals is the molecular orbital label, whose coefficients — the coefficients from the linear combination of Gaussian functions — correspond to the i^{th} entry of coefficients, and whose exponents are in the i^{th} entry of exponents.

This is a good reference from a commonly used basis set site called GenECP: k_gen

Okay, now onto your question about how to put all of this into a molecular Hamiltonian. You can use qml.qchem.molecular_hamiltonian (qml.qchem.molecular_hamiltonian — PennyLane 0.33.0 documentation) and provide the keyword arguments alpha and coeff with your exponents and coefficients, respectively. However, if your end goal is to just create a Hamiltonian, you don’t need to use load_basisset :slight_smile:. Check out the documentation for qml.qchem.molecular_hamiltonian!

Let me know if this helps :slight_smile:

Thanks for the information, now I get why the qml.qchem.molecular_hamiltonian have that load_data flag, I didn’t understand their usage the first time that I see it.

It sad not having more elements available, but I will be waiting for it :smile:. Thanks for all.

1 Like

Hey @jnorambu, we will be adding the support for elements with higher atomic numbers soon. In the meantime, you can track this here and take a look at the related branch that should allow the support for now.

2 Likes