# F operator missing when creating Electronic Hamiltonian with ITensorChemistry.jl

**URL:** <https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162>\
**Category:** DMRG and Numerical Methods\
**Created:** [September 22, 2023, 1:12pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162 "2023-09-22T13:12:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![FTarocco](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@FTarocco](https://itensor.discourse.group/u/FTarocco)\
**Post date:** [September 22, 2023, 1:12pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/1 "2023-09-22T13:12:18Z")

</div>

Hi,  
I was looking at the source of molecular\_orbital\_hamiltonian.jl and noticed that the F operator was not included while creating the OpSum of the electronic hamiltonian.

```julia
  for i in 1:nα, j in 1:nα
    if norm(hα[i, j]) > atol
      add!(hamiltonian, hα[i, j], "c†↑", i, "c↑", j)
      add!(hamiltonian, hα[i, j], "c†↓", i, "c↓", j)
    end
  end

```

I’ve seen in literature that operator F

```julia
function op!(Op::ITensor, ::OpName"F", ::SiteType"ElecK", s::Index)
  Op[s' => 1, s => 1] = +1.0
  Op[s' => 2, s => 2] = -1.0
  Op[s' => 3, s => 3] = -1.0
  return Op[s' => 4, s => 4] = +1.0
end

```

must be applied on the sites that have an odd number of fermionic operators on the left.  
Can I have some clarification?

Thanks so much.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 22, 2023, 1:58pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/2 "2023-09-22T13:58:09Z")

</div>

Are these what you’re referring to: [https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/site\_types/electron.jl#L222-L253](https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/site_types/electron.jl#L222-L253)?

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [September 22, 2023, 1:59pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/3 "2023-09-22T13:59:13Z")

</div>

Oh I see you’re talking about the “ElecK” site type, where is that defined?

---

<div class="post-metadata">

**Author:** ![FTarocco](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@FTarocco](https://itensor.discourse.group/u/FTarocco)\
**Post date:** [September 22, 2023, 2:13pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/4 "2023-09-22T14:13:35Z")

</div>

Yes, i was cross-checking sitetypes and operator used in ITensorChemistry.  
The definition of “ElectK” I’ve made a mistake for searching the source code in ITensor repository.

In ITensorChemistry the sitetype is “Electron”, so I’m referring to this:

> <https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/site_types/electron.jl#L222-L253>

---

<div class="post-metadata">

**Author:** ![FTarocco](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@FTarocco](https://itensor.discourse.group/u/FTarocco)\
**Post date:** [September 22, 2023, 2:16pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/5 "2023-09-22T14:16:40Z")

</div>

In some papers, I’ve seen that fermionic operators have to be integrated with F to keep track of the phase factor originating from two anticommuting electrons on the same site with opposite spin

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [September 22, 2023, 2:28pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/6 "2023-09-22T14:28:34Z")

</div>

Thanks for the question. So the way this works in ITensors.jl is that when using the OpSum system, that system will put in the F operators for you when making Hamiltonians and other kinds of MPO’s. So it will be included, but you won’t see it happening because it will be done automatically behind the scenes.

The way OpSum knows which operators to attach string to is that it calls a function `has_fermion_string` which you can see defined for Electron operators here:  
[https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/site\_types/electron.jl#L321](https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/site_types/electron.jl#L321)

Similarly, if you use functions like `correlation_matrix` to compute quantities like \langle c^\dagger\_i c\_j \rangle then ITensor will put in the F strings for you there too.

The only case where you as a user have to put your own F strings is if you write code purely at the tensor contraction level where you contract e.g. MPS tensors together to compute observables. Hope that helps -

Miles

---

<div class="post-metadata">

**Author:** ![FTarocco](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@FTarocco](https://itensor.discourse.group/u/FTarocco)\
**Post date:** [September 22, 2023, 2:58pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/7 "2023-09-22T14:58:01Z")

</div>

Oh, now I see.  
I’ve checked the autompo function and it’s encoded in the part

> <https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/autompo/opsum_to_mpo_generic.jl#L68-L76>

right?

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [September 22, 2023, 7:42pm UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/8 "2023-09-22T19:42:54Z")

</div>

Yes, that is one place where OpSum handles (odd-parity) fermionic operators. But there are other places too, like this one:  
[https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/autompo/opsum\_to\_mpo.jl#L49](https://github.com/ITensor/ITensors.jl/blob/b04a9738c3de587c18e247353a0ad5cfe165f1d8/src/physics/autompo/opsum_to_mpo.jl#L49)

---

<div class="post-metadata">

**Author:** ![FTarocco](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@FTarocco](https://itensor.discourse.group/u/FTarocco)\
**Post date:** [September 25, 2023, 7:11am UTC](https://itensor.discourse.group/t/f-operator-missing-when-creating-electronic-hamiltonian-with-itensorchemistry-jl/1162/9 "2023-09-25T07:11:24Z")

</div>

Perfect!  
Thanks so much for clarification.

Fabio.
