Пример #1
0
def _test(nr_points, dim, bucket_size, radius):
    """Test neighbor search.

    Test neighbor search using the KD tree C module.

    o nr_points - number of points used in test
    o dim - dimension of coords
    o bucket_size - nr of points per tree node
    o radius - radius of search (typically 0.05 or so) 
    """
    # kd tree search
    kdt = _CKDTree.KDTree(dim, bucket_size)
    coords = random((nr_points, dim))
    center = coords[0]
    kdt.set_data(coords)
    kdt.search_center_radius(center, radius)
    r = kdt.get_indices()
    if r is None:
        l1 = 0
    else:
        l1 = len(r)
    l2 = 0
    # now do a manual search to compare results
    for i in range(0, nr_points):
        p = coords[i]
        if _dist(p, center) <= radius:
            l2 = l2 + 1
    if l1 == l2:
        print "Passed."
    else:
        print "Not passed: %i != %i." % (l1, l2)
Пример #2
0
def _neighbor_test(nr_points, dim, bucket_size, radius):
    """ Test all fixed radius neighbor search.

    Test all fixed radius neighbor search using the 
    KD tree C module.

    o nr_points - number of points used in test
    o dim - dimension of coords
    o bucket_size - nr of points per tree node
    o radius - radius of search (typically 0.05 or so) 
    """
    # KD tree search
    kdt = _CKDTree.KDTree(dim, bucket_size)
    coords = random((nr_points, dim))
    kdt.set_data(coords)
    neighbors = kdt.neighbor_search(radius)
    r = [neighbor.radius for neighbor in neighbors]
    if r is None:
        l1 = 0
    else:
        l1 = len(r)
    # now do a slow search to compare results
    neighbors = kdt.neighbor_simple_search(radius)
    r = [neighbor.radius for neighbor in neighbors]
    if r is None:
        l2 = 0
    else:
        l2 = len(r)
    if l1 == l2:
        print "Passed."
    else:
        print "Not passed: %i != %i." % (l1, l2)
Пример #3
0
 def __init__(self, box, bucket_size=10):
     """
     Parameters
     ----------
     box : array-like or ``None``, optional, default ``None``
       Simulation cell dimensions in the form of
       :attr:`MDAnalysis.trajectory.base.Timestep.dimensions` when
       periodic boundary conditions should be taken into account for
       the calculation of contacts.
     bucket_size : int
       Number of entries in leafs of the KDTree. If you suffer poor
       performance you can play around with this number. Increasing the
       `bucket_size` will speed up the construction of the KDTree but
       slow down the search.
     """
     self.dim = 3  # 3D systems
     self.box = None
     self._dm = None  # matrix of central-cell vectors
     self._rm = None  # matrix of normalized reciprocal vectors
     self.initialize_bm(box)
     self.kdt = _CKDTree.KDTree(self.dim, bucket_size)
     self._indices = list()
Пример #4
0
def _neighbor_test(nr_points, dim, bucket_size, radius):
    """Test all fixed radius neighbor search.

    Test all fixed radius neighbor search using the
    KD tree C module.

    Arguments:
     - nr_points: number of points used in test
     - dim: dimension of coords
     - bucket_size: nr of points per tree node
     - radius: radius of search (typically 0.05 or so)

    Returns true if the test passes.
    """
    # KD tree search
    kdt = _CKDTree.KDTree(dim, bucket_size)
    coords = random.random((nr_points, dim))
    kdt.set_data(coords)
    neighbors = kdt.neighbor_search(radius)
    r = [neighbor.radius for neighbor in neighbors]
    if r is None:
        l1 = 0
    else:
        l1 = len(r)
    # now do a slow search to compare results
    neighbors = kdt.neighbor_simple_search(radius)
    r = [neighbor.radius for neighbor in neighbors]
    if r is None:
        l2 = 0
    else:
        l2 = len(r)
    if l1 == l2:
        # print("Passed.")
        return True
    else:
        print("Not passed: %i != %i." % (l1, l2))
        return False
Пример #5
0
def _test(nr_points, dim, bucket_size, radius):
    """Test neighbor search.

    Test neighbor search using the KD tree C module.

    Arguments:
     - nr_points: number of points used in test
     - dim: dimension of coords
     - bucket_size: nr of points per tree node
     - radius: radius of search (typically 0.05 or so)

    Returns true if the test passes.
    """
    # kd tree search
    kdt = _CKDTree.KDTree(dim, bucket_size)
    coords = random.random((nr_points, dim))
    center = coords[0]
    kdt.set_data(coords)
    kdt.search_center_radius(center, radius)
    r = kdt.get_indices()
    if r is None:
        l1 = 0
    else:
        l1 = len(r)
    l2 = 0
    # now do a manual search to compare results
    for i in range(0, nr_points):
        p = coords[i]
        if _dist(p, center) <= radius:
            l2 = l2 + 1
    if l1 == l2:
        # print("Passed.")
        return True
    else:
        print("Not passed: %i != %i." % (l1, l2))
        return False
Пример #6
0
 def __init__(self, dim, bucket_size=1):
     """Initialize KDTree class."""
     self.dim = dim
     self.kdt = _CKDTree.KDTree(dim, bucket_size)
     self.built = 0
Пример #7
0
 def __init__(self, dim, bucket_size=1):
     self.dim = dim
     self.kdt = _CKDTree.KDTree(dim, bucket_size)
     self.built = 0