anchor.diff:  end
   
   
  -
  -
  -
  -
  -
  +subroutine find_triples_and_quadruples_micro(i_generator,n_selected,det_buffer,Nint,tq,N_tq,microlist,ptr_microlist,N_microlist,key_mask)
  +
  + use bitmasks
  + implicit none
  +
  +  integer, intent(in)            :: i_generator,n_selected, Nint
  +
  +  integer(bit_kind), intent(in)  :: det_buffer(Nint,2,n_selected)
  +  integer                        :: i,j,k,m
  +  logical                        :: is_in_wavefunction
  +  integer                        :: degree(psi_det_size)
  +  integer                        :: idx(0:psi_det_size)
  +  logical                        :: good
  +
  +  integer(bit_kind), intent(out) :: tq(Nint,2,n_selected)
  +  integer, intent(out)           :: N_tq
  +  
  +  
  +  integer                        :: nt,ni
  +  logical, external              :: is_connected_to
  +  
  +  
  +  integer(bit_kind),intent(in)  :: microlist(Nint,2,*)
  +  integer,intent(in)  :: ptr_microlist(0:*)
  +  integer,intent(in)            :: N_microlist(0:*)
  +  integer(bit_kind),intent(in)   :: key_mask(Nint, 2)
  +  
  +  integer :: mobiles(2), smallerlist
  +  
  +  N_tq = 0
  +  
  +  
  +  
  +  i_loop : do i=1,N_selected
  +    call getMobiles(det_buffer(1,1,i), key_mask, mobiles, Nint) 
  +    if(N_microlist(mobiles(1)) < N_microlist(mobiles(2))) then
  +      smallerlist = mobiles(1)
  +    else
  +      smallerlist = mobiles(2)
  +    end if
  +    
  +    if(N_microlist(smallerlist) > 0) then
  +      if(is_connected_to(det_buffer(1,1,i), microlist(1,1,ptr_microlist(smallerlist)), Nint, N_microlist(smallerlist))) then
  +        cycle
  +      end if
  +    end if
  +    
  +    if(N_microlist(0) > 0) then
  +      if(is_connected_to(det_buffer(1,1,i), microlist, Nint, N_microlist(0))) then
  +        cycle
  +      end if
  +    end if
  +
  +    ! Select determinants that are triple or quadruple excitations
  +    ! from the ref
  +    good = .True.
  +    call get_excitation_degree_vector(psi_ref,det_buffer(1,1,i),degree,Nint,N_det_ref,idx) 
  +    !good=(idx(0) == 0) tant que degree > 2 pas retourné par get_excitation_degree_vector
  +    do k=1,idx(0)
  +      if (degree(k) < 3) then
  +        good = .False.
  +        exit
  +      endif
  +    enddo
  +    if (good) then
  +      if (.not. is_in_wavefunction(det_buffer(1,1,i),Nint,N_det)) then
  +        N_tq += 1
  +        do k=1,N_int
  +          tq(k,1,N_tq) = det_buffer(k,1,i)
  +          tq(k,2,N_tq) = det_buffer(k,2,i)
  +        enddo
  +      endif
  +    endif
  +  enddo i_loop
  +end
  +
  +
  +
  +
  +
  +
  
positive.code:       call omp_unset_lock( psi_ref_lock(i_I) )
      enddo
    enddo
    deallocate (dIa_hla,hij_cache)
    deallocate(miniList, idx_miniList)
  end
  
  
  
   BEGIN_PROVIDER [ integer(bit_kind), gen_det_sorted,  (N_int,2,N_det_generators,2) ]
  &BEGIN_PROVIDER [ integer, gen_det_shortcut, (0:N_det_generators,2) ]
  &BEGIN_PROVIDER [ integer, gen_det_version, (N_int, N_det_generators,2) ]
  &BEGIN_PROVIDER [ integer, gen_det_idx, (N_det_generators,2) ]
    gen_det_sorted(:,:,:,1) = psi_det_generators(:,:,:N_det_generators)
    gen_det_sorted(:,:,:,2) = psi_det_generators(:,:,:N_det_generators)
    call sort_dets_ab_v(gen_det_sorted(:,:,:,1), gen_det_idx(:,1), gen_det_shortcut(0:,1), gen_det_version(:,:,1), N_det_generators, N_int)
    call sort_dets_ba_v(gen_det_sorted(:,:,:,2), gen_det_idx(:,2), gen_det_shortcut(0:,2), gen_det_version(:,:,2), N_det_generators, N_int)
  END_PROVIDER
  
  
  subroutine find_triples_and_quadruples(i_generator,n_selected,det_buffer,Nint,tq,N_tq,miniList,N_miniList)
  
negative.code:   integer                        :: N_miniList, ni, leng
    double precision, allocatable  :: hij_cache(:)
    
    integer(bit_kind), allocatable :: microlist(:,:,:), microlist_zero(:,:,:)
    integer, allocatable           :: idx_microlist(:), N_microlist(:), ptr_microlist(:), idx_microlist_zero(:)
    integer :: mobiles(2), smallerlist
    
    
    
    leng = max(N_det_generators, N_det_non_ref)
    allocate(miniList(Nint, 2, leng), idx_minilist(leng), hij_cache(N_det_non_ref))
    
    !create_minilist_find_previous(key_mask, fullList, miniList, N_fullList, N_miniList, fullMatch, Nint)
    call create_minilist_find_previous(key_mask, psi_det_generators, miniList, i_generator-1, N_miniList, fullMatch, Nint)
  