Skip to content

inferBonds() method raises runtime exception due to integer types mismatch #2173

@SwampHiker

Description

@SwampHiker

Description of the bug.

I was trying to create a ball-and-stick model of 1b5n peptide, so I used the .inferBonds() method to extract sticks' coordinates. The method raised a runtime error due to integer type mismatch in kdtree.py:

def get_KDTree_indices(kdtree):
    indices = None
    try:
        indices = kdtree.get_indices()
    except:
        n = kdtree.get_count()
        if n:
            indices = empty(n, int) <- this line creates an array of int64
            kdtree.get_indices(indices) <- this function call expects an array of int32
    return indices

Do you have any error messages or logs?

The bottom of the traceback message looks like this:

File "############\Python\Lib\site-packages\prody\kdtree\kdtree.py", line 304, in get_KDTree_indices
kdtree.get_indices(indices)
~~~~~~~~~~~~~~~~~~^^^^^^^^^
RuntimeError: array has incorrect data format ('q', expected 'l')

What is your setup?

The OS is Windows 10 (64-bit).

How did you install ProDy?

I'm using the latest version of ProDy built from sources on August 29. My local kdtree.py was the same as main's.

What did your code look like?

My relevant code looks like:

atom_group = prody.parsePDB('1b5n', secondary=False, bonds=True)
atom_center = np.mean(atom_group.getCoords(), 0, keepdims=True)
atom_group.setCoords(atom_group.getCoords() - atom_center + np.array([0, 2.5, 0]))

atom_group.inferBonds() <- raises exception

My quick fix

To mitigate the problem, I changed my local kdtree.py:

from numpy import int32

def get_KDTree_indices(kdtree):
    indices = None
    try:
        indices = kdtree.get_indices()
    except:
        n = kdtree.get_count()
        if n:
            indices = empty(n, int32)
            kdtree.get_indices(indices)
    return indices

This fix seems to solve the problem for me.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions