HOMO LUMO extracting energies does not work

Hi, I am trying to extract HOMO LUMO energies from the wavefuction in this way:

HOMO = scf_wfn.epsilon_a_subset(“AO”, “ALL”)[scf_wfn.nalpha()]
LUMO = scf_wfn.epsilon_a_subset(“AO”, “ALL”)[scf_wfn.nalpha() + 1]

it works perfectly with the 1.1 version, but when I use version 1.2.1 , I got the following error:

HOMO = scf_wfn.epsilon_a_subset(“AO”, “ALL”)[scf_wfn.nalpha()]
TypeError: ‘psi4.core.Vector’ object does not support indexing

Any ideas?

That error message could be a lot clearer, and in 1.3, it will be. (For devs, the error message change is included in Py-Findif.) I’m assuming that @dgasmith changed how Psi interfaces with NumPy between 1.1 and 1.2, and that’s what caused the change.

When you call epsilon_a_subset, it doesn’t return a NumPy array directly. It returns a Vector object, from Psi’s internals. This can be useful in some more advanced cases, but if you just want a list of the energies for orbitals with alpha spin, here’s what you can do:

HOMO = scf_wfn.epsilon_a_subset("AO", "ALL").np[scf_wfn.nalpha() - 1]
LUMO = scf_wfn.epsilon_a_subset("AO", "ALL").np[scf_wfn.nalpha()]

.np will let you access the elements of scf_wfn.epsilon_a_subset("AO", "ALL") just like it was a NumPy array!

EDIT: July 2022
A older version of this post contained an indexing error, present in the original post. It’s now fixed.

1 Like

Awesome, thank you, it works!!!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.