Dear Abbout,

thanks for pointing out this useful feature for adding cells from the lead to the scattering region, it really solves my problem.

For the plotting part I had to define the function to be plotted in the following way

--------

def plot_func(site):

    return sys[site](site)

kwant.plotter.map(sys,plot_func,num_lead_cells=2,oversampling=1)


--------


this provides an image of the potential that is used in the leads by kwant. The potential in the leads is defined to be translational invariant in order to avoid problems. The complete script is in attachment for the benefit of other users.


Best,


Sebastiano


On 2017-05-24 12:15, Abbout Adel wrote:
Dear Sebastiano,


If you want to see the potential in the lead you can do this easily with kwant by making some cells of the lead belong to the system and then plot your system as usual.

To do So, you can write:

sys.attach_lead(lead, add_cells=10)

By this, you add 10 cells to the system. (These cells have the potential you defined in the lead)



You can check the documentation [1].

I hope this helps.
Adel




On Wed, May 24, 2017 at 11:00 AM, Sebastiano Peotta <speotta@gmail.com> wrote:
Dear Joseph,

Thanks for the fast answer. I totally agree with adding the float to a function, the script does not run.

I missed the Warning in the kwant tutorial, that is the answer to what I was looking for. It would be nice to have a working example to be included in the tutorial of the use of functions to the define the potential and the hoppings in the leads. Moreover it would be useful that the plotting method "map" would show the value of a function provided by the user also in the leads. Maybe you could think to include these features in the new versions of kwant and the documentation.

Thanks a lot!

Sebastiano



On 24/05/2017 01:04, Joseph Weston wrote:
Hi Sebastiano,

I have seen most of the examples of Kwant usage, but somehow I miss the
usage of functions to define the on-site energy of lattice sites in the
leads. I have attached a simple Kwant script which includes the following
lines

-----------------

sym = kwant.TranslationalSymmetry((0, -1.))

lead = kwant.Builder(sym)

lead[lat.shape(region_lead,(0.,0.))] = 4. + potential # use the same
potential also for the lead !!!

lead[lat.neighbors()] = -1.


------------------
You cannot add a number to a Python function, which is what you are
attempting to do in line 3 above. You would have to put the "4" inside
the definition of "potential" in order to do what you want, exactly
as is done in the Kwant tutorial [1].


Since the leads are automatically attached to the scattering region I would
expect that the potential is evaluated at the sites where the leads is
attached and then repeated according to the translational symmetry given to
the lead. Is this the case? I tried to check this using the "map" method in
kwant.plotter, but the color in correspondence of the leads is an
uninformative grey, which does not belong to the color scale used in the
scattering region. Somehow in the documentation I was not able to find what
happens when a function is used to define the onsite energy in a lead. Can
you fill this gap?
There is a warning in the Kwant tutorial about this exact topic [1].
Any value function used by leads *must* have the declared symmetry
of the lead -- Kwant evaluates the lead Hamiltonian over an arbitrary
unit cell, so you will not get what you expect if your value functions
do not satisfy this symmetry.

Do you think that we could make this warning more prominent in the
tutorial?


Happy Kwanting,

Joe


[1]: https://kwant-project.org/doc/1/tutorial/tutorial2#spatially-dependent-values-through-functions




--
Abbout Adel