Esempio n. 1
0
    def test_ase_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)

        nl = ase_neighborlist(all_cand[0])

        self.assertEqual(len(all_cand[0]), len(nl))
Esempio n. 2
0
    def test_feature_base(self):
        """Test the base feature generator."""
        gadb = DataConnection('{}/data/gadb.db'.format(wkdir))
        all_cand = gadb.get_all_relaxed_candidates()

        f = BaseGenerator()
        nl = ase_neighborlist(all_cand[0])
        assert f.get_neighborlist(all_cand[0]) == nl

        pos = all_cand[0].get_positions()
        assert np.allclose(f.get_positions(all_cand[0]), pos)
Esempio n. 3
0
def ase_to_networkx(atoms, cutoffs=None):
    """Make the NetworkX graph form ASE atoms object.

    The graph is dependent on the generation of the neighborlist. Currently
    this is handled by the version implemented in ASE.

    Parameters
    ----------
    atoms : object
        An ASE atoms object.
    cutoffs : list
        A list of distance paramteres for each atom.

    Returns
    -------
    atoms_graph : object
        A networkx graph object.
    """
    msg = 'Please pass an ASE atoms object, not a {}'.format(type(atoms))
    assert isinstance(atoms, Atoms), msg

    an = atoms.get_atomic_numbers()
    ats = list(range(len(an)))

    atoms_graph = nx.Graph()
    atoms_graph.add_nodes_from(ats)
    for n in atoms_graph:
        atoms_graph.add_node(n, atomic_number=an[n])

    extend_atoms_class(atoms)
    nl = atoms.get_neighborlist()
    if nl is None:
        nl = ase_neighborlist(atoms, cutoffs)

    for i in nl:
        tup = ((i, nl[i][j]) for j in range(len(nl[i])))
        atoms_graph.add_edges_from(tup)

    return atoms_graph
Esempio n. 4
0
    def make_neighborlist(self, candidate, neighbor_number=1):
        """Function to generate the neighborlist.

        Parameters
        ----------
        candidate : object
            Target data object on which to generate neighbor list.
        dx : dict
            Buffer to calculate nearest neighbor pairs in dict format:
            dx = {atomic_number: buffer}.
        neighbor_number : int
            Neighbor shell.
        """
        if self.dtype == 'atoms':
            extend_atoms_class(candidate)
            nl = ase_neighborlist(candidate)
        else:
            raise NotImplementedError('{} data type not implemented.'.format(
                self.dtype))

        candidate.set_neighborlist(nl)

        return nl