Exemplo n.º 1
0
    def _normalize_neighbors(self, data):
        """Function to invert importance of neighbor shells.

        The `catlearn_neighborlist` function returns an array with the neighbor
        shell of atom pairs. The further away two atoms are, the larger the
        number of the neighbor shell. This inverts this relationship so atoms
        that are close to oneanother have larger values.

        Parameters
        ----------
        data : object
            Target data object from which to generate features.

        Returns
        -------
        connection_matrix : array
            The shell weighted connection_matrix.
        """
        # There will be some divide by zero warnings that are handled later.
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")

            # Calculate the matrix representation.
            connection_matrix = catlearn_neighborlist(
                data, max_neighbor=self.max_neighbor)

            # Invert scale of neighbor shells.
            connection_matrix = np.max(connection_matrix) / connection_matrix
            # Replace inf values from zero divide.
            np.place(connection_matrix, connection_matrix == np.inf, 0.)

        con = np.zeros((self.atom_len, self.atom_len))
        con[:len(data), :len(data)] = connection_matrix

        return con
Exemplo n.º 2
0
    def test_catlearn_nl(self):
        """Function to test the ase wrapper."""
        # Connect database generated by a GA search.
        gadb = DataConnection('{}/data/gadb.db'.format(wkdir))

        # Get all relaxed candidates from the db file.
        all_cand = gadb.get_all_relaxed_candidates(use_extinct=False)

        nl1 = catlearn_neighborlist(all_cand[0], max_neighbor=1)
        self.assertEqual((len(all_cand[0]), len(all_cand[0])), np.shape(nl1))
        nl4 = catlearn_neighborlist(all_cand[0], max_neighbor=4)
        self.assertFalse(np.allclose(nl1, nl4))

        nl5 = catlearn_neighborlist(all_cand[0], max_neighbor=5)
        nlfull = catlearn_neighborlist(all_cand[0], max_neighbor='full')
        self.assertFalse(np.allclose(nl4, nl5))
        self.assertTrue(np.allclose(nl5, nlfull))
Exemplo n.º 3
0
    def get_autocorrelation(self, atoms):
        """Return the autocorrelation fingerprint for a molecule."""
        connectivity = catlearn_neighborlist(atoms)

        G = nx.Graph(connectivity)
        distance_matrix = nx.floyd_warshall_numpy(G)
        Bm = np.zeros(distance_matrix.shape)

        n = len(self.parameters)
        W = list_mendeleev_params(atoms.numbers, self.parameters).T

        fingerprint = np.zeros(n * (self.dstar + 1))
        for dd in range(self.dstar + 1):
            B = Bm.copy()
            B[distance_matrix == dd] = 1
            AC = np.dot(np.dot(W, B), W.T).diagonal()
            fingerprint[n * dd:n * (dd + 1)] = AC

        return fingerprint