graphinvent/MolecularGraph.py
def breadth_first_search(self, node_ranking : list,
                             node_init : int=0) -> list:
        """
        Starting from the specified `node_init` in the graph, uses a breadth-
        first search (BFS) algorithm to find all adjacent nodes, returning an
        ordered list of these nodes. Prioritizes the nodes based on the input
        `node_ranking`. The function uses the edge feature tensor to find
        adjacent nodes.

        Args:
        ----
            node_ranking (list) : Contains the ranking of all the nodes in the
                                  graph (e.g. the canonical RDKit node ranking,
                                  or a random ranking).
            node_init (int)     : Index of node to start the BFS from. Default 0.

        Returns:
        -------
            nodes_visited (list) : BFS ordering for nodes in the molecular graph.
        """
        nodes_visited      = [node_init]
        last_nodes_visited = [node_init]

        # loop until all nodes have been visited
        while len(nodes_visited) < self.n_nodes:
            neighboring_nodes = []

            for node in last_nodes_visited:
                neighbor_nodes = []
                for bond_type in range(self.constants.n_edge_features):
                    neighbor_nodes.extend(list(
                        np.nonzero(self.edge_features[node, :, bond_type])[0]
                    ))
                new_neighbor_nodes = list(
                    set(neighbor_nodes) - (set(neighbor_nodes) & set(nodes_visited))
                )
                node_importance    = [node_ranking[neighbor_node] for
                                      neighbor_node in new_neighbor_nodes]

                # check all neighboring nodes and sort in order of importance
                while sum(node_importance) != -len(node_importance):
                    next_node = node_importance.index(max(node_importance))
                    neighboring_nodes.append(new_neighbor_nodes[next_node])
                    node_importance[next_node] = -1

            # append the new, sorted neighboring nodes to list of visited nodes
            nodes_visited.extend(set(neighboring_nodes))

            # update the list of most recently visited nodes
            last_nodes_visited = set(neighboring_nodes)

        return nodes_visited

        Starting from the specified `node_init` in the graph, uses a breadth-
        first search (BFS) algorithm to find all adjacent nodes, returning an
        ordered list of these nodes. Prioritizes the nodes based on the input
        `node_ranking`. The function uses the edge feature tensor to find
        adjacent nodes.

        Args:
        ----
            node_ranking (list) : Contains the ranking of all the nodes in the
                                  graph (e.g. the canonical RDKit node ranking,
                                  or a random ranking).
            node_init (int)     : Index of node to start the BFS from. Default 0.

        Returns:
        -------
            nodes_visited (list) : BFS ordering for nodes in the molecular graph.
        
Starting from the specified `node_init` in the graph, uses a breadth
first search (BFS) algorithm to find all adjacent nodes, returning an
ordered list of these nodes. Prioritizes the nodes based on the input
`node_ranking`. The function uses the edge feature tensor to find
adjacent nodes.
Starting from the specified ` node_init ` in the graph uses a breadth first search ( BFS ) algorithm to find all adjacent nodes returning an ordered list of these nodes . Prioritizes the nodes based on the input ` node_ranking ` . The function uses the edge feature tensor to find adjacent nodes .
def breadth_first_search(self, node_ranking : list,
                             node_init : int=0) -> list:
        nodes_visited      = [node_init]
        last_nodes_visited = [node_init]
        while len(nodes_visited) < self.n_nodes:
            neighboring_nodes = []
            for node in last_nodes_visited:
                neighbor_nodes = []
                for bond_type in range(self.constants.n_edge_features):
                    neighbor_nodes.extend(list(
                        np.nonzero(self.edge_features[node, :, bond_type])[0]
                    ))
                new_neighbor_nodes = list(
                    set(neighbor_nodes) - (set(neighbor_nodes) & set(nodes_visited))
                )
                node_importance    = [node_ranking[neighbor_node] for
                                      neighbor_node in new_neighbor_nodes]
                while sum(node_importance) != -len(node_importance):
                    next_node = node_importance.index(max(node_importance))
                    neighboring_nodes.append(new_neighbor_nodes[next_node])
                    node_importance[next_node] = -1
            nodes_visited.extend(set(neighboring_nodes))
            last_nodes_visited = set(neighboring_nodes)
        return nodes_visited
def breadth_first_search ( self , node_ranking : list , node_init : int = 0 ) -> list : nodes_visited = [ node_init ] last_nodes_visited = [ node_init ] while len ( nodes_visited ) < self . n_nodes : neighboring_nodes = [ ] for node in last_nodes_visited : neighbor_nodes = [ ] for bond_type in range ( self . constants . n_edge_features ) : neighbor_nodes . extend ( list ( np . nonzero ( self . edge_features [ node , : , bond_type ] ) [ 0 ] ) ) new_neighbor_nodes = list ( set ( neighbor_nodes ) - ( set ( neighbor_nodes ) & set ( nodes_visited ) ) ) node_importance = [ node_ranking [ neighbor_node ] for neighbor_node in new_neighbor_nodes ] while sum ( node_importance ) != - len ( node_importance ) : next_node = node_importance . index ( max ( node_importance ) ) neighboring_nodes . append ( new_neighbor_nodes [ next_node ] ) node_importance [ next_node ] = - 1 nodes_visited . extend ( set ( neighboring_nodes ) ) last_nodes_visited = set ( neighboring_nodes ) return nodes_visited
Starting from the specified `node_init` in the graph, uses a breadth
first search (BFS) algorithm to find all adjacent nodes, returning an
ordered list of these nodes.
Starting from the specified ` node_init ` in the graph uses a breadth first search ( BFS ) algorithm to find all adjacent nodes returning an ordered list of these nodes .
"""
        Starting from the specified `node_init` in the graph, uses a breadth-
        first search (BFS) algorithm to find all adjacent nodes, returning an
        ordered list of these nodes. Prioritizes the nodes based on the input
        `node_ranking`. The function uses the edge feature tensor to find
        adjacent nodes.

        Args:
        ----
            node_ranking (list) : Contains the ranking of all the nodes in the
                                  graph (e.g. the canonical RDKit node ranking,
                                  or a random ranking).
            node_init (int)     : Index of node to start the BFS from. Default 0.

        Returns:
        -------
            nodes_visited (list) : BFS ordering for nodes in the molecular graph.
        """ # loop until all nodes have been visited # check all neighboring nodes and sort in order of importance # append the new, sorted neighboring nodes to list of visited nodes # update the list of most recently visited nodes
nodes_visited (list) : BFS ordering for nodes in the molecular graph.
nodes_visited ( list ) : BFS ordering for nodes in the molecular graph .
self
node_ranking
list
Contains the ranking of all the nodes in the
graph .
Contains the ranking of all the nodes in the graph .
node_init
int
Index of node to start the BFS from. Default 0.
Index of node to start the BFS from . Default 0 .