Skip to content

Commit 4b34d19

Browse files
committed
Small changes to Kane-Mele and Haldane examples
1 parent 37a259e commit 4b34d19

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

examples/hm/haldane_model/haldane.py

100644100755
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717

1818
def Hamilton(k, m, t1, t2, phi):
19-
k_a = 2 * np.pi / 3. * np.array([
20-
-k[0] - k[1], 2. * k[0] - k[1], -k[0] + 2. * k[1]
21-
])
22-
k_b = 2 * np.pi * np.array([k[0], -k[0] + k[1], k[1]])
19+
kx, ky = k
20+
k_a = 2 * np.pi / 3. * np.array([-kx - ky, 2. * kx - ky, -kx + 2. * ky])
21+
k_b = 2 * np.pi * np.array([kx, -kx + ky, ky])
2322
H = 2 * t2 * np.cos(phi) * sum([np.cos(-val) for val in k_b]) * identity
2423
H += t1 * sum([np.cos(-val) for val in k_a]) * pauli_x
2524
H += t1 * sum([np.sin(-val) for val in k_a]) * pauli_y
@@ -30,13 +29,11 @@ def Hamilton(k, m, t1, t2, phi):
3029

3130
def get_chern(m, t1, t2, phi):
3231
system = z2pack.hm.System(
33-
lambda k: Hamilton(k, m, t1, t2, phi), bands=1, check_periodic=True
32+
lambda k: Hamilton(k, m, t1, t2, phi), dim=2, bands=1
3433
)
3534

3635
result = z2pack.surface.run(
37-
system=system,
38-
surface=lambda s, t: [t, s, 0.],
39-
min_neighbour_dist=1e-5
36+
system=system, surface=lambda s, t: [t, s], min_neighbour_dist=1e-5
4037
)
4138
return z2pack.invariant.chern(result)
4239

examples/hm/kane_mele_model/run.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def get_kane_mele_hamiltonian(t, lambda_v, lambda_R, lambda_SO):
2121
def inner(k):
2222
k = np.array(k) * 2 * np.pi
23-
kx, ky, kz = k
23+
kx, ky = k
2424
# change to reduced coordinates
2525
x = (kx - ky) / 2
2626
y = (kx + ky) / 2
@@ -43,9 +43,10 @@ def inner(k):
4343
get_kane_mele_hamiltonian(
4444
t=1, lambda_v=0.1, lambda_R=0.05, lambda_SO=0.06
4545
),
46+
dim=2,
4647
check_periodic=True
4748
)
48-
res = z2pack.surface.run(system=system, surface=lambda s, t: [s / 2, t, 0])
49+
res = z2pack.surface.run(system=system, surface=lambda s, t: [s / 2, t])
4950
print('Z2 invariant: {}'.format(z2pack.invariant.z2(res)))
5051
fig, ax = plt.subplots(figsize=[5, 3])
5152
z2pack.plot.wcc(res, axis=ax)

tests/test_hm.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ def test_explicit_bands(bands, weyl_surface, compare_wcc):
3737
compare_wcc(res.wcc)
3838

3939

40+
def test_non_periodic_raises():
41+
"""
42+
Test that the check for periodicity of Hamiltonians raises when given a
43+
non-periodic value.
44+
"""
45+
with pytest.raises(ValueError):
46+
system = z2pack.hm.System( # pylint: disable=unused-variable
47+
lambda k: np.array(
48+
[
49+
[k[2], k[0] -1j * k[1]],
50+
[k[0] + 1j * k[1], -k[2]]
51+
]
52+
),
53+
check_periodic=True
54+
)
55+
56+
4057
def test_invalid_pos():
4158
"""
4259
Test that trying to set too many positions raises.

z2pack/hm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class System(EigenstateSystem):
3737
:param convention: The convention used for the Hamiltonian, following the `pythtb formalism <http://www.physics.rutgers.edu/pythtb/_downloads/pythtb-formalism.pdf>`_. Convention 1 means that the eigenvalues of :math:`\mathcal{H}(\mathbf{k})` are wave vectors :math:`\left|\psi_{n\mathbf{k}}\right>`. With convention 2, they are the cell-periodic Bloch functions :math:`\left|u_{n\mathbf{k}}\right>`.
3838
:type convention: int
3939
40-
:param check_periodic: Evaluate the Hamiltonian at :math:`\{0, 1\}^d` as a simple check if it is periodic.
40+
:param check_periodic: Evaluate the Hamiltonian at :math:`\{0, 1\}^d` as a simple check if it is periodic. Note that this does not work if the Hamiltonian is written such that the eigenstates acquire a phase when being translated by a lattice vector.
4141
:type check_periodic: bool
4242
"""
4343

@@ -63,12 +63,13 @@ def __init__(
6363

6464
if check_periodic:
6565
k_values = itertools.product([0, 1], repeat=dim)
66-
ham_gamma = self._hamilton(next(k_values))
66+
k_first = next(k_values)
67+
ham_first = self._hamilton()
6768
for k in k_values:
68-
if not np.allclose(ham_gamma, self._hamilton(k)):
69+
if not np.allclose(ham_first, self._hamilton(k)):
6970
raise ValueError(
70-
'The given Hamiltonian is not periodic: H(k=0) != H(k={})'
71-
.format(k)
71+
'The given Hamiltonian is not periodic: H(k={}) != H(k={})'
72+
.format(k_first, k)
7273
)
7374

7475
size = len(self._hamilton([0] * dim)) # assuming to be square...

0 commit comments

Comments
 (0)