Dear Sudin,
Your code seems to work fine for me.
Why don't you just use an onsite function as below? (you can put a
condition as you wish)
sys_2[site] returns a function so you need to add the argument of hat
function: sys_2[site](site)
(be careful, this will not work if the leads add some sites to the central
system: in the lead, the potential is given by scalars, in the system by a
function. a small modification is required)
I hope this helps,
Adel
#############################################################################
def make_system(W, L, lim):
## scattering region ##
def Onsite(site):
x,y=site.pos
if y< lim: return x
else: return 0
sys = kwant.Builder()
sys[lat.shape(cross(W,L), (0,0))] = Onsite
sys[lat.neighbors(1)] = -1.
leads = [create_lead_h(W, xsym1,axis=(0,0)),create_lead_h(W,
xsym2,axis=(0,0))]
for lead in leads:
sys.attach_lead(lead)
return sys
def main():
sys_2 = make_system(W=3.5, L=3, lim=-1)
kwant.plotter.plot(sys_2,site_color=lambda
site:sys_2[site](site),colorbar=True, cmap=None)
if __name__ == '__main__':
main()
On Fri, Apr 17, 2020 at 7:06 AM SUDIN GANGULY <sudinganguly(a)gmail.com>
wrote:
> Dear Sir,
>
> Thank you for your reply. The problem I am facing is that if I assign the
> site values like (1,2,3,...) along the bottom line, the colormap of the
> site values are changing whenever I compile the code.
> ############################
> import kwant
> from pylab import *
> import matplotlib.pyplot as plt
> from random import *
> import numpy as np
>
>
> class Honeycomb(kwant.lattice.Polyatomic):
> def __init__(self, name=''):
> prim_vecs = [[0.5, sqrt(3)/2], [1, 0]] # bravais lattice vectors
> # offset the lattice so that it is symmetric around x and y axes
> basis_vecs = [[-0.5, -1/sqrt(12)], [-0.5, 1/sqrt(12)]]
> super(Honeycomb, self).__init__(prim_vecs, basis_vecs, name)
> self.a, self.b = self.sublattices
>
> sys=kwant.Builder()
> lat = Honeycomb()
> a,b= lat.sublattices
>
>
> def cross(W, L):
> def shape(pos):
> return ((-W <= pos[1] <= W and -L <= pos[0] <= L))
> return shape
>
> pv1, pv2 = lat.prim_vecs
>
>
> xsym1 = kwant.TranslationalSymmetry((-pv2)) # lattice symmetry in -x
> direction
> xsym1.add_site_family(lat.sublattices[0], other_vectors=[(-2, 1)])
> xsym1.add_site_family(lat.sublattices[1], other_vectors=[(-2, 1)])
>
> xsym2=kwant.TranslationalSymmetry((pv2))
> xsym2.add_site_family(lat.sublattices[0], other_vectors=[(-2, 1)])
> xsym2.add_site_family(lat.sublattices[1], other_vectors=[(-2, 1)])
>
> def create_lead_h(W, symmetry, axis):
> lead = kwant.Builder(symmetry)
> lead[lat.wire(axis, W)] = 0.
> lead[lat.neighbors(1)] = -1.
> return lead
>
>
> def make_system(W, L, no_of_line):
>
> ## scattering region ##
> sys = kwant.Builder()
> sys[lat.shape(cross(W,L), (0,0))] = 0
> sys[lat.neighbors(1)] = -1.
>
>
> line=[]
> for site in sys.expand(lat.shape(cross(W,L), (0, 0))):
> line.append(site.pos[1])
>
>
> line=set(line)
> line=list(line)
> line=sort(line)
> my_list=[]
> i=1
> for site in sys.expand(lat.shape(cross(W,L), (0, 0))):
> for j in range(0,no_of_line+1,2):
> line_no=j
> if (site.pos[1]==line[line_no] or
> site.pos[1]==line[line_no+1]):
> my_list.append(site)
> sys[site]=i
> i=i+1
>
> ## leads ##
>
> leads = [create_lead_h(W, xsym1,axis=(0,0))]
> leads += [create_lead_h(W, xsym2,axis=(0,0))]
>
> for lead in leads:
> sys.attach_lead(lead)
>
>
> #=============================================================================
> return {'sys': sys }
>
> def main():
> sys_2 = make_system(W=3.5, L=5, no_of_line=1)
> kwant.plotter.plot(sys_2['sys'],site_color=lambda
> site:sys_2['sys'][site],colorbar=True, cmap=None)
>
> if __name__ == '__main__':
> main()
> #################################
>
> I can resolve this issue by collecting the site positions from the array
> named my_list in the given code and then assign the site values
> accordingly. However, this procedure is a bit lengthy. If there is any
> other way to do that with less coding, that will be very helpful.
> With Regards,
> Sudin
>
> On Fri, Apr 17, 2020 at 1:36 AM Abbout Adel <abbout.adel(a)gmail.com> wrote:
>
>> Dear Sudin,
>>
>> Please post the code giving the error or explain better your concern.
>>
>> Could you just do it by defining an on site function?
>>
>> def Onsite(site):
>> x,y=site.pos()
>> i,_=site.tag
>> if y=y0: return Values[i]
>> else: return V0
>>
>>
>> sys[(........)]=Onsite
>>
>> I hope this helps,
>> Adel
>>
>> On Wed, Apr 15, 2020 at 3:45 PM SUDIN GANGULY <sudinganguly(a)gmail.com>
>> wrote:
>>
>>> Dear Sir,
>>>
>>> I want to assign a particular sequence of site values on a particular
>>> line (a number of lines) of a zigzag graphene nanoribbon. For example, the
>>> bottom zigzag line.
>>>
>>> let's say, from the left to right there are 10 sites and I want to put
>>> the onsite values as [1,2,3,...].
>>>
>>> I was able to get the information about the sites that are in the bottom
>>> line and have assigned the site values accordingly. But the problem is that
>>> each time I finalize the system, I get different onsite values along the
>>> bottom line. Is there any way to resolve this? Or maybe this approach is
>>> not the right way to do that.
>>>
>>> A part of my code is given below
>>> ========================
>>> def make_system(W, L, no_of_line):
>>>
>>> ## scattering region ##
>>> sys = kwant.Builder()
>>> sys[lat.shape(cross(W,L), (0,0))] = 0
>>> sys[lat.neighbors(1)] = -1.
>>> #######INFO of the line#########
>>> line=[]
>>> for site in sys.expand(lat.shape(cross(W,L), (0, 0))):
>>> #print (site.pos[0],site.pos[1])
>>> line.append(site.pos[1])
>>>
>>> line=set(line)
>>> line=list(line)
>>> line=sort(line)
>>>
>>>
>>> i=1
>>> for site in sys.expand(lat.shape(cross(W,L), (0, 0))):
>>> for j in range(0,no_of_line+1,2):
>>> line_no=j
>>> if (site.pos[1]==line[line_no] or site.pos[1]==line[line_no+1]):
>>> sys[site]=i
>>> i=i+1
>>> ########################
>>>
>>> With Regards,
>>> Sudin
>>>
>>
>>
>> --
>> Abbout Adel
>>
>
>
> --
> সুদিন
>
--
Abbout Adel