Skip to content

Commit

Permalink
test(kpoints): one more test case for k segments
Browse files Browse the repository at this point in the history
  • Loading branch information
minyez committed Sep 4, 2024
1 parent 5e74101 commit 2df1e0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mushroom/core/kpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def __init__(self, kpts, recp_latt=None, unify_x: bool = False):
if recp_latt is not None:
self.kpts = np.matmul(kpts, recp_latt)
self._ksegs = None
self._find_ksegs()
self._unify_x = unify_x
self._x = None
self._special_x = None
self._index_special_x = None
self._find_ksegs()
_logger.debug("Found segments: %r", self._ksegs)

def _find_ksegs(self):
self._ksegs = find_k_segments(self.kpts)
Expand Down
31 changes: 29 additions & 2 deletions mushroom/core/test/test_kpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ class test_kpath(ut.TestCase):
[11, 10, 2]],
[[0, 0, 0], [0, 0, 1], [0, 0, 2], [2, 0, 2], [1, 0, 2], [0, 0, 2]],
[[0, 0, 0], [0, 0, 1], [0, 0, 2], [1, 0, 2], [2, 0, 2], [3, 0, 2]],
[[0.000000000000, 0.000000000000, 0.000000000000],
[0.075000000000, 0.075000000000, 0.150000000000],
[0.300000000000, 0.300000000000, 0.600000000000],
[0.375000000000, 0.375000000000, 0.750000000000],
[0.425000000000, 0.425000000000, 0.650000000000],
[0.475000000000, 0.475000000000, 0.550000000000],
[0.500000000000, 0.500000000000, 0.500000000000],
[0.550000000000, 0.400000000000, 0.550000000000],
[0.600000000000, 0.300000000000, 0.600000000000],
[0.625000000000, 0.250000000000, 0.625000000000],
[0.550000000000, 0.250000000000, 0.700000000000],
[0.500000000000, 0.250000000000, 0.750000000000],
[0.700000000000, 0.250000000000, 0.550000000000],
[0.750000000000, 0.250000000000, 0.500000000000],
[0.700000000000, 0.200000000000, 0.500000000000],
[0.600000000000, 0.100000000000, 0.500000000000],
[0.500000000000, 0.000000000000, 0.500000000000],]
]
valid_ksegs = [
[(0, 4),],
Expand All @@ -57,6 +74,7 @@ class test_kpath(ut.TestCase):
[(0, 2), (3, 5), (5, 6)],
[(0, 2), (3, 5)],
[(0, 2), (2, 5)],
[(0, 3), (3, 6), (6, 9), (9, 11), (11, 13), (13, 16)],
]
valid_xs = [
[0.0, 1.0, 2.0, 3.0, 4.0],
Expand All @@ -67,6 +85,12 @@ class test_kpath(ut.TestCase):
[0.0, 1.0, 2.0, 2.0, 7.0, 12.0, 17.0],
[0.0, 1.0, 2.0, 2.0, 3.0, 4.0],
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0],
[
0.0, 0.18371173, 0.73484692, 0.91855865, 1.04103314, 1.16350763,
1.22474487, 1.34721936, 1.46969385, 1.53093109, 1.63699711,
1.70770778, 1.9905505, 2.06126118, 2.13197185, 2.27339321,
2.41481457
],
]
valid_spec_xs = [
[0.0, 4.0],
Expand All @@ -77,6 +101,7 @@ class test_kpath(ut.TestCase):
[0.0, 2.0, 12.0, 17.0],
[0.0, 2.0, 4.0],
[0.0, 2.0, 5.0],
[0.0, 0.91855865, 1.22474487, 1.53093109, 1.70770778, 2.06126118, 2.41481457],
]

def test_find_k_segments(self):
Expand All @@ -89,14 +114,16 @@ def test_x(self):
for kpts, x in zip(self.valid_kpts, self.valid_xs):
kp = KPathLinearizer(kpts)
self.assertEqual(len(x), len(kp.x))
self.assertListEqual(x, list(kp.x))
for x1, x2 in zip(x, kp.x):
self.assertAlmostEqual(x1, x2)

def test_special_x(self):
"""check the 1d coordinate of kpath"""
for kpts, spec_x in zip(self.valid_kpts, self.valid_spec_xs):
kp = KPathLinearizer(kpts)
self.assertEqual(len(spec_x), len(kp.special_x))
self.assertListEqual(spec_x, list(kp.special_x))
for x1, x2 in zip(spec_x, kp.special_x):
self.assertAlmostEqual(x1, x2)


class test_mpgrid(ut.TestCase):
Expand Down

0 comments on commit 2df1e0d

Please sign in to comment.