Exemplo n.º 1
0
def test_default():
    p = Parameters({'a': 1, 'b': "foo"})

    assert p.get('c', "default") == "default"

    with pytest.raises(KeyError):
        p.get('c')
Exemplo n.º 2
0
def test_tightbinding_honeycomb():
    nearestNeighbors = {
        RegularChain: 2,
        SquareLattice: 4,
        HoneycombLattice: 3,
        KagomeLattice: 4,
        RubyLattice: 4,
        LiebLattice: 2 * np.sqrt(2)
    }

    for latticeT, nn in nearestNeighbors.items():
        lattice = latticeT()
        params = Parameters({'lattice': lattice, 't': 1})

        s = TightBindingSystem(params)

        path = lattice.getKvectorsPath(resolution=3, pointlabels=['G', 'X'])
        bandstructure = s.solve(path)

        assert len(path.points) == 4

        # Energy at the Gamma point
        g = bandstructure.energies[1][0]

        print("Lattice type: {}".format(latticeT))
        np.testing.assert_almost_equal(g, -params['t'] * nn)
Exemplo n.º 3
0
def test_chern_number_dipolar_honeyomb():
    lattice = HoneycombLattice()

    params = Parameters({
        'lattice': lattice,
        'cutoff': 3,
        'tbar': 1,
        't': 0.54,
        'w': 3,
        'mu': 2.5
    })

    s = DipolarSystem(params)

    bbox = lattice.getKvectorsRhomboid(50)

    bandstructure = s.solve(bbox)

    chernNumbers = [
        bandstructure.getBerryFlux(n) / (2 * np.pi) for n in range(4)
    ]
    np.testing.assert_almost_equal(chernNumbers, [1, 0, -3, 2], decimal=1)

    chernNumbers = [
        bandstructure.getBerryFlux(n, alternative_algorithm=True) / (2 * np.pi)
        for n in range(4)
    ]
    np.testing.assert_almost_equal(chernNumbers, [1, 0, -3, 2], decimal=1)
Exemplo n.º 4
0
def test_paramter_change(recwarn):
    lattice = RegularChain()

    params = Parameters({'lattice': lattice, 't': 1})

    s = TightBindingSystem(params)

    path = lattice.getKvectorsPath(resolution=2, pointlabels=['G', 'X'])

    # Solve for t = 1
    bs = s.solve(path)
    en = bs.energies

    # Change the parameter of the model
    s.params["t"] = 2

    # This is supposed to print a warning
    # because we did not call initialize()
    bs = s.solve(path)
    assert issubclass(recwarn.pop().category, UserWarning)

    # Solve again
    s.initialize()
    bs = s.solve(path)
    en2 = bs.energies

    # All energies should be twice as high
    assert np.all(2 * en == en2)
Exemplo n.º 5
0
def test_simple():
    p = Parameters({'a': 1, 'b': "foo"})
    assert p['a'] == 1
    assert p['b'] == "foo"

    p['a'] = "bar"

    assert p['a'] == "bar"
Exemplo n.º 6
0
def test_chern_number_dipolar_honeyomb():
    lattice = HoneycombLattice()

    params = Parameters({
        'lattice': lattice,
        'cutoff': 3,
        'tbar': 1,
        't': 0.54,
        'w': 3,
        'mu': 2.5
    })

    s = DipolarSystem(params)

    bzone = lattice.getKvectorsZone(50)

    bandstructure = s.solve(bzone)
    chernNumbers = bandstructure.getBerryFlux() / (2 * np.pi)

    np.testing.assert_almost_equal(chernNumbers, [1, 0, -3, 2], decimal=1)
def test_tightbinding_honeycomb():
    lattice = HoneycombLattice()

    params = Parameters({
        'lattice': lattice,
        't': 1
    })

    s = TightBindingSystem(params)

    path = lattice.getKvectorsPath(resolution=4, pointlabels=['A', 'G', 'X'])

    assert len(path.points) == 6

    bandstructure = s.solve(path)

    np.testing.assert_almost_equal(bandstructure.energies[0][0], -1)
    np.testing.assert_almost_equal(bandstructure.energies[1][0], 0)
    np.testing.assert_almost_equal(bandstructure.energies[2][0], -2)
    np.testing.assert_almost_equal(bandstructure.energies[3][0], -3)
    np.testing.assert_almost_equal(bandstructure.energies[5][0], -1)
Exemplo n.º 8
0
def test_dipolar_square():
    lattice = SquareLattice()

    params = Parameters({
        'lattice': lattice,
        'cutoff': 10.001,
        'tbar': 1,
        't': 0,
        'w': 0
    })

    s = DipolarSystem(params)

    path = lattice.getKvectorsPath(resolution=4, pointlabels=['A', 'G', 'X'])

    bandstructure = s.solve(path)

    # Energy at high symmetry points:
    g = bandstructure.energies[3][0]
    m = bandstructure.energies[1][0]
    x = bandstructure.energies[5][0]

    # The following values are calculated analytically (for cutoff=10.001) by Mathematica
    np.testing.assert_almost_equal(g, -8.407854761)
    np.testing.assert_almost_equal(m, +2.641343369)
    np.testing.assert_almost_equal(x, +0.935057004)

    s.params["tbar"] = 0
    s.params["w"] = 1
    s.initialize()
    bandstructure = s.solve(path)

    # Energy at high symmetry points:
    g = bandstructure.energies[3][0]
    m = bandstructure.energies[1][0]
    x = bandstructure.energies[5][0]

    np.testing.assert_almost_equal(g, 0.0)
    np.testing.assert_almost_equal(m, 0.0)
    np.testing.assert_almost_equal(x, -3.719360597)
Exemplo n.º 9
0
        res = v * np.all(dr.vectors == [-0.5, 0.2], axis=3) \
            + v * np.all(dr.vectors == [0.5, -0.2], axis=3) \
            + w * np.all(dr.vectors == [0.5, 0.2], axis=3) \
            + w * np.all(dr.vectors == [-0.5, -0.2], axis=3)

        return np.array([1]) * res[:, :, :, None, None]

lattice = RegularChain()
lattice.addBasisvector([0.5, -0.2])

params = Parameters({
    'lattice': lattice,

    # tunneling strength NW, SE (inter-cell)
    'v': -0.3,

    # tunneling strength NE, SW (intra-cell)
    'w': +.5
})

s = SSHModel(params)

# Infinite chain: calculate Berry phase
bs = s.solve(lattice.getKvectorsZone(300))
print(np.round(bs.getBerryPhase(), 2))

# Finite chain: spectrum and edge states
nSites = 40
lattice.makeFiniteAlongdirection(0, 40)
s.initialize()
Exemplo n.º 10
0
#!/usr/bin/env python3

import sys
sys.path.append("../")

from bandstructure import Parameters
from bandstructure.system import TightBindingSystem
from bandstructure.lattice import HoneycombLattice

lattice = HoneycombLattice()

params = Parameters({'lattice': lattice, 't': 1})

s = TightBindingSystem(params)

# Solve system on high-symmetry path through Brillouin zone
path = lattice.getKvectorsPath(resolution=300,
                               pointlabels=['A', 'G', 'X', 'A'])

bandstructure = s.solve(path)
bandstructure.plot("dispersion.pdf")