molecule.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:InnerOuterRNN 作者: Chemoinformatics 项目源码 文件源码
def create_directed_graphs(self):
        '''
        :return:
        '''
        self.directed_graphs = np.empty(
            (self.no_of_atoms, self.no_of_atoms - 1, 3), dtype=int)

        # parse all the atoms one by one and get directed graph to that atom
        # as the sink node
        for idx in range(self.no_of_atoms):
            # get shortest path from the root to all the other atoms and then reverse the edges.
            path = nx.single_source_dijkstra_path(self.graph, idx)
            G = nx.DiGraph()
            for i in range(self.no_of_atoms):
                temp = path[i]
                temp.reverse()
                G.add_path(temp)

            # do a topological sort to get a order of atoms with all edges pointing to the root
            topological_order = nx.topological_sort(G)

            sorted_path = np.empty((self.no_of_atoms - 1, 3))

            no_of_incoming_edges = {}
            for i in range(self.no_of_atoms - 1):
                node = topological_order[i]
                edge = (nx.edges(G, node))[0]
                if edge[1] in no_of_incoming_edges:
                    index = no_of_incoming_edges[edge[1]]
                    no_of_incoming_edges[edge[1]] += 1
                else:
                    index = 0
                    no_of_incoming_edges[edge[1]] = 1
                sorted_path[i, :] = [node, edge[1], index]
            self.directed_graphs[idx, :, :] = sorted_path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号