Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 378-support-finalization-and-attaching-of-nd-systems
  • backup/210414_randomly_failing_test
  • bands_backport
  • bugfix/tests-without-dependencies
  • cleanup
  • doc/execute
  • document_peierls
  • enh/ci_performance
  • enh/vectorized_evaluation
  • enh/vectorized_finalization
  • enh/vectorized_refactoring
  • feat/stable-testing-images
  • feature/378-nd-finalization
  • feature/no-show
  • feature/plot-hopping-by-length
  • feature/vectorized_finalization
  • feature/vectorized_interface
  • fix/ban_scipy_1_6_1
  • fix/finish_bumping_py37
  • fix/matplotlib_3.4_deprecations
  • fix/remove_future_print_function
  • fix/sympy_numbers
  • fixup/docs
  • fixup/testing-env
  • image_update
  • issue-409-lattice-closest
  • main
  • master
  • oldstable_1.2
  • oldstable_1.3
  • pixi
  • plotter_current_fix
  • pretty-print-fix
  • sparse-modes
  • spec-0000
  • stable
  • stable_py2
  • test
  • vect_adv_constr
  • vect_args
  • vect_eval
  • latest-1.1
  • latest-1.2
  • latest-1.3
  • v0.0.0
  • v0.1.0
  • v0.1.5
  • v0.2.0
  • v0.2.4
  • v1.0.0
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.0.5
  • v1.1.0
  • v1.1.0b0
  • v1.1.0pre0
  • v1.1.1
  • v1.1.2
  • v1.1.3
  • v1.2.0a0
  • v1.2.2
  • v1.2.3
  • v1.3.0
  • v1.3.0a0
  • v1.3.0a1
  • v1.3.1
  • v1.3.2
  • v1.3.3
  • v1.4.0
  • v1.4.0a0
  • v1.4.0a1
  • v1.4.0rc0
  • v1.4.0rc1
  • v1.4.1
  • v1.4.2
  • v1.4.3
  • v1.4.4
  • v1.5.0
  • v1.5.0a0
81 results

Target

Select target project
  • kwant/kwant
  • jbweston/kwant
  • anton-akhmerov/kwant
  • cwg/kwant
  • Mathieu/kwant
  • slavoutich/kwant
  • pacome/kwant
  • behrmann/kwant
  • michaelwimmer/kwant
  • albeercik/kwant
  • eunjongkim/kwant
  • basnijholt/kwant
  • r-j-skolasinski/kwant
  • sahmed95/kwant
  • pablopiskunow/kwant
  • mare/kwant
  • dvarjas/kwant
  • Paul/kwant
  • bbuijtendorp/kwant
  • tkloss/kwant
  • torosdahl/kwant
  • kel85uk/kwant
  • kpoyhonen/kwant
  • Fromeworld/kwant
  • quaeritis/kwant
  • marwahaha/kwant
  • fernandodfufrpe/kwant
  • oly/kwant
  • jiamingh/kwant
  • mehdi2369/kwant
  • ValFadeev/kwant
  • Kostas/kwant
  • chelseabaptiste03/kwant
33 results
Select Git revision
  • boundstate
  • feature/#250/plotly_backend_selection
  • feature/#252/scalarplot_plotly
  • feature/#253/streamplot_plotly
  • feature/boundstate
  • feature/indexable
  • fixup/testing-env
  • kwant2-system
  • master
  • setup-argparse
  • stable
  • stable_py2
  • system2
  • version/pin-sympy
  • latest-1.1
  • latest-1.2
  • latest-1.3
  • v0.0.0
  • v0.1.0
  • v0.1.5
  • v0.2.0
  • v0.2.4
  • v1.0.0
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.0.5
  • v1.1.0
  • v1.1.0b0
  • v1.1.0pre0
  • v1.1.1
  • v1.1.2
  • v1.1.3
  • v1.2.0a0
  • v1.2.2
  • v1.2.3
  • v1.3.0
  • v1.3.0a0
  • v1.3.0a1
  • v1.3.1
  • v1.4.0a0
42 results
Show changes
Showing
with 5 additions and 1041 deletions
################################################################
# Make matplotlib work without X11
################################################################
import matplotlib
matplotlib.use('Agg')
################################################################
# Prepend Kwant's build directory to sys.path
################################################################
import sys
from distutils.util import get_platform
sys.path.insert(0, "../../../build/lib.{0}-{1}.{2}".format(
get_platform(), *sys.version_info[:2]))
################################################################
# Define constants for plotting
################################################################
pt_to_in = 1. / 72.
# Default width of figures in pts
figwidth_pt = 600
figwidth_in = figwidth_pt * pt_to_in
# Width for smaller figures
figwidth_small_pt = 400
figwidth_small_in = figwidth_small_pt * pt_to_in
# Sizes for matplotlib figures
mpl_width_in = figwidth_pt * pt_to_in
mpl_label_size = None # font sizes in points
mpl_tick_size = None
# dpi for conversion from inches
dpi = 90
--- original
+++ modified
@@ -12,6 +12,7 @@
# example, but in the tutorial main text)
# - Modifcations of hoppings/sites after they have been added
+import _defs
from cmath import exp
from math import pi
@@ -81,6 +82,50 @@
return syst
+def make_system_note1(a=1, t=1.0, W=10, r1=10, r2=20):
+ lat = kwant.lattice.square(a)
+ syst = kwant.Builder()
+ def ring(pos):
+ (x, y) = pos
+ rsq = x**2 + y**2
+ return ( r1**2 < rsq < r2**2)
+ syst[lat.shape(ring, (0, 11))] = 4 * t
+ syst[lat.neighbors()] = -t
+ sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
+ lead0 = kwant.Builder(sym_lead0)
+ def lead_shape(pos):
+ (x, y) = pos
+ return (-1 < x < 1) and ( 0.5 * W < y < 1.5 * W )
+ lead0[lat.shape(lead_shape, (0, W))] = 4 * t
+ lead0[lat.neighbors()] = -t
+ lead1 = lead0.reversed()
+ syst.attach_lead(lead0)
+ syst.attach_lead(lead1)
+ return syst
+
+
+def make_system_note2(a=1, t=1.0, W=10, r1=10, r2=20):
+ lat = kwant.lattice.square(a)
+ syst = kwant.Builder()
+ def ring(pos):
+ (x, y) = pos
+ rsq = x**2 + y**2
+ return ( r1**2 < rsq < r2**2)
+ syst[lat.shape(ring, (0, 11))] = 4 * t
+ syst[lat.neighbors()] = -t
+ sym_lead0 = kwant.TranslationalSymmetry((-a, 0))
+ lead0 = 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
+ lead0[lat.neighbors()] = -t
+ lead1 = lead0.reversed()
+ syst.attach_lead(lead0)
+ syst.attach_lead(lead1, lat(0, 0))
+ return syst
+
+
def plot_conductance(syst, energy, fluxes):
# compute conductance
@@ -90,18 +135,31 @@
smatrix = kwant.smatrix(syst, energy, args=[flux])
data.append(smatrix.transmission(1, 0))
- pyplot.figure()
+ fig = pyplot.figure()
pyplot.plot(normalized_fluxes, data)
- pyplot.xlabel("flux [flux quantum]")
- pyplot.ylabel("conductance [e^2/h]")
- pyplot.show()
+ pyplot.xlabel("flux [flux quantum]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.ylabel("conductance [e^2/h]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ fig.savefig("ab_ring_result.pdf")
+ fig.savefig("ab_ring_result.png", dpi=_defs.dpi)
def main():
syst = make_system()
# Check that the system looks as intended.
- kwant.plot(syst)
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, file="ab_ring_syst." + extension,
+ fig_size=size, dpi=_defs.dpi)
+
# Finalize the system.
syst = syst.finalized()
@@ -111,6 +169,17 @@
for i in range(100)])
+ # Finally, some plots needed for the notes
+ syst = make_system_note1()
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, file="ab_ring_note1." + extension,
+ fig_size=size, dpi=_defs.dpi)
+ syst = make_system_note2()
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, file="ab_ring_note2." + extension,
+ fig_size=size, dpi=_defs.dpi)
+
+
# Call the main function if the script gets executed (as opposed to imported).
# See <http://docs.python.org/library/__main__.html>.
if __name__ == '__main__':
--- original
+++ modified
@@ -9,6 +9,7 @@
# --------------------------
# - Computing the band structure of a finalized lead.
+import _defs
import kwant
# For plotting.
@@ -36,10 +37,19 @@
def main():
lead = make_lead().finalized()
- kwant.plotter.bands(lead, show=False)
- pyplot.xlabel("momentum [(lattice constant)^-1]")
- pyplot.ylabel("energy [t]")
- pyplot.show()
+ fig = kwant.plotter.bands(lead, show=False)
+ pyplot.xlabel("momentum [(lattice constant)^-1]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.ylabel("energy [t]", fontsize=_defs.mpl_label_size)
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ for extension in ('pdf', 'png'):
+ fig.savefig("band_structure_result." + extension, dpi=_defs.dpi)
+
# Call the main function if the script gets executed (as opposed to imported).
--- original
+++ modified
@@ -11,6 +11,7 @@
# - Use of `hamiltonian_submatrix` in order to obtain a Hamiltonian
# matrix.
+import _defs
from cmath import exp
import numpy as np
import kwant
@@ -68,24 +69,39 @@
energies.append(ev)
- pyplot.figure()
+ fig = pyplot.figure()
pyplot.plot(Bfields, energies)
- pyplot.xlabel("magnetic field [arbitrary units]")
- pyplot.ylabel("energy [t]")
- pyplot.show()
+ pyplot.xlabel("magnetic field [arbitrary units]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.ylabel("energy [t]", fontsize=_defs.mpl_label_size)
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ for extension in ('pdf', 'png'):
+ fig.savefig("closed_system_result." + extension, dpi=_defs.dpi)
def plot_wave_function(syst):
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+
# Calculate the wave functions in the system.
ham_mat = syst.hamiltonian_submatrix(sparse=True)
evecs = sla.eigsh(ham_mat, k=20, which='SM')[1]
# Plot the probability density of the 10th eigenmode.
- kwant.plotter.map(syst, np.abs(evecs[:, 9])**2,
- colorbar=False, oversampling=1)
+ for extension in ('pdf', 'png'):
+ kwant.plotter.map(
+ syst, np.abs(evecs[:, 9])**2, colorbar=False, oversampling=1,
+ file="closed_system_eigenvector." + extension,
+ fig_size=size, dpi=_defs.dpi)
def plot_current(syst):
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+
# Calculate the wave functions in the system.
ham_mat = syst.hamiltonian_submatrix(sparse=True)
evecs = sla.eigsh(ham_mat, k=20, which='SM')[1]
@@ -93,15 +109,16 @@
# Calculate and plot the local current of the 10th eigenmode.
J = kwant.operator.Current(syst)
current = J(evecs[:, 9])
- kwant.plotter.current(syst, current, colorbar=False)
+ for extension in ('pdf', 'png'):
+ kwant.plotter.current(
+ syst, current, colorbar=False,
+ file="closed_system_current." + extension,
+ fig_size=size, dpi=_defs.dpi)
def main():
syst = make_system()
- # Check that the system looks as intended.
- kwant.plot(syst)
-
# Finalize the system.
syst = syst.finalized()
--- original
+++ modified
@@ -9,6 +9,7 @@
# --------------------------
# - kwant.continuum.discretize
+import _defs
import kwant
import scipy.sparse.linalg
@@ -20,10 +21,19 @@
from matplotlib import pyplot as plt
+def save_figure(file_name):
+ if not file_name:
+ return
+ for extension in ('pdf', 'png'):
+ plt.savefig('.'.join((file_name,extension)),
+ dpi=_defs.dpi, bbox_inches='tight')
+
+
def stadium_system(L=20, W=20):
hamiltonian = "k_x**2 + k_y**2 + V(x, y)"
template = kwant.continuum.discretize(hamiltonian)
- print(template)
+ with open('discretizer_verbose.txt', 'w') as f:
+ print(template, file=f)
def stadium(site):
(x, y) = site.pos
@@ -44,7 +54,7 @@
ham = syst.hamiltonian_submatrix(params=dict(V=potential), sparse=True)
evecs = scipy.sparse.linalg.eigsh(ham, k=10, which='SM')[1]
kwant.plotter.map(syst, abs(evecs[:, n])**2, show=False)
- plt.show()
+ save_figure('discretizer_gs')
def qsh_system(a=20, L=2000, W=1000):
@@ -91,7 +101,8 @@
plt.ylim(-0.05, 0.05)
plt.xlabel('momentum [1/A]')
plt.ylabel('energy [eV]')
- plt.show()
+ save_figure('discretizer_qsh_band')
+
# get scattering wave functions at E=0
wf = kwant.wave_function(syst, energy=0, params=params)
@@ -119,7 +130,7 @@
ax1.set_title('Probability density')
ax2.set_title('Spin density')
- plt.show()
+ save_figure('discretizer_qsh_wf')
def lattice_spacing():
@@ -160,7 +171,7 @@
plot(ax1, a=1)
plot(ax2, a=.25)
- plt.show()
+ save_figure('discretizer_lattice_spacing')
def substitutions():
@@ -173,15 +184,18 @@
sympify('k_x**2 * sz + alpha * k_x * sx', locals=subs),
)
- print(e[0] == e[1] == e[2])
+ with open('discretizer_subs_1.txt', 'w') as f:
+ print(e[0] == e[1] == e[2], file=f)
subs = {'A': 'A(x) + B', 'V': 'V(x) + V_0', 'C': 5}
- print(sympify('k_x * A * k_x + V + C', locals=subs))
+ with open('discretizer_subs_2.txt', 'w') as f:
+ print(sympify('k_x * A * k_x + V + C', locals=subs), file=f)
def main():
template = kwant.continuum.discretize('k_x * A(x) * k_x')
- print(template)
+ with open('discretizer_intro_verbose.txt', 'w') as f:
+ print(template, file=f)
syst = stadium_system()
plot_eigenstate(syst)
# !/bin/sh
# This script regenerates the .diff files in this directory. It's these files
# that are kept under vesion control instead of the scripts themselves.
for f in [a-zA-Z]*.py; do
# We use custom labels to suppress the time stamps which are unnecessary
# here and would only lead to noise in version control.
grep -v '#HIDDEN' ../tutorial/$f |
diff -u --label original --label modified - $f >$f.diff_
if cmp $f.diff_ $f.diff >/dev/null 2>&1; then
rm $f.diff_
else
mv $f.diff_ $f.diff
fi
done
--- original
+++ modified
@@ -10,6 +10,7 @@
# - Application of all the aspects of tutorials 1-3 to a more complicated
# lattice, namely graphene
+import _defs
from math import pi, sqrt, tanh
import kwant
@@ -96,22 +97,40 @@
smatrix = kwant.smatrix(syst, energy)
data.append(smatrix.transmission(0, 1))
- pyplot.figure()
+ fig = pyplot.figure()
pyplot.plot(energies, data)
- pyplot.xlabel("energy [t]")
- pyplot.ylabel("conductance [e^2/h]")
- pyplot.show()
+ pyplot.xlabel("energy [t]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.ylabel("conductance [e^2/h]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ for extension in ('pdf', 'png'):
+ fig.savefig("graphene_result." + extension, dpi=_defs.dpi)
def plot_bandstructure(flead, momenta):
bands = kwant.physics.Bands(flead)
energies = [bands(k) for k in momenta]
- pyplot.figure()
+ fig = pyplot.figure()
pyplot.plot(momenta, energies)
- pyplot.xlabel("momentum [(lattice constant)^-1]")
- pyplot.ylabel("energy [t]")
- pyplot.show()
+ pyplot.xlabel("momentum [(lattice constant)^-1]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.ylabel("energy [t]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ for extension in ('pdf', 'png'):
+ fig.savefig("graphene_bs." + extension, dpi=_defs.dpi)
def main():
@@ -123,8 +142,11 @@
def family_colors(site):
return 0 if site.family == a else 1
- # Plot the closed system without leads.
- kwant.plot(syst, site_color=family_colors, site_lw=0.1, colorbar=False)
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, site_color=family_colors, site_lw=0.1, colorbar=False,
+ file="graphene_syst1." + extension,
+ fig_size=size, dpi=_defs.dpi)
# Compute some eigenvalues.
compute_evs(syst.finalized())
@@ -133,9 +155,11 @@
for lead in leads:
syst.attach_lead(lead)
- # Then, plot the system with leads.
- kwant.plot(syst, site_color=family_colors, site_lw=0.1,
- lead_site_lw=0, colorbar=False)
+ size = (_defs.figwidth_in, 0.9 * _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, site_color=family_colors, colorbar=False, site_lw=0.1,
+ file="graphene_syst2." + extension,
+ fig_size=size, dpi=_defs.dpi, lead_site_lw=0)
# Finalize the system.
syst = syst.finalized()
--- original
+++ modified
@@ -11,6 +11,9 @@
import scipy
+import _defs
+from contextlib import redirect_stdout
+
# For plotting
from matplotlib import pyplot as plt
@@ -36,13 +39,13 @@
# Plot several density of states curves on the same axes.
-def plot_dos(labels_to_data):
+def plot_dos(labels_to_data, file_name=None):
for label, (x, y) in labels_to_data:
plt.plot(x, y, label=label, linewidth=2)
plt.legend(loc=2, framealpha=0.5)
plt.xlabel("energy [t]")
plt.ylabel("DoS [a.u.]")
- plt.show()
+ save_figure(file_name)
plt.clf()
@@ -57,10 +60,18 @@
kwant.plot(fsyst, site_size=site_size, site_color=(0, 0, 1, 0.3), ax=ax)
ax.set_title(title)
ax.set(adjustable='box-forced', aspect='equal')
- plt.show()
+ save_figure(file_name)
plt.clf()
+def save_figure(file_name):
+ if not file_name:
+ return
+ for extension in ('pdf', 'png'):
+ plt.savefig('.'.join((file_name,extension)),
+ dpi=_defs.dpi, bbox_inches='tight')
+
+
def simple_dos_example():
fsyst = make_syst().finalized()
@@ -74,18 +85,24 @@
plot_dos([
('densities', (energies, densities)),
('density subset', (energy_subset, density_subset)),
- ])
+ ],
+ file_name='kpm_dos'
+ )
def dos_integrating_example(fsyst):
spectrum = kwant.kpm.SpectralDensity(fsyst)
- print('identity resolution:', spectrum.integrate())
+ with open('kpm_normalization.txt', 'w') as f:
+ with redirect_stdout(f):
+ print('identity resolution:', spectrum.integrate())
# Fermi energy 0.1 and temperature 0.2
fermi = lambda E: 1 / (np.exp((E - 0.1) / 0.2) + 1)
- print('number of filled states:', spectrum.integrate(fermi))
+ with open('kpm_total_states.txt', 'w') as f:
+ with redirect_stdout(f):
+ print('number of filled states:', spectrum.integrate(fermi))
def increasing_accuracy_example(fsyst):
@@ -99,7 +116,9 @@
plot_dos([
('density', original_dos),
('higher energy resolution', increased_resolution_dos),
- ])
+ ],
+ file_name='kpm_dos_acc'
+ )
spectrum.add_moments(100)
spectrum.add_vectors(5)
@@ -109,7 +128,9 @@
plot_dos([
('density', original_dos),
('higher number of moments', increased_moments_dos),
- ])
+ ],
+ file_name='kpm_dos_r'
+ )
def operator_example(fsyst):
@@ -139,7 +160,9 @@
plot_ldos(fsyst, axes,[
('energy = 0', zero_energy_ldos),
('energy = 1', finite_energy_ldos),
- ])
+ ],
+ file_name='kpm_ldos'
+ )
def vector_factory_example(fsyst):
--- original
+++ modified
@@ -11,6 +11,9 @@
# - operators
# - plotting vector fields
+import _defs
+from contextlib import redirect_stdout
+
from math import sin, cos, tanh, pi
import itertools
import numpy as np
@@ -79,7 +82,13 @@
return syst
-def plot_vector_field(syst, params):
+def save_plot(fname):
+ for extension in ('.pdf', '.png'):
+ plt.savefig(fname + extension,
+ dpi=_defs.dpi, bbox_inches='tight')
+
+
+def plot_vector_field(syst, params, fname=None):
xmin, ymin = min(s.tag for s in syst.sites)
xmax, ymax = max(s.tag for s in syst.sites)
x, y = np.meshgrid(np.arange(xmin, xmax+1), np.arange(ymin, ymax+1))
@@ -88,28 +97,38 @@
m_i = np.reshape(m_i, x.shape + (3,))
m_i = np.rollaxis(m_i, 2, 0)
- fig, ax = plt.subplots(1, 1)
+ fig, ax = plt.subplots(1, 1, figsize=(9, 7))
im = ax.quiver(x, y, *m_i, pivot='mid', scale=75)
fig.colorbar(im)
- plt.show()
+ if fname:
+ save_plot(fname)
+ else:
+ plt.show()
-def plot_densities(syst, densities):
- fig, axes = plt.subplots(1, len(densities))
+def plot_densities(syst, densities, fname=None):
+ fig, axes = plt.subplots(1, len(densities), figsize=(7*len(densities), 7))
for ax, (title, rho) in zip(axes, densities):
kwant.plotter.map(syst, rho, ax=ax, a=4)
ax.set_title(title)
- plt.show()
+ if fname:
+ save_plot(fname)
+ else:
+ plt.show()
+
-def plot_currents(syst, currents):
- fig, axes = plt.subplots(1, len(currents))
+def plot_currents(syst, currents, fname=None):
+ fig, axes = plt.subplots(1, len(currents), figsize=(7*len(currents), 7))
if not hasattr(axes, '__len__'):
axes = (axes,)
for ax, (title, current) in zip(axes, currents):
kwant.plotter.current(syst, current, ax=ax, colorbar=False)
ax.set_title(title)
- plt.show()
+ if fname:
+ save_plot(fname)
+ else:
+ plt.show()
def main():
@@ -119,7 +138,7 @@
wf = kwant.wave_function(syst, energy=-1, params=params)
psi = wf(0)[0]
- plot_vector_field(syst, dict(r0=20, delta=10))
+ plot_vector_field(syst, dict(r0=20, delta=10), fname='mag_field_direction')
# even (odd) indices correspond to spin up (down)
up, down = psi[::2], psi[1::2]
@@ -144,7 +163,7 @@
('$σ_0$', density),
('$σ_z$', spin_z),
('$σ_y$', spin_y),
- ])
+ ], fname='spin_densities')
J_0 = kwant.operator.Current(syst)
J_z = kwant.operator.Current(syst, sigma_z)
@@ -159,7 +178,7 @@
('$J_{σ_0}$', current),
('$J_{σ_z}$', spin_z_current),
('$J_{σ_y}$', spin_y_current),
- ])
+ ], fname='spin_currents')
def following_m_i(site, r0, delta):
m_i = field_direction(site.pos, r0, delta)
@@ -173,7 +192,7 @@
plot_currents(syst, [
(r'$J_{\mathbf{m}_i}$', m_current),
('$J_{σ_z}$', spin_z_current),
- ])
+ ], fname='spin_current_comparison')
def circle(site):
@@ -183,7 +202,9 @@
all_states = np.vstack((wf(0), wf(1)))
dos_in_circle = sum(rho_circle(p) for p in all_states) / (2 * pi)
- print('density of states in circle:', dos_in_circle)
+ with open('circle_dos.txt', 'w') as f:
+ with redirect_stdout(f):
+ print('density of states in circle:', dos_in_circle)
def left_cut(site_to, site_from):
return site_from.pos[0] <= -39 and site_to.pos[0] > -39
@@ -197,8 +218,10 @@
Jz_left = kwant.operator.Current(syst, sigma_z, where=left_cut, sum=True)
Jz_right = kwant.operator.Current(syst, sigma_z, where=right_cut, sum=True)
- print('J_left:', J_left(psi), ' J_right:', J_right(psi))
- print('Jz_left:', Jz_left(psi), ' Jz_right:', Jz_right(psi))
+ with open('current_cut.txt', 'w') as f:
+ with redirect_stdout(f):
+ print('J_left:', J_left(psi), ' J_right:', J_right(psi))
+ print('Jz_left:', Jz_left(psi), ' Jz_right:', Jz_right(psi))
J_m = kwant.operator.Current(syst, following_m_i)
J_z = kwant.operator.Current(syst, sigma_z)
@@ -214,7 +237,7 @@
plot_currents(syst, [
(r'$J_{\mathbf{m}_i}$ (from left)', J_m_left),
(r'$J_{σ_z}$ (from left)', J_z_left),
- ])
+ ], fname='bound_current')
if __name__ == '__main__':
--- original
+++ modified
@@ -9,6 +9,7 @@
# --------------------------
# - demonstrate different ways of plotting
+import _defs
import kwant
from matplotlib import pyplot
@@ -22,7 +23,7 @@
return x**2 + y**2 < r**2
syst = kwant.Builder()
- syst[lat.shape(circle, (0, 0))] = 0
+ syst[lat.shape(circle, (0,0))] = 0
syst[lat.neighbors()] = t
syst.eradicate_dangling()
if tp:
@@ -32,9 +33,11 @@
def plot_system(syst):
- kwant.plot(syst)
- # the standard plot is ok, but not very intelligible. One can do
- # better by playing wioth colors and linewidths
+ # standard plot - not very intelligible for this particular situation
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, file="plot_graphene_syst1." + extension,
+ fig_size=size, dpi=_defs.dpi)
# use color and linewidths to get a better plot
def family_color(site):
@@ -43,7 +46,11 @@
def hopping_lw(site1, site2):
return 0.04 if site1.family == site2.family else 0.1
- kwant.plot(syst, site_lw=0.1, site_color=family_color, hop_lw=hopping_lw)
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, site_lw=0.1, site_color=family_color,
+ hop_lw=hopping_lw, file="plot_graphene_syst2." + extension,
+ fig_size=size, dpi=_defs.dpi)
def plot_data(syst, n):
@@ -58,7 +65,11 @@
# the usual - works great in general, looks just a bit crufty for
# small systems
- kwant.plotter.map(syst, wf, oversampling=10, cmap='gist_heat_r')
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plotter.map(syst, wf, oversampling=10, cmap='gist_heat_r',
+ file="plot_graphene_data1." + extension,
+ fig_size=size, dpi=_defs.dpi)
# use two different sort of triangles to cleanly fill the space
def family_shape(i):
@@ -68,15 +79,22 @@
def family_color(i):
return 'black' if syst.sites[i].family == a else 'white'
- kwant.plot(syst, site_color=wf, site_symbol=family_shape,
- site_size=0.5, hop_lw=0, cmap='gist_heat_r')
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, site_color=wf, site_symbol=family_shape,
+ site_size=0.5, hop_lw=0, cmap='gist_heat_r',
+ file="plot_graphene_data2." + extension,
+ fig_size=size, dpi=_defs.dpi)
# plot by changing the symbols itself
def site_size(i):
return 3 * wf[i] / wf.max()
- kwant.plot(syst, site_size=site_size, site_color=(0, 0, 1, 0.3),
- hop_lw=0.1)
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, site_size=site_size, site_color=(0,0,1,0.3),
+ hop_lw=0.1, file="plot_graphene_data3." + extension,
+ fig_size=size, dpi=_defs.dpi)
def main():
--- original
+++ modified
@@ -11,6 +11,7 @@
# + Use of `kwant.operator` to compute local current
# + Use of `kwant.plotter.current` to plot local current
+import _defs
import math
import matplotlib.pyplot
import kwant
@@ -60,7 +61,10 @@
psi = kwant.wave_function(syst, energy=params['m'], params=params)(0)
J = kwant.operator.Current(syst).bind(params=params)
current = sum(J(p) for p in psi)
- kwant.plotter.current(syst, current)
+ for extension in ('pdf', 'png'):
+ kwant.plotter.current(syst, current,
+ file="plot_qahe_current." + extension,
+ dpi=_defs.dpi)
if __name__ == '__main__':
--- original
+++ modified
@@ -9,6 +9,7 @@
# --------------------------
# - demonstrate different ways of plotting in 3D
+import _defs
import kwant
from matplotlib import pyplot
@@ -33,7 +34,10 @@
# checking shapes:
syst = make_cuboid()
- kwant.plot(syst)
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, file="plot_zincblende_syst1." + extension,
+ fig_size=size, dpi=_defs.dpi)
# visualize the crystal structure better for a very small system
syst = make_cuboid(a=1.5, b=1.5, c=1.5)
@@ -41,8 +45,12 @@
def family_colors(site):
return 'r' if site.family == a else 'g'
- kwant.plot(syst, site_size=0.18, site_lw=0.01, hop_lw=0.05,
- site_color=family_colors)
+ size = (_defs.figwidth_in, _defs.figwidth_in)
+ for extension in ('pdf', 'png'):
+ kwant.plot(syst, site_size=0.18, site_lw=0.01, hop_lw=0.05,
+ site_color=family_colors,
+ file="plot_zincblende_syst2." + extension,
+ fig_size=size, dpi=_defs.dpi)
# Call the main function if the script gets executed (as opposed to imported).
--- original
+++ modified
@@ -9,6 +9,7 @@
# --------------------------
# - Functions as values in Builder
+import _defs
import kwant
# For plotting
@@ -55,19 +56,25 @@
smatrix = kwant.smatrix(syst, energy, args=[-welldepth])
data.append(smatrix.transmission(1, 0))
- pyplot.figure()
+ fig = pyplot.figure()
pyplot.plot(welldepths, data)
- pyplot.xlabel("well depth [t]")
- pyplot.ylabel("conductance [e^2/h]")
- pyplot.show()
+ pyplot.xlabel("well depth [t]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.ylabel("conductance [e^2/h]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ for extension in ('pdf', 'png'):
+ fig.savefig("quantum_well_result." + extension, dpi=_defs.dpi)
def main():
syst = make_system()
- # Check that the system looks as intended.
- kwant.plot(syst)
-
# Finalize the system.
syst = syst.finalized()
--- original
+++ modified
@@ -11,6 +11,7 @@
# - Making scattering region and leads
# - Using the simple sparse solver for computing Landauer conductance
+import _defs
from matplotlib import pyplot
import kwant
@@ -69,7 +70,10 @@
syst.attach_lead(right_lead)
# Plot it, to make sure it's OK
-kwant.plot(syst)
+size = (_defs.figwidth_in, 0.3 * _defs.figwidth_in)
+for extension in ('pdf', 'png'):
+ kwant.plot(syst, file="quantum_wire_syst." + extension,
+ fig_size=size, dpi=_defs.dpi)
# Finalize the system
syst = syst.finalized()
@@ -90,8 +94,13 @@
# Use matplotlib to write output
# We should see conductance steps
-pyplot.figure()
+fig = pyplot.figure()
pyplot.plot(energies, data)
-pyplot.xlabel("energy [t]")
-pyplot.ylabel("conductance [e^2/h]")
-pyplot.show()
+pyplot.xlabel("energy [t]", fontsize=_defs.mpl_label_size)
+pyplot.ylabel("conductance [e^2/h]", fontsize=_defs.mpl_label_size)
+pyplot.setp(fig.get_axes()[0].get_xticklabels(), fontsize=_defs.mpl_tick_size)
+pyplot.setp(fig.get_axes()[0].get_yticklabels(), fontsize=_defs.mpl_tick_size)
+fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+for extension in ('pdf', 'png'):
+ fig.savefig("quantum_wire_result." + extension, dpi=_defs.dpi)
--- original
+++ modified
@@ -13,6 +13,7 @@
# --------------------------
# - Numpy matrices as values in Builder
+import _defs
import kwant
# For plotting
@@ -70,19 +71,24 @@
smatrix = kwant.smatrix(syst, energy)
data.append(smatrix.transmission(1, 0))
- pyplot.figure()
+ fig = pyplot.figure()
pyplot.plot(energies, data)
- pyplot.xlabel("energy [t]")
- pyplot.ylabel("conductance [e^2/h]")
- pyplot.show()
+ pyplot.xlabel("energy [t]", fontsize=_defs.mpl_label_size)
+ pyplot.ylabel("conductance [e^2/h]",
+ fontsize=_defs.mpl_label_size)
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ for extension in ('pdf', 'png'):
+ fig.savefig("spin_orbit_result." + extension, dpi=_defs.dpi)
def main():
syst = make_system()
- # Check that the system looks as intended.
- kwant.plot(syst)
-
# Finalize the system.
syst = syst.finalized()
--- original
+++ modified
@@ -11,6 +11,7 @@
# using conservation laws.
# - Use of discrete symmetries to relate scattering states.
+import _defs
import kwant
import tinyarray
@@ -18,6 +19,7 @@
# For plotting
from matplotlib import pyplot
+from contextlib import redirect_stdout
tau_x = tinyarray.array([[0, 1], [1, 0]])
tau_y = tinyarray.array([[0, -1j], [1j, 0]])
@@ -74,11 +76,19 @@
data.append(smatrix.submatrix((0, 0), (0, 0)).shape[0] -
smatrix.transmission((0, 0), (0, 0)) +
smatrix.transmission((0, 1), (0, 0)))
- pyplot.figure()
+ fig = pyplot.figure()
pyplot.plot(energies, data)
pyplot.xlabel("energy [t]")
pyplot.ylabel("conductance [e^2/h]")
- pyplot.show()
+ pyplot.setp(fig.get_axes()[0].get_xticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ pyplot.setp(fig.get_axes()[0].get_yticklabels(),
+ fontsize=_defs.mpl_tick_size)
+ fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+ fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+ for extension in ('pdf', 'png'):
+ fig.savefig("superconductor_transport_result." + extension,
+ dpi=_defs.dpi)
def check_PHS(syst):
# Scattering matrix
@@ -103,14 +113,13 @@
def main():
syst = make_system(W=10)
- # Check that the system looks as intended.
- kwant.plot(syst)
-
# Finalize the system.
syst = syst.finalized()
# Check particle-hole symmetry of the scattering matrix
- check_PHS(syst)
+ with open('check_PHS_out.txt', 'w') as f:
+ with redirect_stdout(f):
+ check_PHS(syst)
# Compute and plot the conductance
plot_conductance(syst, energies=[0.002 * i for i in range(-10, 100)])
......@@ -21,7 +21,7 @@ New MUMPS-based solver
----------------------
The code for sparse matrix solvers has been reorganized and a new solver has
been added next to `kwant.solvers.sparse`: `kwant.solvers.mumps`. The new
solver uses the `MUMPS <http://graal.ens-lyon.fr/MUMPS/>`_ software package and
solver uses the `MUMPS <https://graal.ens-lyon.fr/MUMPS/>`_ software package and
is much (typically several times) faster than the UMFPACK-based old solver.
In addition, MUMPS uses considerably less memory for a given system while at
the same time it is able to take advantage of more than 2 GiB of RAM.
......
......@@ -3,8 +3,8 @@ What's new in Kwant 1.0
This article explains the new features in Kwant 1.0 compared to Kwant 0.2.
Kwant 1.0 was released on 9 September 2013. Please consult the `full list of
changes in Kwant <https://git.kwant-project.org/kwant/log/?h=v1.0.5>`_ for all
the changes up to the most recent bugfix release.
changes in Kwant <https://gitlab.kwant-project.org/kwant/kwant/-/commits/v1.0.5>`_
for all the changes up to the most recent bugfix release.
Lattice and shape improvements
......
......@@ -4,7 +4,7 @@ What's new in Kwant 1.1
This article explains the user-visible changes in Kwant 1.1.0, released on 21
October 2015. See also the `full list of changes up to the most recent bugfix
release of the 1.1 series
<https://gitlab.kwant-project.org/kwant/kwant/compare/v1.1.0...latest-1.1>`_.
<https://gitlab.kwant-project.org/kwant/kwant/-/compare/v1.1.0...latest-1.1>`_.
Harmonize `~kwant.physics.Bands` with `~kwant.physics.modes`
------------------------------------------------------------
......
......@@ -4,7 +4,7 @@ What's new in Kwant 1.2
This article explains the user-visible changes in Kwant 1.2.2, released on 9
December 2015. See also the `full list of changes up to the most recent bugfix
release of the 1.2 series
<https://gitlab.kwant-project.org/kwant/kwant/compare/v1.2.2...latest-1.2>`_.
<https://gitlab.kwant-project.org/kwant/kwant/-/compare/v1.2.2...latest-1.2>`_.
Kwant 1.2 is identical to Kwant 1.1 except that it has been updated to run on
Python 3.4 and above. Bugfix releases for the 1.1 and 1.2 series will mirror
......