subroutine constructConnections()
integer :: i, j, k, l
logical :: tconnected
integer(n_int) :: dummy(0:NIfTot)
dummy = 0_n_int
nConnects = 0
do i = 1, nBasis
! for each orbital, check which ones have a nonzero one-election matrix element
! this defines the bath structure
do j = 1, nBasis
! use a flag to store if i and j are connected
tconnected = .false.
if (abs(gettmatel(i, j)) > eps .and. i /= j) then
tconnected = .true.
else
! if the 1-electron integral is 0, check the 2-electron one
if (i <= nImp .and. j <= nImp .and. i /= j) then
! this can only be the case for impurity orbitals
do k = 1, nImp
! the orbitals in question cannot count here, as the
! occupation of k cannot change
if (k /= i .and. k /= j) then
! check the 2-electron integral
if (abs(get_umat_el(gtID(i), gtID(k), gtID(k), gtID(j))) > eps) then
tconnected = .true.
exit
end if
end if
end do
end if
end if
if (tconnected) then
! increase the number of connections of i by one
nConnects(i) = nConnects(i) + 1
! if allocated, add the connection
if (allocated(connections)) &
connections(i, nConnects(i)) = j
end if
end do
end do
end subroutine constructConnections