Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
harryjubb opened this issue Aug 7, 2017 · 8 comments
Assignees

Comments

@harryjubb
Copy link

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')
@peterjc
Copy link
Member

peterjc commented Aug 7, 2017

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.

@JoaoRodrigues
Copy link
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!

@JoaoRodrigues
Copy link
Member

JoaoRodrigues commented Aug 8, 2017

@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.

@etal
Copy link
Contributor

etal commented Aug 8, 2017 via email

@JoaoRodrigues
Copy link
Member

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

@peterjc
Copy link
Member

peterjc commented Aug 9, 2017

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

@harryjubb
Copy link
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.

@peterjc
Copy link
Member

peterjc commented Nov 22, 2017

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants