Error visualizing the zigzag graphene lattice using kwant.plot() in tutorial
Hello Kwant users, I am very new to kwant and I am still learning to use the code. So my apologizes for any trivial questions. I working on the tutorial notebooks I found in the here ( https://kwant-project.org/mm16). In the tutorial 3.4.graphene_qshe.ipynb I am trying to visualize the zigzag graphene lattice created using the kwant.Builder and .shape() module using kwant.plot(*sys*). I am getting the following error zigzag_ribbon = kwant.Builder(kwant.TranslationalSymmetry([1, 0])) #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==1), (0, 0))] = 0.2 #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==0), (0, 0))] = -0.2 zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9), (0, 0))] = 0 zigzag_ribbon[graphene.neighbors(1)] = 1 zigzag_ribbon.finalized() kwant.plotter.plot(zigzag_ribbon) #kwant.plotter.bands(zigzag_ribbon.finalized()); ---------------------------------------------------------------------------KeyError Traceback (most recent call last)<ipython-input-84-0b886d56dec5> in <module> 5 zigzag_ribbon[graphene.neighbors(1)] = 1 6 zigzag_ribbon.finalized()----> 7 kwant.plotter.plot(zigzag_ribbon) 8 #kwant.plotter.bands(zigzag_ribbon.finalized()); ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in plot(sys, num_lead_cells, unit, site_symbol, site_size, site_color, site_edgecolor, site_lw, hop_color, hop_lw, lead_site_symbol, lead_site_size, lead_color, lead_site_edgecolor, lead_site_lw, lead_hop_lw, pos_transform, cmap, colorbar, file, show, dpi, fig_size, ax) 962 963 site_size = make_proper_site_spec(site_size, fancy_indexing)--> 964 site_color = make_proper_site_spec(site_color, fancy_indexing) 965 site_edgecolor = make_proper_site_spec(site_edgecolor, fancy_indexing) 966 site_lw = make_proper_site_spec(site_lw, fancy_indexing) ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in make_proper_site_spec(spec, fancy_indexing) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec):--> 909 spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)): ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in <listcomp>(.0) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec):--> 909 spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)): ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in site_color(site) 956 color_mapping = dict(zip(families, cycle)) 957 def site_color(site):--> 958 return color_mapping[site.family] 959 else: 960 # Unknown finalized system, no sites access. KeyError: kwant.lattice.Monatomic([[1.0, 0.0], [0.5, 0.8660254037844386]], [0.0, 0.5773502691896258], '1', None) However, I am able to plot the dispersion and all that. Also, I am able to visualize the square lattice presented in other tutorials. Do we have to do something different to visualize non-square lattice ? Thanks for your help -- Srilok Srinivasan Graduate Student Mechanical Engineering Iowa State University, Ames, IA
Sorry I forgot to mention that I am using the Kwant version 1.4.01a1
Thanks
On Mon, Nov 19, 2018 at 5:38 PM Srilok Srinivasan
Hello Kwant users,
I am very new to kwant and I am still learning to use the code. So my apologizes for any trivial questions.
I working on the tutorial notebooks I found in the here ( https://kwant-project.org/mm16). In the tutorial 3.4.graphene_qshe.ipynb I am trying to visualize the zigzag graphene lattice created using the kwant.Builder and .shape() module using kwant.plot(*sys*). I am getting the following error
zigzag_ribbon = kwant.Builder(kwant.TranslationalSymmetry([1, 0])) #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==1), (0, 0))] = 0.2 #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==0), (0, 0))] = -0.2 zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9), (0, 0))] = 0 zigzag_ribbon[graphene.neighbors(1)] = 1 zigzag_ribbon.finalized() kwant.plotter.plot(zigzag_ribbon) #kwant.plotter.bands(zigzag_ribbon.finalized());
---------------------------------------------------------------------------KeyError Traceback (most recent call last)<ipython-input-84-0b886d56dec5> in <module> 5 zigzag_ribbon[graphene.neighbors(1)] = 1 6 zigzag_ribbon.finalized()----> 7 kwant.plotter.plot(zigzag_ribbon) 8 #kwant.plotter.bands(zigzag_ribbon.finalized()); ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in plot(sys, num_lead_cells, unit, site_symbol, site_size, site_color, site_edgecolor, site_lw, hop_color, hop_lw, lead_site_symbol, lead_site_size, lead_color, lead_site_edgecolor, lead_site_lw, lead_hop_lw, pos_transform, cmap, colorbar, file, show, dpi, fig_size, ax) 962 963 site_size = make_proper_site_spec(site_size, fancy_indexing)--> 964 site_color = make_proper_site_spec(site_color, fancy_indexing) 965 site_edgecolor = make_proper_site_spec(site_edgecolor, fancy_indexing) 966 site_lw = make_proper_site_spec(site_lw, fancy_indexing) ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in make_proper_site_spec(spec, fancy_indexing) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec):--> 909 spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)): ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in <listcomp>(.0) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec):--> 909 spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)): ~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in site_color(site) 956 color_mapping = dict(zip(families, cycle)) 957 def site_color(site):--> 958 return color_mapping[site.family] 959 else: 960 # Unknown finalized system, no sites access. KeyError: kwant.lattice.Monatomic([[1.0, 0.0], [0.5, 0.8660254037844386]], [0.0, 0.5773502691896258], '1', None)
However, I am able to plot the dispersion and all that. Also, I am able to visualize the square lattice presented in other tutorials. Do we have to do something different to visualize non-square lattice ?
Thanks for your help -- Srilok Srinivasan Graduate Student Mechanical Engineering Iowa State University, Ames, IA
-- Srilok Srinivasan Graduate Student Mechanical Engineering Iowa State University, Ames, IA
Hi Srilok,
Right now plotting of detached finalized leads isn't supported and is
tracked in the issue
https://gitlab.kwant-project.org/kwant/kwant/issues/18
Cheers,
Anton
On Tue, Nov 20, 2018 at 9:22 AM Srilok Srinivasan
Sorry I forgot to mention that I am using the Kwant version 1.4.01a1
Thanks
On Mon, Nov 19, 2018 at 5:38 PM Srilok Srinivasan
wrote: Hello Kwant users,
I am very new to kwant and I am still learning to use the code. So my apologizes for any trivial questions.
I working on the tutorial notebooks I found in the here (https://kwant-project.org/mm16). In the tutorial 3.4.graphene_qshe.ipynb I am trying to visualize the zigzag graphene lattice created using the kwant.Builder and .shape() module using kwant.plot(sys). I am getting the following error
zigzag_ribbon = kwant.Builder(kwant.TranslationalSymmetry([1, 0])) #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==1), (0, 0))] = 0.2 #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==0), (0, 0))] = -0.2 zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9), (0, 0))] = 0 zigzag_ribbon[graphene.neighbors(1)] = 1 zigzag_ribbon.finalized() kwant.plotter.plot(zigzag_ribbon) #kwant.plotter.bands(zigzag_ribbon.finalized());
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-84-0b886d56dec5> in <module> 5 zigzag_ribbon[graphene.neighbors(1)] = 1 6 zigzag_ribbon.finalized() ----> 7 kwant.plotter.plot(zigzag_ribbon) 8 #kwant.plotter.bands(zigzag_ribbon.finalized());
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in plot(sys, num_lead_cells, unit, site_symbol, site_size, site_color, site_edgecolor, site_lw, hop_color, hop_lw, lead_site_symbol, lead_site_size, lead_color, lead_site_edgecolor, lead_site_lw, lead_hop_lw, pos_transform, cmap, colorbar, file, show, dpi, fig_size, ax) 962 963 site_size = make_proper_site_spec(site_size, fancy_indexing) --> 964 site_color = make_proper_site_spec(site_color, fancy_indexing) 965 site_edgecolor = make_proper_site_spec(site_edgecolor, fancy_indexing) 966 site_lw = make_proper_site_spec(site_lw, fancy_indexing)
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in make_proper_site_spec(spec, fancy_indexing) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec): --> 909 spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)):
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in <listcomp>(.0) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec): --> 909 spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)):
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in site_color(site) 956 color_mapping = dict(zip(families, cycle)) 957 def site_color(site): --> 958 return color_mapping[site.family] 959 else: 960 # Unknown finalized system, no sites access.
KeyError: kwant.lattice.Monatomic([[1.0, 0.0], [0.5, 0.8660254037844386]], [0.0, 0.5773502691896258], '1', None)
However, I am able to plot the dispersion and all that. Also, I am able to visualize the square lattice presented in other tutorials. Do we have to do something different to visualize non-square lattice ?
Thanks for your help -- Srilok Srinivasan Graduate Student Mechanical Engineering Iowa State University, Ames, IA
-- Srilok Srinivasan Graduate Student Mechanical Engineering Iowa State University, Ames, IA
Just to respond to Anton:
Right now plotting of detached finalized leads isn't supported and is tracked in the issue https://gitlab.kwant-project.org/kwant/kwant/issues/18
They're not plotting a finalized system:
zigzag_ribbon = kwant.Builder(kwant.TranslationalSymmetry([1, 0])) #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==1), (0, 0))] = 0.2 #zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9 and pos[1]%2 ==0), (0, 0))] = -0.2 zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9), (0, 0))] = 0 zigzag_ribbon[graphene.neighbors(1)] = 1 zigzag_ribbon.finalized() kwant.plotter.plot(zigzag_ribbon) #kwant.plotter.bands(zigzag_ribbon.finalized());
so this should totally still work (and indeed it does on Kwant 1.3.3, or when taking a minimal example as I illustrated in my email. Joe
Hi Srilok,
I am very new to kwant and I am still learning to use the code. So my apologizes for any trivial questions.
I working on the tutorial notebooks I found in the here (https://kwant-project.org/mm16). In the tutorial 3.4.graphene_qshe.ipynb I am trying to visualize the zigzag graphene lattice created using the kwant.Builder and .shape() module using kwant.plot(/sys/). I am getting the following error
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-84-0b886d56dec5> in <module> 5 zigzag_ribbon[graphene.neighbors(1)] = 1 6 zigzag_ribbon.finalized() ----> 7kwant.plotter.plot(zigzag_ribbon) 8 #kwant.plotter.bands(zigzag_ribbon.finalized());
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in plot(sys, num_lead_cells, unit, site_symbol, site_size, site_color, site_edgecolor, site_lw, hop_color, hop_lw, lead_site_symbol, lead_site_size, lead_color, lead_site_edgecolor, lead_site_lw, lead_hop_lw, pos_transform, cmap, colorbar, file, show, dpi, fig_size, ax) 962 963 site_size = make_proper_site_spec(site_size, fancy_indexing) --> 964site_color = make_proper_site_spec(site_color, fancy_indexing) 965 site_edgecolor = make_proper_site_spec(site_edgecolor, fancy_indexing) 966 site_lw = make_proper_site_spec(site_lw, fancy_indexing)
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in make_proper_site_spec(spec, fancy_indexing) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec): --> 909spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)):
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in <listcomp>(.0) 907 def make_proper_site_spec(spec, fancy_indexing=False): 908 if callable(spec): --> 909spec = [spec(i[0]) for i in sites if i[1] is None] 910 if (fancy_indexing and _p.isarray(spec) 911 and not isinstance(spec, np.ndarray)):
~/anaconda3/lib/python3.6/site-packages/kwant/plotter.py in site_color(site) 956 color_mapping = dict(zip(families, cycle)) 957 def site_color(site): --> 958return color_mapping[site.family] 959 else: 960 # Unknown finalized system, no sites access.
KeyError: kwant.lattice.Monatomic([[1.0, 0.0], [0.5, 0.8660254037844386]], [0.0, 0.5773502691896258], '1', None)
Thanks for the bug report! This is very strange; when I download the notebook and run it I indeed see the error that you reported, however when I try to run the following minimal example it succeeds:
import numpy as np import matplotlib.pyplot import kwant
graphene = kwant.lattice.general([[1, 0], [1/2, np.sqrt(3)/2]], # lattice vectors [[0, 0], [0, 1/np.sqrt(3)]]) # Coordinates of the sites
zigzag_ribbon = kwant.Builder(kwant.TranslationalSymmetry([1, 0])) zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9), (0, 0))] = 0 zigzag_ribbon[graphene.neighbors(1)] = 1
print(kwant.__version__) kwant.plot(zigzag_ribbon);
I'll investigate a bit more and report my results. Happy Kwanting, Joe
Hi everyone,
This is very strange; when I download the notebook and run it I indeed see the error that you reported, however when I try to run the following minimal example it succeeds:
import numpy as np import matplotlib.pyplot import kwant
graphene = kwant.lattice.general([[1, 0], [1/2, np.sqrt(3)/2]], # lattice vectors [[0, 0], [0, 1/np.sqrt(3)]]) # Coordinates of the sites
zigzag_ribbon = kwant.Builder(kwant.TranslationalSymmetry([1, 0])) zigzag_ribbon[graphene.shape((lambda pos: abs(pos[1]) < 9), (0, 0))] = 0 zigzag_ribbon[graphene.neighbors(1)] = 1
print(kwant.__version__) kwant.plot(zigzag_ribbon);
I'll investigate a bit more and report my results.
%run matplotlib_setup.ipy
Found it! In Kwant 1.4.0a1 we tweaked Kwant's plotting so that sites from different families (sublattices) would use the colors from Matplotlib's color cycle by default. In the March Meeting tutorial notebooks there is a line: that loads some custom matplotlib setup to make the plots look a bit better in the notebooks. Looking into 'matplotlib_setup.ipy' we see the following suspicious line:
mpl.rc('axes', prop_cycle=mpl.cycler('color', ['black'])) which was included to stop all the bandstructure plots being multicolored (because it's distracting), however because there are fewer
colors than there are site families (2 site families in graphene) the color cycling in Kwant's plotter broke.
This is a bug in Kwant, and I've opened an issue [1] on our bugtracker. I'll fix this today and it'll go into the v1.4.0 release (that we will make sometime between now and christmas). In the short term you can fix this in a couple of ways: + either downgrade to Kwant 1.3.3 + or change the offending line in 'matplotlib_setup.ipy' to: mpl.rc('axes', prop_cycle=mpl.cycler('color', ['black', 'black'])) + or wait until I push a change to the tutorial notebooks later today and then re-download them Thanks for the report, and happy kwanting! Joe [1]: https://gitlab.kwant-project.org/kwant/kwant/issues/257
participants (3)
-
Anton Akhmerov
-
Joseph Weston
-
Srilok Srinivasan