# Parsing Numbers as Basis Sets directly into PySCF

I was just wondering, and I bet others have come across this before, whether there is a way to parse numpy arrays as basis into PySCF. Let's say I want the exponents corresponding to numpy.losgcale(-4,4,9) as exponents for S-type basis functions. is there a way to tell the gto.mol object to just use these numbers as basis input? And what if I want to add contractions? I can see that there is a way to print numpy.losgcale(-4,4,9) into a format that is then understood by gto.parser but this seems is an unnecessary intermediate step.

Yes, this is very simple to do. Logarithmically spaced exponents constitute an even-tempered basis set, and there is already a function in PySCF to construct such a basis set: it is called expand_etb and the code is easy to read:

def expand_etb(l, n, alpha, beta):
return [[l, [alpha*beta**i, 1]] for i in reversed(range(n))]


The function generates the basis set in the internal basis set format of PySCF, which is an array that specifies the angular momentum l, and then a list of the exponents and contraction coefficients. The above code is for a primitive basis set, which has 1 as the contraction coefficient. For a more complicated example, you can have a look at the PySCF interface to the Basis Set Exchange's Python library.

Using the basis set in a calculation is very straightforward, here is code adapted from examples/02-molden.py:

basis = {'He': gto.expand_etbs(((0, 4, 1., 2.), (1, 3, 1., 2.)))})


This example thus assigns helium an even-tempered basis set with 4 s-functions (exponents 1, 2, 4, and 8) and 2 p-functions (exponents 1, 2, and 4).

Note that if you are writing code that is useful beyond PySCF, you might look into interfacing directly with the Basis Set Exchange, since that way you can get out your basis sets also in other formats. As I wrote above, PySCF has a native interface to the Basis Set Exchange.

Addendum: actually, the examples/gto/04-input_basis.py example has an even simpler format to input even-tempered basis sets:

    basis = {
'O': gto.etbs([(0, 4, 1.5, 2.2),  # s-function
(1, 2, 0.5, 2.2)]) # p-function
}


However, to use an arbitrary array of exponents as a basis set, you just need to convert it into the PySCF internal format with e.g.

def pyscf_basis(angular_momentum, exponents):
'''Converts the input array of exponents for angular_momentum into the PySCF internal format'''
return [[angular_momentum, [exponent, 1]] for exponent in exponents]


and concatenate the definitions for the basis functions of various angular momenta.