def find(reaction_tree: ReactionTree) -> None:
        """
        Find the repeating patterns and mark the nodes

        :param reaction_tree: the reaction tree to process
        """
        for node in reaction_tree.reactions():
            # We are only interesting of starting at the very first reaction
            if any(reaction_tree.graph[mol] for mol in node.reactants[0]):
                continue
            actions = _RepeatingPatternIdentifier._list_reactions(
                reaction_tree, node)
            if len(actions) < 5:
                continue

            hashes = [
                hash_reactions([rxn1, rxn2], sort=False)
                for rxn1, rxn2 in zip(actions[:-1:2], actions[1::2])
            ]
            for idx, (hash1, hash2) in enumerate(zip(hashes[:-1], hashes[1:])):
                if hash1 == hash2:
                    _RepeatingPatternIdentifier._hide_reaction(
                        reaction_tree, actions[idx * 2])
                    _RepeatingPatternIdentifier._hide_reaction(
                        reaction_tree, actions[idx * 2 + 1])
                    reaction_tree.has_repeating_patterns = True
                # The else-clause prevents removing repeating patterns in the middle of a route
                else:
                    break
示例#2
0
 def _score_reaction_tree(self, tree: ReactionTree) -> float:
     reactions = list(tree.reactions())
     if not reactions:
         return 0.0
     occurences = [
         reaction.metadata.get("library_occurence", 0)
         for reaction in reactions
     ]
     return sum(occurences) / len(reactions)
示例#3
0
 def _score_reaction_tree(self, tree: ReactionTree) -> float:
     return len(list(tree.reactions()))