You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print(sys.version)
3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0]
>>> import platform; print(platform.python_implementation()); print(platform.platform())
CPython
Linux-4.18.0-13-generic-x86_64-with-Ubuntu-18.04-bionic
>>> import Bio; print(Bio.__version__)
1.73
Expected behaviour
I should be able to write v = Vector(2, 2, 2) / 2 to divide a vector by a scalar.
Actual behaviour
An error is raised: TypeError: unsupported operand type(s) for /: 'Vector' and 'int'
It appears to be due to the fact that BioPython supplied __div__ for Vectors, but in python 3.x we need to supply __truediv__ and __floordiv__ instead. My current work-around is to call Vector(2, 2, 2).__div__(2)
Activity
platinhom commentedon Feb 1, 2019
You can add
Bio.PDB.Vector.__truediv__ = Bio.PDB.Vector.__div__before use.Biopython should modify the
Bio/PDB/vectors.py, addfrom __future__ import divisionand modify__div__to__truediv__.peterjc commentedon Feb 1, 2019
This clearly highlights that vector division is missing in our unit tests, visible here (the
__contains__method also looks untested):https://codecov.io/gh/biopython/biopython/src/master/Bio/PDB/vectors.py
Ideally we'd add something like @sconstable's example to
Tests/test_PDB_vectors.pyas part of fixing this.@platinhom Your fix sounds perfect - do you want to make a pull request?
platinhom commentedon Feb 1, 2019
@peterjc OK, I have pull a request.
Vector division broken in python 3.x biopython#1914
peterjc commentedon Feb 2, 2019
It turns out a Python 2 and 3 fix was a little different, but you got there with #1920. Well done.
Note for next time, GitHub lets you update a pull request by updating the associated branch, so you don't have to make new pull requests.
Vector division broken in python 3.x #1914
peterjc commentedon Mar 16, 2019
Fixed by #1920, thanks for reporting this issue.