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:
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.
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.