subroutine calc_hamil_contribs_semistoch(nvecs, krylov_array, h_matrix, partial_vecs)
use bit_rep_data, only: IlutBits
use core_space_util, only: cs_replicas
use Parallel_neci, only: iProcIndex
use SystemData, only: nel
integer, intent(in) :: nvecs
integer(n_int), intent(in) :: krylov_array(0:, :)
real(dp), intent(inout) :: h_matrix(:, :)
real(dp), intent(in) :: partial_vecs(:, :)
integer :: idet, i, j
integer :: nI_spawn(nel)
integer(n_int) :: int_sign(lenof_all_signs)
real(dp) :: real_sign(lenof_all_signs)
do idet = 1, cs_replicas(1)%determ_sizes(iProcIndex)
int_sign = krylov_array(IlutBits%ind_pop:IlutBits%ind_pop + lenof_all_signs - 1, idet)
real_sign = transfer(int_sign, real_sign)
do i = 1, nvecs
do j = i, nvecs
h_matrix(i, j) = h_matrix(i, j) + &
(real_sign(kp_ind_2(j)) * partial_vecs(kp_ind_1(i), idet) + &
real_sign(kp_ind_1(j)) * partial_vecs(kp_ind_2(i), idet)) / 2.0_dp
end do
end do
end do
end subroutine calc_hamil_contribs_semistoch