Ejemplo n.º 1
0
def test_hopping_generator():
    """Generated next-nearest hoppings should produce the same result as the builtin lattice"""
    from scipy.spatial import cKDTree

    @pb.hopping_generator("tnn_test", energy=graphene.t_nn)
    def next_nearest(x, y, z):
        pos = np.stack([x, y, z], axis=1)
        dmin = graphene.a * 0.95
        dmax = graphene.a * 1.05
        kdtree = cKDTree(pos)
        coo = kdtree.sparse_distance_matrix(kdtree, dmax).tocoo()
        idx = coo.data > dmin
        return coo.row[idx], coo.col[idx]

    @pb.onsite_energy_modifier
    def onsite_offset(energy):
        return energy + 3 * graphene.t_nn

    model = pb.Model(graphene.monolayer(), next_nearest, onsite_offset,
                     graphene.hexagon_ac(1))
    expected = pb.Model(graphene.monolayer(2), graphene.hexagon_ac(1))
    assert pytest.fuzzy_equal(model.hamiltonian, expected.hamiltonian)

    @pb.hopping_generator("t_new", energy=1.0)
    def bad_generator():
        """Different array lengths"""
        return [0, 1, 2], [0, 1]

    model = pb.Model(graphene.monolayer(), pb.primitive(3, 3), bad_generator)
    with pytest.raises(RuntimeError) as excinfo:
        model.eval()
    assert "the number of `from` and `to` indices must be equal" in str(
        excinfo.value)
Ejemplo n.º 2
0
def test_primitive():
    """The primitive shape can be positioned using the lattice origin"""
    model = pb.Model(graphene.monolayer(), pb.primitive(2, 2))
    assert model.system.num_sites == 8
    assert np.isclose(model.system.x.min(), -1.5 * graphene.a, rtol=1e-3)
    assert np.isclose(model.system.y.min(), -2 * graphene.a_cc, rtol=1e-3)

    model = pb.Model(
        graphene.monolayer().with_offset(
            [0.5 * graphene.a, 0.5 * graphene.a_cc]), pb.primitive(2, 2))
    assert model.system.num_sites == 8
    assert np.isclose(model.system.x.min(), -graphene.a, rtol=1e-3)
    assert np.isclose(model.system.y.min(), -1.5 * graphene.a_cc, rtol=1e-3)
Ejemplo n.º 3
0
    def factory(v1, v2, energy=np.linspace(0, 0.1, 10)):
        model = pb.Model(graphene.monolayer(),
                         graphene.hexagon_ac(side_width=15),
                         pb.constant_potential(v1), pb.constant_potential(v2))

        kpm = pb.greens.kpm(model)
        return kpm.deferred_ldos(energy, broadening=0.15, position=[0, 0])
Ejemplo n.º 4
0
def test_ldos_sublattice():
    """LDOS for A and B sublattices should be antisymmetric for graphene with a mass term"""
    model = pb.Model(graphene.monolayer(), graphene.hexagon_ac(10), graphene.mass_term(1))
    kpm = pb.greens.kpm(model)

    a, b = (kpm.calc_ldos(np.linspace(-5, 5, 50), 0.1, [0, 0], sub) for sub in ('A', 'B'))
    assert pytest.fuzzy_equal(a.ldos, b.ldos[::-1], rtol=1e-3, atol=1e-6)
Ejemplo n.º 5
0
def test_structure_map_plot(compare_figure):
    model = pb.Model(graphene.monolayer(), pb.rectangle(0.8))
    structure_map = model.structure_map(model.system.x * model.system.y)

    with compare_figure() as chk:
        structure_map.plot(site_radius=(0.03, 0.05))
    assert chk.passed
Ejemplo n.º 6
0
def test_ldos_sublattice():
    """LDOS for A and B sublattices should be antisymmetric for graphene with a mass term"""
    model = pb.Model(graphene.monolayer(), graphene.hexagon_ac(10), graphene.mass_term(1))
    kpm = pb.chebyshev.kpm(model)

    a, b = (kpm.calc_ldos(np.linspace(-5, 5, 50), 0.1, [0, 0], sub) for sub in ('A', 'B'))
    assert pytest.fuzzy_equal(a.ldos, b.ldos[::-1], rtol=1e-3, atol=1e-6)
Ejemplo n.º 7
0
 def test_warnings():
     """Extra arguments and ignored by pybinding -- warn users"""
     kwant_sys = pb.Model(graphene.monolayer(), pb.rectangle(1,
                                                             1)).tokwant()
     with pytest.warns(UserWarning):
         kwant_sys.hamiltonian_submatrix(sparse=True, args=(1, ))
     with pytest.warns(UserWarning):
         kwant_sys.hamiltonian_submatrix(sparse=True, params=dict(v=1))
Ejemplo n.º 8
0
def ring_model():
    def ring(inner_radius, outer_radius):
        def contains(x, y, _):
            r = np.sqrt(x**2 + y**2)
            return np.logical_and(inner_radius < r, r < outer_radius)
        return pb.FreeformShape(contains, width=[2 * outer_radius, 2 * outer_radius])

    return pb.Model(graphene.monolayer(), ring(3, 5))
Ejemplo n.º 9
0
    def test_hamiltonian_submatrix_sites():
        """The `to_sites` and `from_sites` arguments are not supported"""
        kwant_sys = pb.Model(graphene.monolayer(), pb.rectangle(1,
                                                                1)).tokwant()

        with pytest.raises(RuntimeError) as excinfo:
            kwant_sys.hamiltonian_submatrix(to_sites=1, from_sites=1)
        assert "not supported" in str(excinfo.value)
Ejemplo n.º 10
0
def test_sites():
    model = pb.Model(graphene.monolayer(), pb.primitive(2, 2))
    system = model.system

    sites = pb.system.Sites(system.positions, system.sublattices, system.lattice)
    idx = system.num_sites // 2
    assert idx == sites.find_nearest(system.xyz[idx])
    assert idx == sites.find_nearest(system.xyz[idx], system.sublattices[idx])
    assert sites.find_nearest([0, 0], 'A') != sites.find_nearest([0, 0], 'B')
Ejemplo n.º 11
0
def test_structure_map_plot(compare_figure):
    model = pb.Model(graphene.monolayer(), pb.rectangle(0.8))
    system = model.system
    data = np.arange(system.num_sites)
    structure_map = pb.results.StructureMap.from_system(data, system)

    with compare_figure() as chk:
        structure_map.plot_structure(site_radius=(0.03, 0.05), cbar_props=False)
    assert chk.passed
Ejemplo n.º 12
0
def test_structure_map_plot(compare_figure):
    model = pb.Model(graphene.monolayer(), pb.rectangle(0.8))
    data = [3, 11, 19, 26, 5, 13, 21, 0, 7, 15, 23, 2, 9, 17,
            10, 18, 25, 4, 12, 20, 27, 6, 14, 22, 1, 8, 16, 24]
    structure_map = model.structure_map(data)

    with compare_figure() as chk:
        structure_map.plot(site_radius=(0.03, 0.05))
    assert chk.passed
Ejemplo n.º 13
0
def test_sites():
    model = pb.Model(graphene.monolayer(), pb.primitive(2, 2))
    system = model.system

    sites = pb.system.Sites(system.positions, system.sublattices)
    idx = system.num_sites // 2
    assert idx == sites.find_nearest(system.xyz[idx])
    assert idx == sites.find_nearest(system.xyz[idx], system.sublattices[idx])
    assert sites.find_nearest([0, 0], 'A') != sites.find_nearest([0, 0], 'B')
Ejemplo n.º 14
0
    def factory(v, energy=np.linspace(0, 0.1, 10)):
        model = pb.Model(
            graphene.monolayer(),
            graphene.hexagon_ac(side_width=15),
            pb.constant_potential(v)
        )

        kpm = pb.greens.kpm(model)
        return kpm.deferred_ldos(energy, broadening=0.15, position=[0, 0])
Ejemplo n.º 15
0
def model():
    def ring(inner_radius, outer_radius):
        def contains(x, y, _):
            r = np.sqrt(x**2 + y**2)
            return np.logical_and(inner_radius < r, r < outer_radius)

        return pb.FreeformShape(contains,
                                width=[2 * outer_radius, 2 * outer_radius])

    return pb.Model(graphene.monolayer(), ring(3, 5))
Ejemplo n.º 16
0
def test_optimized_hamiltonian():
    """Currently available only in internal interface"""
    from pybinding import _cpp
    model = pb.Model(graphene.monolayer(), graphene.hexagon_ac(10))
    h = model.hamiltonian
    oh = _cpp.OptimizedHamiltonian(model.raw_hamiltonian, 0)

    assert oh.matrix.shape == h.shape
    assert oh.sizes[-1] == h.shape[0]
    assert len(oh.indices) == h.shape[0]
Ejemplo n.º 17
0
def test_optimized_hamiltonian():
    """Currently available only in internal interface"""
    from pybinding import _cpp
    model = pb.Model(graphene.monolayer(), graphene.hexagon_ac(10))
    h = model.hamiltonian
    oh = _cpp.OptimizedHamiltonian(model.raw_hamiltonian, 0)

    assert oh.matrix.shape == h.shape
    assert oh.sizes[-1] == h.shape[0]
    assert len(oh.indices) == h.shape[0]
Ejemplo n.º 18
0
def test_structure_map_plot(compare_figure):
    import matplotlib.pyplot as plt

    model = pb.Model(graphene.monolayer(), pb.rectangle(0.8))
    structure_map = model.structure_map(model.system.x * model.system.y)

    with compare_figure() as chk:
        structure_map.plot(site_radius=(0.03, 0.05))
        plt.gca().set_aspect("equal", "datalim")
    assert chk.passed
Ejemplo n.º 19
0
    def factory(v, energy=np.linspace(0, 0.1, 10)):
        model = pb.Model(graphene.monolayer(),
                         graphene.hexagon_ac(side_width=15),
                         pb.constant_potential(v))

        kpm = pb.kpm(model, kernel=pb.lorentz_kernel())
        return kpm.deferred_ldos(energy,
                                 broadening=0.15,
                                 position=[0, 0],
                                 sublattice="B")
Ejemplo n.º 20
0
def test_kpm_reuse():
    """KPM should return the same result when a single object is used for multiple calculations"""
    model = pb.Model(graphene.monolayer(), graphene.hexagon_ac(10))
    kpm = pb.greens.kpm(model)
    energy = np.linspace(-5, 5, 50)
    broadening = 0.1

    for position in [0, 0], [6, 0]:
        actual = kpm.calc_ldos(energy, broadening, position)
        expected = pb.greens.kpm(model).calc_ldos(energy, broadening, position)
        assert pytest.fuzzy_equal(actual, expected, rtol=1e-3, atol=1e-6)
Ejemplo n.º 21
0
def test_kpm_reuse():
    """KPM should return the same result when a single object is used for multiple calculations"""
    model = pb.Model(graphene.monolayer(), graphene.hexagon_ac(10))
    kpm = pb.chebyshev.kpm(model)
    energy = np.linspace(-5, 5, 50)
    broadening = 0.1

    for position in [0, 0], [6, 0]:
        actual = kpm.calc_ldos(energy, broadening, position)
        expected = pb.chebyshev.kpm(model).calc_ldos(energy, broadening, position)
        assert pytest.fuzzy_equal(actual, expected, rtol=1e-3, atol=1e-6)
Ejemplo n.º 22
0
 def make_model(v0=0):
     model = pb.Model(
         graphene.monolayer().with_min_neighbors(1),
         pb.rectangle(length, width),
         potential_barrier(v0),
     )
     model.attach_lead(
         -1, pb.line([-length / 2, -width / 2], [-length / 2, width / 2]))
     model.attach_lead(
         +1, pb.line([length / 2, -width / 2], [length / 2, width / 2]))
     return model
Ejemplo n.º 23
0
def monolayer_density(energy):
    # define the density of monolayer graphene
    lattice_gr = graphene.monolayer()
    l1gr, l2gr = lattice_gr.vectors
    l1gr, l2gr = l1gr[0:2], l2gr[0:2]

    Ac = np.linalg.norm(np.cross(l1gr, l2gr))
    vf = 3 / (2) * abs(graphene.t) * graphene.a_cc  #: [eV*nm] Fermi velocity

    dos_slg = 1 * Ac / np.pi * np.abs(energy) / vf**2

    return dos_slg
Ejemplo n.º 24
0
def test_api():
    model = pb.Model(graphene.monolayer(), pb.primitive(2, 2))
    system = model.system

    idx = system.num_sites // 2
    assert idx == system.find_nearest(system.xyz[idx])
    assert idx == system.find_nearest(system.xyz[idx], 'B')
    assert system.find_nearest([0, 0], 'A') != system.find_nearest([0, 0], 'B')

    with pytest.raises(IndexError) as excinfo:
        system.find_nearest([0, 0], 'invalid_sublattice')
    assert "There is no sublattice" in str(excinfo.value)
Ejemplo n.º 25
0
def test_hopping_generator():
    """Generated next-nearest hoppings should produce the same result as the builtin lattice"""
    from scipy.spatial import cKDTree

    @pb.hopping_generator("tnn_test", energy=graphene.t_nn)
    def next_nearest(x, y, z):
        pos = np.stack([x, y, z], axis=1)
        dmin = graphene.a * 0.95
        dmax = graphene.a * 1.05
        kdtree = cKDTree(pos)
        coo = kdtree.sparse_distance_matrix(kdtree, dmax).tocoo()
        idx = coo.data > dmin
        return coo.row[idx], coo.col[idx]

    @pb.onsite_energy_modifier
    def onsite_offset(energy):
        return energy + 3 * graphene.t_nn

    model = pb.Model(graphene.monolayer(), next_nearest, onsite_offset, graphene.hexagon_ac(1))
    expected = pb.Model(graphene.monolayer(2), graphene.hexagon_ac(1))
    assert pytest.fuzzy_equal(model.hamiltonian, expected.hamiltonian)
Ejemplo n.º 26
0
def test_site_generator():
    """Generated some disordered sites"""
    @pb.site_generator("New", energy=0.4)
    def site_gen():
        x = [10, 20, 30]
        y = [1, 2, 3]
        z = [0, -1, -2]
        return x, y, z

    model = pb.Model(graphene.monolayer(), graphene.hexagon_ac(1), site_gen)
    s = model.system[model.system.x >= 10]
    assert s.num_sites == 3
    assert pytest.fuzzy_equal(s.x, [10, 20, 30])
    assert pytest.fuzzy_equal(s.y, [1, 2, 3])
    assert pytest.fuzzy_equal(s.z, [0, -1, -2])
Ejemplo n.º 27
0
def test_lapack(baseline, plot_if_fails):
    model = pb.Model(graphene.monolayer(), pb.translational_symmetry())
    solver = pb.solver.lapack(model)
    assert pytest.fuzzy_equal(solver.eigenvalues, [-3*abs(graphene.t), 3*abs(graphene.t)])

    from math import pi, sqrt
    g = [0, 0]
    k1 = [-4*pi / (3*sqrt(3) * graphene.a_cc), 0]
    m = [0, 2*pi / (3 * graphene.a_cc)]
    k2 = [2*pi / (3*sqrt(3) * graphene.a_cc), 2*pi / (3 * graphene.a_cc)]

    bands = solver.calc_bands(k1, g, m, k2, step=3)
    expected = baseline(bands)
    plot_if_fails(bands, expected, 'plot')
    assert pytest.fuzzy_equal(bands, expected, 2.e-2, 1.e-6)
Ejemplo n.º 28
0
def test_api():
    lattice = graphene.monolayer()
    shape = pb.rectangle(1)
    model = pb.Model(lattice, shape)

    assert model.lattice is lattice
    assert model.shape is shape

    # empty sequences are no-ops
    model.add(())
    model.add([])

    with pytest.raises(RuntimeError) as excinfo:
        model.add(None)
    assert "None" in str(excinfo.value)
Ejemplo n.º 29
0
def test_api():
    model = pb.Model(graphene.monolayer(), pb.primitive(2, 2))
    system = model.system

    idx = system.num_sites // 2
    assert idx == system.find_nearest(system.xyz[idx])
    assert idx == system.find_nearest(system.xyz[idx], system.sublattices[idx])
    assert system.find_nearest([0, 0], 'A') != system.find_nearest([0, 0], 'B')

    invalid_sublattice = 99
    with pytest.raises(KeyError) as excinfo:
        system.find_nearest([0, 0], invalid_sublattice)
    assert "There is no sublattice" in str(excinfo.value)

    with pytest.raises(KeyError) as excinfo:
        system.find_nearest([0, 0], 'invalid_sublattice')
    assert "There is no sublattice" in str(excinfo.value)
Ejemplo n.º 30
0
def test_api():
    model = pb.Model(graphene.monolayer(), pb.primitive(2, 2))
    system = model.system

    idx = system.num_sites // 2
    assert idx == system.find_nearest(system.xyz[idx])
    assert idx == system.find_nearest(system.xyz[idx], 'B')
    assert system.find_nearest([0, 0], 'A') != system.find_nearest([0, 0], 'B')

    with pytest.raises(IndexError) as excinfo:
        system.find_nearest([0, 0], 'invalid_sublattice')
    assert "There is no Site named" in str(excinfo.value)

    assert np.allclose(system.expanded_positions.x, system.positions.x)

    s = pb.Model(group6_tmd.monolayer_3band("MoS2"), pb.primitive(2, 2)).system
    assert s.expanded_positions.x.size == s.positions.x.size * 3
Ejemplo n.º 31
0
def test_freeform(baseline, plot_if_fails):
    def donut(inner_radius, outer_radius):
        def contains(x, y, _):
            r = np.sqrt(x**2 + y**2)
            return np.logical_and(inner_radius < r, r < outer_radius)

        return pb.FreeformShape(contains,
                                width=[2 * outer_radius, 2 * outer_radius])

    assert pytest.fuzzy_equal(
        donut(0.5, 1).vertices,
        [[-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0]] * 2)

    shape = donut(0.6, 1.1)
    model = pb.Model(graphene.monolayer(), shape)
    expected = baseline(model.system)
    plot_if_fails(model.system, expected, 'plot')
    plot_if_fails(shape, shape, 'plot')
    assert pytest.fuzzy_equal(model.system, expected, 1.e-4, 1.e-6)
Ejemplo n.º 32
0
def test_freeform(baseline, plot_if_fails):
    def donut(inner_radius, outer_radius):
        def contains(x, y, _):
            r = np.sqrt(x**2 + y**2)
            return np.logical_and(inner_radius < r, r < outer_radius)

        return pb.FreeformShape(contains, width=[2 * outer_radius, 2 * outer_radius])

    assert pytest.fuzzy_equal(
        donut(0.5, 1).vertices,
        [[ 1, 1, 0], [ 1, 1, 0], [ 1, -1, 0], [ 1, -1, 0],
         [-1, 1, 0], [-1, 1, 0], [-1, -1, 0], [-1, -1, 0]]
    )

    shape = donut(0.6, 1.1)
    model = pb.Model(graphene.monolayer(), shape)
    expected = baseline(model.system)
    plot_if_fails(model.system, expected, 'plot')
    plot_if_fails(shape, shape, 'plot')
    assert pytest.fuzzy_equal(model.system, expected, 1.e-4, 1.e-6)
Ejemplo n.º 33
0
def test_moments(model, plot_if_fails):
    energy = np.linspace(0, 2, 25)
    broadening = 0.15
    position = dict(position=[0, 0], sublattice="A")

    kpm = pb.kpm(model, silent=True)
    expected_ldos = kpm.calc_ldos(energy, broadening, **position)

    def manual_ldos():
        idx = model.system.find_nearest(**position)
        alpha = np.zeros(model.hamiltonian.shape[0])
        alpha[idx] = 1

        a, b = kpm.scaling_factors
        num_moments = kpm.kernel.required_num_moments(broadening / a)
        moments = kpm.moments(num_moments, alpha)

        ns = np.arange(num_moments)
        scaled_energy = (energy - b) / a
        k = 2 / (a * np.pi * np.sqrt(1 - scaled_energy**2))
        chebyshev = np.cos(ns * np.arccos(scaled_energy[:, np.newaxis]))
        return k * np.sum(moments.real * chebyshev, axis=1)

    ldos = expected_ldos.with_data(manual_ldos())
    plot_if_fails(ldos, expected_ldos, "plot")
    assert pytest.fuzzy_equal(ldos, expected_ldos, rtol=1e-4, atol=1e-6)

    with pytest.raises(RuntimeError) as excinfo:
        kpm.moments(10, [1, 2, 3])
    assert "Size mismatch" in str(excinfo.value)

    with pytest.raises(RuntimeError) as excinfo:
        kpm = pb.kpm(pb.Model(graphene.monolayer()))
        kpm.moments(10, [1j, 2j])
    assert "Hamiltonian is real, but the given argument 'alpha' is complex" in str(
        excinfo.value)
Ejemplo n.º 34
0
def calc_radius(num_sites, lattice=graphene.monolayer()):
    """The approximate radius of a circle which can contain the given number of lattice sites"""
    unit_area = np.linalg.norm(np.cross(*lattice.vectors)) / len(
        lattice.sublattices)
    return math.sqrt(num_sites * unit_area / math.pi)
Ejemplo n.º 35
0
    """PN junction potential

    The `y0` argument is the position of the junction, while `v1` and `v2`
    are the values of the potential (in eV) before and after the junction.
    """
    @pb.onsite_energy_modifier
    def potential(energy, y):
        energy[y < y0] += v1
        energy[y >= y0] += v2
        return energy

    return potential


model = pb.Model(
    graphene.monolayer(),
    pb.rectangle(1.2),  # width in nanometers
    pb.translational_symmetry(a1=True, a2=False),
    mass_term(delta=2.5),  # eV
    pn_juction(y0=0, v1=-2.5, v2=2.5)  # y0 in [nm] and v1, v2 in [eV]
)
model.system.plot()
plt.show()


# plot the potential: note that pn_junction cancels out delta on some sites
model.onsite_map.plot_structure(cmap="coolwarm", site_radius=0.04)
pb.pltutils.colorbar(label="U (eV)")
plt.show()

# compute the bands
Ejemplo n.º 36
0
"""Several finite-sized systems created using builtin lattices and shapes"""
import pybinding as pb
from pybinding.repository import graphene
import matplotlib.pyplot as plt
from math import pi

pb.pltutils.use_style()

model = pb.Model(
    graphene.monolayer(),
    pb.rectangle(x=2, y=1.2)
)
model.plot()
plt.show()


model = pb.Model(
    graphene.monolayer(),
    pb.regular_polygon(num_sides=6, radius=1.4, angle=pi/6)
)
model.plot()
plt.show()


# A graphene-specific shape which guaranties armchair edges on all sides
model = pb.Model(
    graphene.bilayer(),
    graphene.hexagon_ac(side_width=1)
)
model.plot()
plt.show()
Ejemplo n.º 37
0
import pytest

import pybinding as pb
from pybinding.repository import graphene

models = {
    'graphene-monolayer': [graphene.monolayer(), graphene.hexagon_ac(1)],
    'graphene-monolayer-alt': [graphene.monolayer_alt(), pb.rectangle(1.6, 1.4)],
    'graphene-monolayer-4atom': [graphene.monolayer_4atom()],
    'graphene-monolayer-nn': [graphene.monolayer(2), pb.regular_polygon(6, 0.9)],
    'graphene-monolayer-periodic-1d': [graphene.monolayer(), pb.primitive(5, 5),
                                       pb.translational_symmetry(a1=True, a2=False)],
    'graphene-monolayer-periodic-1d-alt': [graphene.monolayer_4atom(), pb.rectangle(1),
                                           pb.translational_symmetry(a1=False, a2=0.6)],
    'graphene-monolayer-periodic-2d': [graphene.monolayer(), pb.primitive(a1=5, a2=5),
                                       pb.translational_symmetry(a1=1, a2=1)],
    'graphene-monolayer-4atom-periodic-2d': [graphene.monolayer_4atom(), pb.rectangle(1),
                                             pb.translational_symmetry(a1=0.6, a2=0.6)],
    'graphene-bilayer': [graphene.bilayer(), graphene.hexagon_ac(0.6)],
}


@pytest.fixture(scope='module', ids=list(models.keys()), params=models.values())
def model(request):
    return pb.Model(*request.param)


def test_api():
    model = pb.Model(graphene.monolayer(), pb.primitive(2, 2))
    system = model.system
Ejemplo n.º 38
0
def model():
    return pb.Model(graphene.monolayer(), pb.rectangle(1))
Ejemplo n.º 39
0
 def test_kwant_error():
     """Raise an exception if kwant isn't installed"""
     model = pb.Model(graphene.monolayer())
     with pytest.raises(ImportError) as excinfo:
         model.tokwant()
     assert "kwant isn't installed" in str(excinfo.value)
Ejemplo n.º 40
0
def test_polygon(polygon, baseline, plot_if_fails):
    model = pb.Model(graphene.monolayer(), polygon)
    expected = baseline(model.system)
    plot_if_fails(model.system, expected, 'plot')
    plot_if_fails(polygon, polygon, 'plot')
    assert pytest.fuzzy_equal(model.system, expected, 1.e-4, 1.e-6)
Ejemplo n.º 41
0
"""Calculate and plot the band structure of monolayer graphene"""
import pybinding as pb
import matplotlib.pyplot as plt
from math import sqrt, pi
from pybinding.repository import graphene

pb.pltutils.use_style()


model = pb.Model(
    graphene.monolayer(),  # predefined lattice from the material repository
    pb.translational_symmetry()    # creates an infinite sheet of graphene
)
solver = pb.solver.lapack(model)  # eigensolver from the LAPACK library

# significant points in graphene's Brillouin zone
a_cc = graphene.a_cc  # carbon-carbon distance
Gamma = [0, 0]
K1 = [-4*pi / (3*sqrt(3)*a_cc), 0]
M = [0, 2*pi / (3*a_cc)]
K2 = [2*pi / (3*sqrt(3)*a_cc), 2*pi / (3*a_cc)]

# plot the bands through the desired points
bands = solver.calc_bands(K1, Gamma, M, K2)
bands.plot(point_labels=['K', r'$\Gamma$', 'M', 'K'])
plt.show()
Ejemplo n.º 42
0
 def make_model(radius, potential=0.2, magnetic_field=3):
     return pb.Model(graphene.monolayer().with_min_neighbors(2),
                     pb.circle(radius),
                     circular_pn_junction(potential, radius),
                     graphene.constant_magnetic_field(magnetic_field))
Ejemplo n.º 43
0
import pytest
import numpy as np

import pybinding as pb
from pybinding.repository import graphene

models = {
    'graphene-pristine': [graphene.monolayer(), pb.rectangle(15)],
    'graphene-pristine-oversized': [graphene.monolayer(), pb.rectangle(20)],
    'graphene-const_potential': [graphene.monolayer(), pb.rectangle(15),
                                 pb.constant_potential(0.5)],
    'graphene-magnetic_field': [graphene.monolayer(), pb.rectangle(15),
                                graphene.constant_magnetic_field(1e3)],
}


@pytest.fixture(scope='module', ids=list(models.keys()), params=models.values())
def model(request):
    return pb.Model(*request.param)


@pytest.fixture(scope='module')
def kpm(model):
    return [pb.greens.kpm(model, optimization_level=i) for i in range(4)]


def test_ldos(kpm, baseline, plot_if_fails):
    energy = np.linspace(0, 2, 25)
    results = [k.calc_ldos(energy, broadening=0.15, position=(0, 0)) for k in kpm]

    expected = pb.results.LDOS(energy, baseline(results[0].ldos.astype(np.float32)))
Ejemplo n.º 44
0
def model():
    return pb.Model(graphene.monolayer(), pb.rectangle(1))
Ejemplo n.º 45
0
def model():
    return pb.Model(graphene.monolayer())
Ejemplo n.º 46
0
def build_model(*params):
    model = pb.Model(graphene.monolayer(), *params)
    model.report()
    return model
Ejemplo n.º 47
0
import pytest

import pybinding as pb
from pybinding.repository import graphene

lattices = {
    'graphene-monolayer': graphene.monolayer(),
    'graphene-monolayer-alt': graphene.monolayer_alt(),
    'graphene-monolayer-4atom': graphene.monolayer_4atom(),
    'graphene-monolayer-nn': graphene.monolayer(2),
    'graphene-bilayer': graphene.bilayer(),
}


@pytest.fixture(scope='module',
                ids=list(lattices.keys()),
                params=lattices.values())
def lattice(request):
    return request.param


@pytest.fixture
def mock_lattice():
    a_cc, a, t = 1, 1.73, 1
    lat = pb.Lattice([a, 0], [0.5 * a, 0.866 * a])
    lat.add_sublattices(['a', (0, -a_cc / 2)], ['b', (0, a_cc / 2)])
    lat.add_hoppings([(0, 0), 'a', 'b', t], [(1, -1), 'a', 'b', t],
                     [(0, -1), 'a', 'b', t])
    lat.min_neighbors = 2
    return lat
Ejemplo n.º 48
0
import pytest

import pybinding as pb
from pybinding.repository import graphene

lattices = {
    'graphene-monolayer': graphene.monolayer(),
    'graphene-monolayer-alt': graphene.monolayer_alt(),
    'graphene-monolayer-4atom': graphene.monolayer_4atom(),
    'graphene-monolayer-nn': graphene.monolayer(2),
    'graphene-bilayer': graphene.bilayer(),
}


@pytest.fixture(scope='module', ids=list(lattices.keys()), params=lattices.values())
def lattice(request):
    return request.param


@pytest.fixture
def mock_lattice():
    a_cc, a, t = 1, 1.73, 1
    lat = pb.Lattice([a, 0], [0.5 * a, 0.866 * a])
    lat.add_sublattices(
        ['a', (0, -a_cc/2)],
        ['b', (0,  a_cc/2)]
    )
    lat.add_hoppings(
        [(0,  0), 'a', 'b', t],
        [(1, -1), 'a', 'b', t],
        [(0, -1), 'a', 'b', t]