anchor.diff:          !    <D|H|D>, the diagonal Hamiltonian matrix element involving D for
           !    systems defined by integrals read in from an FCIDUMP file.
   
  -        use basis, only: basis_length
  +        use basis, only: basis_length, basis_fns
           use determinants, only: decode_det
  -        use molecular_integrals, only: get_one_body_int_mol, get_two_body_int_mol, &
  -                                       get_two_body_int_mol_nonzero, one_e_h_integrals, &
  -                                       coulomb_integrals
  +        use molecular_integrals, only: get_one_body_int_mol_nonzero, get_two_body_int_mol_nonzero, &
  +                                       one_e_h_integrals, coulomb_integrals
           use system, only: nel, Ecore
   
           real(p) :: hmatel
  
positive.code:         hmatel = Ecore
          do iel = 1, nel
              i = occ_list(iel)
              hmatel = hmatel + get_one_body_int_mol(one_e_h_integrals, i, i)
              do jel = iel, nel
                  j = occ_list(jel)
                  hmatel = hmatel + get_two_body_int_mol_nonzero(coulomb_integrals, i, j, i, j) &
                                  - get_two_body_int_mol(coulomb_integrals, i, j, j, i)
              end do
          end do
  
  
negative.code: 
      end function slater_condon2_mol
  
      elemental function slater_condon2_mol_excit(i, j, a, b, perm) result(hmatel)
  
          ! In:
          !    i: the spin-orbital from which an electron is excited in
          !       the reference determinant.
          !    j: the spin-orbital from which an electron is excited in
          !       the reference determinant.
          !    a: the spin-orbital into which an electron is excited in
          !       the excited determinant.
          !    b: the spin-orbital into which an electron is excited in
          !       the excited determinant.
          !    perm: true if an odd number of permutations are required for
          !       D and D_{ij}^{ab} to be maximally coincident.
          ! Returns:
          !    < D | H | D_{ij}^{ab} >, the Hamiltonian matrix element between a 
          !        determinant and a single excitation of it for systems defined
          !        by integrals read in from an FCIDUMP file.
          !
          ! Note that we don't actually need to directly refer to |D>.
          !
          ! WARNING: This function assumes that the D_{ij}^{ab} is a symmetry allowed
          ! excitation from D (and so the matrix element is *not* zero by
          ! symmetry).  This is less safe that slater_condon1_mol but much faster
          ! as it allows symmetry checking to be skipped in the integral lookups.
  
          use basis, only: basis_fns
          use molecular_integrals, only: get_two_body_int_mol_nonzero, coulomb_integrals
          use system, only: nel
  
          real(p) :: hmatel
          integer, intent(in) :: i, j, a, b
          logical, intent(in) :: perm
  
          ! < D | H | D_{ij}^{ab} > = < ij || ab >
  
          hmatel = 0.0_p
  
          if (basis_fns(i)%Ms == basis_fns(a)%Ms) &
              hmatel = hmatel + get_two_body_int_mol_nonzero(coulomb_integrals, i, j, a, b) 
          if (basis_fns(i)%Ms == basis_fns(b)%Ms) &
              hmatel = hmatel - get_two_body_int_mol_nonzero(coulomb_integrals, i, j, b, a)
  
          if (perm) hmatel = -hmatel
  
      end function slater_condon2_mol_excit
  
  endmodule hamiltonian_molecular
  