예제 #1
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.kpm(model, silent=True)
    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.kpm(model).calc_ldos(energy, broadening, position)
        assert pytest.fuzzy_equal(actual, expected, rtol=1e-3, atol=1e-6)
예제 #2
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.kpm(model, kernel=pb.lorentz_kernel())
        return kpm.deferred_ldos(energy, broadening=0.15, position=[0, 0])
예제 #3
0
def test_dos(params, baseline, plot_if_fails):
    configurations = [
        {
            'matrix_format': "ELL",
            'optimal_size': False,
            'interleaved': False
        },
        {
            'matrix_format': "ELL",
            'optimal_size': True,
            'interleaved': True
        },
    ]
    model = pb.Model(*params)

    kernel = pb.lorentz_kernel()
    strategies = [
        pb.kpm(model, kernel=kernel, silent=True, **c) for c in configurations
    ]

    energy = np.linspace(0, 2, 25)
    results = [kpm.calc_dos(energy, broadening=0.15) for kpm in strategies]

    expected = results[0].with_data(
        baseline(results[0].data.astype(np.float32)))
    for i in range(len(results)):
        plot_if_fails(results[i], expected, 'plot', label=i)

    for result in results:
        assert pytest.fuzzy_equal(result, expected, rtol=1e-3, atol=1e-6)
예제 #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.kpm(model, silent=True)

    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.data, b.data[::-1], rtol=1e-3, atol=1e-6)
예제 #5
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)
예제 #6
0
def test_kpm_multiple_indices(model):
    """KPM can take a vector of column indices and return the Green's function for all of them"""
    kpm = pb.kpm(model, silent=True)

    num_sites = model.system.num_sites
    i, j = num_sites // 2, num_sites // 4
    energy = np.linspace(-0.3, 0.3, 10)
    broadening = 0.8

    cols = [j, j + 1, j + 2]
    gs = kpm.calc_greens(i, cols, energy, broadening)
    assert len(gs) == len(cols)

    g = kpm.calc_greens(j, i, energy, broadening)
    assert pytest.fuzzy_equal(gs[0], g)
예제 #7
0
def test_conductivity(params, baseline, plot_if_fails):
    configurations = [
        {
            'matrix_format': "ELL",
            'optimal_size': False,
            'interleaved': False
        },
        {
            'matrix_format': "ELL",
            'optimal_size': True,
            'interleaved': True
        },
    ]
    model = pb.Model(*params)

    kernel = pb.lorentz_kernel()
    strategies = [
        pb.kpm(model, energy_range=[-9, 9], kernel=kernel, silent=True, **c)
        for c in configurations
    ]

    energy = np.linspace(-2, 2, 25)
    results = [
        kpm.calc_conductivity(energy,
                              broadening=0.5,
                              temperature=0,
                              num_points=200) for kpm in strategies
    ]

    expected = results[0].with_data(
        baseline(results[0].data.astype(np.float32)))
    for i in range(len(results)):
        plot_if_fails(results[i], expected, "plot", label=i)

    for result in results:
        assert pytest.fuzzy_equal(result, expected, rtol=1e-2, atol=1e-5)
예제 #8
0
complete_lattice = pb.load('lattice_' + name[:-4])
num_x = 1
num_y = 1
print('Done loading ', flush=True)
print('Making the model', flush=True)

# check for the bonds
model = pb.Model(
    complete_lattice, pb.force_double_precision(),
    pb.translational_symmetry(a1=num_x * np.linalg.norm(l1),
                              a2=num_y * np.linalg.norm(l2)))
model.eval()
print(model.report(), flush=True)
kpm = pb.kpm(model,
             kernel=pb.jackson_kernel(),
             matrix_format="CSR",
             optimal_size=False,
             interleaved=False)
print(kpm.scaling_factors)

nx = 5
ny = 4
e_min = -11.7
e_max = +9.3

num_a1 = 640
num_a2 = 512

num_moments = 12000

# make config object which caries info about
예제 #9
0
    U = 5 * S3  # Onsite term
    # Building the lattice model
    lat = pb.Lattice(a1=[1, 0, 0], a2=[0, 1, 0], a3=[0, 0, 1])
    lat.add_sublattices(('A', [0, 0, 0], U))
    lat.add_hoppings(([1, 0, 0], 'A', 'A', Tx), ([0, 1, 0], 'A', 'A', Ty),
                     ([0, 0, 1], 'A', 'A', Tz))
    # generating the model object by combinig the lattice and the Peierls field
    model = pb.Model(lat, pb.primitive(a1=dim, a2=dim, a3=dim),
                     constant_magnetic_field(B=B, theta=theta))
    return model


# Calculate DOS
# We use jackson kernel here that is good for DOS
kpm = pb.kpm(mymodel(args.dim, theta, args.B),
             silent=True,
             energy_range=[-13, 13],
             kernel=pb.jackson_kernel())
# we approximate the bulk dos with the local DOS at the center of the lattice
# the calculation is performed at this step
dos = kpm.calc_ldos(energy=linspace(-args.Eran, args.Eran, 3000),
                    position=[0, 0, 0],
                    broadening=args.broad)

# build up the name of the output file
if args.out == False:
    out = '-'.join([
        'dos', 'dim',
        str(args.dim), 'theta',
        str(args.theta0), 'B',
        str(args.B)
    ])