[Biopython-dev] inconsistent return values Bio.PDB.NeighborSearch.search()

Hongbo Zhu macrozhu at gmail.com
Wed Aug 3 13:47:07 UTC 2011

Hi, python-developers,

In the current version of BioPython (source code as of 3 Aug. 2011), it
seems the outcome of *Bio.PDB.NeighborSearch.search()* is inconsistent if
different levels are specified when the returned list is empty.


> ns.search(center, radius, 'A')
> []
> ns.search(center, radius, 'R') # similar for levels 'C', 'M', 'S'
> IndexError: list index out of range

Obviously, this is because the Bio.PDB.NeighborSearch.search() functions
tries to convert returned list to levels other than 'A' using
function Bio.PDB.Selection.unfold_entities() (see line 92 in
NeighborSearch.py). In function unfold_entities(), the first element of
input argument entity_list is evaluated without entity_list being checked
for emptiness (see line 47 in Selection.py). An IndexError is raised when
entity_list is empty.

So, I think either the length of the returned list in
should be checked before invoking Bio.PDB.Selection.unfold_entities(), or
the function Bio.PDB.Selection.unfold_entities() should be revised so that
it simply returns an empty list if the argument entity_list is empty. I
prefer the latter solution because this would also fix other similar
situations when  Bio.PDB.Selection.unfold_entities() is invoked in other

And it seems "Sorry, entering bugs into the product Biopython has been

Hongbo Zhu

More information about the Biopython-dev mailing list