Skip to content
Snippets Groups Projects
Commit e6ae9762 authored by Kwant authors's avatar Kwant authors Committed by Christoph Groth
Browse files

development leading up to version 0.1

parent f9bda42a
No related branches found
Tags v0.1.0
No related merge requests found
Showing
with 1993 additions and 0 deletions
*~
MANIFEST
*.pyc
*.so
/kwant/*/*.c
/kwant/_static_version.py
/build
/dist
/doc/build
/doc/source/reference/generated/
/doc/source/images/*.png
/doc/source/images/*.pdf
/doc/source/images/.*_flag
# This file specifies the files to be included in the source distribution
# in addition to the default ones.
recursive-include kwant *.pxd
recursive-include kwant *.h
recursive-include kwant test_*.py
include TODO.txt
recursive-include examples *.py
include doc/other/*[a-zA-Z]
include doc/Makefile
recursive-include doc/source *.rst *.py *.svg
recursive-include doc/source/_static *[a-zA-Z]
recursive-include doc/templates *[a-zA-Z]
prune doc/source/reference/generated
recursive-include doc/sphinxext *.py *.txt *.in
=============================================================
kwant, a package for numerical quantum transport calculations
=============================================================
Licence
=======
This software is NOT TO BE DISTRIBUTED, neither in part nor as a whole.
The only exception to this is the ``doc/sphinxext`` subdirectory, which is free
software. (See the file ``LICENSE.txt`` in that subdirectory.)
Installation
============
The prerequisites are
- More or less current versions of `Python <http://python.org>`_ and `SciPy
<http://scipy.org>`_. Python 2.6 and scipy 0.7.2 should be enough.
- `Cython <http://cython.org/>`_ -- Version 0.13 works for us.
optional:
- `pycairo <http://cairographics.org/pycairo/>`_ (for plotting)
- `matplotlib <http://matplotlib.sourceforge.net/>`_ (for some of the
examples)
kwant can be build and installed using distutils, following standard python
conventions. To build and install, run the following commands in the root
directory of the package. ::
python setup.py build
python setup.py install
The second command has to be run as root (e.g. prefixing it with ``sudo``). By
default the package will be installed under ``/usr/local``. You can change
this using the ``--prefix`` option, e.g.::
python setup.py install --prefix=/opt
If you would like to install kwant into your home directory only you can use ::
python setup.py install --home=~
This does not require superuser priviledges. If you install kwant in this way
be sure to tell python where to find it. This can be done by setting the
``PYTHONPATH`` environment variable::
export PYTHONPATH=$HOME/lib/python
You can make this setting permanent by adding this line to your the file
``.bashrc`` in your home directory.
To check successful installation try executing some examples in the
``examples`` subdirectory.
Documentation
=============
To build the documentation, kwant has to be installed as described in the
previous section. The `sphinx documentation generator
<http://sphinx.pocoo.org/>`_ is required.
HTML documentation can be built by entering the ``doc`` subdirectory of the
kwant package and executing ``make html``. PDF documentation is generated by
executing ``make latex`` followed by a ``make all-pdf`` in ``doc/build/latex``.
Because of some quirks of how sphinx works, it might be necessary to execute
``make clean`` between building HTML and PDF documentation. If this is not
done, sphinx might mistakenly use PNG files for PDF output.
Please consult the documentation for further information on how to use kwant.
Hacking
=======
To work on the library itself it is useful to build it in-place. This can be
done with the following command ::
python setup.py build_ext -i
The ``kwant`` subdirectory of the source distribution will be thus turned into
a proper python package which can be imported. To be able to import kwant from
within python, one can either work in the root directory of the distribution
(where the subdirectory ``kwant`` is located), or make a (symbolic) link from
somewhere in the Python search path to the the package subdirectory.
Some conventions to keep in mind:
* Please keep the code consistent by adhering to the already used naming and
formatting conventions. We generally follow the `"Style Guide for Python
Code" <http://www.python.org/dev/peps/pep-0008/>`_ and the `"Docstring
Conventions" <http://www.python.org/dev/peps/pep-0257/>`_.
* Write tests for all the important functionality you add. Be sure not to
break existing tests.
Tests
=====
We use the `nose testing framework
<http://somethingaboutorange.com/mrl/projects/nose/>`_. To run the tests,
execute the command ``nosetests`` from the root directory of the package after
it has been built in place.
TODO.txt 0 → 100644
Roughly in order of importance. -*-org-*-
* Define a few benchmarks and check performance. Optimize the code.
* Write a fast tiny array module.
(If this turns out to be a performance bottleneck.)
* Provide support for calculating and nicely plotting LDOS.
Make a tutorial example for this.
* Allow attaching lead with further then nearest slice hoppings.
The most easy way to do this is increasing the period of the lead.
* Optionally show site coordinates when plotting a system.
* Add support for easily adding magnetic field to a system.
* Generalize InfiniteSystem to multiple directions.
* Add support for optimization of lead fundamental domains.
* Write a module to generate "functional" random numbers.
This is a good starting point:
http://www.cs.umbc.edu/~olano/papers/GPUTEA.pdf
* Write a RGF solver which uses graph/slicer.
* Implement the C solver interface.
* Wrap TB_SIM as a solver.
* Wrap umfpack or some other sparse linear algebra library with Cython.
Use it directly in sparse solver. This will allow to fine-tune the solution
of sparse systems.
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# In difference to the original Makefile, we convert all SVG files to PDF for
# LaTeX output. For HTML output, we don't create PNGs but rather use the SVG
# files directly.
IMAGESOURCES = $(shell find source -name "*.svg")
GENERATEDPDF = $(patsubst %.svg, %.pdf, $(IMAGESOURCES))
# Tutorial images.
TUTORIAL1A_IMAGES = source/images/tutorial1a_result.png source/images/tutorial1a_result.pdf source/images/tutorial1a_sys.png source/images/tutorial1a_sys.pdf
TUTORIAL2A_IMAGES = source/images/tutorial2a_result.png source/images/tutorial2a_result.pdf
TUTORIAL2B_IMAGES = source/images/tutorial2b_result.png source/images/tutorial2b_result.pdf
TUTORIAL2C_IMAGES = source/images/tutorial2c_result.png source/images/tutorial2c_result.pdf source/images/tutorial2c_sys.png source/images/tutorial2c_sys.pdf source/images/tutorial2c_note1.png source/images/tutorial2c_note1.pdf source/images/tutorial2c_note2.png source/images/tutorial2c_note2.pdf
TUTORIAL3A_IMAGES = source/images/tutorial3a_result.png source/images/tutorial3a_result.pdf
TUTORIAL3B_IMAGES = source/images/tutorial3b_result.png source/images/tutorial3b_result.pdf source/images/tutorial3b_sys.png source/images/tutorial3b_sys.pdf
TUTORIAL4_IMAGES = source/images/tutorial4_result.png source/images/tutorial4_result.pdf source/images/tutorial4_sys1.png source/images/tutorial4_sys1.pdf source/images/tutorial4_sys2.png source/images/tutorial4_sys2.pdf source/images/tutorial4_bs.png source/images/tutorial4_bs.pdf
ALL_TUTORIAL_IMAGES = $(TUTORIAL1A_IMAGES) $(TUTORIAL2A_IMAGES) $(TUTORIAL2B_IMAGES) $(TUTORIAL2C_IMAGES) $(TUTORIAL3A_IMAGES) $(TUTORIAL3B_IMAGES) $(TUTORIAL4_IMAGES)
.PHONY: help clean realclean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/* $(GENERATEDPDF)
-rm -rf source/reference/generated
realclean: clean
-rm -f $(ALL_TUTORIAL_IMAGES) source/images/.*_flag
html: $(ALL_TUTORIAL_IMAGES)
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml: $(ALL_TUTORIAL_IMAGES)
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
pickle: $(ALL_TUTORIAL_IMAGES)
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json: $(ALL_TUTORIAL_IMAGES)
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp: $(ALL_TUTORIAL_IMAGES)
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp: $(ALL_TUTORIAL_IMAGES)
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/kwant.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/kwant.qhc"
latex: $(GENERATEDPDF) $(ALL_TUTORIAL_IMAGES)
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
%.pdf: %.svg
inkscape --export-pdf=$@ $<
# Generation of tutorial images. This requires some serious make trickery, see
# http://article.gmane.org/gmane.comp.gnu.make.general/5806
$(TUTORIAL1A_IMAGES): source/images/.tutorial1a_flag
@:
source/images/.tutorial1a_flag: source/images/tutorial1a.py
cd source/images/ && python tutorial1a.py
touch source/images/.tutorial1a_flag
$(TUTORIAL2A_IMAGES): source/images/.tutorial2a_flag
@:
source/images/.tutorial2a_flag: source/images/tutorial2a.py
cd source/images/ && python tutorial2a.py
touch source/images/.tutorial2a_flag
$(TUTORIAL2B_IMAGES): source/images/.tutorial2b_flag
@:
source/images/.tutorial2b_flag: source/images/tutorial2b.py
cd source/images/ && python tutorial2b.py
touch source/images/.tutorial2b_flag
$(TUTORIAL2C_IMAGES): source/images/.tutorial2c_flag
@:
source/images/.tutorial2c_flag: source/images/tutorial2c.py
cd source/images/ && python tutorial2c.py
touch source/images/.tutorial2c_flag
$(TUTORIAL3A_IMAGES): source/images/.tutorial3a_flag
@:
source/images/.tutorial3a_flag: source/images/tutorial3a.py
cd source/images/ && python tutorial3a.py
touch source/images/.tutorial3a_flag
$(TUTORIAL3B_IMAGES): source/images/.tutorial3b_flag
@:
source/images/.tutorial3b_flag: source/images/tutorial3b.py
cd source/images/ && python tutorial3b.py
touch source/images/.tutorial3b_flag
$(TUTORIAL4_IMAGES): source/images/.tutorial4_flag
@:
source/images/.tutorial4_flag: source/images/tutorial4.py
cd source/images/ && python tutorial4.py
touch source/images/.tutorial4_flag
File added
File added
@import "default.css";
/**
* Spacing fixes
div.body p, div.body dd, div.body li {
line-height: 125%;
}
ul.simple {
margin-top: 0;
margin-bottom: 0;
padding-top: 0;
padding-bottom: 0;
}
*/
/* spacing around blockquoted fields in parameters/attributes/returns */
/*Essential. Otherwise there is way too much space around*/
td.field-body > blockquote {
margin-top: 0.1em;
margin-bottom: 0.5em;
}
/* THE NEXT TWO ARE EVENTUALLY IMPORTANT I THINK */
/* spacing around example code
div.highlight > pre {
padding: 2px 5px 2px 5px;
}
*/
/* spacing in see also definition lists
dl.last > dd {
margin-top: 1px;
margin-bottom: 5px;
margin-left: 30px;
}
*/
/* hide overflowing content in the sidebar
div.sphinxsidebarwrapper p.topless {
overflow: hidden;
}
*/
/**
* Hide dummy toctrees
ul {
padding-top: 0;
padding-bottom: 0;
margin-top: 0;
margin-bottom: 0;
}
ul li {
padding-top: 0;
padding-bottom: 0;
margin-top: 0;
margin-bottom: 0;
}
ul li a.reference {
padding-top: 0;
padding-bottom: 0;
margin-top: 0;
margin-bottom: 0;
}
*/
/**
* Make high-level subsections easier to distinguish from top-level ones
div.body h3 {
background-color: transparent;
}
div.body h4 {
border: none;
background-color: transparent;
}
*/
/**
* Scipy colors
body {
background-color: rgb(100,135,220);
}
div.document {
background-color: rgb(230,230,230);
}
div.sphinxsidebar {
background-color: rgb(230,230,230);
}
div.related {
background-color: rgb(100,135,220);
}
div.sphinxsidebar h3 {
color: rgb(0,102,204);
}
div.sphinxsidebar h3 a {
color: rgb(0,102,204);
}
div.sphinxsidebar h4 {
color: rgb(0,82,194);
}
div.sphinxsidebar p {
color: black;
}
div.sphinxsidebar a {
color: #355f7c;
}
div.sphinxsidebar ul.want-points {
list-style: disc;
}
*/
.field-list th {
color: rgb(0,50,150);
background-color: #EEE8AA;
white-space: nowrap; /*Essential. Otherwise the colons can break
into a new line*/
}
/**
* Extra admonitions
div.tip {
background-color: #ffffe4;
border: 1px solid #ee6;
}
div.plot-output {
clear-after: both;
}
div.plot-output .figure {
float: left;
text-align: center;
margin-bottom: 0;
padding-bottom: 0;
}
div.plot-output .caption {
margin-top: 2;
padding-top: 0;
}
div.plot-output p.admonition-title {
display: none;
}
div.plot-output:after {
content: "";
display: block;
height: 0;
clear: both;
}
*/
/*
div.admonition-example {
background-color: #e4ffe4;
border: 1px solid #ccc;
}*/
/**
* Styling for field lists
*/
table.field-list th {
border-left: 2px solid #999 !important;
padding-left: 5px;
}
table.field-list {
border-collapse: separate; /*Essential. Otherwise Parameters and Returns
are sharing one solid colored field. That looks
weird.*/
border-spacing: 10px;
}
/**
* Styling for footnotes
table.footnote td, table.footnote th {
border: none;
}
*/
div.specialnote-title {
font-size: 105%;
font-weight: bold;
font-color: #3B4D3C;
background-color: #DCE4DC;
padding: 1em;
padding-top: 0.4em;
padding-bottom: 0.4em;
margin-top: 1em;
margin-bottom: 0px;
border-width: 1px;
border-color: #546C55;
border-style: solid;
}
div.specialnote-body {
background-color: #DCE4DC;
padding: 1em;
padding-top: 0.1em;
padding-bottom: 0.4em;
margin-top: 0px;
border-width: 1px;
border-top-width: 0px;
border-color: #546C55;
border-style: solid;
}
function togglediv(id) {
var buttontext;
buttontext = $("#" + id + "-button").text();
if(buttontext == 'show') {
$("#" + id + "-button").text('hide');
}
else {
$("#" + id + "-button").text('show');
}
$("#" + id + "-body").slideToggle('swing');
}
# -*- coding: utf-8 -*-
#
# kwant documentation build configuration file, created by
# sphinx-quickstart on Tue Jan 11 09:39:28 2011.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
import kwant
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
sys.path.insert(0, os.path.abspath('../sphinxext'))
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary',
'sphinx.ext.todo', 'sphinx.ext.pngmath', 'numpydoc',
'kwantdoc']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['../templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'kwant'
copyright = u'2011-2012, A. R. Akhmerov, C. W. Groth, X. Waintal, M. Wimmer'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = kwant.version.version[:]
for i, s in enumerate(release):
if s not in '0123456790.':
break
# The short X.Y version.
version = release[:i]
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = []
# The reST default role (used for this markup: `text`) to use for all documents.
default_role = "autolink"
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# Do not show all class members automatically in the class documentation
numpydoc_show_class_members = False
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'default'
html_style = 'kwant.css'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
html_use_modindex = False
# This is needed too.
html_domain_indices = False
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'kwantdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
latex_paper_size = 'a4'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'kwant.tex', u'kwant Documentation',
u'A. R. Akhmerov, C. W. Groth, X. Waintal, M. Wimmer',
'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
latex_use_modindex = False
# This is needed too.
latex_domain_indices = False
# -- Options for autodoc -------------------------------------------------------
# Generate stub pages for autosummary directives.
autosummary_generate = True
autoclass_content = "both"
autodoc_default_flags = ['show-inheritance']
# Default width of figures in pixels
figwidth_px = 600
# Width for smaller figures
figwidth_small_px = 400
pt_to_in = 1./72.
# Default width of figures in pts
figwidth_pt = 300
# Width for smaller figures
figwidth_small_pt = 200
figwidth_small_in = figwidth_small_pt * pt_to_in
# Sizes for matplotlib figures
mpl_width_in = figwidth_pt * pt_to_in
mpl_label_size = 10 # font sizes in points
mpl_tick_size = 9
# Physics background
# ------------------
# Conductance of a quantum wire; subbands
#
# Kwant features highlighted
# --------------------------
# - Builder for setting up transport systems easily
# - Making scattering region and leads
# - Using the simple sparse solver for computing Landauer conductance
import kwant
import latex, html
# First, define the tight-binding system
sys = kwant.Builder()
# Here, we are only working with square lattices
lat = kwant.lattice.Square()
sys.default_site_group = lat
t = 1.0
W = 10
L = 30
# Define the scattering region
for i in xrange(L):
for j in xrange(W):
sys[(i, j)] = 4 * t
# hoppig in y-direction
if j > 0 :
sys[(i, j), (i, j-1)] = - t
#hopping in x-direction
if i > 0:
sys[(i, j), (i-1, j)] = -t
# Then, define the leads:
# First the lead to the left
# (Note: in the current version, TranslationalSymmetry takes a
# realspace vector)
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
lead0 = kwant.Builder(sym_lead0)
lead0.default_site_group = lat
for j in xrange(W):
lead0[(0, j)] = 4 * t
if j > 0:
lead0[(0, j), (0, j-1)] = - t
lead0[(1, j), (0, j)] = - t
# Then the lead to the right
sym_lead1 = kwant.TranslationalSymmetry([lat.vec((1, 0))])
lead1 = kwant.Builder(sym_lead1)
lead1.default_site_group = lat
for j in xrange(W):
lead1[(0, j)] = 4 * t
if j > 0:
lead1[(0, j), (0, j-1)] = - t
lead1[(1, j), (0, j)] = - t
# Then attach the leads to the system
sys.attach_lead(lead0)
sys.attach_lead(lead1)
# finalize the system
fsys = sys.finalized()
# and plot it, to make sure it's proper
kwant.plot(fsys, "tutorial1a_sys.pdf", width=latex.figwidth_pt)
kwant.plot(fsys, "tutorial1a_sys.png", width=html.figwidth_px)
# Now that we have the system, we can compute conductance
energies = []
data = []
for ie in xrange(100):
energy = ie * 0.01
# compute the scattering matrix at energy energy
smatrix = kwant.solvers.sparse.solve(fsys, energy)
# compute the transmission probability from lead 0 to
# lead 1
energies.append(energy)
data.append(smatrix.transmission(1, 0))
# Use matplotlib to write output
# We should see conductance steps
import pylab
pylab.plot(energies, data)
pylab.xlabel("energy [in units of t]",
fontsize=latex.mpl_label_size)
pylab.ylabel("conductance [in units of e^2/h]",
fontsize=latex.mpl_label_size)
fig = pylab.gcf()
pylab.setp(fig.get_axes()[0].get_xticklabels(),
fontsize=latex.mpl_tick_size)
pylab.setp(fig.get_axes()[0].get_yticklabels(),
fontsize=latex.mpl_tick_size)
fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.)
fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
fig.savefig("tutorial1a_result.pdf")
fig.savefig("tutorial1a_result.png", dpi=(html.figwidth_px/latex.mpl_width_in))
# Physics background
# ------------------
# Gaps in quantum wires with spin-orbit coupling and Zeeman splititng,
# as theoretically predicted in
# http://prl.aps.org/abstract/PRL/v90/i25/e256601
# and (supposedly) experimentally oberved in
# http://www.nature.com/nphys/journal/v6/n5/abs/nphys1626.html
#
# Kwant features highlighted
# --------------------------
# - Numpy matrices as values in Builder
import kwant
import numpy
import latex, html
# define sigma-matrices for convenience
sigma_0 = numpy.eye(2)
sigma_x = numpy.array([[0, 1], [1, 0]])
sigma_y = numpy.array([[0, -1j], [1j, 0]])
sigma_z = numpy.array([[1, 0], [0, -1]])
# First, define the tight-binding system
sys = kwant.Builder()
# Here, we are only working with square lattices
# for simplicity, take lattice constant = 1
a = 1
lat = kwant.lattice.Square(a)
t = 1.0
alpha = 0.5
e_z = 0.08
W = 10
L = 30
# Define the scattering region
def rectangle(pos):
(x, y) = pos
return ( -0.5 < x < L - 0.5 ) and ( -0.5 < y < W - 0.5 )
sys[lat.shape(rectangle, (0, 0))] = 4 * t * sigma_0 + e_z * sigma_z
# hoppings in x-direction
sys[sys.possible_hoppings((1, 0), lat, lat)] = - t * sigma_0 - \
1j * alpha * sigma_y
# hoppings in y-directions
sys[sys.possible_hoppings((0, 1), lat, lat)] = - t * sigma_0 + \
1j * alpha * sigma_x
# Then, define the leads:
# First the lead to the left
# (Note: in the current version, TranslationalSymmetry takes a
# realspace vector)
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
lead0 = kwant.Builder(sym_lead0)
lead0.default_site_group = lat
def lead_shape(pos):
(x, y) = pos
return (-1 < x < 1) and ( -0.5 < y < W - 0.5 )
lead0[lat.shape(lead_shape, (0, 0))] = 4 * t * sigma_0 + e_z * sigma_z
# hoppings in x-direction
lead0[lead0.possible_hoppings((1, 0), lat, lat)] = - t * sigma_0 - \
1j * alpha * sigma_y
# hoppings in y-directions
lead0[lead0.possible_hoppings((0, 1), lat, lat)] = - t * sigma_0 + \
1j * alpha * sigma_x
# Then the lead to the right
# there we can use a special function that simply reverses the direction
lead1 = lead0.reversed()
# Then attach the leads to the system
sys.attach_lead(lead0)
sys.attach_lead(lead1)
# finalize the system
fsys = sys.finalized()
# Now that we have the system, we can compute conductance
energies = []
data = []
for ie in xrange(100):
energy = ie * 0.01 - 0.3
# compute the scattering matrix at energy energy
smatrix = kwant.solvers.sparse.solve(fsys, energy)
# compute the transmission probability from lead 0 to
# lead 1
energies.append(energy)
data.append(smatrix.transmission(1, 0))
# Use matplotlib to write output
# We should see conductance steps
import pylab
pylab.plot(energies, data)
pylab.xlabel("energy [in units of t]",
fontsize=latex.mpl_label_size)
pylab.ylabel("conductance [in units of e^2/h]",
fontsize=latex.mpl_label_size)
fig = pylab.gcf()
pylab.setp(fig.get_axes()[0].get_xticklabels(),
fontsize=latex.mpl_tick_size)
pylab.setp(fig.get_axes()[0].get_yticklabels(),
fontsize=latex.mpl_tick_size)
fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.)
fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
fig.savefig("tutorial2a_result.pdf")
fig.savefig("tutorial2a_result.png",
dpi=(html.figwidth_px/latex.mpl_width_in))
# Physics background
# ------------------
# transmission through a quantum well
#
# Kwant features highlighted
# --------------------------
# - Functions as values in Builder
import kwant
import latex, html
# First, define the tight-binding system
sys = kwant.Builder()
# Here, we are only working with square lattices
# for simplicity, take lattice constant = 1
a = 1
lat = kwant.lattice.Square(a)
t = 1.0
alpha = 0.5
e_z = 0.08
W = 10
L = 30
# Define the scattering region
def rectangle(pos):
(x, y) = pos
return ( -0.5 < x < L - 0.5 ) and ( -0.5 < y < W - 0.5 )
def potential(site):
(x, y) = site.pos
if 10 < x < 20:
return pot
else:
return 0
def onsite(site):
return 4 * t + potential(site)
sys[lat.shape(rectangle, (0, 0))] = onsite
for hopping in lat.nearest:
sys[sys.possible_hoppings(*hopping)] = - t
# Then, define the leads:
# First the lead to the left
# (Note: in the current version, TranslationalSymmetry takes a
# realspace vector)
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
lead0 = kwant.Builder(sym_lead0)
lead0.default_site_group = lat
def lead_shape(pos):
(x, y) = pos
return (-1 < x < 1) and ( -0.5 < y < W - 0.5 )
lead0[lat.shape(lead_shape, (0, 0))] = 4 * t
for hopping in lat.nearest:
lead0[lead0.possible_hoppings(*hopping)] = - t
# Then the lead to the right
# there we can use a special function that simply reverses the direction
lead1 = lead0.reversed()
# Then attach the leads to the system
sys.attach_lead(lead0)
sys.attach_lead(lead1)
# finalize the system
fsys = sys.finalized()
# Now that we have the system, we can compute conductance
energy = 0.2
wellpot = []
data = []
for ipot in xrange(100):
pot = - ipot * 0.01
# compute the scattering matrix at energy energy
smatrix = kwant.solvers.sparse.solve(fsys, energy)
# compute the transmission probability from lead 0 to
# lead 1
wellpot.append(-pot)
data.append(smatrix.transmission(1, 0))
# Use matplotlib to write output
# We should see conductance steps
import pylab
pylab.plot(wellpot, data)
pylab.xlabel("well depth [in units of t]",
fontsize=latex.mpl_label_size)
pylab.ylabel("conductance [in units of e^2/h]",
fontsize=latex.mpl_label_size)
fig = pylab.gcf()
pylab.setp(fig.get_axes()[0].get_xticklabels(),
fontsize=latex.mpl_tick_size)
pylab.setp(fig.get_axes()[0].get_yticklabels(),
fontsize=latex.mpl_tick_size)
fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.)
fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
fig.savefig("tutorial2b_result.pdf")
fig.savefig("tutorial2b_result.png",
dpi=(html.figwidth_px/latex.mpl_width_in))
# Physics background
# ------------------
# Flux-dependent transmission through a quantum ring
#
# Kwant features highlighted
# --------------------------
# - More complex shapes with lattices
# - Allows for discussion of subtleties of `attach_lead` (not in the
# example, but in the tutorial main text)
# - Modifcations of hoppings/sites after they have been added
from cmath import exp
from math import pi
import kwant
import latex, html
# First, define the tight-binding system
sys = kwant.Builder()
# Here, we are only working with square lattices
# for simplicity, take lattice constant = 1
a = 1
lat = kwant.lattice.Square(a)
t = 1.0
W = 10
r1 = 10
r2 = 20
# Define the scattering region
# Now, we aim for a more compelx shape, namely a ring (or annulus)
def ring(pos):
(x, y) = pos
rsq = x**2 + y**2
return ( r1**2 < rsq < r2**2)
sys[lat.shape(ring, (0, 11))] = 4 * t
for hopping in lat.nearest:
sys[sys.possible_hoppings(*hopping)] = - t
# In order to introduce a flux through the ring, we introduce a phase
# on the hoppings on the line cut through one of the arms
# since we want to change the flux without modifying Builder repeatedly,
# we define the modified hoppings as a function that takes the flux
# as a global variable.
def fluxphase(site1, site2):
return exp(1j * phi)
# Now go through all the hoppings and modify those in the lower
# arm of the ring that go from x=0 to x=1
for (site1, site2) in sys.hoppings():
ix1, iy1 = site1.tag
ix2, iy2 = site2.tag
hopx = tuple(sorted((ix1, ix2)))
if hopx == (0, 1) and iy1 == iy2 and iy1 < 0:
sys[lat(hopx[1], iy1), lat(hopx[0], iy1)] = fluxphase
# Then, define the leads:
# First the lead to the left
# (Note: in the current version, TranslationalSymmetry takes a
# realspace vector)
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
lead0 = kwant.Builder(sym_lead0)
lead0.default_site_group = lat
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
for hopping in lat.nearest:
lead0[lead0.possible_hoppings(*hopping)] = - t
# Then the lead to the right
# there we can use a special function that simply reverses the direction
lead1 = lead0.reversed()
# Then attach the leads to the system
sys.attach_lead(lead0)
sys.attach_lead(lead1)
# finalize the system
fsys = sys.finalized()
# and plot it, to make sure it's proper
kwant.plot(fsys, "tutorial2c_sys.pdf", width=latex.figwidth_pt)
kwant.plot(fsys, "tutorial2c_sys.png", width=html.figwidth_px)
# Now that we have the system, we can compute conductance
energy = 0.15
phases = []
data = []
for iphi in xrange(100):
phi = iphi * 0.01 * 3 * 2 * pi
# compute the scattering matrix at energy energy
smatrix = kwant.solve(fsys, energy)
# compute the transmission probability from lead 0 to
# lead 1
phases.append(phi / (2 * pi))
data.append(smatrix.transmission(1, 0))
# Use matplotlib to write output
# We should see conductance steps
import pylab
pylab.plot(phases, data)
pylab.xlabel("flux [in units of the flux quantum]",
fontsize=latex.mpl_label_size)
pylab.ylabel("conductance [in units of e^2/h]",
fontsize=latex.mpl_label_size)
fig = pylab.gcf()
pylab.setp(fig.get_axes()[0].get_xticklabels(),
fontsize=latex.mpl_tick_size)
pylab.setp(fig.get_axes()[0].get_yticklabels(),
fontsize=latex.mpl_tick_size)
fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.)
fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
fig.savefig("tutorial2c_result.pdf")
fig.savefig("tutorial2c_result.png",
dpi=(html.figwidth_px/latex.mpl_width_in))
# Finally, some plots needed for the notes
sys = kwant.Builder()
sys[lat.shape(ring, (0, 11))] = 4 * t
for hopping in lat.nearest:
sys[sys.possible_hoppings(*hopping)] = - t
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
lead0 = kwant.Builder(sym_lead0)
lead0.default_site_group = lat
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
for hopping in lat.nearest:
lead0[lead0.possible_hoppings(*hopping)] = - t
# Then the lead to the right
# there we can use a special function that simply reverses the direction
lead1 = lead0.reversed()
# Then attach the leads to the system
sys.attach_lead(lead0)
sys.attach_lead(lead1)
# finalize the system
fsys = sys.finalized()
# and plot it, to make sure it's proper
kwant.plot(fsys, "tutorial2c_note1.pdf", width=latex.figwidth_small_pt)
kwant.plot(fsys, "tutorial2c_note1.png", width=html.figwidth_small_px)
sys = kwant.Builder()
sys[lat.shape(ring, (0, 11))] = 4 * t
for hopping in lat.nearest:
sys[sys.possible_hoppings(*hopping)] = - t
sym_lead0 = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
lead0 = kwant.Builder(sym_lead0)
lead0.default_site_group = lat
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
for hopping in lat.nearest:
lead0[lead0.possible_hoppings(*hopping)] = - t
# Then the lead to the right
# there we can use a special function that simply reverses the direction
lead1 = lead0.reversed()
# Then attach the leads to the system
sys.attach_lead(lead0)
sys.attach_lead(lead1, lat(0, 0))
# finalize the system
fsys = sys.finalized()
# and plot it, to make sure it's proper
kwant.plot(fsys, "tutorial2c_note2.pdf", width=latex.figwidth_small_pt)
kwant.plot(fsys, "tutorial2c_note2.png", width=html.figwidth_small_px)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="250"
height="205"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.47 r22583"
sodipodi:docname="tutorial2c_sketch.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.0">
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective3026" />
<inkscape:perspective
id="perspective3635"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.5106232"
inkscape:cx="54.499548"
inkscape:cy="102.0132"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:object-nodes="true"
inkscape:grid-points="true"
gridtolerance="1.3"
objecttolerance="0.8"
gridanglex="8.4666669mm"
gridanglez="8.4666669mm"
grid_units="mm"
inkscape:window-width="1399"
inkscape:window-height="974"
inkscape:window-x="57"
inkscape:window-y="0"
inkscape:window-maximized="0"
units="pt">
<inkscape:grid
id="GridFromPre046Settings"
type="xygrid"
originx="0px"
originy="0px"
spacingx="2mm"
spacingy="2mm"
color="#0000ff"
empcolor="#ff0400"
opacity="0.2"
empopacity="0.37647059"
empspacing="5"
units="mm"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-114.19886,19.255464)">
<path
style="fill:none;stroke:#000000;stroke-width:2.91644573;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
d="m 292.43863,75.559443 c 0,29.083897 -23.60435,52.688207 -52.68822,52.688207 -29.08392,0 -52.68818,-23.60431 -52.68818,-52.688207 0,-29.083901 23.60426,-52.688202 52.68818,-52.688202 29.08391,0 52.68822,23.604301 52.68822,52.688202 z"
id="path37307" />
<g
id="g38103"
style="fill:none;stroke:#000000;stroke-width:0.625;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
transform="matrix(4.6663129,0,0,4.6663129,-1242.7479,-57.338034)">
<path
id="path38105"
style="fill:none;stroke:#000000;stroke-width:0.625;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 291.10885,24.772314 6.48497,0.02214 c 3.35206,-13.407233 11.42324,-16.3201141 20.32977,-16.3207844 8.90637,-6.702e-4 16.34147,2.3839234 19.96964,16.3207844 l 6.16611,0.03299 m -0.0331,6.854657 -6.1677,-0.03489 c -3.36971,13.202794 -11.16975,17.013197 -20.07612,17.012527 -8.90653,-6.7e-4 -16.67166,-3.363359 -20.32977,-17.012527 l -6.27014,-0.02403"
sodipodi:nodetypes="ccsccccscc" />
</g>
<path
sodipodi:type="arc"
style="opacity:0.95;fill:#ff0000;fill-opacity:1;stroke:none"
id="path3602"
sodipodi:cx="64.400978"
sodipodi:cy="74.404541"
sodipodi:rx="0.98904526"
sodipodi:ry="0.98904526"
d="m 65.390023,74.404541 c 0,0.546235 -0.44281,0.989045 -0.989045,0.989045 -0.546235,0 -0.989045,-0.44281 -0.989045,-0.989045 0,-0.546235 0.44281,-0.989045 0.989045,-0.989045 0.546235,0 0.989045,0.44281 0.989045,0.989045 z"
transform="matrix(4.6663129,0,0,4.6663129,-62.675572,-272.11353)" />
<path
style="fill:none;stroke:#ff0000;stroke-width:2.33315659;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:4.66631287, 2.33315643;stroke-dashoffset:0"
d="M 237.70766,74.685746 237.44391,183.60434"
id="path3604"
sodipodi:nodetypes="cc" />
<g
transform="matrix(1.2202792,0,0,-1.2202792,244.56422,79.414671)"
inkscape:label="phi"
id="g3637">
<g
transform="scale(0.1,0.1)"
id="g3639">
<path
id="path3641"
style="fill:#ff0000;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 125.012,52.4102 c 55.929,4.3203 96,37.7695 96,74.1018 0,37.41 -41.153,70.136 -96,74.476 l 0,19.934 c 0,12.098 0,17.09 34.136,17.09 l 11.864,0 0,11 c -12.91,-1.071 -45.91,-1.071 -60.614,-1.071 -14.7066,0 -48.0582,0 -60.9683,1.071 l 0,-11 11.75,0 c 33.832,0 33.832,-4.633 33.832,-17.09 l 0,-19.934 C 40.2812,195.57 2.01172,162.48 2.01172,126.871 2.01172,89.8203 41.6992,57.8086 95.0117,52.4102 l 0,-20.1407 C 95.0117,20.0391 95.0117,15 61.1797,15 l -11.75,0 0,-11 c 12.9101,1.07031 45.9101,1.07031 60.6093,1.07031 14.711,0 48.063,0 60.973,-1.07031 l 0,11 -11.864,0 c -34.136,0 -34.136,4.6797 -34.136,17.2695 l 0,20.1407 z M 95,60 c -50.5781,6.8789 -56.9883,43.84 -56.9883,66.301 0,18.84 3.5586,59.418 56.9883,66.687 L 95,60 z m 30.012,132.988 C 174.871,187.219 185,154.059 185,126.672 185,105.051 179.57,66.4805 125.012,60" />
</g>
</g>
</g>
</svg>
This diff is collapsed.
# Physics background
# ------------------
# band structure of a simple quantum wire in tight-binding approximation
#
# Kwant features highlighted
# --------------------------
# - Computing the band structure of a finalized lead.
import kwant
import numpy as np
from math import pi
import latex, html
a = 1
lat = kwant.lattice.Square(a)
t = 1.0
W = 10
# Define a lead:
sym_lead = kwant.TranslationalSymmetry([lat.vec((-1, 0))])
lead = kwant.Builder(sym_lead)
lead.default_site_group = lat
for j in xrange(W):
lead[(0, j)] = 4 * t
if j > 0:
lead[(0, j), (0, j-1)] = - t
lead[(1, j), (0, j)] = - t
# Now compute the band structure
# Only a finalized lead has the information about bandstructure
flead = lead.finalized()
momenta = np.arange(-pi, pi + .01, 0.02 * pi)
energy_list = [flead.energies(k) for k in momenta]
import pylab
pylab.plot(momenta, energy_list)
pylab.xlabel("momentum [in untis of (lattice constant)^-1]",
fontsize=latex.mpl_label_size)
pylab.ylabel("energy [in units of t]",
fontsize=latex.mpl_label_size)
fig = pylab.gcf()
pylab.setp(fig.get_axes()[0].get_xticklabels(),
fontsize=latex.mpl_tick_size)
pylab.setp(fig.get_axes()[0].get_yticklabels(),
fontsize=latex.mpl_tick_size)
fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.)
fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
fig.savefig("tutorial3a_result.pdf")
fig.savefig("tutorial3a_result.png",
dpi=(html.figwidth_px/latex.mpl_width_in))
# Physics background
# ------------------
# Fock-darwin spectrum of a quantum dot (energy spectrum in
# as a function of a magnetic field)
#
# Kwant features highlighted
# --------------------------
# - Use of `hamiltonian_submatrix` in order to obtain a Hamiltonian
# matrix.
from cmath import exp
import kwant
import latex, html
# First, define the tight-binding system
sys = kwant.Builder()
# Here, we are only working with square lattices
# for simplicity, take lattice constant = 1
a = 1
lat = kwant.lattice.Square(a)
t = 1.0
r = 10
# Define the quantum dot
def circle(pos):
(x, y) = pos
rsq = x**2 + y**2
return rsq < r**2
def hopx(site1, site2):
y = site1.pos[1]
return - t * exp(-1j * B * y)
sys[lat.shape(circle, (0, 0))] = 4 * t
# hoppings in x-direction
sys[sys.possible_hoppings((1, 0), lat, lat)] = hopx
# hoppings in y-directions
sys[sys.possible_hoppings((0, 1), lat, lat)] = - t
# It's a closed system for a change, so no leads
# finalize the system
fsys = sys.finalized()
# and plot it, to make sure it's proper
kwant.plot(fsys, "tutorial3b_sys.pdf")
kwant.plot(fsys, "tutorial3b_sys.png")
# In the following, we compute the spectrum of the quantum dot
# using dense matrix methods. This works in this toy example,
# as the system is tiny. In a real example, one would want to use
# sparse matrix methods
import scipy.linalg as la
Bs = []
energies = []
for iB in xrange(100):
B = iB * 0.002
# Obtain the Hamiltonian as a dense matrix
ham_mat = fsys.hamiltonian_submatrix()
ev = la.eigh(ham_mat, eigvals_only=True)
Bs.append(B)
energies.append(ev[:15])
import pylab
pylab.plot(Bs, energies)
pylab.xlabel("magnetic field [some arbitrary units]",
fontsize=latex.mpl_label_size)
pylab.ylabel("energy [in units of t]",
fontsize=latex.mpl_label_size)
fig = pylab.gcf()
pylab.setp(fig.get_axes()[0].get_xticklabels(),
fontsize=latex.mpl_tick_size)
pylab.setp(fig.get_axes()[0].get_yticklabels(),
fontsize=latex.mpl_tick_size)
fig.set_size_inches(latex.mpl_width_in, latex.mpl_width_in*3./4.)
fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
fig.savefig("tutorial3b_result.pdf")
fig.savefig("tutorial3b_result.png",
dpi=(html.figwidth_px/latex.mpl_width_in))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment