# Attaching leads to honeycomb lattice

**URL:** https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304
**Category:** Quantum
**Created:** [March 7, 2024, 3:23pm UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304 "2024-03-07T15:23:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![alex123](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@alex123](https://discourse.julialang.org/u/alex123)
#### Post date: [March 7, 2024, 3:23pm UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304/1 "2024-03-07T15:23:07Z")

</div>

Hi,

I am trying to attach leads with a honeycomb basis to a honeycomb lattice, and can’t seem to understand why my code doesn’t work, I don’t really understand the logic of attaching the lead (and how the r variable is defined):

hgraph = LP.honeycomb() |\> onsite(4) - hopping(1) |\> supercell(3,3)  
glead = LP.honeycomb() |\> onsite(4) - hopping(1) |\> supercell((0, 1), region = r → abs(r[1]) \<= √3/3)  
|\> greenfunction(GS.Schur(boundary = 0));

g = hgraph |\>  
attach(glead, region = r → r[1] == 1) |\>  
greenfunction

The parent lattice and lead look as follows:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/3/032efc735195d2c945dc19e4bfc30398c840127f.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/8/38096afb2f78ff82f772544d41cb615511086a44.png)

@pablosanjose

---

<div class="post-metadata">

### Author: ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)
#### Post date: [March 7, 2024, 4:19pm UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304/2 "2024-03-07T16:19:17Z")

</div>

Something like this?

```julia
julia> using GLMakie, Quantica

julia> glead = LP.honeycomb() |> onsite(4) - hopping(1) |> supercell((1,-1), region = r -> -3.5 <= r[2] <= 3.5) |> greenfunction(GS.Schur(boundary = 0));

julia> qplot(glead, selector = siteselector(; cells = 1:10), sitecolor = :blue)

julia> gcentral = LP.honeycomb() |> onsite(4) - hopping(1) |> supercell(region = RP.rectangle((11,10))) |> attach(glead, region = r -> r[1] > 5.1 && -3.5 <= r[2] <= 3.5) |> greenfunction;

julia> qplot(gcentral, children =(; selector = siteselector(cells = 1:3), sitecolor = :blue))

```

 ![Screenshot 2024-03-07 at 17.17.00](https://global.discourse-cdn.com/julialang/original/3X/d/7/d7a8a4735b466ac49b9447be77eaab795b0c46c4.png)  
 ![Screenshot 2024-03-07 at 17.17.55](https://global.discourse-cdn.com/julialang/original/3X/0/c/0c2115e4c07b8f7ba5fb38bf677d27ae2be37365.png)

Note that these plots use current master, which you can get with `] add Quantica#master`

---

<div class="post-metadata">

### Author: ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)
#### Post date: [March 7, 2024, 4:22pm UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304/3 "2024-03-07T16:22:46Z")

</div>

The `attach` logic is probably a bit confusing at first. The way to understand it is that it adds a self energy to some sites in your Hamiltonian, creating a “contact” on those sites. The core syntax is then simply `attach(h::AbstractHamiltonian, Σ::SelfEnergy; sites...)`, or the curried version `h |> attach(Σ; sites...)`. Then, instead of you actually building the self energy, you have a series of additional `attach` methods (see docs), like the `h |> attach(glead::GreenFunction; sites...)` above, that compute the self-energy for you. The net result is an `OpenHamiltonian`, that when converted to a `GreenFunction` with the appropiate `GreenSolver` (here `GS.Schur`), allows you to compute different observables.

---

<div class="post-metadata">

### Author: ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)
#### Post date: [March 7, 2024, 5:54pm UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304/4 "2024-03-07T17:54:15Z")

</div>

Another geometry, perhaps closer to what you had in mind:

```julia
julia> glead = LP.honeycomb() |> onsite(4) - hopping(1) |> supercell(3,1) |> supercell((0,-1))|> greenfunction(GS.Schur(boundary = 0));

julia> gcentral = LP.honeycomb() |> onsite(4) - hopping(1) |> supercell(3,3) |> supercell |> attach(glead, region = r -> SA[-√3/2,1/2]' * r < 0) |> greenfunction;

julia> qplot(gcentral)

```

Note that since the central lattice is just a piece of the lead in this case, any observable you compute with `gcentral` (round sites) you could also get with `glead` (square sites, extending to infinity)

 ![Screenshot 2024-03-07 at 18.53.18](https://global.discourse-cdn.com/julialang/original/3X/4/a/4aa92f8647073b5c9f86d95c2377891cee81b369.png)

---

<div class="post-metadata">

### Author: ![Milt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milt/32/205510_2.png) [@Milt](https://discourse.julialang.org/u/Milt)
#### Post date: [April 11, 2024, 4:18pm UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304/6 "2024-04-11T16:18:02Z")

</div>

Hi @pablosanjose ,

Is it possible to attach a square lead onto a honeycombe lattice?

I am attempting to attach leads horizontally in the following way:

```julia
glead = LP.square(a0 = 2*cos(π/6), dim = 2) |> onsite(4) - hopping(1) |> supercell((1,0), region = r -> -2 <= r[2] <= 2) |> greenfunction(GS.Schur(boundary = 0));

cell = LP.honeycomb() |> onsite(4) - hopping(1) |> supercell(region = RP.rectangle((14,14))) |> transform(Rot)

green = cell |> 
attach(glead, region = r -> r[1] > 7 && -1.5 <= r[2] <= 1.5, reverse = false) |> 
greenfunction

```

Many thanks

---

<div class="post-metadata">

### Author: ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)
#### Post date: [April 12, 2024, 9:10am UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304/7 "2024-04-12T09:10:32Z")

</div>

Hi @Milt, yes you can. Since the glead and cell are not lattice-matched, you need to use the `attach(::GreenSlice, ::Model; siteselection...)` syntax, i.e. you need to define how the two systems are coupled. You also need to make sure `siteselection` selects a finite number of sites (otherwise attach will throw a [currently obscure] error), and you need to translate the unit cell of glead that you want to couple (given in GreenSlice) so that it is located where you want.

Following your example you would then need something like this:

```julia
using Quantica
using GLMakie

Rot = r -> SA[0 -1; 1 0] * r

glead = LP.square(a0 = 2*cos(π/6), dim = 2) |> onsite(4) - hopping(1) |> supercell((1,0), region = r -> -2 <= r[2] <= 2) |> translate((6,0)) |> greenfunction(GS.Schur(boundary = 0));

cell = LP.honeycomb() |> onsite(4) - hopping(1) |> supercell(region = RP.rectangle((14,14))) |> transform(Rot)

green = cell |> attach(glead[cells = 1], -hopping(1, range = 2), region = r -> r[1] > 6.5 && -1.5 <= r[2] <= 1.5) |> greenfunction

qplot(green)

```

The plot (using current Quantica master) would give you this

 ![Screenshot 2024-04-12 at 11.10.13](https://global.discourse-cdn.com/julialang/original/3X/7/8/7803ef92d842b7c5a22f834d8bb5e4acb5b5a626.jpeg)

---

<div class="post-metadata">

### Author: ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)
#### Post date: [April 12, 2024, 9:30am UTC](https://discourse.julialang.org/t/attaching-leads-to-honeycomb-lattice/111304/8 "2024-04-12T09:30:41Z")

</div>

That said, I suspect you wanted to have the same lattice spacing in the lead, right? It’s good to remember that the default lattice spacing of all lattice preset is one. In the honeycomb that is the next-nearest-neighbor distance, so the nearest neighbor distance is 1/sqrt(3). Hence, you might have intended to do

```julia
using Quantica
using GLMakie

Rot = r -> SA[0 -1; 1 0] * r

glead = LP.square(a0 = 1, dim = 2) |> onsite(4) - hopping(1) |> supercell((1,0), region = r -> -1 <= r[2] <= 1) |> translate((6.5,0)) |> greenfunction(GS.Schur(boundary = 0));

cell = LP.honeycomb() |> onsite(4) - hopping(1) |> supercell(region = RP.rectangle((14,14))) |> transform(Rot)

green = cell |> attach(glead[cells = 1], -hopping(1), region = r -> r[1] > 6.5 && -1.5 <= r[2] <= 1.5) |> greenfunction

qplot(green)

```

 ![Screenshot 2024-04-12 at 11.28.52](https://global.discourse-cdn.com/julialang/original/3X/3/5/3504ae7f36bf446a46962569073fa7e43e9f10fb.jpeg)

It would seem that the cell surface and the lead are lattice-matched, but the two lattices have different number of sublattices, so currently one must use the more general attach method. You got me thinking, however, that one could perhaps generalize the simplified attach method a bit to make it work also in this case. I’ll give it a try when I have time.
