forked from biopython/biopython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_PDB_KDTree.py
50 lines (43 loc) · 1.68 KB
/
test_PDB_KDTree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 2009-2010 by Eric Talevich. All rights reserved.
# Revisions copyright 2010 by Peter Cock. All rights reserved.
#
# Converted by Eric Talevich from an older unit test copyright 2002
# by Thomas Hamelryck.
#
# This code is part of the Biopython distribution and governed by its
# license. Please see the LICENSE file that should have been included
# as part of this package.
"""Unit tests for those parts of the Bio.PDB module using Bio.KDTree."""
import unittest
try:
from numpy.random import random
except ImportError:
from Bio import MissingExternalDependencyError
raise MissingExternalDependencyError(\
"Install NumPy if you want to use Bio.PDB.")
try:
from Bio.KDTree import _CKDTree
except ImportError:
from Bio import MissingExternalDependencyError
raise MissingExternalDependencyError(\
"C module in Bio.KDTree not compiled")
from Bio.PDB.NeighborSearch import NeighborSearch
class NeighborTest(unittest.TestCase):
def test_neighbor_search(self):
"""NeighborSearch: Find nearby randomly generated coordinates.
Based on the self test in Bio.PDB.NeighborSearch.
"""
class RandomAtom:
def __init__(self):
self.coord = 100 * random(3)
def get_coord(self):
return self.coord
for i in range(0, 20):
atoms = [RandomAtom() for j in range(100)]
ns = NeighborSearch(atoms)
hits = ns.search_all(5.0)
self.assertTrue(isinstance(hits, list), hits)
self.assertTrue(len(hits) >= 0, hits)
if __name__ == '__main__':
runner = unittest.TextTestRunner(verbosity=2)
unittest.main(testRunner=runner)