anchor.diff:      end do
       dIj_unique(1:size(X), s) = X(1:size(X))
   
  -!    double precision, external :: ddot
  -!    if (ddot (size(X), dIj_unique, 1, X, 1) < 0.d0) then
  -!      dIj_unique(1:size(X),s) = -X(1:size(X))
  -!    endif
  -    
     enddo
  -
  -  ! Adjust phase of dIj_unique
  -
  -!  double precision :: snorm
  -!  X = 0.d0
  -!  snorm = 0.d0
  -!  do s=1,N_states
  -!    norm = 0.d0
  -!    do i=1,N_det_non_ref
  -!      norm = norm + psi_non_ref_coef(i,s)*psi_non_ref_coef(i,s)
  -!    enddo
  -!    norm = dsqrt(norm)
  -!    X(1:size(X)) = X(1:size(X)) + dIj_unique(1:size(X),s) * norm
  -!    snorm += norm
  -!  enddo
  -!  X = X/snorm
   
     do s=1,N_states
   
  
positive.code:         i = active_excitation_to_determinants_idx(j,a_coll)
          if (i==0) exit
          rho_mrcc(i,s) = rho_mrcc(i,s) + active_excitation_to_determinants_val(s,j,a_coll) * dIj_unique(a_col,s)
  !        rho_mrcc(i,s) = rho_mrcc(i,s) + active_excitation_to_determinants_val(s,j,a_coll) * X(a_col)
        enddo
      end do
  
  
negative.code:    enddo
     call u_0_S2_u_0(CI_eigenvectors_s2_dressed,CI_eigenvectors_dressed,N_det,psi_det,N_int,&
            N_states_diag,size(CI_eigenvectors_dressed,1))
  
     deallocate (eigenvectors,eigenvalues)
       
  