# Lattice functions in itensor Julia

**URL:** <https://itensor.discourse.group/t/lattice-functions-in-itensor-julia/45>\
**Category:** ITensor Julia Questions\
**Tags:** dmrg\
**Created:** [April 17, 2022, 2:29pm UTC](https://itensor.discourse.group/t/lattice-functions-in-itensor-julia/45 "2022-04-17T14:29:53Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [April 19, 2022, 8:19pm UTC](https://itensor.discourse.group/t/lattice-functions-in-itensor-julia/45/5 "2022-04-19T20:19:13Z")

</div>

Hi KevinH,  
This may not answer all of your questions, but first of all I can tell you a bit more about what the data in a LatticeBond object means so you can be sure to write the third neighbor terms correctly.

A key thing is getting the `s1` and `s2` arguments (`n`,`n+Ny` and things like that) correct when making a LatticeBond. The meaning of these integers are the sites along a one-dimension “zig zag” path going through the lattice. This is because the primary use of LatticeBond is for making MPO tensor networks which are one-dimensional.

First, I’m providing a drawing of what I mean by a zig-zag path through an (Nx=4,Ny=4) square lattice. Note how the site numbers go up the first column (1,2,3,4), then jump to the bottom again (5,6,7,8) and so on.

 ![IMG_E3F020202B46-1](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/a85cf503e5bcfde062f6e06a41cd319e04e5c7f5.jpeg)

I’ve drawn all of the first and second neighbor bonds, for the case of `yperiodic=false` and I drew two of the third-neighbor bonds that you want to make.

Now let’s take the first-neighbor bonds coming out of site 6 as an example. You can see that the one going up connects to a site number that is one higher, so then we would make the LatticeBond for this bond as

```auto
LatticeBond(n,n+1,x,y,x,y+1)

```

Then let’s take the bond going to the right out of site 6. This one connects to site 10 which is `6+4` or `6+Ny` where `Ny=4` in this example. So for that kind of bond, we make a LatticeBond like

```auto
LatticeBond(n,n+Ny,x,y,x+1,y)

```

So for third-neighbor bonds, the pattern you will need is something like `n,n+2` for the vertical bonds going up and `n,n+2*Ny` for the horizontal bonds going to the right. But then in the code you can see additional care is needed to make these bonds only when there is actually a valid site to connect to. So for the example of first-neighbor bonds going up, we only make them when `y < Ny` otherwise we are at the top of the lattice and there are no more sites above to connect to.

I hope that helps explain most of the non-periodic bonds and how to make them.

For the y-periodic bonds, what you do is imagine another copy of the system above, with the same site numberings and everything. So in the drawing above (though I don’t show any periodic bonds explicitly there), if `yperiodic=true` then there would be a first-neighbor bond coming out of the top of site 4 connecting to the site “above” which is actually site 1 again. So we need a bond connecting site 1 to site 4 and that is what is made in the code for the case of `if yperiodic && y == 1`. You would do something similar for second- and third-neighbor bonds, drawing a second copy of the system above and working out the connections of the bonds that come out of the top of the lattice.’’

Here is a drawing of how to see the case of `yperiodic=true` and the first-neighbor bonds sticking out of the top:

 ![IMG_D85A0422B74B-1](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/0bae13864612ba93d2b2a7108e35115af100c670.jpeg)

Hope that helps!

Finally, I would suggest putting your function through a lot of tests. Count the number of bonds it returns: is it the right number for a bunch of different lattices? Maybe you can also run DMRG on an MPO made from your modified lattice function for a solvable case of your Hamiltonian (like say if it is a fermion system and there is a non-interacting limit) so you can compare your DMRG result to a numerically exact result.

---

_[View the full topic](https://itensor.discourse.group/t/lattice-functions-in-itensor-julia/45)._
