Skip to content

Commit

Permalink
error out before causing segfault in atomselect edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
stefdoerr committed Oct 21, 2024
1 parent 0bd9da3 commit b521624
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions moleculekit/atomselect/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def analyze(mol: Molecule, bonds, _profile=False):
masses.append(periodictable[el].mass)
masses = np.array(masses, dtype=np.float32)

if bonds.max() >= mol.numAtoms:
raise ValueError(
"Bonds array contains atoms which are not in the molecule. "
f"The maximum atom index in the bonds array is {bonds.max()} while the molecule contains {mol.numAtoms} atoms."
)

if not _profile:
analyze_molecule(
mol.numAtoms,
Expand Down

0 comments on commit b521624

Please sign in to comment.