Skip to content

Commit 56b09d6

Browse files
committed
bug: corrected some bugs on valid shifts
1 parent 70d1e64 commit 56b09d6

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

sisl/geom/nanoribbon.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def _parse_shift(self, shift, prev, align):
406406
self._junction_error(prev, "LONE ATOMS: Previous odd section, which has an open end,"
407407
" is wider than the incoming one. A wider odd section must always"
408408
" have a closed end. You can solve this by making the previous section"
409-
" one unit smaller or larger (L = L +- 1).", "raise"
409+
" one unit smaller or larger (L = L +- 1).", self.on_lone_atom
410410
)
411411

412412
# Get the difference in width between the previous and this ribbon section
@@ -415,8 +415,8 @@ def _parse_shift(self, shift, prev, align):
415415
# on 1, 2, 3 or 4 atoms. After that, the cycle just repeats (e.g. 5 == 1, etc).
416416
diff_mod = W_diff % 4
417417

418-
# Now, we need to calculate the offset that we have to apply to the incoming
419-
# section depending on several factors.
418+
# Calculate the shifts that are valid (don't leave atoms with less than 2 bonds)
419+
# This depends on several factors.
420420
if diff_mod % 2 == 0 and W % 2 == 1:
421421
# Both sections are odd
422422

@@ -445,7 +445,7 @@ def _parse_shift(self, shift, prev, align):
445445

446446
# Update the valid shift limits if the sections are aligned on any of the edges.
447447
shift_offset = self._offset_from_center(align, prev)
448-
valid_shifts += shift_offset
448+
valid_shifts -= shift_offset
449449
elif prev.W == W:
450450
valid_shifts = np.array([0])
451451
else:
@@ -469,7 +469,7 @@ def _parse_shift(self, shift, prev, align):
469469
shift_offset = self._offset_from_center(align, prev)
470470

471471
# Apply the offsets and calculate the maximum and minimum shifts.
472-
min_shift, max_shift = -shift_lim + shift_offset, shift_lim + shift_offset
472+
min_shift, max_shift = -shift_lim - shift_offset, shift_lim - shift_offset
473473

474474
valid_shifts = np.arange(min_shift, max_shift + 1, 2)
475475
else:

sisl/geom/tests/test_geom.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,18 @@ def test_graphene_heteroribbon():
118118

119119
def test_graphene_heteroribbon_errors():
120120
# 7-open with 9 can only be perfectly aligned.
121-
graphene_heteroribbon([(7,1), (9,1)], align="center", on_lone_atom="raise")
121+
# Let's test it from the center
122+
graphene_heteroribbon([(7, 1), (9, 1)], align="center", on_lone_atom="raise")
122123
with pytest.raises(ValueError):
123-
graphene_heteroribbon([(7,1), (9,1,-1)], align="center", on_lone_atom="raise")
124+
graphene_heteroribbon([(7, 1), (9, 1, -1)], align="center", on_lone_atom="raise")
125+
# From the bottom
126+
graphene_heteroribbon([(7, 1), (9, 1, -1)], align="bottom", on_lone_atom="raise")
127+
with pytest.raises(ValueError):
128+
graphene_heteroribbon([(7, 1), (9, 1, 0)], align="bottom", on_lone_atom="raise")
129+
# And from the top
130+
graphene_heteroribbon([(7, 1), (9, 1, 1)], align="top", on_lone_atom="raise")
131+
with pytest.raises(ValueError):
132+
graphene_heteroribbon([(7, 1), (9, 1, -1)], align="top", on_lone_atom="raise")
124133

125134
grap_heteroribbon = partial(
126135
graphene_heteroribbon, align="auto", shift_quantum=True

0 commit comments

Comments
 (0)