Skip to content

Python3 PDB NeighborSearch: TypeError: '<' not supported between instances of 'Residue' and 'Residue' #1356

Closed

Description

@harryjubb

Setup

I am reporting a problem with Biopython version, Python version, and operating
system as follows:

import sys; print(sys.version)
import platform; print platform.python_implementation(); print(platform.platform())
import Bio; print(Bio.__version__)
>>> import sys; print(sys.version)
3.6.2 (default, Jul 26 2017, 17:09:31)
[GCC 5.4.0 20160609]

>>> import platform; print(platform.python_implementation()); print(platform.platform())
CPython
Linux-4.4.0-87-generic-x86_64-with-debian-stretch-sid

>>> import Bio; print(Bio.__version__)
1.70

Expected behaviour

ns.search_all(2.0, level='R') to return all pairs of residues in the NeighborSearch object that are within 2 Angstroms of each other.

Actual behaviour

Traceback (most recent call last):
  File "/home/ubuntu/repos/pipeline/venv362/lib/python3.6/site-packages/doit/action.py", line 403, in execute
    returned_value = self.py_callable(*self.args, **kwargs)
  File "/home/ubuntu/repos/pipeline/tasks/pdb_analysis.py", line 687, in fix_ligand_overlaps
    clashing_waters = ns.search_all(2.0, level='R')
  File "/home/ubuntu/repos/pipeline/venv362/lib/python3.6/site-packages/Bio/PDB/NeighborSearch.py", line 128, in search_all
    next_level_pair_list = self._get_unique_parent_pairs(next_level_pair_list)
  File "/home/ubuntu/repos/pipeline/venv362/lib/python3.6/site-packages/Bio/PDB/NeighborSearch.py", line 65, in _get_unique_parent_pairs
    elif p1 < p2:
TypeError: '<' not supported between instances of 'Residue' and 'Residue'

Steps to reproduce

Minimal script to reproduce the problem:

import urllib.request
from Bio.PDB import PDBParser
from Bio.PDB import NeighborSearch

urllib.request.urlretrieve('https://files.rcsb.org/download/10GS.pdb', '10gs.pdb')

pdbparser = PDBParser()
structure = pdbparser.get_structure('', '10gs.pdb')

ns = NeighborSearch(list(structure.get_atoms()))

clashes = ns.search_all(2.0, level='R')

Activity

  1. peterjc commented on Aug 7, 2017

    @peterjc
    Member

    Object ordering is something which changed drastically from Python 2 to Python 3, and it appears there are still things missing in the PDB code for this (and missing unit test coverage).

    Cross reference #1189 which is related and was fixed after Biopython 1.70 was released.

  2. JoaoRodrigues commented on Aug 8, 2017

    @JoaoRodrigues
    Member

    Can confirm it here on an independent piece of code. I'll have a look. Thanks for assigning this Peter, and thanks @harryjubb for raising it!

  3. JoaoRodrigues commented on Aug 8, 2017

    @JoaoRodrigues
    Member

    @peterjc this also breaks in 1.69 and Python 3. I don't really understand how the comparison was done before, truth be told. The private sorting methods were never called afaik, unless there is some magic somewhere.

    My first guess is that we need to define __gt__ and other comparison operators for each object?

    Edit
    From portingguide.org:
    In Python 3, the cmp style of comparisons was dropped. All objects that implemented __cmp__ must be updated to implement all of the rich methods instead.

  4. etal commented on Aug 8, 2017

    @etal
    Contributor
  5. JoaoRodrigues commented on Aug 8, 2017

    @JoaoRodrigues
    Member

    I think I fixed it. @harryjubb could you test it on your end?

  6. peterjc commented on Aug 9, 2017

    @peterjc
    Member

    Thanks for working on this - I agree a full implementation of sorting with tests is the best plan here 🥇

  7. harryjubb commented on Nov 22, 2017

    @harryjubb
    Author

    Apologies for the long delay: have run a quick test and so far so good! Thanks for fixing it :), I'll keep trying it out.

  8. peterjc commented on Nov 22, 2017

    @peterjc
    Member

    OK, I'll close this issue now - but please do report back if you run into any problems. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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