def test_join_incompatible_dimension():
    """Test that models with unequal dimension can not be joined."""
    model1 = tbmodels.Model(hop={(0, ): np.eye(3)})
    model2 = tbmodels.Model(hop={(0, 0): np.eye(3)})
    with pytest.raises(ValueError) as excinfo:
        tbmodels.Model.join_models(model1, model2)
    assert "dimension" in str(excinfo.value)
def test_join_incompatible_unit_cell():
    """Test that models with unequal unit cell can not be joined."""
    model1 = tbmodels.Model(uc=np.eye(3), size=2)
    model2 = tbmodels.Model(uc=np.eye(3), size=2)
    model3 = tbmodels.Model(uc=np.diag([1.1, 1, 1]), size=2)
    with pytest.raises(ValueError) as excinfo:
        tbmodels.Model.join_models(model1, model2, model3)
    assert "unit cell" in str(excinfo.value)
Exemple #3
0
def test_non_hermitian_1():
    """
    Check that an error is raised when the given hoppings do not correspond
    to a hermitian Hamiltonian.
    """
    with pytest.raises(ValueError):
        tbmodels.Model(size=2, hop={(0, 0, 0): np.eye(2), (1, 0, 0): np.eye(2)})
Exemple #4
0
def test_invalid_hopping_matrix():
    """
    Check that an error is raised when the passed size does not match the
    shape of hopping matrices.
    """
    with pytest.raises(ValueError):
        tbmodels.Model(size=2, hop={(0, 0, 0): np.eye(4)})
Exemple #5
0
def test_unequal_orbital_number():
    model = tbmodels.Model(pos=[[0., 0.], [0.5, 0.5], [0.5, 0.5]],
                           on_site=[1, 0.7, -1.2])
    t1 = 0.1
    t2 = 0.15
    t3 = 0.4
    for phase, R in zip([1, -1j, 1j, -1], itertools.product([0, -1], [0, -1])):
        model.add_hop(t1 * phase, 0, 1, R)
        model.add_hop(t3 * phase, 1, 2, R)

    for R in ((r[0], r[1]) for r in itertools.permutations([0, 1])):
        model.add_hop(t2, 0, 0, R)
        model.add_hop(-t2, 1, 1, R)
        model.add_hop(-t2, 2, 2, R)

    latt = model.to_kwant_lattice()
    sym = kwant.TranslationalSymmetry(latt.vec((1, 0)), latt.vec((0, 1)))
    sys = kwant.Builder(sym)
    sys[latt.shape(lambda p: True, (0, 0))] = 0
    model.add_hoppings_kwant(sys)
    sys = wraparound.wraparound(sys).finalized()

    for k in KPT:
        k = k[:2]
        k_kwant = tuple(np.array(k) * 2 * np.pi)
        np.testing.assert_allclose(model.eigenval(k),
                                   la.eigvalsh(
                                       sys.hamiltonian_submatrix(k_kwant)),
                                   atol=1e-8)
Exemple #6
0
def tb_model():
    """
    Creates a simple TBmodels tight-binding model.
    """
    t1, t2 = (0.2, 0.3)

    model = tbmodels.Model(on_site=(1, 1, -1, -1),
                           pos=[[0., 0., 0.], [0., 0., 0.], [0.5, 0.5, 0.],
                                [0.5, 0.5, 0.]],
                           occ=2)

    for p, R in zip([1, 1j, -1j, -1], itertools.product([0, -1], [0, -1],
                                                        [0])):
        model.add_hop(overlap=p * t1, orbital_1=0, orbital_2=2, R=R)
        model.add_hop(overlap=p.conjugate() * t1,
                      orbital_1=1,
                      orbital_2=3,
                      R=R)

    for R in ((r[0], r[1], 0) for r in itertools.permutations([0, 1])):
        model.add_hop(t2, 0, 0, R)
        model.add_hop(t2, 1, 1, R)
        model.add_hop(-t2, 2, 2, R)
        model.add_hop(-t2, 3, 3, R)
    return model
def HaldaneTB(delta,t1,hop2,phi):
# define lattice vectors
    lat=[[1.0,0.0],[0.5,np.sqrt(3.0)/2.0]]
# define coordinates of orbitals
    orb=[[1./3.,1./3.],[2./3.,2./3.]]

# make two dimensional tight-binding Haldane model
    haldane=tbm.Model(on_site=[-delta,delta],
                      dim=2,
                      pos=orb,
                      uc=np.array(lat))

# set model parameters
    t2=hop2*np.exp(1.j*phi)


# set hoppings (one for each connected pair of orbitals)
# from j in R to i in 0
# (amplitude, i, j, [lattice vector to cell containing j])
    haldane.add_hop(t1, 0, 1, [ 0, 0])
    haldane.add_hop(t1, 1, 0, [ 1, 0])
    haldane.add_hop(t1, 1, 0, [ 0, 1])
# add second neighbour complex hoppings
    haldane.add_hop(t2 , 0, 0, [ 0, -1])
    haldane.add_hop(t2 , 0, 0, [ 1, 0])
    haldane.add_hop(t2 , 0, 0, [ -1, 1])
    haldane.add_hop(t2 , 1, 1, [ -1, 0])

    haldane.add_hop(t2 , 1, 1, [ 1,-1])
    haldane.add_hop(t2 , 1, 1, [ 0, 1])
    return haldane
Exemple #8
0
def test_non_hermitian_1():
    with pytest.raises(ValueError):
        model = tbmodels.Model(size=2,
                               hop={
                                   (0, 0, 0): np.eye(2),
                                   (1, 0, 0): np.eye(2)
                               })
Exemple #9
0
    def inner(t1, t2, sparsity_default=False, **kwargs):
        dim = kwargs.get("dim", 3)
        defaults = {}
        defaults["pos"] = [[0] * 2, [0.5] * 2]
        if dim < 2:
            raise ValueError("dimension must be at least 2")
        if dim > 2:
            for position in defaults["pos"]:
                position.extend([0] * (dim - 2))
        defaults["occ"] = 1
        defaults["on_site"] = (1, -1)
        defaults["size"] = 2
        defaults["dim"] = None
        defaults["sparse"] = sparsity_default
        model = tbmodels.Model(**ChainMap(kwargs, defaults))

        for phase, r_part in zip([1, -1j, 1j, -1],
                                 itertools.product([0, -1], [0, -1])):
            R = list(r_part)
            R.extend([0] * (dim - 2))
            model.add_hop(t1 * phase, 0, 1, R)

        for r_part in itertools.permutations([0, 1]):
            R = list(r_part)
            R.extend([0] * (dim - 2))
            model.add_hop(t2, 0, 0, R)
            model.add_hop(-t2, 1, 1, R)
        return model
Exemple #10
0
def test_unequal_orbital_number():
    """
    Check converting a simple model to kwant, where the two positions
    don't have an equal number of orbitals.
    """
    model = tbmodels.Model(pos=[[0., 0.], [0.5, 0.5], [0.5, 0.5]], on_site=[1, 0.7, -1.2])
    t1 = 0.1
    t2 = 0.15
    t3 = 0.4
    for phase, R in zip([1, -1j, 1j, -1], itertools.product([0, -1], [0, -1])):
        model.add_hop(t1 * phase, 0, 1, R)
        model.add_hop(t3 * phase, 1, 2, R)

    for R in ((r[0], r[1]) for r in itertools.permutations([0, 1])):
        model.add_hop(t2, 0, 0, R)
        model.add_hop(-t2, 1, 1, R)
        model.add_hop(-t2, 2, 2, R)

    latt = model.to_kwant_lattice()
    sym = kwant.TranslationalSymmetry(latt.vec((1, 0)), latt.vec((0, 1)))  # pylint: disable=no-member
    sys = kwant.Builder(sym)  # pylint: disable=no-member
    sys[latt.shape(lambda p: True, (0, 0))] = 0
    model.add_hoppings_kwant(sys)
    sys = wraparound.wraparound(sys).finalized()

    for k in KPT:
        k = k[:2]
        np.testing.assert_allclose(
            model.eigenval(k), la.eigvalsh(sys.hamiltonian_submatrix(params=to_kwant_params(k))), atol=1e-8
        )
Exemple #11
0
def test_invalid_empty():
    """
    Check that trying to convert an incomplete tight-binding model to
    hr format raises an error.
    """
    model = tbmodels.Model(size=2, dim=3)
    with pytest.raises(ValueError):
        model.to_hr()
Exemple #12
0
def test_wrong_key_length():
    with pytest.raises(ValueError):
        model = tbmodels.Model(size=2,
                               hop={
                                   (0, 0, 0): np.eye(2),
                                   (1, 0, 0): np.eye(2),
                                   (-1, 0, 0, 0): np.eye(2)
                               },
                               contains_cc=False)
Exemple #13
0
def test_wrong_pos_dim():
    with pytest.raises(ValueError):
        model = tbmodels.Model(size=2,
                               hop={
                                   (0, 0, 0): np.eye(2),
                                   (1, 0, 0): np.eye(2),
                                   (-1, 0, 0): np.eye(2)
                               },
                               contains_cc=False,
                               pos=((0., ) * 3, (0.5, ) * 4))
Exemple #14
0
def test_wrong_uc_shape():
    with pytest.raises(ValueError):
        model = tbmodels.Model(size=2,
                               hop={
                                   (0, 0, 0): np.eye(2),
                                   (1, 0, 0): np.eye(2),
                                   (-1, 0, 0): np.eye(2)
                               },
                               contains_cc=False,
                               pos=((0., ) * 3, (0.5, ) * 3),
                               uc=np.array([[1, 2], [3, 4], [5, 6]]))
Exemple #15
0
def test_wrong_key_length():
    """
    Check that an error is raised when the reciprocal lattice vectors
    have inconsistent lengths.
    """
    with pytest.raises(ValueError):
        tbmodels.Model(
            size=2,
            hop={(0, 0, 0): np.eye(2), (1, 0, 0): np.eye(2), (-1, 0, 0, 0): np.eye(2)},
            contains_cc=False,
        )
def test_compare_pythtb():
    pt_model = pt.tb_model(1, 1, lat=[[1]], orb=[[0], [0.2]])
    tb_model = tb.Model(dim=1, pos=[[0], [0.2]], uc=[[1]])

    pt_model.set_hop(3j, 0, 1, [1])
    tb_model.add_hop(3j, 0, 1, [1])

    assert np.isclose(pt_model._gen_ham([0]), tb_model.hamilton([0])).all()
    assert np.isclose(pt_model._gen_ham([0]), tb_model.hamilton([0], convention=1)).all()

    assert np.isclose(pt_model._gen_ham([1]), tb_model.hamilton([1], convention=1)).all()
    assert np.isclose(pt_model._gen_ham([0.2]), tb_model.hamilton(0.2, convention=1)).all()
Exemple #17
0
def test_wrong_uc_shape():
    """
    Check that an error is raised when the unit cell is not square.
    """
    with pytest.raises(ValueError):
        tbmodels.Model(
            size=2,
            hop={(0, 0, 0): np.eye(2), (1, 0, 0): np.eye(2), (-1, 0, 0): np.eye(2)},
            contains_cc=False,
            pos=((0.0,) * 3, (0.5,) * 3),
            uc=np.array([[1, 2], [3, 4], [5, 6]]),
        )
Exemple #18
0
def test_wrong_pos_dim():
    """
    Check that an error is raised when the positions have inconsistent
    dimensions.
    """
    with pytest.raises(ValueError):
        tbmodels.Model(
            size=2,
            hop={(0, 0, 0): np.eye(2), (1, 0, 0): np.eye(2), (-1, 0, 0): np.eye(2)},
            contains_cc=False,
            pos=((0.0,) * 3, (0.5,) * 4),
        )
Exemple #19
0
def test_wrong_pos_length():
    """
    Check that an error is raised when the number of positions does not
    match the given size.
    """
    with pytest.raises(ValueError):
        tbmodels.Model(
            size=2,
            hop={(0, 0, 0): np.eye(2), (1, 0, 0): np.eye(2), (-1, 0, 0): np.eye(2)},
            contains_cc=False,
            pos=((0.0,) * 3, (0.5,) * 3, (0.2,) * 3),
        )
Exemple #20
0
def test_compare_pythtb():
    """
    Compare a tight-binding model against a PythTB reference, using convention 1.
    """
    pt_model = pt.tb_model(1, 1, lat=[[1]], orb=[[0], [0.2]])
    tb_model = tb.Model(dim=1, pos=[[0], [0.2]], uc=[[1]])

    pt_model.set_hop(3j, 0, 1, [1])
    tb_model.add_hop(3j, 0, 1, [1])

    # pylint: disable=protected-access
    assert np.isclose(pt_model._gen_ham([0]), tb_model.hamilton([0])).all()
    assert np.isclose(pt_model._gen_ham([0]),
                      tb_model.hamilton([0], convention=1)).all()

    assert np.isclose(pt_model._gen_ham([1]),
                      tb_model.hamilton([1], convention=1)).all()
    assert np.isclose(pt_model._gen_ham([0.2]),
                      tb_model.hamilton(0.2, convention=1)).all()
def tbmodels_Haldane():
    delta=0.2
    t=-1.0
    t2 =0.15*np.exp((1.j)*np.pi/2.)
    t2c=t2.conjugate()
    my_model = tbmodels.Model(
            on_site=[delta, -delta],uc = [[1.0,0.0],[0.5,np.sqrt(3.0)/2.0]], dim=2, occ=1, pos=[[1./3.,1./3.],[2./3.,2./3.]]
            )
    my_model.add_hop(t, 0, 1, [ 0, 0])
    my_model.add_hop(t, 1, 0, [ 1, 0])
    my_model.add_hop(t, 1, 0, [ 0, 1])
    my_model.add_hop(t2 , 0, 0, [ 1, 0])
    my_model.add_hop(t2 , 1, 1, [ 1,-1])
    my_model.add_hop(t2 , 1, 1, [ 0, 1])
    my_model.add_hop(t2c, 1, 1, [ 1, 0])
    my_model.add_hop(t2c, 0, 0, [ 1,-1])
    my_model.add_hop(t2c, 0, 0, [ 0, 1])
    
    return my_model
Exemple #22
0
def tb_system():
    t1, t2 = (0.2, 0.3)

    model = tbmodels.Model(on_site=(1, 1, -1, -1),
                           pos=[[0., 0., 0.], [0., 0., 0.], [0.5, 0.5, 0.],
                                [0.5, 0.5, 0.]],
                           occ=2)

    for p, R in zip([1, 1j, -1j, -1], itertools.product([0, -1], [0, -1],
                                                        [0])):
        model.add_hop(overlap=p * t1, orbital_1=0, orbital_2=2, R=R)
        model.add_hop(overlap=p.conjugate() * t1,
                      orbital_1=1,
                      orbital_2=3,
                      R=R)

    for R in ((r[0], r[1], 0) for r in itertools.permutations([0, 1])):
        model.add_hop(t2, 0, 0, R)
        model.add_hop(t2, 1, 1, R)
        model.add_hop(-t2, 2, 2, R)
        model.add_hop(-t2, 3, 3, R)

    return z2pack.tb.System(model)
Exemple #23
0
    def inner(t1, t2, sparsity_default=False, **kwargs):
        dim = kwargs.get('dim', 3)
        defaults = {}
        defaults['pos'] = [[0] * 2, [0.5] * 2]
        if dim < 2:
            raise ValueError('dimension must be at least 2')
        elif dim > 2:
            for p in defaults['pos']:
                p.extend([0] * (dim - 2))
        defaults['occ'] = 1
        defaults['on_site'] = (1, -1)
        defaults['size'] = 2
        defaults['dim'] = None
        defaults['sparse'] = sparsity_default
        model = tbmodels.Model(**ChainMap(kwargs, defaults))

        for phase, R in zip([1, -1j, 1j, -1], itertools.product([0, -1], [0, -1], [0])):
            model.add_hop(t1 * phase, 0, 1, R)

        for R in ((r[0], r[1], 0) for r in itertools.permutations([0, 1])):
            model.add_hop(t2, 0, 0, R)
            model.add_hop(-t2, 1, 1, R)
        return model
Exemple #24
0
def test_invalid_hopping_matrix():
    with pytest.raises(ValueError):
        model = tbmodels.Model(size=2, hop={(0, 0, 0): np.eye(4)})
Exemple #25
0
# Example for the interface TBmodels-WannierBerri. Extracted from
# http://www.physics.rutgers.edu/~dhv/pythtb-book-examples/ptb_samples.html
# but written in TBmodels format (http://z2pack.ethz.ch/tbmodels/doc/1.3/index.html)
# 3D model of Li on bcc lattice, with s orbitals only
# set tbmodel parameters

Es= 4.5    # site energy
t =-1.4    # hopping parameter
r0=np.array([-0.5, 0.5, 0.5])
r1=np.array([ 0.5,-0.5, 0.5])
r2=np.array([ 0.5, 0.5,-0.5])
uc=np.array([r0,r1,r2])# in rows

cc=True
tbmodel = tb.Model(on_site=[Es], dim=3, occ=1, pos=[[0.0,0.0,0.0]],uc=uc,contains_cc=cc)

# set hoppings along four unique bonds
# note that neighboring cell must be specified in lattice coordinates
for R in ([1,0,0],[0,1,0],[0,0,1],[1,1,1]):
    tbmodel.add_hop(t, 0, 0, R)

system=wb.System_TBmodels(tbmodel,berry=True)
Efermi=np.linspace(-7,16,1000)
# Define the generators of the point group of the crystal (Im-3m)
# generators extracted from Bilbao Crystallographic Center
# (using same notation as https://www.cryst.ehu.es/cgi-bin/cryst/programs/nph-point_genpos?w2do=gens&num=32&what=)
# C2z axis (predefined): ITA200z=SYM.Rotation(2,[0,0,1])
# C2y axis (predefined): ITA20y0=SYM.Rotation(2,[0,1,0])
# Inversion (predefined)
ITA3M111=SYM.Rotation(3,[1,1,1])# C3 axis along 111
Exemple #26
0
def test_size_from_hop():
    """
    Check that the size can be obtained from hopping matrices.
    """
    model = tbmodels.Model(hop={(0, 0, 0): np.zeros((4, 4))})
    assert model.size == 4
Exemple #27
0
def test_dim_from_uc():
    """Check that the dimension can be inferred from the unit cell."""
    model = tbmodels.Model(uc=((1, 0), (0, 1)), size=5)
    assert model.dim == 2
Exemple #28
0
def test_invalid_empty():
    model = tbmodels.Model(size=2, dim=3)
    with pytest.raises(ValueError):
        model.to_hr()
Exemple #29
0
t1, t2 = (0.2, 0.3)

settings = {'num_lines': 11,
            'pos_tol': 1e-2,
            'gap_tol': 2e-2,
            'move_tol': 0.3,
            'iterator': range(8, 27, 2),
            'min_neighbour_dist': 1e-2,
           }

model = tbmodels.Model(
    on_site=(1, 1, -1, -1), 
    pos=[
        [0., 0., 0.], 
        [0., 0., 0.], 
        [0.5, 0.5, 0.], 
        [0.5, 0.5, 0.]
    ],
    occ=2
)

for p, R in zip([1, 1j, -1j, -1], itertools.product([0, -1], [0, -1], [0])):
    model.add_hop(overlap=p * t1, orbital_1=0, orbital_2=2, R=R)
    model.add_hop(overlap=p.conjugate() * t1, orbital_1=1, orbital_2=3, R=R)

for R in ((r[0], r[1], 0) for r in itertools.permutations([0, 1])):
    model.add_hop(t2, 0, 0, R)
    model.add_hop(t2, 1, 1, R)
    model.add_hop(-t2, 2, 2, R)
    model.add_hop(-t2, 3, 3, R)
Exemple #30
0
import tbmodels
import itertools

model = tbmodels.Model(
    on_site=[1, -1],
    dim=3,
    occ=1,
    pos=[[0., 0., 0.], [0.5, 0.5, 0.]]
)

t1, t2 = (0.1, 0.2)
for phase, R in zip([1, -1j, 1j, -1], itertools.product([0, -1], [0, -1], [0])):
    model.add_hop(t1 * phase, 0, 1, R)
    
for R in ((r[0], r[1], 0) for r in itertools.permutations([0, 1])):
    model.add_hop(t2, 0, 0, R)
    model.add_hop(-t2, 1, 1, R)