Contour plot of the conductance
Dear all, I am new to Kwant and Python. I want to consider a contour plot of the conductance as a function of energy and the well depth for Tutorial 2.3.2. The contour plot is similar to the one on the homepage in “Conductance of a Corbino disk in a quantum Hall regime”, but the codes are not shown in the tutorials. I want to learn this example since it will be more flexible to consider the effects of the device parameters. I want to output the results into a .txt file with the energy in the first column, well depths in the second column, conductance in the third column, so I can plot the contour by origin. Tutorial 2.3.2 is a simple example to consider the contour plot, and we may only need to do small changes. The codes for Tutorial 2.3.2 areattached. Could you help me? Thanks in advance. Kwok-Long Lee
Dear Lee Kwok-Long, To be able to work with Kwant there's no way around learning the basics of Python. There are plenty of good tutorials available on the internet. We recommend the official Python tutorial (https://docs.python.org/2/tutorial/index.html) and “Software carpentry” (http://software-carpentry.org/v5/novice/python/index.html). You wrote:
I want to output the results into a .txt file with the energy in the first column, well depths in the second column, conductance in the third column, so I can plot the contour by origin.
You can add a function print_conductances to the tutorial script: def plot_conductance(sys, energies, welldepths): for energy in energies: for welldepth in welldepths: smatrix = kwant.smatrix(sys, energy, args=[-welldepth]) print energy, welldepth, smatrix.transmission(1, 0) Call it like this: plot_conductance(sys, energies=[0.01 * i for i in xrange(100)], welldepths=[0.01 * i for i in xrange(100)]) The data will be printed as you wished. In order to print it to a file and not to the terminal screen, redirect the output to a file when running the script (this will even work with Windows as far as I know): python script.py >conductance.dat Note that if you want to make a 2d plot of this data, you can directly use matplotlib’s imshow. There’s no need to output the data to a file. Best regards, Christoph
Dear Christoph, Thanks a lot for your helpful reply. I have another question about " smatrix = kwant.smatrix(sys, energy, args=[-welldepth])", and I found in tutorial 2.3.2 the expression "kwant.smatrix allows us to specify a list, *args*, that will be passed additional arguments to the functions that provide the Hamiltonian matrix elements." So *args *passed additional arguments to the "def make_system", but the corresponding parameter in def make_system is unclear, for example, in tutorial 2.3.2 the corresponding parameter for args =[-welldepth] is the "potential(site, pot)". When we have more than one additional arguments like args=[-welldepth, hex], how can kwant.smatrix(sys, energy, args=[-welldepth,hex]) find the right corresponding parameters in def make_system, will it cause mistakes? I mean hex in args=[-welldepth,hex]) may passed value to potential(site, pot). Best regards, Kwok-Long Lee On Thu, Dec 4, 2014 at 5:49 PM, <christoph.groth@cea.fr> wrote:
Dear Lee Kwok-Long,
To be able to work with Kwant there's no way around learning the basics of Python. There are plenty of good tutorials available on the internet. We recommend the official Python tutorial (https://docs.python.org/2/ tutorial/index.html) and “Software carpentry” (http://software-carpentry. org/v5/novice/python/index.html).
You wrote:
I want to output the results into a .txt file with the energy in the
first column, well depths in the second column, conductance in the third column, so I can plot the contour by origin.
You can add a function print_conductances to the tutorial script:
def plot_conductance(sys, energies, welldepths): for energy in energies: for welldepth in welldepths: smatrix = kwant.smatrix(sys, energy, args=[-welldepth]) print energy, welldepth, smatrix.transmission(1, 0)
Call it like this:
plot_conductance(sys, energies=[0.01 * i for i in xrange(100)], welldepths=[0.01 * i for i in xrange(100)])
The data will be printed as you wished. In order to print it to a file and not to the terminal screen, redirect the output to a file when running the script (this will even work with Windows as far as I know):
python script.py >conductance.dat
Note that if you want to make a 2d plot of this data, you can directly use matplotlib’s imshow. There’s no need to output the data to a file.
Best regards, Christoph
Dear Kwok-Long Lee, You wrote:
I have another question about " smatrix = kwant.smatrix(sys, energy, args=[-welldepth])", and I found in tutorial 2.3.2 the expression "kwant.smatrix allows us to specify a list, *args*, that will be passed additional arguments to the functions that provide the Hamiltonian matrix elements." So *args *passed additional arguments to the "def make_system", but the corresponding parameter in def make_system is unclear, for example, in tutorial 2.3.2 the corresponding parameter for args =[-welldepth] is the "potential(site, pot)". When we have more than one additional arguments like args=[-welldepth, hex], how can kwant.smatrix(sys, energy, args=[-welldepth,hex]) find the right corresponding parameters in def make_system, will it cause mistakes? I mean hex in args=[-welldepth,hex]) may passed value to potential(site, pot).
Kwant’s “args” are explained here: http://kwant-project.org/doc/1.0/pre/whatsnew/1.0#parameters-to-hamiltonian args is a sequence (i.e. list) that is passed as additional arguments to all value functions of the system. So, if you call kwant.smatrix(sys, energy, args=[-welldepth, hex]), all your value functions will need to take two additional arguments. For example: def onsite(site, foo, bar): … “onsite” is a site value function, so with empty “args” it would need to accept a single argument, a site. If args has length 2, the function needs to take exactly two additional arguments. Their names do not matter, only the order does. All of this has been inspired by Python’s own *-syntax by the way: https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists Christoph
participants (3)
-
Christoph Groth
-
christoph.groth@cea.fr
-
Lee Kwok-Long