diff --git a/pyscf/pbc/tools/pbc.py b/pyscf/pbc/tools/pbc.py index 397a0d9a28..d67521e45b 100644 --- a/pyscf/pbc/tools/pbc.py +++ b/pyscf/pbc/tools/pbc.py @@ -465,9 +465,17 @@ def madelung(cell, kpts): return 2*cell.omega/np.pi**0.5-np.einsum('i,i,i->', ZSI.conj(), ZSI, coulG*weights).real -def get_monkhorst_pack_size(cell, kpts): - skpts = cell.get_scaled_kpts(kpts).round(decimals=6) - Nk = np.array([len(np.unique(ki)) for ki in skpts.T]) +def get_monkhorst_pack_size(cell, kpts, tol=1e-5): + kpts = np.reshape(kpts, (-1,3)) + min_tol = tol + assert kpts.shape[0] < 1/min_tol + if kpts.shape[0] == 1: + Nk = np.array([1,1,1]) + else: + tol = max(10**(-int(-np.log10(1/kpts.shape[0]))-2), min_tol) + skpts = cell.get_scaled_kpts(kpts) + Nk = np.array([np.count_nonzero(abs(ski[1:]-ski[:-1]) > tol) + 1 + for ski in np.sort(skpts.T)]) return Nk