molecule.py 文件源码

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

项目:InnerOuterRNN 作者: Chemoinformatics 项目源码 文件源码
def reduce_graph_rings(self):
        '''
        :return:
        '''
        cycle_name_format = "R_{:}"
        index = 0
        cycle = self.get_cycle()

        while cycle:
            cycle_name = cycle_name_format.format(index)
            self.graph.add_node(cycle_name)

            # ebunch = zip(cycle, (cycle[1:] + cycle[:1]))
            self.graph.remove_edges_from(cycle)

            for node1, node2 in cycle:
                if isinstance(node1, six.string_types):
                    self.graph.add_edge(node1, cycle_name,
                                        attr_dict={"bond_features": Molecule.bond_features_between_contract_rings()})
                    continue

                neighbours = self.graph.neighbors(node1)
                if not neighbours:
                    continue
                for neighbour in neighbours:
                    edge_attrs = self.get_bond_features(neighbour, node1)
                    self.graph.add_edge(neighbour, cycle_name, attr_dict={
                        "bond_features": edge_attrs})
                    self.graph.remove_edge(node1, neighbour)

            nx.set_node_attributes(self.graph, "atom_features",
                                   values={cycle_name: Molecule.atom_features_of_contract_rings(0)})

            for node1, node2 in cycle:
                if not isinstance(node1, six.string_types):
                    self.graph.remove_node(node1)
            index += 1
            cycle = self.get_cycle()

        self.graph = nx.convert_node_labels_to_integers(self.graph,
                                                        first_label=0)

        nx.draw(self.graph)
        self.no_of_atoms = len(self.graph)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号