How to add random but opposite onsite potential on graphene?

Dear community, I want to add random potentials on graphene. Within each unit cell, I want A site have the oppsite value to B site. That is, random across unit cells, but symmetric respect to zero within every unit cell. How to achieve this? I have tried to do so, but cannot find a way. Below is my code: ``` import numpy as np import kwant low = 0 high = 1 def make_syst(a=1): syst = kwant.Builder() lat = kwant.lattice.honeycomb(a, norbs=1, name=['a', 'b']) r = 10 def circle(pos): x, y = pos return x ** 2 + y ** 2 < r ** 2 def onsite(site, low, high): return np.random.uniform(low, high) # first attempt using function, not working, also cannot gurantee a, b are truly opposite in value # syst[lat.a.shape(circle, (0, 0))] = onsite # syst[lat.b.shape(circle, (0, 0))] = -1*onsite # wrong # second attempt, still not right m = np.random.uniform(low, high) syst[lat.a.shape(circle, (0, 0))] = m syst[lat.b.shape(circle, (0, 0))] = -m syst[lat.neighbors()] = 1 return syst.finalized() fsyst = make_syst() # kwant.plot(fsyst) H = fsyst.hamiltonian_submatrix(params=dict(high=high, low=low)) Es = np.linalg.eigvalsh(H) plt.plot(Es, '.') plt.show() ``` Thanks for help!

Dear Wilson, You said *I want to add random potentials on graphene. Within each unit cell, I want A site have the oppsite value to B site*. In fact you just need to set in the onsite function the sublattice dependence (I mean for instance *return +1 if site.family==a else -1.*) *SO in your case:* a, b =lat.sublattices def onsite(site,low, high): return *+1**np.random.uniform(low, high) if ifsite.family==*a* else -1*np.random.uniform(low, high) *or simply use the kwant.digest prebuilt function as* sites =list(syst.sites()) Random_sites = random.choices(sites, k = 10) def onsite(site): return *+*0.5 *kwant.digest.uniform(repr(Random_sites)) + 0.5 if if site.family==aelse* -* 0.5 * kwant.digest.uniform(repr(Random_sites)) + 0.5 I hope this will help. Best, Adel Le mer. 25 mai 2022 à 17:53, <wilson2048@outlook.com> a écrit :
Dear community,
I want to add random potentials on graphene. Within each unit cell, I want A site have the oppsite value to B site. That is, random across unit cells, but symmetric respect to zero within every unit cell. How to achieve this? I have tried to do so, but cannot find a way.
Below is my code:
``` import numpy as np import kwant
low = 0 high = 1 def make_syst(a=1): syst = kwant.Builder() lat = kwant.lattice.honeycomb(a, norbs=1, name=['a', 'b'])
r = 10
def circle(pos): x, y = pos return x ** 2 + y ** 2 < r ** 2
def onsite(site, low, high): return np.random.uniform(low, high)
# first attempt using function, not working, also cannot gurantee a, b are truly opposite in value # syst[lat.a.shape(circle, (0, 0))] = onsite # syst[lat.b.shape(circle, (0, 0))] = -1*onsite # wrong
# second attempt, still not right m = np.random.uniform(low, high) syst[lat.a.shape(circle, (0, 0))] = m syst[lat.b.shape(circle, (0, 0))] = -m
syst[lat.neighbors()] = 1 return syst.finalized()
fsyst = make_syst() # kwant.plot(fsyst) H = fsyst.hamiltonian_submatrix(params=dict(high=high, low=low)) Es = np.linalg.eigvalsh(H) plt.plot(Es, '.') plt.show() ```
Thanks for help!

Dear Wilson, The proposed solution I have commented* on was wrong and it does not work in your case since. **kwant.digest.uniform or **or random.uniform do provide different values for A and B sulattices even if we fix the seed*. In fact kwant defines the sublattice within the same tag with different site values. For this reason,* the proposed solution will not work* *even when including the sublattice condition in the onsite(site)* function depending on the site variable *The function **random.uniform will not work in your case anymore since you can not set the tag variable there.* In fact, the situation is somehow tricky. *So you need to use a tag as a variable*. I have corrected your script and it is working now. You can use site_color=family_color in kwant.plot() to see the opposite onsite value with red and blue colors in your system. *You don't need to use low=0 and high=+1 since we will use kwant.digest.uniform.* *Here is the script and I hope it will be the correct solution looking for:* import kwant import numpy as np from math import sqrt import matplotlib.pyplot as plt from types import SimpleNamespace from ipywidgets import interact from mpl_toolkits import mplot3d import warnings warnings.filterwarnings('ignore') def onsite(site): #we define a value which will be assined to both a and sublattices v= 0.5 * kwant.digest.uniform(repr(site.tag)) + 0.5 return +v if site.family==sub_a else -v r = 10 a=1 syst = kwant.Builder() lat = kwant.lattice.honeycomb(a, norbs=1, name=['sub_a', 'sub_b']) sub_a, sub_b = lat.sublattices def circle(pos): x, y = pos return x ** 2 + y ** 2 < r ** 2 syst[lat.shape(circle, (0, 0))] = onsite syst[lat.neighbors()] = 1 fsyst=syst.finalized() # kwant.plot(fsyst) H = fsyst.hamiltonian_submatrix(params=dict()) Es = np.linalg.eigvalsh(H) plt.plot(Es, '.') plt.show() def family_color(site): v= 0.5 * kwant.digest.uniform(repr(site.tag)) + 0.5 return +v if site.family==sub_a else -v kwant.plot(syst, site_color=family_color, site_size=None, cmap='jet', colorbar=True,fig_size=(15, 10)) plt.show() best Le mer. 25 mai 2022 à 20:21, Adel Belayadi <adelphys@gmail.com> a écrit :
Dear Wilson, You said *I want to add random potentials on graphene. Within each unit cell, I want A site have the oppsite value to B site*. In fact you just need to set in the onsite function the sublattice dependence (I mean for instance *return +1 if site.family==a else -1.*)
*SO in your case:* a, b =lat.sublattices def onsite(site,low, high): return *+1**np.random.uniform(low, high) if ifsite.family==*a* else -1*np.random.uniform(low, high)
*or simply use the kwant.digest prebuilt function as* sites =list(syst.sites()) Random_sites = random.choices(sites, k = 10) def onsite(site): return *+*0.5 *kwant.digest.uniform(repr(Random_sites)) + 0.5 if if site.family==aelse* -* 0.5 * kwant.digest.uniform(repr(Random_sites)) + 0.5
I hope this will help.
Best, Adel
Le mer. 25 mai 2022 à 17:53, <wilson2048@outlook.com> a écrit :
Dear community,
I want to add random potentials on graphene. Within each unit cell, I want A site have the oppsite value to B site. That is, random across unit cells, but symmetric respect to zero within every unit cell. How to achieve this? I have tried to do so, but cannot find a way.
Below is my code:
``` import numpy as np import kwant
low = 0 high = 1 def make_syst(a=1): syst = kwant.Builder() lat = kwant.lattice.honeycomb(a, norbs=1, name=['a', 'b'])
r = 10
def circle(pos): x, y = pos return x ** 2 + y ** 2 < r ** 2
def onsite(site, low, high): return np.random.uniform(low, high)
# first attempt using function, not working, also cannot gurantee a, b are truly opposite in value # syst[lat.a.shape(circle, (0, 0))] = onsite # syst[lat.b.shape(circle, (0, 0))] = -1*onsite # wrong
# second attempt, still not right m = np.random.uniform(low, high) syst[lat.a.shape(circle, (0, 0))] = m syst[lat.b.shape(circle, (0, 0))] = -m
syst[lat.neighbors()] = 1 return syst.finalized()
fsyst = make_syst() # kwant.plot(fsyst) H = fsyst.hamiltonian_submatrix(params=dict(high=high, low=low)) Es = np.linalg.eigvalsh(H) plt.plot(Es, '.') plt.show() ```
Thanks for help!

Dear Adel: Thank you very much for the help. I've tried your solution; it is perfectly what I need! The kwant.digest and site.tag are really what I am looking for. Best, Wilson ________________________________ From: Adel Belayadi <adelphys@gmail.com> Sent: Thursday, May 26, 2022 8:55 AM To: wilson2048@outlook.com <wilson2048@outlook.com> Cc: kwant-discuss@python.org <kwant-discuss@python.org> Subject: Re: [Kwant] How to add random but opposite onsite potential on graphene? Dear Wilson, The proposed solution I have commented on was wrong and it does not work in your case since. kwant.digest.uniform or or random.uniform do provide different values for A and B sulattices even if we fix the seed. In fact kwant defines the sublattice within the same tag with different site values. For this reason, the proposed solution will not work even when including the sublattice condition in the onsite(site) function depending on the site variable The function random.uniform will not work in your case anymore since you can not set the tag variable there. In fact, the situation is somehow tricky. So you need to use a tag as a variable. I have corrected your script and it is working now. You can use site_color=family_color in kwant.plot() to see the opposite onsite value with red and blue colors in your system. You don't need to use low=0 and high=+1 since we will use kwant.digest.uniform. Here is the script and I hope it will be the correct solution looking for: import kwant import numpy as np from math import sqrt import matplotlib.pyplot as plt from types import SimpleNamespace from ipywidgets import interact from mpl_toolkits import mplot3d import warnings warnings.filterwarnings('ignore') def onsite(site): #we define a value which will be assined to both a and sublattices v= 0.5 * kwant.digest.uniform(repr(site.tag)) + 0.5 return +v if site.family==sub_a else -v r = 10 a=1 syst = kwant.Builder() lat = kwant.lattice.honeycomb(a, norbs=1, name=['sub_a', 'sub_b']) sub_a, sub_b = lat.sublattices def circle(pos): x, y = pos return x ** 2 + y ** 2 < r ** 2 syst[lat.shape(circle, (0, 0))] = onsite syst[lat.neighbors()] = 1 fsyst=syst.finalized() # kwant.plot(fsyst) H = fsyst.hamiltonian_submatrix(params=dict()) Es = np.linalg.eigvalsh(H) plt.plot(Es, '.') plt.show() def family_color(site): v= 0.5 * kwant.digest.uniform(repr(site.tag)) + 0.5 return +v if site.family==sub_a else -v kwant.plot(syst, site_color=family_color, site_size=None, cmap='jet', colorbar=True,fig_size=(15, 10)) plt.show() best Le mer. 25 mai 2022 à 20:21, Adel Belayadi <adelphys@gmail.com<mailto:adelphys@gmail.com>> a écrit : Dear Wilson, You said I want to add random potentials on graphene. Within each unit cell, I want A site have the oppsite value to B site. In fact you just need to set in the onsite function the sublattice dependence (I mean for instance return +1 if site.family==a else -1.) SO in your case: a, b =lat.sublattices def onsite(site,low, high): return +1*np.random.uniform(low, high) if ifsite.family==a else -1*np.random.uniform(low, high) or simply use the kwant.digest prebuilt function as sites =list(syst.sites()) Random_sites = random.choices(sites, k = 10) def onsite(site): return +0.5 *kwant.digest.uniform(repr(Random_sites)) + 0.5 if if site.family==aelse - 0.5 * kwant.digest.uniform(repr(Random_sites)) + 0.5 I hope this will help. Best, Adel Le mer. 25 mai 2022 à 17:53, <wilson2048@outlook.com<mailto:wilson2048@outlook.com>> a écrit : Dear community, I want to add random potentials on graphene. Within each unit cell, I want A site have the oppsite value to B site. That is, random across unit cells, but symmetric respect to zero within every unit cell. How to achieve this? I have tried to do so, but cannot find a way. Below is my code: ``` import numpy as np import kwant low = 0 high = 1 def make_syst(a=1): syst = kwant.Builder() lat = kwant.lattice.honeycomb(a, norbs=1, name=['a', 'b']) r = 10 def circle(pos): x, y = pos return x ** 2 + y ** 2 < r ** 2 def onsite(site, low, high): return np.random.uniform(low, high) # first attempt using function, not working, also cannot gurantee a, b are truly opposite in value # syst[lat.a.shape(circle, (0, 0))] = onsite # syst[lat.b.shape(circle, (0, 0))] = -1*onsite # wrong # second attempt, still not right m = np.random.uniform(low, high) syst[lat.a.shape(circle, (0, 0))] = m syst[lat.b.shape(circle, (0, 0))] = -m syst[lat.neighbors()] = 1 return syst.finalized() fsyst = make_syst() # kwant.plot(fsyst) H = fsyst.hamiltonian_submatrix(params=dict(high=high, low=low)) Es = np.linalg.eigvalsh(H) plt.plot(Es, '.') plt.show() ``` Thanks for help!
participants (3)
-
Adel Belayadi
-
wilson wilson
-
wilson2048@outlook.com