Re: [Kwant] 3D structure construction with leads
Dear Anton, first, let me thank you for your help. I got some problems with it: 1) If I use the "ugly" way, there is an error popping up as soon as I attach the leads in the manner I wrote in my first mail: ... lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t lead[lat.neighbors()] = -t sys.attach_lead(lead) sys.attach_lead(lead.reversed()) ... ERROR: "ValueError: Builder does not interrupt the lead, this lead cannot be attached." 2) If I use the second way, there is a memory error even before attaching the leads. "... lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t lead[lat.neighbors()] = -t" I dont't know if I'm too stupid/new to kwant/... but I can't solve it. Best Julian
Dear Julian,
Once you execute make_cuboid(), you see the following error message:
12 13 lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) ---> 14 lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t 15 lead[lat.neighbors()] = -t 16
TypeError: 'Polyatomic' object is not callable
You wrote `lat(0, j, i)`, which is the correct way to deal with Monatomic lattices in Kwant. In fact this is just a short hand notation for a site of the lattice lat with Bravais vectors 0, j, i. If lat was a monatomic lattice, the code you're using would just add a bunch of sites of the form lat(0, j, i). In your case lat has several sublattices, so `lat(0, j, i)` does not have any meaning in Kwant. There are two ways to fix your code. If you want to stick to generator expressions [=loops of the form `(f(i) for i in somewhere)`], you can write e.g.
lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t
However, as you see, this becomes ugly. It's better to use shape, similarly to the way you defined the scattering region:
def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b
sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t
Note that here the lead_shape doesn't depend on the x-coordinate of the site, as required by translation invariance in x-direction. More generally, the shape function for the lead should respect the lead translational symmetry, or the results may be not what you would expect.
I hope this helps, Anton
On Mon, May 19, 2014 at 9:39 AM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear all,
I'm triying to figure out how to attach symmetrical leads to a 3D zincblende -structure in kwant. The code I used so far:
lat = kwant.lattice.general([(0, 0.5, 0.5), (0.5, 0, 0.5), (0.5, 0.5, 0)], [(0, 0, 0), (0.25, 0.25, 0.25)]) a, b = lat.sublattices def make_cuboid(t=1.0, a=15, b=10, c=5): def cuboid_shape(pos): x, y, z = pos return 0 <= x < a and 0 <= y < b and 0 <= z < c
sys = kwant.Builder() sys[lat.shape(cuboid_shape, (0, 0, 0))] = 4 * t sys[lat.neighbors()] = -t
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t lead[lat.neighbors()] = -t
#sys.attach_lead(lead) #sys.attach_lead(lead.reversed())
return sys
causes errors. Could you help me and tell me how to attach the leads in 3D,please?
Best regards,
Julian Depatment of Physics & Astronomy University of Würzburg (Germany)
Dear Julian, In order to meaningfully attach the lead to the system, the lead should be "stopped" by the system. That means if I follow the lead hoppings from unit cells that are far from the system (say -infinity), then eventually every possible path should end up at a system site, and there should be no path to +infinity that avoids the system. In your case the lead has a different (wider) cross-section than the system and that is the reason why the error message appears. Double-check the shapes of the lead and the system (in particular check whether a, b, and c appear consistently). The other error appears because you are adding sites from inside the lead shape (and that one is an infinite stripe, since it doesn't depend on the x-coordinate) to the system. It then doesn't come as a surprise that when you try to add infinite amount of sites to the system, you run out of memory. The lead, however has translational symmetry that matches the lead_shape, and allows to represent the infinite amount of sites using finite memory. So instead of sys[lat.shape(lead_shape, ...)] you should use lead[lat.shape(lead_shape, ...)]. Best, Anton On Tue, May 20, 2014 at 3:49 PM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear Anton,
first, let me thank you for your help. I got some problems with it:
1) If I use the "ugly" way, there is an error popping up as soon as I attach the leads in the manner I wrote in my first mail:
...
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t lead[lat.neighbors()] = -t
sys.attach_lead(lead) sys.attach_lead(lead.reversed()) ...
ERROR: "ValueError: Builder does not interrupt the lead, this lead cannot be attached."
2) If I use the second way, there is a memory error even before attaching the leads.
"...
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t lead[lat.neighbors()] = -t"
I dont't know if I'm too stupid/new to kwant/... but I can't solve it.
Best Julian
Dear Julian,
Once you execute make_cuboid(), you see the following error message:
12 13 lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) ---> 14 lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t 15 lead[lat.neighbors()] = -t 16
TypeError: 'Polyatomic' object is not callable
You wrote `lat(0, j, i)`, which is the correct way to deal with Monatomic lattices in Kwant. In fact this is just a short hand notation for a site of the lattice lat with Bravais vectors 0, j, i. If lat was a monatomic lattice, the code you're using would just add a bunch of sites of the form lat(0, j, i). In your case lat has several sublattices, so `lat(0, j, i)` does not have any meaning in Kwant. There are two ways to fix your code. If you want to stick to generator expressions [=loops of the form `(f(i) for i in somewhere)`], you can write e.g.
lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t
However, as you see, this becomes ugly. It's better to use shape, similarly to the way you defined the scattering region:
def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b
sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t
Note that here the lead_shape doesn't depend on the x-coordinate of the site, as required by translation invariance in x-direction. More generally, the shape function for the lead should respect the lead translational symmetry, or the results may be not what you would expect.
I hope this helps, Anton
On Mon, May 19, 2014 at 9:39 AM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear all,
I'm triying to figure out how to attach symmetrical leads to a 3D zincblende -structure in kwant. The code I used so far:
lat = kwant.lattice.general([(0, 0.5, 0.5), (0.5, 0, 0.5), (0.5, 0.5, 0)], [(0, 0, 0), (0.25, 0.25, 0.25)]) a, b = lat.sublattices def make_cuboid(t=1.0, a=15, b=10, c=5): def cuboid_shape(pos): x, y, z = pos return 0 <= x < a and 0 <= y < b and 0 <= z < c
sys = kwant.Builder() sys[lat.shape(cuboid_shape, (0, 0, 0))] = 4 * t sys[lat.neighbors()] = -t
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t lead[lat.neighbors()] = -t
#sys.attach_lead(lead) #sys.attach_lead(lead.reversed())
return sys
causes errors. Could you help me and tell me how to attach the leads in 3D,please?
Best regards,
Julian Depatment of Physics & Astronomy University of Würzburg (Germany)
Dear Anton, now everything works. Thank you very much for the help. Just one note: The two methods yield different results, e.g. I attach a picture of the system. Method 2 is what I was expecting. Best Julian Zitat von Anton Akhmerov <anton.akhmerov@gmail.com>:
Dear Julian,
In order to meaningfully attach the lead to the system, the lead should be "stopped" by the system. That means if I follow the lead hoppings from unit cells that are far from the system (say -infinity), then eventually every possible path should end up at a system site, and there should be no path to +infinity that avoids the system. In your case the lead has a different (wider) cross-section than the system and that is the reason why the error message appears. Double-check the shapes of the lead and the system (in particular check whether a, b, and c appear consistently).
The other error appears because you are adding sites from inside the lead shape (and that one is an infinite stripe, since it doesn't depend on the x-coordinate) to the system. It then doesn't come as a surprise that when you try to add infinite amount of sites to the system, you run out of memory. The lead, however has translational symmetry that matches the lead_shape, and allows to represent the infinite amount of sites using finite memory. So instead of sys[lat.shape(lead_shape, ...)] you should use lead[lat.shape(lead_shape, ...)].
Best, Anton
On Tue, May 20, 2014 at 3:49 PM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear Anton,
first, let me thank you for your help. I got some problems with it:
1) If I use the "ugly" way, there is an error popping up as soon as I attach the leads in the manner I wrote in my first mail:
...
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t lead[lat.neighbors()] = -t
sys.attach_lead(lead) sys.attach_lead(lead.reversed()) ...
ERROR: "ValueError: Builder does not interrupt the lead, this lead cannot be attached."
2) If I use the second way, there is a memory error even before attaching the leads.
"...
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t lead[lat.neighbors()] = -t"
I dont't know if I'm too stupid/new to kwant/... but I can't solve it.
Best Julian
Dear Julian,
Once you execute make_cuboid(), you see the following error message:
12 13 lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) ---> 14 lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t 15 lead[lat.neighbors()] = -t 16
TypeError: 'Polyatomic' object is not callable
You wrote `lat(0, j, i)`, which is the correct way to deal with Monatomic lattices in Kwant. In fact this is just a short hand notation for a site of the lattice lat with Bravais vectors 0, j, i. If lat was a monatomic lattice, the code you're using would just add a bunch of sites of the form lat(0, j, i). In your case lat has several sublattices, so `lat(0, j, i)` does not have any meaning in Kwant. There are two ways to fix your code. If you want to stick to generator expressions [=loops of the form `(f(i) for i in somewhere)`], you can write e.g.
lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t
However, as you see, this becomes ugly. It's better to use shape, similarly to the way you defined the scattering region:
def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b
sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t
Note that here the lead_shape doesn't depend on the x-coordinate of the site, as required by translation invariance in x-direction. More generally, the shape function for the lead should respect the lead translational symmetry, or the results may be not what you would expect.
I hope this helps, Anton
On Mon, May 19, 2014 at 9:39 AM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear all,
I'm triying to figure out how to attach symmetrical leads to a 3D zincblende -structure in kwant. The code I used so far:
lat = kwant.lattice.general([(0, 0.5, 0.5), (0.5, 0, 0.5), (0.5, 0.5, 0)], [(0, 0, 0), (0.25, 0.25, 0.25)]) a, b = lat.sublattices def make_cuboid(t=1.0, a=15, b=10, c=5): def cuboid_shape(pos): x, y, z = pos return 0 <= x < a and 0 <= y < b and 0 <= z < c
sys = kwant.Builder() sys[lat.shape(cuboid_shape, (0, 0, 0))] = 4 * t sys[lat.neighbors()] = -t
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t lead[lat.neighbors()] = -t
#sys.attach_lead(lead) #sys.attach_lead(lead.reversed())
return sys
causes errors. Could you help me and tell me how to attach the leads in 3D,please?
Best regards,
Julian Depatment of Physics & Astronomy University of Würzburg (Germany)
----- Anhänge (Die Links sind bis zum 30.11.2014 gültig) https://webmail.uni-wuerzburg.de/imp/attachment.php?u=s221330&t=1400671840&f=sys01.tif https://webmail.uni-wuerzburg.de/imp/attachment.php?u=s221330&t=1400671840&f=sys02.tif
Dear Julian, I believe, the only reason for the two methods yielding different results could be the wrong loop parameters for the first method. Best, Anton On Wed, May 21, 2014 at 1:30 PM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear Anton,
now everything works. Thank you very much for the help. Just one note: The two methods yield different results, e.g. I attach a picture of the system.
Method 2 is what I was expecting.
Best Julian
Zitat von Anton Akhmerov <anton.akhmerov@gmail.com>:
Dear Julian,
In order to meaningfully attach the lead to the system, the lead should be "stopped" by the system. That means if I follow the lead hoppings from unit cells that are far from the system (say -infinity), then eventually every possible path should end up at a system site, and there should be no path to +infinity that avoids the system. In your case the lead has a different (wider) cross-section than the system and that is the reason why the error message appears. Double-check the shapes of the lead and the system (in particular check whether a, b, and c appear consistently).
The other error appears because you are adding sites from inside the lead shape (and that one is an infinite stripe, since it doesn't depend on the x-coordinate) to the system. It then doesn't come as a surprise that when you try to add infinite amount of sites to the system, you run out of memory. The lead, however has translational symmetry that matches the lead_shape, and allows to represent the infinite amount of sites using finite memory. So instead of sys[lat.shape(lead_shape, ...)] you should use lead[lat.shape(lead_shape, ...)].
Best, Anton
On Tue, May 20, 2014 at 3:49 PM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear Anton,
first, let me thank you for your help. I got some problems with it:
1) If I use the "ugly" way, there is an error popping up as soon as I attach the leads in the manner I wrote in my first mail:
...
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t lead[lat.neighbors()] = -t
sys.attach_lead(lead) sys.attach_lead(lead.reversed()) ...
ERROR: "ValueError: Builder does not interrupt the lead, this lead cannot be attached."
2) If I use the second way, there is a memory error even before attaching the leads.
"...
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t lead[lat.neighbors()] = -t"
I dont't know if I'm too stupid/new to kwant/... but I can't solve it.
Best Julian
Dear Julian,
Once you execute make_cuboid(), you see the following error message:
12 13 lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) ---> 14 lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t 15 lead[lat.neighbors()] = -t 16
TypeError: 'Polyatomic' object is not callable
You wrote `lat(0, j, i)`, which is the correct way to deal with Monatomic lattices in Kwant. In fact this is just a short hand notation for a site of the lattice lat with Bravais vectors 0, j, i. If lat was a monatomic lattice, the code you're using would just add a bunch of sites of the form lat(0, j, i). In your case lat has several sublattices, so `lat(0, j, i)` does not have any meaning in Kwant. There are two ways to fix your code. If you want to stick to generator expressions [=loops of the form `(f(i) for i in somewhere)`], you can write e.g.
lead[(sublattice(0, y, z) for sublattice in lat.sublattices for y in xrange(a) for z in xrange(b))] = 4 * t
However, as you see, this becomes ugly. It's better to use shape, similarly to the way you defined the scattering region:
def lead_shape(pos): return 0 <= pos[1] < a and 0 <= pos[2] < b
sys[lat.shape(lead_shape, (0, 0, 0))] = 4 * t
Note that here the lead_shape doesn't depend on the x-coordinate of the site, as required by translation invariance in x-direction. More generally, the shape function for the lead should respect the lead translational symmetry, or the results may be not what you would expect.
I hope this helps, Anton
On Mon, May 19, 2014 at 9:39 AM, Julian Schary <julian.schary@stud-mail.uni-wuerzburg.de> wrote:
Dear all,
I'm triying to figure out how to attach symmetrical leads to a 3D zincblende -structure in kwant. The code I used so far:
lat = kwant.lattice.general([(0, 0.5, 0.5), (0.5, 0, 0.5), (0.5, 0.5, 0)], [(0, 0, 0), (0.25, 0.25, 0.25)]) a, b = lat.sublattices def make_cuboid(t=1.0, a=15, b=10, c=5): def cuboid_shape(pos): x, y, z = pos return 0 <= x < a and 0 <= y < b and 0 <= z < c
sys = kwant.Builder() sys[lat.shape(cuboid_shape, (0, 0, 0))] = 4 * t sys[lat.neighbors()] = -t
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0, 0))) lead[(lat(0, j, i) for j in xrange(a) for i in xrange(b))] = 4 * t lead[lat.neighbors()] = -t
#sys.attach_lead(lead) #sys.attach_lead(lead.reversed())
return sys
causes errors. Could you help me and tell me how to attach the leads in 3D,please?
Best regards,
Julian Depatment of Physics & Astronomy University of Würzburg (Germany)
----- Anhänge (Die Links sind bis zum 30.11.2014 gültig) https://webmail.uni-wuerzburg.de/imp/attachment.php?u=s221330&t=1400671840&f=sys01.tif https://webmail.uni-wuerzburg.de/imp/attachment.php?u=s221330&t=1400671840&f=sys02.tif
participants (2)
-
Anton Akhmerov -
Julian Schary