Skip to content

Commit c428039

Browse files
authored
Allow passing a specific sublattice to add_hoppings_kwant. (#105)
Also removes duplicate setting of the kwant hopping matrices.
1 parent 8f2cffd commit c428039

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

tbmodels/_tb_model.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ def to_kwant_lattice(self):
866866
pos_abs = np.dot(np.array([sl.pos for sl in sublattices]), uc)
867867
return kwant.lattice.general(prim_vecs=uc, basis=pos_abs)
868868

869-
def add_hoppings_kwant(self, kwant_sys):
869+
def add_hoppings_kwant(self, kwant_sys, kwant_sublattices=None):
870870
"""
871871
Sets the on-site energies and hopping terms for an existing kwant system to those of the :class:`.Model`.
872872
@@ -875,7 +875,8 @@ def add_hoppings_kwant(self, kwant_sys):
875875
import kwant # pylint: disable=import-outside-toplevel
876876

877877
sublattices = self._get_sublattices()
878-
kwant_sublattices = self.to_kwant_lattice().sublattices
878+
if kwant_sublattices is None:
879+
kwant_sublattices = self.to_kwant_lattice().sublattices
879880

880881
# handle R = 0 case (on-site)
881882
on_site_mat = copy.deepcopy(self._array_cast(self.hop[self._zero_vec]))
@@ -894,10 +895,7 @@ def add_hoppings_kwant(self, kwant_sys):
894895

895896
# R = 0 terms between different sublattices
896897
for i, s1 in enumerate(sublattices):
897-
for j, s2 in enumerate(sublattices):
898-
if i == j:
899-
# handled above
900-
continue
898+
for j, s2 in enumerate(sublattices[i + 1 :], start=i + 1):
901899
kwant_sys[
902900
kwant.builder.HoppingKind(
903901
self._zero_vec,
@@ -908,10 +906,10 @@ def add_hoppings_kwant(self, kwant_sys):
908906

909907
# R != 0 terms
910908
for R, mat in self.hop.items():
909+
mat = self._array_cast(mat)
911910
# special case R = 0 handled already
912911
if R == self._zero_vec:
913912
continue
914-
mat = self._array_cast(mat)
915913
minus_R = tuple(-np.array(R))
916914
for i, s1 in enumerate(sublattices):
917915
for j, s2 in enumerate(sublattices):
@@ -922,11 +920,6 @@ def add_hoppings_kwant(self, kwant_sys):
922920
minus_R, kwant_sublattices[i], kwant_sublattices[j]
923921
)
924922
] = sub_matrix
925-
kwant_sys[
926-
kwant.builder.HoppingKind(
927-
R, kwant_sublattices[j], kwant_sublattices[i]
928-
)
929-
] = np.transpose(np.conj(sub_matrix))
930923
return kwant_sys
931924

932925
def _get_sublattices(self):

0 commit comments

Comments
 (0)