Repository navigation
moved self-test from Vector.py - #1127
Conversation
deleted self test and placed in `Tests/test_PDB.py`
moved `Bio/PDB/Vector.py` test inside method test_Vector
|
|
||
| class Vector(object): | ||
| """3D vector.""" | ||
| "3D vector" |
There was a problem hiding this comment.
These should be triple-quotes as per the docstring standard PEP257 https://www.python.org/dev/peps/pep-0257/
There was a problem hiding this comment.
This is why the style check is failing under TravisCI, lots of entries like this from the pydocstyle tool;
D300: Use """triple double quotes""" (found '-quotes)
You can install this code checking tool with pip install pydocstyle
| import numpy | ||
|
|
||
|
|
||
| def m2rotaxis(m): |
There was a problem hiding this comment.
Why are you removing this function (and the others after it) from Bio.Vector? They are part of the module's public API and should stay here.
There was a problem hiding this comment.
This explains why many of the tests are failing on TravisCI, e.g.
======================================================================
ERROR: test_DSSP_tool
----------------------------------------------------------------------
Traceback (most recent call last):
File "run_tests.py", line 436, in runTest
suite = loader.loadTestsFromName(name)
File "/opt/python/2.7.9/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
module = __import__('.'.join(parts_copy))
File "/home/travis/build/biopython/biopython/Tests/test_DSSP_tool.py", line 17, in <module>
from Bio.PDB import PDBParser
File "/home/travis/build/biopython/biopython/build/lib.linux-x86_64-2.7/Bio/PDB/__init__.py", line 27, in <module>
from .Polypeptide import PPBuilder, CaPPBuilder, is_aa, standard_aa_names
File "/home/travis/build/biopython/biopython/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.py", line 60, in <module>
from Bio.PDB.Vector import calc_dihedral, calc_angle
ImportError: cannot import name calc_dihedral
There was a problem hiding this comment.
Apologies, I thought they were testing methods since they were outside the Class definition.
I'll sort them out this weekend.
re-instated methods outside Vector class and removed the self-test
added `test_Vector()` method with more tests
|
One side note, when I test for the division operand I get this error: where |
corrected the docstring
moved `from numpy.random import random`
|
If division works under Python 2, that's likely a bug we should fix under Python 3. |
|
There are still some minor style issue being picked up by TravisCI running flake8, You should be able to install flake8 locally using |
|
|
||
| def rotaxis2m(theta, vector): | ||
| """Calculate a left multiplying rotation matrix that rotates | ||
| """Rotaxi2m method. |
There was a problem hiding this comment.
How about Calculate left multiplying rotation matrix as the docstring one-line summary?
|
|
||
| def refmat(p, q): | ||
| """Return a (left multiplying) matrix that mirrors p onto q. | ||
| """ |
There was a problem hiding this comment.
The first line of the docstring should be on the triple-quote line, see PEP257 https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings
| finally: | ||
| os.remove(filename) | ||
|
|
||
| def test_deepcopy_of_structure_with_disorder(self): |
There was a problem hiding this comment.
You seem to have accidentally removed this PDB test for deepcopy?
| self.assertEqual(calc_dihedral(v1, v2, v3, v4), 1.5707963267948966) | ||
| ref = refmat(v1, v3) | ||
| rot = rotmat(v1, v3) | ||
| self.assertEqual(ref[0].all(), numpy.array([1.0, 0.0, 0.0]).all()) |
There was a problem hiding this comment.
I think the .all() bits should be removed, note numpy.array([1.0, 0.0, 0.0]).all() u
is just False.
There was a problem hiding this comment.
This is a behavior that I don't understand.
When I launch the unittest of this script from my local machine, the entire test compiles successfully without a warning.
Is it just this one line or all the others that make a comparison with a numpy.array?
There was a problem hiding this comment.
I think you should remove every .all() in your tests, it just reduces an array to a single boolean value (usually True but it would be False for a zero vector).
$ python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = numpy.random.random(3)
>>> b = numpy.random.random(3)
>>> a == b#
array([False, False, False], dtype=bool)
>>> a.all() == b.all()
True
>>> a.all()
True
>>> b.all()
True
| self.assertEqual(v1.normsq(), 1.0) | ||
| v1[2] = 10 | ||
| self.assertEqual(v1.__getitem__(2), 10) | ||
| angle = random() * numpy.pi |
There was a problem hiding this comment.
Can this onwards be a separate test method?
There was a problem hiding this comment.
Do you mean the part from line 1184 or 1187?
There was a problem hiding this comment.
Lines 1198 to 1193 looked self contained:
def test_Vector(self):
...
angle = random() * numpy.pi
axis = Vector(random(3) - random(3))
axis.normalize()
m = rotaxis(angle, axis)
cangle, caxis = m2rotaxis(m)
self.assertAlmostEqual((angle - cangle), 0.0)
self.assertEqual((axis - caxis).get_array().all(), numpy.array([0, 0, 0]).all())Could you do:
def test_Vector(self):
...
def test_angles(self):
angle = random() * numpy.pi
axis = Vector(random(3) - random(3))
axis.normalize()
m = rotaxis(angle, axis)
cangle, caxis = m2rotaxis(m)
self.assertAlmostEqual((angle - cangle), 0.0)
self.assertEqual((axis - caxis).get_array().all(), numpy.array([0, 0, 0]).all())|
TravisCI is failing currently on Python 3.6 with: As noted earlier, removing the |
| from Bio.PDB import make_dssp_dict | ||
| from Bio.PDB import DSSP | ||
| from Bio.PDB.NACCESS import process_asa_data, process_rsa_data | ||
| from numpy.random import random |
There was a problem hiding this comment.
Please move this next to the other numpy imports, e.g. after line 26:
from numpy.linalg import svd, det|
The style failure looks easy to fix, You should be able to install this code checking tool locally with |
|
The line |
|
I understand now why you were trying to use >>> import numpy
>>> a = numpy.array([1.0, 2.0, 3.0])
>>> b = numpy.array([1.0, 2.0, 3.0])
>>> a == b
array([ True, True, True], dtype=bool)
>>> numpy.array_equal(a, b)
TrueMore generally, using |
|
Apologies for the error in The matter with At the moment I'm trying both options to test |
|
Before updating this PR, there is one problem. If I run the following commands in the Python console I get the displayed result: >>> import numpy
>>> from Bio.PDB import Vector
>>> from numpy.random import random
>>> from Bio.PDB import rotaxis,m2rotaxis
>>> angle = random() * numpy.pi
>>> axis = Vector(random(3) - random(3))
>>> axis.normalize()
>>> m = rotaxis(angle, axis)
>>> cangle, caxis = m2rotaxis(m)
>>> axis
<Vector 0.08, -0.10, -0.99>
>>> caxis
<Vector 0.08, -0.10, -0.99>
>>> numpy.array_equal((axis-caxis).get_array(),numpy.array([0,0,0]))
TrueOn the other hand, I get the following if run in Powershell: Do you think it depends on the environment?
|
|
You can give a second argument like Try using something like this: self.assertTrue(numpy.array_equal((axis - caxis).get_array(), numpy.array([0, 0, 0])),
"Expected zero vector, got %r" % (axis - caxis).get_array())I've not checked this but isn't this just trying to compare self.assertAlmostEqual(axis, caxis, places=3) |
|
Probably what is happening is that |
|
I started with the second suggestion since it seems logical, but there is this problem now: It seems that I changed the test to: self.assertTrue(numpy.array_equal(axis.get_array(), caxis.get_array()),
"Expected zero vector, got %r" % (axis - caxis).get_array())but each time the arrays have similar values but not equal. In this case the test will fail more frequently that it should because of a matter of precision. Does having the |
|
If With the How about something like this (again, untested)? self.assertAlmostEqual(axis.get_array(), caxis.get_array(), places=3) |
self.assertAlmostEqual(axis.get_array(), caxis.get_array(), places=3)doesn't work either because two I'll stick with the message and commit the new files. |
|
How about: self.assertTrue(numpy.allclose(axis.get_array(), caxis.get_array(),
"Want %r and %r to be almost equal" % (axis, caxis))The |
Codecov Report
@@ Coverage Diff @@
## master #1127 +/- ##
==========================================
- Coverage 80.81% 79.64% -1.17%
==========================================
Files 322 322
Lines 49446 51001 +1555
==========================================
+ Hits 39961 40622 +661
- Misses 9485 10379 +894
Continue to review full report at Codecov.
|
|
Don't worry about the CodeCov numbers - it seems to be a little unreliable at the moment because I made some setting changes on the master branch. |
| "Bio.Blast.Applications", | ||
| "Bio.Emboss.Applications", | ||
| "Bio.GenBank", | ||
| "Bio.Graphics.GenomeDiagram._Colors", |
There was a problem hiding this comment.
Please remove this change as it not relevant to the PDB Vector test work.
|
Other than the extra change to |
|
|
|
Thank you :) |
Squashed commit of pull request biopython#1127
In reference to issue #820, I've moved the self test part of
Bio/PDB/Vector.pyintoTests/test_PDB.py.