How to align the atomic orbitals between pyscf and psi4

Dear Developers,
I found that the Hamiltonians obtained from pyscf and psi4 are different. For example,

from pyscf import gto, scf
import psi4

mol = gto.M(atom='O 0 0 0; H 0 1 0; H 0 0 1', basis='def2-svp')
rhf = scf.RHF(mol)
rhf.kernel()
H_pyscf = rhf.get_hcore()

geom = """
    O 0 0 0
    H 0 1 0
    H 0 0 1
    symmetry c1
    units angstrom
"""
mol_psi4 = psi4.geometry(geom)
psi4.set_options({'reference': 'rhf', 'basis': 'def2-SVP'})
scf_e, scf_wfn = psi4.energy('scf', molecule=mol_psi4, return_wfn=True)
H_psi4 = scf_wfn.H().np

Since the Hamiltonian is a (24, 24) matrix, I only print the first dimension here:

# H_pyscf[0]
array([-3.29856601e+01,  1.11013177e+01,  5.12600489e+00,  0.00000000e+00,
        1.99302401e-02,  1.99302401e-02,  0.00000000e+00,  2.67199490e-03,
        2.67199490e-03,  0.00000000e+00,  0.00000000e+00,  7.22474019e-04,
        0.00000000e+00, -1.25136171e-03,  1.37360210e+00,  1.96479169e+00,
        0.00000000e+00, -2.50325889e+00,  6.39602699e-04,  1.37360210e+00,
        1.96479169e+00,  0.00000000e+00,  6.39602699e-04, -2.50325889e+00])

# H_psi4[0]
array([-3.29856601e+01,  1.11013177e+01,  5.12600489e+00,  2.81856159e-02,
        0.00000000e+00,  0.00000000e+00,  3.77877143e-03,  0.00000000e+00,
        0.00000000e+00,  7.22474018e-04,  0.00000000e+00,  0.00000000e+00,
       -1.25136171e-03,  0.00000000e+00,  1.37360210e+00,  1.96479168e+00,
       -1.76961906e+00,  0.00000000e+00, -1.77052360e+00,  1.37360210e+00,
        1.96479168e+00, -1.76961906e+00,  0.00000000e+00,  1.77052360e+00])

The AOs in pyscf are

['0 O 1s    ', '0 O 2s    ', '0 O 3s    ', '0 O 2px   ', '0 O 2py   ', '0 O 2pz   ', '0 O 3px   ', '0 O 3py   ', '0 O 3pz   ', '0 O 3dxy  ', '0 O 3dyz  ', '0 O 3dz^2 ', '0 O 3dxz  ', '0 O 3dx2-y2', '1 H 1s    ', '1 H 2s    ', '1 H 2px   ', '1 H 2py   ', '1 H 2pz   ', '2 H 1s    ', '2 H 2s    ', '2 H 2px   ', '2 H 2py   ', '2 H 2pz   ']

The differences are occured when l>0 but it will not change the eigenvals. So what the difference between the definition of AOs in pyscf and psi4? And how to align the AOs between pyscf and psi4?

The molecule probably isn’t even aligned. Add

nocom
noreorient

to geom, just like you added symmetry c1. This will prevent Psi from moving the molecule in space.

Thank you for the suggestion. I tried with

geom = """
    O 0 0 0
    H 0 1 0
    H 0 0 1
    symmetry c1
    units angstrom
    nocom
    noreorient
"""

Then the H_psi4[0] is

array([-3.29856601e+01,  1.11013177e+01,  5.12600489e+00,  1.99302401e-02,
        0.00000000e+00,  1.99302401e-02,  2.67199490e-03,  0.00000000e+00,
        2.67199490e-03,  7.22474018e-04,  0.00000000e+00,  0.00000000e+00,
       -1.25136171e-03,  0.00000000e+00,  1.37360210e+00,  1.96479168e+00,
        6.39602697e-04,  0.00000000e+00, -2.50325888e+00,  1.37360210e+00,
        1.96479168e+00, -2.50325888e+00,  0.00000000e+00,  6.39602697e-04])

which are still different from that of pyscf.

PySCF and Psi4 use different AO orderings, and it looks like that’s the only remaining cause of disagreement. See here for details of AO ordering in Psi.

There’s also the question of whether PySCF is using the same molecular orientation as Psi4.

Thanks for your response. It is very helpful. I investigate the related information you provided, and find that the AO ordering in psi4 is 0, +1, -1, +2, -2. A quick check is to look at the Hamiltonian I provided above. The Hamiltonian under ‘O 2p’ AOs are

m -1 0 +1
H_pyscf 0.00000000e+00 1.99302401e-02 1.99302401e-02
H_psi4 1.99302401e-02 1.99302401e-02 0.00000000e+00

which seems have a permtation?
But for the Hamiltonian under ‘O 3d’ AOs

m -2 -1 0 +1 +2
H_pyscf 0.00000000e+00 0.00000000e+00 7.22474019e-04 0.00000000e+00 -1.25136171e-03
H_psi4 0.00000000e+00 0.00000000e+00 7.22474018e-04 0.00000000e+00 -1.25136171e-03

which are the same. I’m confuse about this.

Thank you for the response. I’m sorry that I don’t understand what the meaning of molecular orientation as the coordinates are the same.

Since the eigenvals of Hamiltonians from pyscf and psi4 are the same, these two Hamiltonians should be transformed by a unitary transformation. So what is this unitary transformation?

The transformation is not necessarily unitary due to differences in the way the basis functions are defined; see How to transform the Hamiltonians between pyscf and psi4? · Issue #2123 · pyscf/pyscf · GitHub for the PySCF side of the discussion.