Print two electron integrals

Hi, I’m new to the forum.
I have a question external to psi4, but I hope someone can help me. I’m programming a small HF code which handles 2-el integrals up to [pppp] shells for now. I managed to reproduce exactly reported integrals for STO-3G methane, and also the SCF energy. However, when I changed to an acetilene molecule (with p functions on more than one center), I got a deviation on the energy. Also If I do 6-31g calculations on CH4 I get a value which is off (~-46 Ha versus ~-40 Ha reference value), and if I do 6-31g on acetile I get around -9000 Ha.
For these types of calculations I can only compare the energy or the one-electron matrices (which are correct to about 1e-12). I’m almost sure the problem lies in integrals which contain [pp **] shells with p functions which are different (either different centers or different exponents), and my bug vanishes for highly symmetric cases, but after weeks I cannot find the problem.
My question is if someone could provide me with a list of integrals for some small molecule containing more than one C, N or O atom with an STO-3G or 6-31g basis. (I could also code some other basis, but for now I can only handle s and p type functions)
I know it can be done with psi4. I have downloaded it but still wasn’t able to use it because I’m having problems installing a new version of python. I don’t know hoy much time it will take me to solve the python issue and learn to use psi4, and this integral bug is breaking my head.
If someone could help me I would deeply appreciate it.
Best regards,
Nicolas

You might want to check out the Psi4Numpy repo here: https://github.com/psi4/psi4numpy

I don’t have a link on my phone but Psi4 is conda installable which gets a complete binary package. This should be in the installation part of our manual.

I would recommend debugging against LIBCINT. it is easy to install it, however a bit tedious to operate if you are not a pro at C (PySCF offers a more friendly interface to the library but I never managed to get around it).
That way you can check values for individual <ab|cd> integrals with arbitrary GTOs (be mindful of normalisation and L-ordering). Should be faster to find the bug if it is indeed in the ERI algorithm. The full J/K matrixes also involve a sum over occupied states of appropriate spin… the bug may be there too.

In the meantime, here are some data for some small organics:


There are 6 molecules from the Rupp/Ramakrishnan dataset. Geometries are in the input files.
The .dat files are the overlap, Fock (Fa) and one-electron (H) matrixes.All matrix elements below 1.0e-16 were zeroed for sanity.
Calculations are direct RHF SCF with STO-3G basis from PSI4. I am not sure what exactly is in the Fock matrix… I printed out wavefunction.Fa(), so I guess it is H+J-K for the spin-up electrons only. Devs shall correct me if wrong. You should be able to get the (J-K) matrix but probably not the individual parts. I am also adding now the explicit ERIs obtained from the MintsHelper class in PSI4. Let me know if you want more molecules. Hope this helps.

Just out of curiosity… how are you dealing with the ERI? Are you using some well established scheme or some new method?

Felix, thank you very much for the answer and data. It’s really useful.
When I posted the other day I had a large difference in energy. Finally I found out that the problem was not in the ERIs but on the way I was using the 8-fold permutational symmetry of the ERIs to do only the unique integrals. I constructed the ERI(a,b,c,d) matrix using this symmetry, and when I switched back to doing the full matrix, there were about 4 elements (in 17^4) that had some deviations. I still don’t know why is that, but started doing all the integrals, and then my energy was almost correct. I was about to post an answer here, but noticed that instead of -40.18… Ha for 6-31g methane obtained with Orca, I got -40.20… Ha. This small difference I still can’t figure out. So there is still some problem.
For the ERIs I’m using Obara-Saika derived methods, something similar to Head-Gordon Pople. I use the vertical recurrence to obtain the [L s s s] integrals (up to [g s s s] integrals with one algorithm and up to [L = 10 s s s] with another algorithm, slightly slower but allowing arbitrary angular momentum). I use the electron transfer recursion to obtain [La s Lc s] integrals, then I contract and then use horizontal recursion to obtain the full integral matrices for each shell. The code is vectorized, and works on all cartesian components simultaneously.
I do permutations to get all shells into the order I just described, and I think the permutations are correct.
Once again, thank you very much,
I’ll post when/if I solve the problem.
Best,
Nicolas

Hi felix
I am new to Psi4 . I want to get these 2 electron in batches. As, I am using more than 300 basis sets so the size of matrix is exceeding the RAM. Can you please suggest how I can get that ?

Hi,

I am not sure, but this is something worth trying:


import psi4
import numpy

psi4.core.set_output_file('test.out', False)
psi4.set_memory('24 GB')

mol = psi4.geometry("""                                                                                                                                               
units ang                                                                                                                                                             
symmetry c1                                                                                                                                                           
C -0.0126981359 1.0858041578 0.0080009958                                                                                                                             
H 0.002150416 -0.0060313176 0.0019761204                                                                                                                              
H 1.0117308433 1.4637511618 0.0002765748                                                                                                                              
H -0.540815069 1.4475266138 -0.8766437152                                                                                                                             
H -0.5238136345 1.4379326443 0.9063972942                                                                                                                             
""")
mol.fix_com(True)
mol.fix_orientation(True)

psi4.set_options({'basis': 'cc-pvdz'})
psi4.set_options({'scf_type': 'DIRECT'})
psi4.set_options({'maxiter': 500})
psi4.set_options({'reference': 'rhf'})

E, wf = psi4.energy('HF', molecule=mol, return_wfn=True)

mints = psi4.core.MintsHelper(wf.basisset())
block = mints.ao_eri_shell(0,0,0,3).to_array(copy=False, dense=True)

print(block)

Some of the options might be irrelevant, I just copied one of my old input files…

The important part is the last 3 lines, where we get a MintsHelper (documentation here) object for integrals calculations, and compute ERIs for a set of shells. In this CH4 example, shell 0 and 3 are the first s AO and the first p AO of carbon in the basis set respectively. The resulting block is this tensor:

[[[[-2.71867626e-23 -4.32095857e-22 -1.71788507e-23]]]]

The shape of the block depends on the type of shells. I guess you can write a loop to get them all, and avoid the ones that should be zero due to symmetry and the duplicate ones ( [ijkl] = [jikl] = [ijlk] = [lkij] = …)
In my example I ran the SCF calculation to get a wavefunction and used its basis set to initialise the MintsHelper. It might be possible to construct the basis set without having to run anything, for example with:

basis = psi4.core.BasisSet.build(mol)

Hope this helps.