Molden Orbital Rotation Issue

#1

I am attempting to manually swap entries in the MO coefficient matrices of an HF-generated wfn object, then use psi4.molden() to view the swapped orbitals. However, both the indexing and the actual orbital shapes seem to be wrong for the neutral Scandium atom, despite the manually inspected Ca and Cb arrays being correct. I swapped orbital indices 14 and 27 in the numpy array, but which should mean orbitals 15 and 28 were swapped in molden’s notation. However, 14 and 28 were swapped in molden notation; see vim diff below:

Additionally, the orbitals molden generates after the rotation are asymmetric, e.g.

image

turns into

I’m using the following code to obtain this transformation:

psi4.molden(wfn, 'pre-rotation.molden')
            cb = wfn.Cb().to_array()
            ca = wfn.Ca().to_array()
            self.molecule.n_orbitals = len(ca)
            ca[:][self.active+self.reorder]=ca[:][self.reorder+self.active]
            cb[:][self.active+self.reorder]=cb[:][self.reorder+self.active]
            ca = psi4.core.Matrix.from_array(ca)
            cb = psi4.core.Matrix.from_array(cb)
            wfn.Cb().copy(cb)                       
            wfn.Ca().copy(ca)
            psi4.molden(wfn, 'scr.molden')

where self.active = [9,10,11,12,13,14] and self.reorder = [9,10,11,12,13,27]

I suspect this is an issue unique to very high symmetry systems, and I am running it in c1 if that matters. Any help is appreciated!

#2

The fact that you are running this in c1 means that Psi shouldn’t be using symmetry at all, so I would be surprised if this issue is “unique to very high symmetry systems”.

Before anything else: are you trying to swap molecular orbitals or atomic orbitals?

#3

They should be one and the same here, but in general I want to be swapping molecular orbitals.

#4

Thanks!

Psi is just fine. The problem is your NumPy slices do not mean what you think they mean.

When Python sees ca[:][self.active+self.reorder], it parses it piece by piece and forgets what the previous piece was. When it sees ca, it knows to refer to the matrix, and then it sees [:], which tells it to slice all rows. When it sees [self.active+self.reorder], it sees it has a matrix and you have a single slice and interprets that as a row slice. It has no memory of the fact that it just did a row slice. Consequently, you are flipping atomic orbitals in the current version, now molecular orbtials. The correct NumPy looks like ca[:, self.active+self.reorder]. When I change your code accordingly, all works as expected.

As for why atomic orbital flips cause a problem, molden has its own atomic orbital ordering convention. I’m not surprised that Psi’s internal convention doesn’t match Molden’s. I’d need more detailed information about the basis set you used to work that out for sure, but that’s my guess.

1 Like
#5

Okay, thank you; that helps tremendously! As a bonus, it did fix the molden orderings. In general this sort of rotation has been consistent with molden’s rotations for me in the past, which is part of why I was so alarmed.