Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/biotite/structure/bonds.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class BondList(Copyable):
# Input contains bonds (index 0 and 1)
# including the bond type value (index 2)
# Bond indices:
for bond_a, bond_b, _ in bonds:
if bond_a == bond_b:
raise ValueError(f"Atom {bond_a} cannot bind to itself {bond_b}")
self._bonds[:,:2] = np.sort(
# Indices are sorted per bond
# so that the lower index is at the first position
Expand All @@ -294,6 +297,9 @@ class BondList(Copyable):
# Indices are sorted per bond
# so that the lower index is at the first position
elif bonds.shape[1] == 2:
for bond_a, bond_b in bonds:
if bond_a == bond_b:
raise ValueError(f"Atom {bond_a} cannot bind to itself {bond_b}")
# Input contains the bonds without bond type
# -> Default: Set bond type ANY (0)
self._bonds[:,:2] = np.sort(
Expand Down Expand Up @@ -937,6 +943,9 @@ class BondList(Copyable):
if bond_type >= len(BondType):
raise ValueError(f"BondType {bond_type} is invalid")

if atom_index1 == atom_index2:
raise ValueError("Atom indices must be different because the same atom cannot be bonded to itself")

cdef uint32 index1 = _to_positive_index(atom_index1, self._atom_count)
cdef uint32 index2 = _to_positive_index(atom_index2, self._atom_count)
_sort(&index1, &index2)
Expand Down