create_one_spin_basis Function

public function create_one_spin_basis(n_orbs, n_spins) result(one_spin_basis)


Type IntentOptional Attributes Name
integer, intent(in) :: n_orbs
integer, intent(in) :: n_spins

Return Value integer(kind=n_int), allocatable, (:)


Source Code

Source Code

    function create_one_spin_basis(n_orbs, n_spins) result(one_spin_basis)
        integer, intent(in) :: n_orbs, n_spins
        integer(n_int), allocatable :: one_spin_basis(:)
#ifdef DEBUG_
        character(*), parameter :: this_routine = "create_one_spin_basis"

        integer :: n_max_states, i, right_zero
        integer(n_int) :: count_mask, n_set_zero

        n_max_states = int(choose_i64(n_orbs, n_spins))


        ! create the first basis state:
        one_spin_basis(1) = maskr(n_spins)

        ! implement my matlab routine to create the basis states:
        ! but now i have to do it for spin-orbital encoding!
        ! but do this afterwards so the mapping is easier for off-half-filling!
        do i = 2, n_max_states

            ! copy last state:
            one_spin_basis(i) = one_spin_basis(i - 1)

            ! find the right-most zero with atleast one 1 right of it
            right_zero = right_most_zero(one_spin_basis(i), n_orbs)

            ! if the right-most zero is bigger than n_orbs already, we should
            ! have been finished already..
            ASSERT(right_zero <= n_orbs)

            ! i need to count the number of 1 right of this zero
            ! so i want a mask where every bit right of right_zero is set
            ! to one
            count_mask = maskr(right_zero - 1)
            n_set_zero = popcnt(iand(one_spin_basis(i), count_mask))

            ! now i want to set the right_most zero to one
            one_spin_basis(i) = ibset(one_spin_basis(i), right_zero - 1)

            ! and everything to 0 right of it for now
            one_spin_basis(i) = iand(one_spin_basis(i), not(count_mask))

            ! and then we want to set n_set_zero bits to the very right of
            ! our bit-string
            one_spin_basis(i) = merge_bits(one_spin_basis(i), maskr(n_set_zero - 1, n_int), not(maskr(n_set_zero - 1, n_int)))

        end do

    end function create_one_spin_basis