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!