diff --git a/kwant/continuum/discretizer.py b/kwant/continuum/discretizer.py index ad79642aea7b737aa4c26fe5c534dabf5f421380..7fcc9e01de1493dd45f36c8c43dc7061533abe23 100644 --- a/kwant/continuum/discretizer.py +++ b/kwant/continuum/discretizer.py @@ -409,10 +409,10 @@ def _discretize_expression(expression, coords): def _extract_hoppings(expr): """Read hoppings and perform shortening operation.""" expr = sympy.expand(expr) - summands = expr.as_ordered_terms() + summands = [e.as_ordered_factors() for e in expr.as_ordered_terms()] - offset = [_read_offset(s.args[-1]) for s in summands] - coeffs = [sympy.Mul(*s.args[:-1]) for s in summands] + offset = [_read_offset(s[-1]) for s in summands] + coeffs = [sympy.Mul(*s[:-1]) for s in summands] offset = np.array(offset, dtype=int) # rescale the offsets for each coordinate by their greatest # common divisor across the summands. e.g: diff --git a/kwant/continuum/tests/test_discretizer.py b/kwant/continuum/tests/test_discretizer.py index 149150d54c63e1cf71892eec650e1ffd84b313a2..8d0fbb1ae36a8cc6c6c944dd6166dcc3a02feba3 100644 --- a/kwant/continuum/tests/test_discretizer.py +++ b/kwant/continuum/tests/test_discretizer.py @@ -104,6 +104,10 @@ def test_simple_derivations(commutative): kx, ky, kz = sympy.symbols('k_x k_y k_z', commutative=commutative) test = { kx**2 : {(0,): 2/a**2, (1,): -1/a**2}, + kx**2 + 1 : {(0,): 1 + 2/a**2, (1,): -1/a**2}, + kx**2 + 2 : {(0,): 2 + 2/a**2, (1,): -1/a**2}, + kx**2 + 1.0 : {(0,): 1.0 + 2/a**2, (1,): -1/a**2}, + kx**2 + 2.0 : {(0,): 2.0 + 2/a**2, (1,): -1/a**2}, kx**2 + ky**2 : {(0, 1): -1/a**2, (0, 0): 4/a**2, (1, 0): -1/a**2}, kx**2 + ky**2 + kz**2 : {(1, 0, 0): -1/a**2, (0, 0, 1): -1/a**2,