[Biopython-dev] Bio.PDB on Python 3
Eric Talevich
eric.talevich at gmail.com
Wed Oct 20 02:52:27 UTC 2010
On Tue, Oct 19, 2010 at 10:01 PM, Eric Talevich <eric.talevich at gmail.com> wrote:
> On Mon, Aug 16, 2010 at 9:47 AM, Peter <biopython at maubp.freeserve.co.uk> wrote:
>> Hi all,
>>
>> A while back I installed NumPy from their svn under Python 3, so that I
>> could test more of Biopython. I hadn't really looked at Bio.PDB until
>> recently because test_PDB.py depended on Bio.KDTree which needs
>> some C code to be compiled (which we haven't tried yet).
>>
> [...]
>>
>> This has revealed there are at least two issues with Bio.PDB to be
>> addressed (see below).
>>
> [...]
>>
>> ======================================================================
>> ERROR: test_ExposureCN (__main__.Exposure)
>> HSExposureCN.
>> ----------------------------------------------------------------------
>> Traceback (most recent call last):
>> File "test_PDB.py", line 612, in setUp
>> structure=PDBParser(PERMISSIVE=True).get_structure('X', pdb_filename)
>> File "/home/xxx/lib/python3.1/site-packages/Bio/PDB/PDBParser.py",
>> line 64, in get_structure
>> self._parse(file.readlines())
>> File "/home/xxx/lib/python3.1/site-packages/Bio/PDB/PDBParser.py",
>> line 84, in _parse
>> self.trailer=self._parse_coordinates(coords_trailer)
>> File "/home/xxx/lib/python3.1/site-packages/Bio/PDB/PDBParser.py",
>> line 200, in _parse_coordinates
>> fullname, serial_number, element)
>> File "/home/xxx/lib/python3.1/site-packages/Bio/PDB/StructureBuilder.py",
>> line 185, in init_atom
>> duplicate_atom=residue[name]
>> TypeError: 'DisorderedResidue' object is not subscriptable
>>
>
[...]
>
> So here's what I'm doing:
> - In DisorderedEntityWrapper, implement __getitem__(self, id) such
> that self.selected_child[id] is returned instead. This fixes most of
> the errors but produces/uncovers three new ones. These new errors also
> seem to indicate that magic methods on DisorderedEntityWrapper aren't
> being handled through __getattr__ in Python 3.
> - Fix the new errors.
>
>
> I'll post the patch here before pushing it upstream once I get it working.
As if we didn't have a better mechanism for this... here's a patch
that seems to work on both Pythons.
-Eric
diff --git a/Bio/PDB/Entity.py b/Bio/PDB/Entity.py
index ed17308..af2fcc7 100644
--- a/Bio/PDB/Entity.py
+++ b/Bio/PDB/Entity.py
@@ -165,10 +165,27 @@ class DisorderedEntityWrapper:
raise AttributeError
return getattr(self.selected_child, method)
+ def __getitem__(self, id):
+ "Return the child with the given id."
+ return self.selected_child[id]
+
def __setitem__(self, id, child):
"Add a child, associated with a certain id."
self.child_dict[id]=child
+ def __iter__(self):
+ "Return the number of children."
+ return iter(self.selected_child)
+
+ def __len__(self):
+ "Return the number of children."
+ return len(self.selected_child)
+
+ def __sub__(self, other):
+ """Subtraction with another object."""
+ return self.selected_child - other
+
+
# Public methods
def get_id(self):
More information about the Biopython-dev
mailing list