def test_neighbor_list_shape(self):
        """
    Simple test that Neighbor Lists have right shape.
    """
        nblist_featurizer = NeighborListAtomicCoordinates()
        N = self.mol.GetNumAtoms()
        coords = get_coords(self.mol)
        x_bins, y_bins, z_bins = get_cells(coords,
                                           nblist_featurizer.neighbor_cutoff)

        nblist_featurizer = NeighborListAtomicCoordinates()
        nblist = nblist_featurizer._featurize(self.mol)[1]
        assert isinstance(nblist, dict)
        assert len(nblist.keys()) == N
        for (atom, neighbors) in nblist.items():
            assert isinstance(atom, int)
            assert isinstance(neighbors, list)
            assert len(neighbors) <= N

        # Do a manual distance computation and make
        for i in range(N):
            for j in range(N):
                dist = np.linalg.norm(coords[i] - coords[j])
                print("Distance(%d, %d) = %f" % (i, j, dist))
                if dist < nblist_featurizer.neighbor_cutoff and i != j:
                    assert j in nblist[i]
                else:
                    assert j not in nblist[i]
Exemplo n.º 2
0
  def test_neighbor_list_shape(self):
    """
    Simple test that Neighbor Lists have right shape.
    """
    nblist_featurizer = NeighborListAtomicCoordinates()
    N = self.mol.GetNumAtoms()
    coords = get_coords(self.mol)
    x_bins, y_bins, z_bins = get_cells(coords, nblist_featurizer.neighbor_cutoff)

    nblist_featurizer = NeighborListAtomicCoordinates()
    nblist = nblist_featurizer._featurize(self.mol)[1]
    assert isinstance(nblist, dict)
    assert len(nblist.keys()) == N
    for (atom, neighbors) in nblist.items():
      assert isinstance(atom, int)
      assert isinstance(neighbors, list)
      assert len(neighbors) <= N

    # Do a manual distance computation and make 
    for i in range(N):
      for j in range(N):
        dist = np.linalg.norm(coords[i] - coords[j])
        print("Distance(%d, %d) = %f" % (i, j, dist))
        if dist < nblist_featurizer.neighbor_cutoff and i != j:
          assert j in nblist[i]
        else:
          assert j not in nblist[i]
Exemplo n.º 3
0
  def test_put_atoms_in_cells(self):
    """
    Test that atoms are placed into correct cells.
    """
    # As in previous example, coordinates span size-2 cube on (-1, 1)
    coords = np.array(
        [[1., 1., 1.],
         [-1., -1., -1.]])
    # Set cell size (neighbor_cutoff) at 1 angstrom.
    neighbor_cutoff = 1
    # We should get 2 bins in each dimension
    x_bins, y_bins, z_bins = get_cells(coords, neighbor_cutoff)

    cell_to_atoms, atom_to_cell = put_atoms_in_cells(
        coords, x_bins, y_bins, z_bins)

    # Both cell_to_atoms and atom_to_cell are dictionaries
    assert isinstance(cell_to_atoms, dict)
    assert isinstance(atom_to_cell, dict)

    # atom_to_cell should be of len 2 since 2 atoms
    assert len(atom_to_cell) == 2

    # cell_to_atoms should be of len 8 since 8 cells total.
    assert len(cell_to_atoms) == 8

    # We have two atoms. The first is in highest corner (1,1,1)
    # Second atom should be in lowest corner (0, 0, 0)
    assert atom_to_cell[0] == (1, 1, 1)
    assert atom_to_cell[1] == (0, 0, 0)

    # (1,1,1) should contain atom 0. (0, 0, 0) should contain atom 1.
    # Everything else should be an empty list
    for cell, atoms in cell_to_atoms.items():
      if cell == (1, 1, 1):
        assert atoms == [0]
      elif cell == (0, 0, 0):
        assert atoms == [1]
      else:
        assert atoms == []
    def test_get_cells(self):
        """
    Test that coordinates are split into cell appropriately.
    """
        # The coordinates span the cube of side-length 2 set on (-1, 1)
        coords = np.array([[1., 1., 1.], [-1., -1., -1.]])
        # Set cell size (neighbor_cutoff) at 1 angstrom.
        neighbor_cutoff = 1
        # We should get 2 bins in each dimension
        x_bins, y_bins, z_bins = get_cells(coords, neighbor_cutoff)

        # Check bins are lists
        assert isinstance(x_bins, list)
        assert isinstance(y_bins, list)
        assert isinstance(z_bins, list)

        assert len(x_bins) == 2
        assert x_bins == [(-1.0, 0.0), (0.0, 1.0)]
        assert len(y_bins) == 2
        assert y_bins == [(-1.0, 0.0), (0.0, 1.0)]
        assert len(z_bins) == 2
        assert z_bins == [(-1.0, 0.0), (0.0, 1.0)]
    def test_put_atoms_in_cells(self):
        """
    Test that atoms are placed into correct cells.
    """
        # As in previous example, coordinates span size-2 cube on (-1, 1)
        coords = np.array([[1., 1., 1.], [-1., -1., -1.]])
        # Set cell size (neighbor_cutoff) at 1 angstrom.
        neighbor_cutoff = 1
        # We should get 2 bins in each dimension
        x_bins, y_bins, z_bins = get_cells(coords, neighbor_cutoff)

        cell_to_atoms, atom_to_cell = put_atoms_in_cells(
            coords, x_bins, y_bins, z_bins)

        # Both cell_to_atoms and atom_to_cell are dictionaries
        assert isinstance(cell_to_atoms, dict)
        assert isinstance(atom_to_cell, dict)

        # atom_to_cell should be of len 2 since 2 atoms
        assert len(atom_to_cell) == 2

        # cell_to_atoms should be of len 8 since 8 cells total.
        assert len(cell_to_atoms) == 8

        # We have two atoms. The first is in highest corner (1,1,1)
        # Second atom should be in lowest corner (0, 0, 0)
        assert atom_to_cell[0] == (1, 1, 1)
        assert atom_to_cell[1] == (0, 0, 0)

        # (1,1,1) should contain atom 0. (0, 0, 0) should contain atom 1.
        # Everything else should be an empty list
        for cell, atoms in cell_to_atoms.items():
            if cell == (1, 1, 1):
                assert atoms == [0]
            elif cell == (0, 0, 0):
                assert atoms == [1]
            else:
                assert atoms == []
Exemplo n.º 6
0
  def test_get_cells(self):
    """
    Test that coordinates are split into cell appropriately.
    """
    # The coordinates span the cube of side-length 2 set on (-1, 1)
    coords = np.array(
        [[1., 1., 1.],
         [-1., -1., -1.]])
    # Set cell size (neighbor_cutoff) at 1 angstrom.
    neighbor_cutoff = 1
    # We should get 2 bins in each dimension
    x_bins, y_bins, z_bins = get_cells(coords, neighbor_cutoff)

    # Check bins are lists
    assert isinstance(x_bins, list)
    assert isinstance(y_bins, list)
    assert isinstance(z_bins, list)

    assert len(x_bins) == 2
    assert x_bins ==[(-1.0, 0.0), (0.0, 1.0)] 
    assert len(y_bins) == 2
    assert y_bins ==[(-1.0, 0.0), (0.0, 1.0)] 
    assert len(z_bins) == 2
    assert z_bins ==[(-1.0, 0.0), (0.0, 1.0)]