# sltcnd_0_base_ua Function

## private pure function sltcnd_0_base_ua(nI, exc) result(hel)

### Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nI(nel)
type(Excite_0_t), intent(in) :: exc

## Source Code

    pure function sltcnd_0_base_ua(nI, exc) result(hel)
! Calculate the  by the SlaterCondon Rules when the two
! determinants are the same (so we only need to specify one).
integer, intent(in) :: nI(nel)
type(Excite_0_t), intent(in) :: exc
HElement_t(dp) :: hel

HElement_t(dp) :: hel_sing, hel_doub, hel_tmp
integer :: id(nel), i, j, idN, idX

#ifdef WARNING_WORKAROUND_
associate(exc => exc); end associate
#endif

! Sum in the one electron integrals (KE --> TMAT)
hel_sing = sum(GetTMATEl(nI, nI))

! Obtain the spatial rather than spin indices if required
id = nI

! Sum in the two electron contributions. Use max(id...) as we cannot
! guarantee that if j>i then nI(j)>nI(i).
hel_doub = (0)
hel_tmp = (0)
do i = 1, nel - 1
do j = i + 1, nel
idX = max(id(i), id(j))
idN = min(id(i), id(j))
hel_doub = hel_doub + get_umat_el(idN, idX, idN, idX)
end do
end do

! Exchange contribution only considered if tExch set.
! This is only separated from the above loop to keep "if (tExch)" out
! of the tight loop for efficiency.
if (tExch) then
do i = 1, nel - 1
do j = i + 1, nel
! Exchange contribution is zero if I,J are alpha/beta
if ((G1(nI(i))%Ms == G1(nI(j))%Ms) .or. tReltvy) then
idX = max(id(i), id(j))
idN = min(id(i), id(j))
hel_tmp = hel_tmp - get_umat_el(idN, idX, idX, idN)
end if
end do
end do
end if
hel = hel_doub + hel_tmp + hel_sing

end function sltcnd_0_base_ua