anchor.diff:  
       end subroutine collapse_cluster
   
  +    subroutine convert_excitor_to_determinant(excitor, excitor_level, excitor_population)
  +
  +        ! We usually consider an excitor as a bit string representation of the
  +        ! determinant formed by applying the excitor (a group of annihilation
  +        ! and creation operators) to the reference determinant; indeed the
  +        ! determinant form is required when constructing Hamiltonian matrix
  +        ! elements.  However, the resulting determinant might actually contain
  +        ! a sign change, which needs to be absorbed into the (signed) population
  +        ! of excips on the excitor.
  +
  +        ! This results from the fact that a determinant, |D>, is defined as:
  +        !   |D> = a^+_i a^+_j ... a^+_k |0>,
  +        ! where |0> is the vacuum, a^+_i creates an electron in the i-th
  +        ! orbital, i<j<...<k and |0> is the vacuum.  An excitor is defined as
  +        !   t_{ij...k}^{ab...c} = a^+_a a^+_b ... a^+_c a_i a_j ... a_k
  +        ! where i<j<...<k and a<b<...<c.  (This definition is somewhat
  +        ! arbitrary; the key thing is to be consistent.)  Hence applying an
  +        ! excitor to the reference might result in a change of sign, i.e.
  +        ! t_{ij}^{ab} |D_0> = -|D_{ij}^{ab}>.  As a more concrete example,
  +        ! consider a set of spin states (as the extension to fermions is
  +        ! irrelevant to the argument), with the reference:
  +        !   |D_0> = | 1 2 3 >
  +        ! and the excitor
  +        !   t_{13}^{58}
  +        ! Thus:
  +        !   t_{13}^{58} | 1 2 3 > = + a^+_5 a^+_8 a_3 a_1 a^+_1 a^+_2 a^+_3 |0>
  +        !                         = + a^+_5 a^+_8 a_3 a^+_2 a^+_3 |0>
  +        !                         = - a^+_5 a^+_8 a_3 a^+_3 a^+_2 |0>
  +        !                         = - a^+_5 a^+_8 a^+_2 |0>
  +        !                         = + a^+_5 a^+_2 a^+_8 |0>
  +        !                         = - a^+_2 a^+_5 a^+_8 |0>
  +        !                         = - | 2 5 8 >
  +        ! Similarly
  +        !   t_{12}^{58} | 1 2 3 > = + a^+_5 a^+_8 a_2 a_1 a^+_1 a^+_2 a^+_3 |0>
  +        !                         = + a^+_5 a^+_8 a_2 a^+_2 a^+_3 |0>
  +        !                         = + a^+_5 a^+_8 a^+_3 |0>
  +        !                         = - a^+_5 a^+_3 a^+_8 |0>
  +        !                         = + a^+_3 a^+_5 a^+_8 |0>
  +        !                         = + | 3 5 8 >
  +
  +        ! This potential sign change must be taken into account; we do so by
  +        ! absorbing the sign into the signed population of excips on the
  +        ! excitor.
  +
  +        ! Essentially taken from Alex Thom's original implementation.
  +
  +        ! In:
  +        !    excitor: bit string of the Slater determinant formed by applying
  +        !        the excitor to the reference determinant.
  +        !    excitor_level: excitation level, relative to the reference
  +        !        determinant, of the excitor.  Equal to the number of
  +        !        annihilation (or indeed creation) operators in the excitor.
  +        ! In/Out:
  +        !    excitor_population: population of excips on the excitor.  On output
  +        !        this acquires, if required, a sign change due to applying the
  +        !        excitor to the reference determinant to form a Slater determinant.
  +        !        Note that this is still a *signed* variable on input.
  +
  +        use basis, only: basis_length
  +        use const, only: i0_end
  +        use fciqmc_data, only: f0
  +
  +        integer(i0), intent(in) :: excitor(basis_length)
  +        integer, intent(in) :: excitor_level
  +        integer, intent(inout) :: excitor_population
  +
  +        integer(i0) :: excitation(basis_length)
  +        integer :: ibasis, ibit, ncreation, nannihilation
  +
  +        ! Bits involved in the excitation from the reference determinant.
  +        excitation = ieor(f0, excitor)
  +
  +        nannihilation = excitor_level
  +        ncreation = excitor_level
  +
  +        ! Obtain sign change by (implicitly) constructing the determinant formed
  +        ! by applying the excitor to the reference determinant.
  +        do ibasis = 1, basis_length
  +            do ibit = 0, i0_end
  +                if (btest(f0(ibasis),ibit)) then
  +                    ! Occupied orbital in reference.
  +                    if (btest(excitation(ibasis),ibit)) then
  +                        ! Orbital excited from...annihilate electron.
  +                        ! This amounts to one fewer operator in the cluster through
  +                        ! which the other creation operators in the determinant must
  +                        ! permute.
  +                        nannihilation = nannihilation - 1
  +                    else
  +                        ! Orbital is occupied in the reference and once the
  +                        ! excitor has been applied.
  +                        ! Permute the corresponding creation operator through
  +                        ! the remaining creation and annihilation operators of
  +                        ! the excitor (which operate on orbitals with a higher
  +                        ! index than the current orbital).
  +                        ! If the permutation is odd, then we incur a sign
  +                        ! change.
  +                        if (mod(nannihilation+ncreation,2) == 1) &
  +                            excitor_population = -excitor_population
  +                    end if
  +                else if (btest(excitation(ibasis),ibit)) then
  +                    ! Orbital excited to...create electron.
  +                    ! This amounts to one fewer operator in the cluster through
  +                    ! which the creation operators in the determinant must
  +                    ! permute.
  +                    ! Note due to definition of the excitor, it is guaranteed
  +                    ! that this is created in the correct place, ie there are no
  +                    ! other operators in the excitor it needs to be interchanged
  +                    ! with.
  +                    ncreation = ncreation - 1
  +                end if
  +            end do
  +        end do
  +
  +    end subroutine convert_excitor_to_determinant
  +
   end module ccmc
  
positive.code: 
          use calc, only: truncation_level
          use determinants, only: det_info
          use dSFMT_interface, only: genrand_real2
          use fciqmc_data, only: f0, D0_population, tot_walkers, &
                                 walker_population, walker_dets
  
negative.code:             pcluster = pcluster/(1.0_p - psize)
          end if
  
          select case(cluster_size)
          case(0)
              ! Must be the reference.
  