digital-chemistry-laboratory / libconeangle

Library for calculating exact ligand cone angles
MIT License
12 stars 1 forks source link

Out of bound indexing #2

Closed awvwgk closed 2 years ago

awvwgk commented 2 years ago

Out of bound indexing is not handled gracefully at the moment. Trying some funny things in the session below, which eventually did crash the library:

❯ python
Python 3.10.2 | packaged by conda-forge | (main, Mar  8 2022, 15:53:57) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import libconeangle
>>> libconeangle.cone_angle([[0.0, 0.0, -0.52], [0.0, 0.0, 1.76], [0.0, 0.0, 2.86]], [2.1, 1.7, 1.52], 1)
(96.4237340645161, array([0., 0., 1.]), [2])
>>> libconeangle.cone_angle([[0.0, 0.0, -0.52], [0.0, 0.0, 1.76], [0.0, 0.0, 2.86]], [2.1, 1.7, 1.52], 0)
 Atoms within vdW radius of metal atom.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/awvwgk/projects/src/git/mctc-tools/libconeangle/libconeangle/coneangle.py", line 54, in cone_angle
    raise ValueError("libconeangle exited with non-zero exit code: {stat}")
ValueError: libconeangle exited with non-zero exit code: {stat}
>>> libconeangle.cone_angle([[0.0, 0.0, -0.52], [0.0, 0.0, 1.76], [0.0, 0.0, 2.86]], [2.1, 1.7, 1.52], 3)
 Atoms within vdW radius of metal atom.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/awvwgk/projects/src/git/mctc-tools/libconeangle/libconeangle/coneangle.py", line 54, in cone_angle
    raise ValueError("libconeangle exited with non-zero exit code: {stat}")
ValueError: libconeangle exited with non-zero exit code: {stat}
>>> libconeangle.cone_angle([[0.0, 0.0, -0.52], [0.0, 0.0, 1.76], [0.0, 0.0, 2.86]], [2.1, 1.7, 1.52], -1)
 Atoms within vdW radius of metal atom.
free(): invalid pointer
zsh: IOT instruction (core dumped)  python

Also, the indexing should preferably be C-compatible, i.e. starting from 0.