subroutine pick_virtual_electron_single(nI, part_type, elec, pgen_elec, calc_pgen)
! same as above for a single excitation
! remember: elec is really just the number in the ilut!
integer, intent(in) :: nI(nel), part_type
integer, intent(out) :: elec
real(dp), intent(out) :: pgen_elec
logical, intent(in), optional :: calc_pgen
character(*), parameter :: this_routine = "pick_virtual_electron_single"
integer :: i, n_valid, j, ind
integer:: virt_elecs(nel)
! what do we need here?
! count all the electrons in the virtual of the reference, then
! create a list of them and pick one uniformly
n_valid = 0
j = 1
virt_elecs = -1
elec = -1
do i = 1, nel
if (is_in_virt_mask(nI(i), part_type)) then
! the electron is in the virtual of the
n_valid = n_valid + 1
virt_elecs(j) = i
j = j + 1
end if
end do
if (n_valid == 0) then
! something went wrong
! yes.. this means it was called on the hartree fock..
! but i think aborting the excitation is enough.. i do not
! need to stop_all or? but this could catch some bugs..
elec = 0
pgen_elec = 0.0_dp
return
end if
! does this work with an optional logical as input:
ASSERT(n_valid > 0)
pgen_elec = 1.0_dp / real(n_valid, dp)
! if i only want to calculate the pgens i dont want to call the
! random number generator
if (present(calc_pgen)) then
if (calc_pgen) return
end if
! and now pick a random number:
ind = 1 + floor(genrand_real2_dSFMT() * n_valid)
elec = virt_elecs(ind)
ASSERT(elec > 0)
end subroutine pick_virtual_electron_single