subroutine build_full_hamiltonian_from_sparse(this, full_ham)
type(HamiltonianCalcType), intent(inout) :: this
HElement_t(dp), intent(out) :: full_ham(:, :)
HElement_t(dp), allocatable :: vec(:)
integer :: i, ierr
write(stdout, *) "converting sparse hamiltonian to full"
safe_malloc(vec, (this%space_size))
do i = 1, this%space_size
call MPIBarrier(ierr)
vec = h_cast(0.0_dp)
vec(i) = h_cast(1.0_dp)
if (iprocindex == root) then
call multiply_hamil_and_vector(this, vec, full_ham(i, 1:this%space_size))
else
call multiply_hamil_and_vector(this, vec, this%temp_out)
end if
write(stdout, *) i, "hamiltonian columns converted"
call MPIBarrier(ierr)
end do
safe_free(vec)
end subroutine build_full_hamiltonian_from_sparse