Commit ab6df0dd authored by Anton Akhmerov's avatar Anton Akhmerov Committed by Christoph Groth
Browse files

allow to plot systems with leads with empty interface, add test

parent 8df9dfc7
......@@ -329,7 +329,7 @@ def sys_leads_sites(sys, n_lead_copies=2):
if isinstance(sys, builder.Builder):
sites = [(site, None, 0) for site in sys.sites()]
for leadnr, lead in enumerate(sys.leads):
if hasattr(lead, 'builder'):
if hasattr(lead, 'builder') and len(lead.interface):
sites.extend(((site, leadnr, i) for site in
lead.builder.sites() for i in
xrange(n_lead_copies)))
......@@ -337,7 +337,8 @@ def sys_leads_sites(sys, n_lead_copies=2):
sites = [(i, None, 0) for i in xrange(sys.graph.num_nodes)]
for leadnr, lead in enumerate(sys.leads):
# We will only plot leads with a graph and with a symmetry.
if hasattr(lead, 'graph') and hasattr(lead, 'symmetry'):
if hasattr(lead, 'graph') and hasattr(lead, 'symmetry') and \
len(sys.lead_interfaces[leadnr]):
sites.extend(((site, leadnr, i) for site in
xrange(lead.slice_size) for i in
xrange(n_lead_copies)))
......@@ -385,10 +386,16 @@ def sys_leads_pos(sys, site_lead_nr):
return np.zeros((dim,)), 0
if is_builder:
sym = sys.leads[lead_nr].builder.symmetry
site = sys.leads[lead_nr].interface[0]
try:
site = sys.leads[lead_nr].interface[0]
except IndexError:
return (0, 0)
else:
sym = sys.leads[lead_nr].symmetry
site = sys.site(sys.lead_interfaces[lead_nr][0])
try:
site = sys.site(sys.lead_interfaces[lead_nr][0])
except IndexError:
return (0, 0)
dom = sym.which(site)[0] + 1
# TODO (Anton): vec = sym.periods[0] not supported by ta.ndarray
# Remove conversion to np.ndarray when not necessary anymore.
......@@ -446,7 +453,7 @@ def sys_leads_hoppings(sys, n_lead_copies=2):
yield sym.act([-shift], site2), sym.act([-shift], site1)
for leadnr, lead in enumerate(sys.leads):
if hasattr(lead, 'builder'):
if hasattr(lead, 'builder') and len(lead.interface):
hoppings.extend(((hop, leadnr, i) for hop in
lead_hoppings(lead.builder) for i in
xrange(n_lead_copies)))
......@@ -459,7 +466,8 @@ def sys_leads_hoppings(sys, n_lead_copies=2):
hoppings.extend(((hop, None, 0) for hop in ll_hoppings(sys)))
for leadnr, lead in enumerate(sys.leads):
# We will only plot leads with a graph and with a symmetry.
if hasattr(lead, 'graph') and hasattr(lead, 'symmetry'):
if hasattr(lead, 'graph') and hasattr(lead, 'symmetry') and \
len(sys.lead_interfaces[leadnr]):
hoppings.extend(((hop, leadnr, i) for hop in
ll_hoppings(lead) for i in
xrange(n_lead_copies)))
......@@ -513,10 +521,16 @@ def sys_leads_hopping_pos(sys, hop_lead_nr):
return np.zeros((dim,)), 0
if is_builder:
sym = sys.leads[lead_nr].builder.symmetry
site = sys.leads[lead_nr].interface[0]
try:
site = sys.leads[lead_nr].interface[0]
except IndexError:
return (0, 0)
else:
sym = sys.leads[lead_nr].symmetry
site = sys.site(sys.lead_interfaces[lead_nr][0])
try:
site = sys.site(sys.lead_interfaces[lead_nr][0])
except IndexError:
return (0, 0)
dom = sym.which(site)[0] + 1
# TODO (Anton): vec = sym.periods[0] not supported by ta.ndarray
# Remove conversion to np.ndarray when not necessary anymore.
......
......@@ -7,6 +7,7 @@
# http://kwant-project.org/authors.
import tempfile
import warnings
import nose
import kwant
from kwant import plotter
......@@ -31,12 +32,15 @@ def sys_2d(W=3, r1=3, r2=8):
sys[sys.possible_hoppings(*hopping)] = - t
sym_lead0 = kwant.TranslationalSymmetry(lat.vec((-1, 0)))
lead0 = kwant.Builder(sym_lead0)
lead2 = kwant.Builder(sym_lead0)
def lead_shape(pos):
(x, y) = pos
return (-1 < x < 1) and (-W / 2 < y < W / 2)
lead0[lat.shape(lead_shape, (0, 0))] = 4 * t
lead2[lat.shape(lead_shape, (0, 0))] = 4 * t
sys.attach_lead(lead2)
for hopping in lat.nearest:
lead0[lead0.possible_hoppings(*hopping)] = - t
lead1 = lead0.reversed()
......@@ -109,6 +113,9 @@ def test_plot():
plot(sys2d, show=False)
with tempfile.TemporaryFile('w+b') as output:
plot(sys3d, file=output)
warnings.simplefilter('ignore')
plot(sys2d.finalized(), file=output)
warnings.simplefilter('once')
def test_map():
......@@ -116,7 +123,9 @@ def test_map():
with tempfile.TemporaryFile('w+b') as output:
plotter.map(sys, lambda site: site.tag[0], file=output,
method='linear', a=4, oversampling=4, cmap='flag')
warnings.simplefilter('ignore')
plotter.map(sys.finalized(), xrange(len(sys.sites())),
file=output)
warnings.simplefilter('once')
nose.tools.assert_raises(ValueError, plotter.map,
sys, xrange(len(sys.sites())), file=output)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment