set_alpha_beta_spins Function

public function set_alpha_beta_spins(beta_mask, n_orbs, t_beta) result(beta_spins)

Arguments

Type IntentOptional Attributes Name
integer(kind=n_int), intent(in) :: beta_mask
integer, intent(in) :: n_orbs
logical, intent(in) :: t_beta

Return Value integer(kind=n_int)


Contents

Source Code


Source Code

    function set_alpha_beta_spins(beta_mask, n_orbs, t_beta) result(beta_spins)
        ! a function which converts a flag of spatial beta-spins to a
        ! spin orbita basis, eg.: 0011 -> 00 00 01 01
        integer(n_int), intent(in) :: beta_mask
        integer, intent(in) :: n_orbs
        logical, intent(in) :: t_beta
        integer(n_int) :: beta_spins

        integer, allocatable :: nOnes(:)
        integer :: i

        allocate(nOnes(popcnt(iand(beta_mask, int(maskr(n_orbs), n_int)))))

        beta_spins = 0_n_int
        if (size(nOnes) == 0) then
            return
        else
            call decode_bit_det(nOnes, [beta_mask])

            if (t_beta) then
                ! then we want to set beta spins:
                nOnes = 2 * nOnes - 1
            else
                ! otherwise we want to set alpha spins
                nOnes = 2 * nOnes
            end if

            do i = 1, size(nOnes)
                beta_spins = ibset(beta_spins, nOnes(i) - 1)
            end do
        end if

    end function set_alpha_beta_spins