Beispiel #1
0
def test_periodic_next_nearest():
    # Lattice chain
    latt = lp.simple_chain(neighbors=2)
    latt.build(9)
    latt.set_periodic(0)
    assert 8 in latt.neighbors(0, distidx=1)

    # Square lattice
    latt = lp.simple_square(neighbors=2)
    latt.build((4, 4))
    latt.set_periodic(0)
    assert_elements_equal1d(latt.neighbors(0, 1), [6, 21])
    assert_elements_equal1d(latt.neighbors(1, 1), [7, 5, 20, 22])
    assert_elements_equal1d(latt.neighbors(2, 1), [8, 6, 21, 23])
    assert_elements_equal1d(latt.neighbors(3, 1), [9, 7, 22, 24])
    assert_elements_equal1d(latt.neighbors(4, 1), [8, 23])
    latt.set_periodic(1)
    assert_elements_equal1d(latt.neighbors(0, 1), [6, 9])
    assert_elements_equal1d(latt.neighbors(5, 1), [1, 4, 11, 14])
    assert_elements_equal1d(latt.neighbors(10, 1), [6, 9, 16, 19])
    assert_elements_equal1d(latt.neighbors(15, 1), [11, 14, 21, 24])
    assert_elements_equal1d(latt.neighbors(20, 1), [16, 19])
    # Only check corners for both axis periodic
    latt.set_periodic([0, 1])
    assert_elements_equal1d(latt.neighbors(0, 1), [6, 9, 21, 24])
    assert_elements_equal1d(latt.neighbors(4, 1), [5, 8, 20, 23])
    assert_elements_equal1d(latt.neighbors(20, 1), [1, 4, 16, 19])
    assert_elements_equal1d(latt.neighbors(23, 1), [0, 3, 15, 18])
Beispiel #2
0
def test_minimum_distances_chain():
    latt = lp.simple_chain()
    latt.build(4)
    assert_array_equal(latt.minimum_distances(0), [0.0, 1.0, 2.0, 3.0, 4.0])
    assert_array_equal(latt.minimum_distances(1), [1.0, 0.0, 1.0, 2.0, 3.0])
    assert_array_equal(latt.minimum_distances(2), [2.0, 1.0, 0.0, 1.0, 2.0])
    assert_array_equal(latt.minimum_distances(3), [3.0, 2.0, 1.0, 0.0, 1.0])
    assert_array_equal(latt.minimum_distances(4), [4.0, 3.0, 2.0, 1.0, 0.0])
    latt.set_periodic(0)
    assert_array_equal(latt.minimum_distances(0), [0.0, 1.0, 2.0, 2.0, 1.0])
    assert_array_equal(latt.minimum_distances(1), [1.0, 0.0, 1.0, 2.0, 2.0])
    assert_array_equal(latt.minimum_distances(2), [2.0, 1.0, 0.0, 1.0, 2.0])
    assert_array_equal(latt.minimum_distances(3), [2.0, 2.0, 1.0, 0.0, 1.0])
    assert_array_equal(latt.minimum_distances(4), [1.0, 2.0, 2.0, 1.0, 0.0])
Beispiel #3
0
def test_simple_chain():
    latt = lp.simple_chain(a=1, neighbors=1)
    latt.build(3)

    # Check correct building
    assert latt.num_sites == 4

    expected = np.atleast_2d([0.0, 1.0, 2.0, 3.0]).T
    actual = latt.data.positions
    assert_array_equal(expected, actual)

    latt = lp.simple_chain(a=1, neighbors=1)
    latt.build(3)
    # Check neighbors
    expected = [1]
    actual = latt.nearest_neighbors(0)
    assert_array_equal(expected, actual)

    expected = [0, 2]
    actual = latt.nearest_neighbors(1)
    assert_array_equal(expected, sorted(actual))

    # Check periodic boundary conditions
    latt.set_periodic(0)
    expected = [1, 3]
    actual = latt.nearest_neighbors(0)
    assert_array_equal(expected, sorted(actual))

    latt = lp.simple_chain(a=1, neighbors=2)
    latt.build(6)
    expected = [0, 2, 3]
    actual = latt.neighbors(1)
    assert_array_equal(expected, sorted(actual))

    expected = [0, 1, 3, 4]
    actual = latt.neighbors(2)
    assert_array_equal(expected, sorted(actual))
Beispiel #4
0
def test_repeat():
    # Only check size, connections are handled by append
    latt = lp.simple_chain()
    latt.build(4, primitive=False)
    latt.repeat()
    assert latt.num_sites == 10

    latt = lp.simple_square()
    latt.build((4, 4), primitive=False)
    latt.repeat(1, ax=0)
    assert_array_equal(latt.shape, (9, 4))

    latt = lp.simple_square()
    latt.build((4, 4), primitive=False)
    latt.repeat(1, ax=1)
    assert_array_equal(latt.shape, (4, 9))
Beispiel #5
0
def test_extend():
    # Only check size, connections are handled by append
    latt = lp.simple_chain()
    latt.build(4, primitive=False)
    latt.extend(2)
    assert latt.num_sites == 8

    latt = lp.simple_square()
    latt.build((4, 4), primitive=False)
    latt.extend(2, ax=0)
    assert_array_equal(latt.shape, (7, 4))

    latt = lp.simple_square()
    latt.build((4, 4), primitive=False)
    latt.extend(2, ax=1)
    assert_array_equal(latt.shape, (4, 7))
Beispiel #6
0
def test_periodic_nearest():
    # Lattice chain
    latt = lp.simple_chain()
    latt.build(9)
    latt.set_periodic(0)
    assert 9 in latt.neighbors(0)

    # Square lattice
    latt = lp.simple_square()
    latt.build((4, 4))

    latt.set_periodic(0)
    assert_elements_equal1d(latt.nearest_neighbors(0), [1, 5, 20])
    assert_elements_equal1d(latt.nearest_neighbors(1), [0, 2, 6, 21])
    assert_elements_equal1d(latt.nearest_neighbors(2), [1, 3, 7, 22])
    assert_elements_equal1d(latt.nearest_neighbors(3), [2, 4, 8, 23])
    assert_elements_equal1d(latt.nearest_neighbors(4), [3, 9, 24])
    latt.set_periodic(1)
    assert_elements_equal1d(latt.nearest_neighbors(0), [1, 5, 4])
    assert_elements_equal1d(latt.nearest_neighbors(5), [0, 6, 10, 9])
    assert_elements_equal1d(latt.nearest_neighbors(10), [5, 11, 15, 14])
    assert_elements_equal1d(latt.nearest_neighbors(15), [10, 16, 20, 19])
    assert_elements_equal1d(latt.nearest_neighbors(20), [15, 21, 24])
    # Only check corners for both axis periodic
    latt.set_periodic([0, 1])
    assert_elements_equal1d(latt.nearest_neighbors(0), [1, 5, 20, 24])
    assert_elements_equal1d(latt.nearest_neighbors(4), [3, 9, 20, 24])
    assert_elements_equal1d(latt.nearest_neighbors(20), [0, 15, 21, 24])
    assert_elements_equal1d(latt.nearest_neighbors(24), [4, 19, 20, 23])

    # graphene lattice
    latt = lp.graphene()
    latt.build((5.5, 4.5))

    latt.set_periodic(0)
    assert_elements_equal1d(latt.nearest_neighbors(0), [1, 15])
    assert_elements_equal1d(latt.nearest_neighbors(2), [3, 15, 21])
    assert_elements_equal1d(latt.nearest_neighbors(8), [9, 21, 23])
    latt.set_periodic(1)
    assert_elements_equal1d(latt.nearest_neighbors(1), [0, 4, 16])
    assert_elements_equal1d(latt.nearest_neighbors(6), [5, 7, 17])
    assert_elements_equal1d(latt.nearest_neighbors(7), [6, 14, 22])
    # Only check corners for both axis periodic
    latt.set_periodic([0, 1])
    assert_elements_equal1d(latt.nearest_neighbors(0), [1, 15, 23])
    assert_elements_equal1d(latt.nearest_neighbors(8), [9, 21, 23])
Beispiel #7
0
def test_remove_periodic():
    latt = lp.simple_chain()
    latt.build(9)
    latt.set_periodic(0)
    latt.set_periodic(None)
    assert 9 not in latt.neighbors(0)
Beispiel #8
0
hexagonal = Lattice.hexagonal(a=1)
rhexagonal = Lattice(
    np.array([[+2.0943951, +3.62759873], [+2.0943951, -3.62759873]]))
sc = Lattice.sc(a=1.0)
rsc = Lattice(TWOPI * np.eye(3))

fcc = Lattice.fcc(a=1.0)
rfcc = Lattice(TWOPI * np.array([[+1, +1, -1], [+1, -1, +1], [-1, +1, +1]]))
bcc = Lattice.bcc(a=1.0)
rbcc = Lattice(TWOPI * np.array([[+1, +1, 0], [0, -1, +1], [-1, 0, +1]]))

LATTICES = [chain, square, rect, hexagonal, sc, fcc, bcc]
RLATTICES = [rchain, rsquare, rrect, rhexagonal, rsc, rfcc, rbcc]

STRUCTURES = list()
_latt = lp.simple_chain()
_latt.build(4)
STRUCTURES.append(_latt)
_latt = lp.simple_square()
_latt.build((4, 4))
STRUCTURES.append(_latt)
_latt = lp.simple_cubic()
_latt.build((4, 4, 4))
STRUCTURES.append(_latt)


@st.composite
def structures(draw):
    return draw(st.sampled_from(STRUCTURES))

Beispiel #9
0
def test_wignerseitz_symmetry_points():
    # Test 1D
    latt = simple_chain()
    ws = latt.wigner_seitz_cell()
    origin, corners, edge_centers, face_centers = ws.symmetry_points()
    assert_array_equal(origin, [0.0])
    assert_array_equal(corners, [[-0.5], [0.5]])
    assert edge_centers is None
    assert face_centers is None

    # Test 2D
    latt = simple_square()
    ws = latt.wigner_seitz_cell()
    origin, corners, edge_centers, face_centers = ws.symmetry_points()

    assert_array_equal(origin, [0.0, 0.0])
    assert_array_equal(
        2 * corners, [[-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0]]
    )
    assert_array_equal(
        2 * edge_centers, [[0.0, -1.0], [-1.0, 0.0], [1.0, 0.0], [0.0, 1.0]]
    )
    assert face_centers is None

    # Test 3D
    latt = simple_cubic()
    ws = latt.wigner_seitz_cell()
    origin, corners, edge_centers, face_centers = ws.symmetry_points()

    c = [
        [-0.5, -0.5, -0.5],
        [0.5, -0.5, -0.5],
        [-0.5, -0.5, 0.5],
        [0.5, -0.5, 0.5],
        [-0.5, 0.5, -0.5],
        [0.5, 0.5, -0.5],
        [0.5, 0.5, 0.5],
        [-0.5, 0.5, 0.5],
    ]
    e = [
        [-0.5, -0.5, 0.0],
        [0.0, -0.5, -0.5],
        [0.5, -0.5, 0.0],
        [0.0, -0.5, 0.5],
        [-0.5, 0.5, 0.0],
        [0.0, 0.5, 0.5],
        [0.5, 0.5, 0.0],
        [0.0, 0.5, -0.5],
        [0.5, 0.0, 0.5],
        [0.0, 0.5, 0.5],
        [-0.5, 0.0, 0.5],
        [0.0, -0.5, 0.5],
        [-0.5, -0.5, 0.0],
        [-0.5, 0.0, -0.5],
        [-0.5, 0.5, 0.0],
        [-0.5, 0.0, 0.5],
        [0.5, 0.0, -0.5],
        [0.0, 0.5, -0.5],
        [-0.5, 0.0, -0.5],
        [0.0, -0.5, -0.5],
        [0.5, -0.5, 0.0],
        [0.5, 0.0, -0.5],
        [0.5, 0.5, 0.0],
        [0.5, 0.0, 0.5],
    ]

    f = [
        [0.0, -0.5, 0.0],
        [0.0, 0.5, 0.0],
        [0.0, 0.0, 0.5],
        [-0.5, 0.0, 0.0],
        [0.0, 0.0, -0.5],
        [0.5, 0.0, 0.0],
    ]

    assert_array_equal(origin, [0.0, 0.0, 0.0])
    assert_array_equal(corners, c)
    assert_array_equal(edge_centers, e)
    assert_array_equal(face_centers, f)
Beispiel #10
0
import os
import time
import tracemalloc
import numpy as np
import matplotlib.pyplot as plt
import lattpy as lp

MB = 1024 * 1024
MAX_SITES = 10_000_000
RUNS = 3
MAX_POINTS = 30

overwrite = False
latts = {
    "chain": lp.simple_chain(),
    "square": lp.simple_square(),
    "hexagonal": lp.simple_hexagonal(),
    "cubic": lp.simple_cubic(),
}


class Profiler:
    """Profiler object for measuring time, memory and other stats."""

    def __init__(self):
        self._timefunc = time.perf_counter
        self._snapshot = None
        self._t0 = 0
        self._m0 = 0
        self._thread = None