subroutine apply_transformation(nI, orig_orbs, trans_orbs, nJ, n_phase)
! apply the transformation encoded in the orig_orbs and trans_orbs
! to nI to obtain nJ. nJ will not be sorted except
! the phase is present, where the fermionic phase from reshuffling the
! orbitals into natural order is also outputted.
integer, intent(in) :: nI(nel), orig_orbs(nBasis / 2), trans_orbs(nBasis / 2)
integer, intent(out) :: nJ(nel)
integer, intent(out), optional :: n_phase
#ifdef DEBUG_
character(*), parameter :: this_routine = "apply_transformation"
#endif
integer :: i, pos
nJ = 0
do i = 1, nel
! i cant use binary search, since orig orbs is not sorted!
! pos = binary_search_int(orig_orbs, get_spatial(nI(i)))
pos = stupid_search(orig_orbs, get_spatial(nI(i)))
! it has to be found!
if (pos <= 0) then
print *, "orig_orbs: ", orig_orbs
print *, "nI: ", nI
print *, "spatial: ", get_spatial(nI)
end if
ASSERT(pos > 0)
if (is_beta(nI(i))) then
nJ(i) = 2 * trans_orbs(pos) - 1
else
nJ(i) = 2 * trans_orbs(pos)
end if
end do
if (present(n_phase)) then
call sort_orbitals(nJ, n_phase)
! call sort(nJ, par = n_phase)
end if
end subroutine apply_transformation