コード例 #1
0
def capped_distance_array(a, b, cellsize, box=None):
    """Calculate all pairwise distances between *a* and *b* up to *max_dist*

    If given, *box* defines the unit cell size for periodic boundaries
    """
    cga = CellGrid(box, cellsize, a)
    cgb = CellGrid(box, cellsize, b)

    return cellgrid_distance_array(cga, cgb)
コード例 #2
0
    def test_placement(self):
        points = np.array([[0.1, 0.1, 0.1], [0.9, 0.9, 0.9]])

        cg = CellGrid(box=np.ones(3), cellsize=0.25)
        cg.coordinates = points

        assert all(cg._cell_addresses[0] == np.array([0, 0, 0]))
        assert all(cg._cell_addresses[1] == np.array([3, 3, 3]))
        assert cg._cell_indices[0] == 0
        assert cg._cell_indices[1] == 63
コード例 #3
0
    def test_placement(self):
        points = np.array([[0.1, 0.1, 0.1],
                           [0.9, 0.9, 0.9]])

        cg = CellGrid(box=np.ones(3), max_dist=0.25)
        cg.coordinates = points

        assert all(cg._cell_addresses[0] == np.array([0, 0, 0]))
        assert all(cg._cell_addresses[1] == np.array([3, 3, 3]))
        assert cg._cell_indices[0] == 0
        assert cg._cell_indices[1] == 63
コード例 #4
0
    def test_change_max_dist(self):
        """Redefine max dist"""
        cg = CellGrid(box=np.ones(3), cellsize=0.25)

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([4, 4, 4]))
        assert cg._total_cells == 64
        assert len(cg) == 64

        cg.cellsize = 0.50

        assert all(cg._cell_size == np.array([0.50, 0.50, 0.50]))
        assert all(cg._ncells == np.array([2, 2, 2]))
        assert cg._total_cells == 8
        assert len(cg) == 8
コード例 #5
0
    def test_change_box(self):
        """Redefine box"""
        cg = CellGrid(box=np.ones(3), cellsize=0.25)

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([4, 4, 4]))
        assert cg._total_cells == 64
        assert len(cg) == 64

        cg.box = np.ones(3) * 2

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([8, 8, 8]))
        assert cg._total_cells == 512
        assert len(cg) == 512
コード例 #6
0
    def test_change_max_dist(self):
        """Redefine max dist"""
        cg = CellGrid(box=np.ones(3), max_dist=0.25)

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([4, 4, 4]))
        assert cg._total_cells == 64
        assert len(cg) == 64

        cg.max_dist = 0.50

        assert all(cg._cell_size == np.array([0.50, 0.50, 0.50]))
        assert all(cg._ncells == np.array([2, 2, 2]))
        assert cg._total_cells == 8
        assert len(cg) == 8
コード例 #7
0
    def test_change_box(self):
        """Redefine box"""
        cg = CellGrid(box=np.ones(3), max_dist=0.25)

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([4, 4, 4]))
        assert cg._total_cells == 64
        assert len(cg) == 64

        cg.box = np.ones(3) * 2

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([8, 8, 8]))
        assert cg._total_cells == 512
        assert len(cg) == 512
コード例 #8
0
    def test_creation_2(self):
        """Box split into 4, 0.22 needs to round up to 0.25"""
        cg = CellGrid(box=np.ones(3), cellsize=0.22)

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([4, 4, 4]))
        assert cg._total_cells == 64
コード例 #9
0
    def test_creation(self):
        """Box split directly into 4 cells"""
        cg = CellGrid(box=np.ones(3), cellsize=0.25)

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([4, 4, 4]))
        assert cg._total_cells == 64
        assert len(cg) == 64
コード例 #10
0
    def test_create_cg_views(self):
        for prec in self.precs:
            points = np.array(
                [[0.8, 0.8, 0.8], [0.1, 0.1, 0.1], [0.9, 0.9, 0.9]],
                dtype=prec)

            cg = CellGrid(box=np.ones(3), cellsize=0.25, coordinates=points)

            views = cg._views
            assert len(views) == cg._total_cells
            assert all(views[0][0][0] == points[1])
            assert all(views[26][0] == points[0, 2])
コード例 #11
0
    def test_create_cg_views_2(self):
        # 8 cells
        # 1 coordinate in cell 0 (first)
        # 2 coordinates in cell 7 (last)
        for prec in self.precs:
            points = np.array(
                [[0.8, 0.8, 0.8], [0.1, 0.1, 0.1], [0.9, 0.9, 0.9]],
                dtype=prec)

            cg = CellGrid(box=np.ones(3), cellsize=0.50, coordinates=points)

            for cell, exp in zip(cg, [1, 0, 0, 0, 0, 0, 0, 2]):
                assert len(cell) == exp
コード例 #12
0
def capped_self_distance_array(a, cellsize, box, particles_per_cell=30):
    """
    Optimized to identify pair contacts within a distance
    Cellsize is changed based on the maximum of number of 
    particles per cell and provided cellsize
    """
    if particles_per_cell is not None:
        cellsize = min(
            max(cellsize, _per_cell(a.shape[0], box, particles_per_cell)),
            0.33 * min(box))
    cga = CellGrid(box, cellsize, a)

    return cellgrid_self_distance_array(cga)
コード例 #13
0
    def test_sorting(self):
        points = np.array([[0.8, 0.8, 0.8], [0.1, 0.1, 0.1], [0.9, 0.9, 0.9]])

        cg = CellGrid(box=np.ones(3), cellsize=0.25, coordinates=points)

        assert all(cg._original_indices == np.array([1, 0, 2]))
        assert all(cg._order == np.array([1, 0, 2]))
        for val, ref in zip(
                cg._sorted_coords,
                np.array([[0.1, 0.1, 0.1], [0.8, 0.8, 0.8], [0.9, 0.9, 0.9]])):
            assert all(val == ref)

        # Check that sorted coordinates are continuous C
        # important for later work
        assert cg._sorted_coords.flags['C'] == True
コード例 #14
0
    def test_creation_3(self):
        cg = CellGrid(box=np.array([1.0, 1.0, 2.0]), cellsize=0.25)

        assert all(cg._cell_size == np.array([0.25, 0.25, 0.25]))
        assert all(cg._ncells == np.array([4, 4, 8]))
        assert cg._total_cells == 128
コード例 #15
0
    def test_nocoords(self):
        cg = CellGrid(box=np.ones(3), cellsize=0.25)
        cg.coordinates = None

        assert cg.coordinates is None
コード例 #16
0
    def test_nocoords(self):
        cg = CellGrid(box=np.ones(3), max_dist=0.25)
        cg.coordinates = None

        assert cg.coordinates is None