  subroutine set_vbare(vbare)
    use constants, only : dp
    use pw_types,  only : field, available, construct, field_ft, &
                          reciprocal_to_direct_space, reciprocal_space
    use structure, only  : atom, atoms, element, pseudo, species
    
    type(field)              :: vbare
    real(DP)                 :: q, dq
    complex(DP), pointer     :: vg(:), s(:)
    integer                  :: i,j,k, ig,  indx, n

    if (.not.available(vbare)) then
       call construct(vbare,RECIPROCAL_SPACE)
    else
       vbare%state = RECIPROCAL_SPACE
       vbare%val(:,:,:) = cmplx(ZERO,ZERO)
    end if

    do ig=1, vbare%ngm
       q = sqrt(vbare%gg(ig)*tpiba2)
       i = vbare%ig1(ig)
       j = vbare%ig2(ig)
       k = vbare%ig3(ig)

       do n=1, size(species)
          vg => species(n)%ps%vg
          s  => species(n)%s
          vbare%val(i,j,k) = vbare%val(i,j,k) + s(ig)*vg(ig)
       end do
    end do

    call field_ft(vbare,RECIPROCAL_TO_DIRECT_SPACE)
    
    return
  end subroutine set_vbare
