subroutine diagonalize_core(e_value, e_vector, rep)
real(dp), intent(out) :: e_value
HElement_t(dp), intent(out), allocatable :: e_vector(:)
type(core_space_t), intent(in) :: rep
type(DavidsonCalcType) :: davidsonCalc
integer :: ierr
character(*), parameter :: t_r = "diagonalize_core"
call create_sparse_ham_from_core(rep)
! Call the Davidson routine to find the ground state of the core space.
call perform_davidson(davidsonCalc, parallel_sparse_hamil_type, .true.)
e_value = davidsonCalc%davidson_eigenvalue
allocate(e_vector(rep%determ_space_size))
e_vector = davidsonCalc%davidson_eigenvector
write(stdout, '(a30)') "Davidson calculation complete."
write(stdout, '("Deterministic total energy:",1X,f15.10)') &
e_value + Hii
call neci_flush(stdout)
call DestroyDavidsonCalc(davidsonCalc)
! call LogMemDealloc(t_r, DavidsonTag, ierr)
deallocate(hamil_diag, stat=ierr)
call LogMemDealloc(t_r, HDiagTag, ierr)
call deallocate_sparse_ham(sparse_ham, SparseHamilTags)
end subroutine diagonalize_core