function apply_inversion_wf(ilut_list, sort_ind) result(inv_wf)
! apply inversion symmetry to a wavefunction
integer(n_int), intent(inout) :: ilut_list(:, :)
integer, intent(out), optional :: sort_ind(size(ilut_list, 2))
integer(n_int) :: inv_wf(0:size(ilut_list, 1) - 1, size(ilut_list, 2))
integer :: orig_orbs(nBasis / 2), trans_orbs(nBasis / 2), i, &
orig_states(nel, size(ilut_list, 2)), inv_states(nel, size(ilut_list, 2))
real(dp) :: orig_weights(size(ilut_list, 2)), temp_sign(lenof_sign), &
inv_weights(size(ilut_list, 2))
orig_orbs = get_spatial(brr(1:nBasis:2))
trans_orbs = apply_inversion(orig_orbs)
! decode the original information
do i = 1, size(ilut_list, 2)
call decode_bit_det(orig_states(:, i), ilut_list(:, i))
call extract_sign(ilut_list(:, i), temp_sign)
orig_weights(i) = temp_sign(1)
end do
if (present(sort_ind)) then
call transform_states(orig_orbs, trans_orbs, size(ilut_list, 2), &
orig_states, orig_weights, ilut_list, inv_states, inv_weights, &
inv_wf, sort_ind)
else
call transform_states(orig_orbs, trans_orbs, size(ilut_list, 2), &
orig_states, orig_weights, ilut_list, inv_states, inv_weights, inv_wf)
end if
end function apply_inversion_wf