def make_system(): sys = kwant.Builder() sys[graphene.shape(disk, (0, 0))] = onsite sys[graphene.neighbors()] = -s0 sys[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppings]] = spin_orbit_v sys[kwant.HoppingKind((0, 0), a, b)] = hop_ras_e1 sys[kwant.HoppingKind((0, 1), a, b)] = hop_ras_e2 sys[kwant.HoppingKind((-1, 1), a, b)] = hop_ras_e3 lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) lead[graphene.shape((lambda pos: abs(pos[1]) < 10), (0, 0))] = onsite_lead lead[graphene.neighbors()] = -s0 lead[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppings]] = spin_orbit_v_lead sys.attach_lead(lead) sys.attach_lead(lead.reversed()) return sys.finalized()
def make_system(): sys = kwant.Builder() sys[lat_u.shape(disk,(0,0))] = onsite sys[lat_d.shape(disk,(0,0))] = onsite sys[lat_u.neighbors()] = 1 sys[lat_d.neighbors()] = 1 sys[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppings]] = nnn sys[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppingsd]] = nnn sys[kwant.HoppingKind((0, 0), a,bd)] = hop_ras_e1 sys[kwant.HoppingKind((0, 1), a,bd)] = hop_ras_e2 sys[kwant.HoppingKind((-1, 1), a,bd)] = hop_ras_e3 sys[kwant.HoppingKind((0, 0), ad,b)] = hop_ras_e1 sys[kwant.HoppingKind((0, 1), ad,b)] = hop_ras_e2 sys[kwant.HoppingKind((-1, 1), ad,b)] = hop_ras_e3 # sym_left = kwant.TranslationalSymmetry((-1, 0)) # lead0 = kwant.Builder(sym_left) # lead0[lat_u.shape((lambda pos: abs(pos[1]) < width), (0, 0))]=onsite#1 # lead0[lat_u.neighbors()] = 1 # lead0[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppings]] = nnn ## # left hole lead # lead1 = kwant.Builder(sym_left) # lead1[lat_d.shape((lambda pos: abs(pos[1]) < width), (0, 0))]=onsite#1 # lead1[lat_d.neighbors()] = 1 # lead1[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppingsd]] = nnn # # sys.attach_lead(lead0) #spin up # sys.attach_lead(lead1) #spin down # sys.attach_lead(lead0.reversed()) #lead3 spin up # sys.attach_lead(lead1.reversed()) #lead4 spin down sym0u = kwant.TranslationalSymmetry((-1,0)) sym0u.add_site_family(lat_u.sublattices[0], other_vectors=[(-1, 2)]) sym0u.add_site_family(lat_u.sublattices[1], other_vectors=[(-1, 2)]) lead0_u = kwant.Builder(sym0u) lead0_u[lat_u.shape(lead0_shape,(0,1))]= onsite # 1# lead0_u[lat_u.neighbors()] = 1 lead0_u[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppings]] = nnn sys.attach_lead(lead0_u) #================================left_down0===================================== sym0d = kwant.TranslationalSymmetry((-1,0)) sym0d.add_site_family(lat_d.sublattices[0], other_vectors=[(-1, 2)]) sym0d.add_site_family(lat_d.sublattices[1], other_vectors=[(-1, 2)]) lead0_d = kwant.Builder(sym0d) lead0_d[lat_d.shape(lead0_shape,(0,1))]= onsite # 1# lead0_d[lat_d.neighbors()] = 1 lead0_d[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppingsd]] = nnn sys.attach_lead(lead0_d) sys.attach_lead(lead0_u.reversed()) sys.attach_lead(lead0_d.reversed()) return sys
def test_operator_construction(): lat, syst = _random_square_system(3) fsyst = syst.finalized() N = len(fsyst.sites) # test construction failure if norbs not given latnone = kwant.lattice.chain() syst[latnone(0)] = 1 for A in opservables: raises(ValueError, A, syst.finalized()) del syst[latnone(0)] # test construction failure when dimensions of onsite do not match for A in opservables: raises(ValueError, A, fsyst, onsite=np.eye(2)) # test that error is raised when input array is the wrong size for A in opservables: a = A(fsyst) kets = list(map(np.ones, [(0, ), (N - 1, ), (N + 1, ), (N, 1)])) for ket in kets: raises(ValueError, a, ket) raises(ValueError, a, ket, ket) raises(ValueError, a.act, ket) raises(ValueError, a.act, ket, ket) # Test failure on non-hermitian for A in (ops.Density, ops.Current, ops.Source): raises(ValueError, A, fsyst, 1j) # Test output dtype ket = np.ones(len(fsyst.sites)) for A in (ops.Density, ops.Current, ops.Source): a = A(fsyst) a_nonherm = A(fsyst, check_hermiticity=False) assert a(ket, ket).dtype == np.complex128 assert a(ket).dtype == np.float64 assert a_nonherm(ket, ket).dtype == np.complex128 assert a_nonherm(ket).dtype == np.complex128 # test construction with different numbers of orbitals lat2 = kwant.lattice.chain(norbs=2) extra_sites = [lat2(i) for i in range(N)] syst[extra_sites] = np.eye(2) syst[zip(fsyst.sites, extra_sites)] = ta.matrix([1, 1]) for A in opservables: raises(ValueError, A, syst.finalized(), onsite=np.eye(2)) A(syst.finalized()) A.onsite == np.eye(2) del syst[extra_sites] check = [(ops.Density, np.arange(N).reshape(-1, 1), ta.identity(1)), (ops.Current, np.array(list(fsyst.graph)), ta.identity(1)), (ops.Source, np.arange(N).reshape(-1, 1), ta.identity(1))] # test basic construction for A, where, onsite in check: a = A(fsyst) assert np.all(np.asarray(a.where) == where) assert all(a.onsite == onsite for i in range(N)) # test construction with dict `onsite` for A in opservables: B = A(fsyst, {lat: 1}) assert all(B.onsite(i) == 1 for i in range(N)) # test construction with a functional onsite for A in opservables: B = A(fsyst, lambda site: site.pos[0]) # x-position operator assert all(B.onsite(i) == fsyst.sites[i].pos[0] for i in range(N)) # test construction with `where` given by a sequence where = [lat(2, 2), lat(1, 1)] fwhere = tuple(fsyst.id_by_site[s] for s in where) A = ops.Density(fsyst, where=where) assert np.all(np.asarray(A.where).reshape(-1) == fwhere) where = [(lat(2, 2), lat(1, 2)), (lat(0, 0), lat(0, 1))] fwhere = np.asarray([(fsyst.id_by_site[a], fsyst.id_by_site[b]) for a, b in where]) A = ops.Current(fsyst, where=where) assert np.all(np.asarray(A.where) == fwhere) # test construction with `where` given by a function tag_list = [(1, 0), (1, 1), (1, 2)] def where(site): return site.tag in tag_list A = ops.Density(fsyst, where=where) assert all(fsyst.sites[A.where[w, 0]].tag in tag_list for w in range(A.where.shape[0])) where_list = set(kwant.HoppingKind((1, 0), lat)(syst)) fwhere_list = set( (fsyst.id_by_site[a], fsyst.id_by_site[b]) for a, b in where_list) def where(a, b): return (a, b) in where_list A = ops.Current(fsyst, where=where) assert all((a, b) in fwhere_list for a, b in A.where) # test that `sum` is passed to constructors correctly for A in opservables: A(fsyst, sum=True).sum == True
def test_fd_mismatch(): # The fundamental domains of the two 1D symmetries that make up T are # incompatible. This produced a bug where certain systems could be wrapped # around in all directions, but could not be wrapped around when 'keep' is # provided. sqrt3 = np.sqrt(3) lat = kwant.lattice.general([(sqrt3, 0), (-sqrt3 / 2, 1.5)]) T = kwant.TranslationalSymmetry((sqrt3, 0), (0, 3)) syst1 = kwant.Builder(T) syst1[lat(1, 1)] = syst1[lat(0, 1)] = 1 syst1[lat(1, 1), lat(0, 1)] = 1 syst2 = kwant.Builder(T) syst2[lat(0, 0)] = syst2[lat(0, -1)] = 1 syst2[lat(0, 0), lat(0, -1)] = 1 # combine the previous two syst3 = kwant.Builder(T) syst3.update(syst1) syst3.update(syst2) for syst in (syst1, syst2, syst3): wraparound(syst) wraparound(syst, keep=0) wraparound(syst, keep=1) ## Test that spectrum of non-trivial system (including above cases) ## is the same, regardless of the way in which it is wrapped around lat = kwant.lattice.general([(sqrt3, 0), (-sqrt3 / 2, 1.5)], [(sqrt3 / 2, 0.5), (0, 1)]) a, b = lat.sublattices T = kwant.TranslationalSymmetry((3 * sqrt3, 0), (0, 3)) syst = kwant.Builder(T) syst[(l(i, j) for i in range(-1, 2) for j in range(-1, 2) for l in (a, b))] = 0 syst[kwant.HoppingKind((0, 0), b, a)] = -1j syst[kwant.HoppingKind((1, 0), b, a)] = 2j syst[kwant.HoppingKind((0, 1), a, b)] = -2j def spectrum(syst, keep): syst = wraparound(syst, keep=keep).finalized() ks = ('k_x', 'k_y', 'k_z') if keep is None: def _(*args): params = dict(zip(ks, args)) return np.linalg.eigvalsh( syst.hamiltonian_submatrix(params=params)) else: def _(*args): params = dict(zip(ks, args)) kext = params.pop(ks[keep]) B = kwant.physics.Bands(syst, params=params) return B(kext) return _ spectra = [spectrum(syst, keep) for keep in (None, 0, 1)] # Check that spectra are the same at k=0. Checking finite k # is more tricky, as we would also need to transform the k vectors E_k = np.array([spec(0, 0) for spec in spectra]).transpose() assert all(np.allclose(E, E[0]) for E in E_k) # Test square lattice with oblique unit cell lat = kwant.lattice.general(np.eye(2)) translations = kwant.lattice.TranslationalSymmetry([2, 2], [0, 2]) syst = kwant.Builder(symmetry=translations) syst[lat.shape(lambda site: True, [0, 0])] = 1 syst[lat.neighbors()] = 1 # Check that spectra are the same at k=0. spectra = [spectrum(syst, keep) for keep in (None, 0, 1)] E_k = np.array([spec(0, 0) for spec in spectra]).transpose() assert all(np.allclose(E, E[0]) for E in E_k) # Test Rocksalt structure # cubic lattice that contains both sublattices lat = kwant.lattice.general(np.eye(3)) # Builder with FCC translational symmetries. translations = kwant.lattice.TranslationalSymmetry([1, 1, 0], [1, 0, 1], [0, 1, 1]) syst = kwant.Builder(symmetry=translations) syst[lat(0, 0, 0)] = 1 syst[lat(0, 0, 1)] = -1 syst[lat.neighbors()] = 1 # Check that spectra are the same at k=0. spectra = [spectrum(syst, keep) for keep in (None, 0, 1, 2)] E_k = np.array([spec(0, 0, 0) for spec in spectra]).transpose() assert all(np.allclose(E, E[0]) for E in E_k) # Same with different translation vectors translations = kwant.lattice.TranslationalSymmetry([1, 1, 0], [1, -1, 0], [0, 1, 1]) syst = kwant.Builder(symmetry=translations) syst[lat(0, 0, 0)] = 1 syst[lat(0, 0, 1)] = -1 syst[lat.neighbors()] = 1 # Check that spectra are the same at k=0. spectra = [spectrum(syst, keep) for keep in (None, 0, 1, 2)] E_k = np.array([spec(0, 0, 0) for spec in spectra]).transpose() assert all(np.allclose(E, E[0]) for E in E_k) # Test that spectrum in slab geometry is identical regardless of choice of unit # cell in rocksalt structure def shape(site): return abs(site.tag[2]) < 4 lat = kwant.lattice.general(np.eye(3)) # First choice: primitive UC translations = kwant.lattice.TranslationalSymmetry([1, 1, 0], [1, -1, 0], [1, 0, 1]) syst = kwant.Builder(symmetry=translations) syst[lat(0, 0, 0)] = 1 syst[lat(0, 0, 1)] = -1 # Set all the nearest neighbor hoppings for d in [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]]: syst[(lat(0, 0, 0), lat(*d))] = 1 wrapped = kwant.wraparound.wraparound(syst, keep=2) finitewrapped = kwant.Builder() finitewrapped.fill(wrapped, shape, start=np.zeros(3)) sysf = finitewrapped.finalized() spectrum1 = [ np.linalg.eigvalsh( sysf.hamiltonian_submatrix(params=dict(k_x=k, k_y=0))) for k in np.linspace(-np.pi, np.pi, 5) ] # Second choice: doubled UC with third translation purely in z direction translations = kwant.lattice.TranslationalSymmetry([1, 1, 0], [1, -1, 0], [0, 0, 2]) syst = kwant.Builder(symmetry=translations) syst[lat(0, 0, 0)] = 1 syst[lat(0, 0, 1)] = -1 syst[lat(1, 0, 1)] = 1 syst[lat(-1, 0, 0)] = -1 for s in np.array([[0, 0, 0], [1, 0, 1]]): for d in np.array([[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]]): syst[(lat(*s), lat(*(s + d)))] = 1 wrapped = kwant.wraparound.wraparound(syst, keep=2) finitewrapped = kwant.Builder() finitewrapped.fill(wrapped, shape, start=np.zeros(3)) sysf = finitewrapped.finalized() spectrum2 = [ np.linalg.eigvalsh( sysf.hamiltonian_submatrix(params=dict(k_x=k, k_y=0))) for k in np.linspace(-np.pi, np.pi, 5) ] assert np.allclose(spectrum1, spectrum2)
def hop_ras_e2_d(site1,site2,Lambda_R=Lambda_R): return 1j*Lambda_R*(0.5 - 1j*sqrt(3)/2.0) def hop_ras_e3_d(site1,site2,Lambda_R=Lambda_R): return 1j*Lambda_R*(0.5 + 1j*sqrt(3)/2.0) sys[lat_u.shape(Rectangle,(0,1))]=onsite #even with 0 onsite potential, we need to use the zero matrix and not a scalar. sys[lat_d.shape(Rectangle,(0,1))]=onsite sys[lat_u.neighbors()] = 1 sys[lat_d.neighbors()] = 1 sys[kwant.HoppingKind((0, 0), a,d)] = hop_ras_e1 sys[kwant.HoppingKind((0, 1), a,d)] = hop_ras_e2_u sys[kwant.HoppingKind((-1, 1), a,d)] = hop_ras_e3_u sys[kwant.HoppingKind((0, 0), c,b)] = hop_ras_e1 sys[kwant.HoppingKind((0, 1), c,b)] = hop_ras_e2_d sys[kwant.HoppingKind((-1, 1), c,b)] = hop_ras_e3_d #Here we chose the clockwise Vij which are +1 (as retuned by Hop_value). The other ones (-1) will be given directly #by the hermeticity of the Hamiltonian hoppings1_u = (((1, 0), a,a), ((-1, 1), a,a), ((0, -1), a,a)) hoppings2_u = (((1, 0), b,b), ((-1, 1), b,b), ((0, -1), b,b)) hoppings1_d = (((1, 0), c,c), ((-1, 1), c,c), ((0, -1), c,c)) hoppings2_d = (((1, 0), d,d), ((-1, 1), d,d), ((0, -1), d,d)) sys[[kwant.builder.HoppingKind(*hopping) for hopping in hoppings1_u]] = Hop_Value_u
def hop_ras_e2(site1, site2, Lambda_R=Lambda_R, t1=1): return t1 * sigma_0 + 1j * Lambda_R * (0.5 * sigma_x - sqrt(3) / 2.0 * sigma_y) def hop_ras_e3(site1, site2, Lambda_R=Lambda_R, t1=1): return t1 * sigma_0 + 1j * Lambda_R * (0.5 * sigma_x + sqrt(3) / 2.0 * sigma_y) sys[lat.shape( Rectangle, (0, 1) )] = onsite #even with 0 onsite potential, we need to use the zero matrix and not a scalar. #sys[lat.neighbors()]=t1*sigma_0 sys[kwant.HoppingKind((0, 0), a, b)] = hop_ras_e1 sys[kwant.HoppingKind((0, 1), a, b)] = hop_ras_e2 sys[kwant.HoppingKind((-1, 1), a, b)] = hop_ras_e3 #Here we chose the clockwise Vij which are +1 (as retuned by Hop_value). The other ones (-1) will be given directly #by the hermeticity of the Hamiltonian hoppings1 = (((1, 0), a, a), ((-1, 1), a, a), ((0, -1), a, a)) hoppings2 = (((1, 0), b, b), ((-1, 1), b, b), ((0, -1), b, b)) sys[[kwant.builder.HoppingKind(*hopping) for hopping in hoppings1]] = Hop_Value sys[[kwant.builder.HoppingKind(*hopping) for hopping in hoppings2]] = Hop_Value #==========================left================================== def lead_shape(pos, ly=ly): x, y = pos return 1 <= y < ly