示例#1
0
    def get_outcomes(self,
                     smiles,
                     mincount,
                     template_prioritization,
                     start_at=-1,
                     end_at=-1,
                     singleonly=True,
                     stop_if=False,
                     template_count=10000,
                     max_cum_prob=1.0):
        """Performs a one-step synthesis reaction for a given SMILES string.

        Each candidate in self.result.products is of type ForwardProduct

        Args:
            smiles (str): SMILES string of ??
            mincount (int): Minimum popularity of used templates.
            template_prioritization (??): Specifies method to use for ordering
                templates.
            start_at (int, optional): Index of first prioritized template to
                use. (default: {-1})
            end_at (int, optional): Index of prioritized template to stop
                before. (default: {-1})
            singleonly (bool, optional): Whether to reduce each product to the
                largest (longest) one. (default: {True})
            stop_if (bool or string, optional): SMILES string of molecule to
                stop at if found, or False for no target. (default: {False})
            template_count (int, optional): Maximum number of templates to use.
                (default: {10000})
            max_cum_prob (float, optional): Maximum cumulative probability of
                all templates used. (default: {1.0})
        """
        self.get_template_prioritizers(template_prioritization)
        # Get sorted by popularity during loading.
        if template_prioritization == gc.popularity:
            prioritized_templates = self.templates
        else:
            self.template_prioritizer.set_max_templates(template_count)
            self.template_prioritizer.set_max_cum_prob(max_cum_prob)
            prioritized_templates = self.template_prioritizer.get_priority(
                (self.templates, smiles))
        self.mincount = mincount
        self.start_at = start_at
        self.singleonly = singleonly
        self.stop_if = stop_if

        if end_at == -1 or end_at >= len(self.templates):
            self.end_at = len(self.templates)
        else:
            self.end_at = end_at
        # Define mol to operate on
        mol = Chem.MolFromSmiles(smiles)
        clean_reactant_mapping(mol)
        [a.SetIsotope(i + 1) for (i, a) in enumerate(mol.GetAtoms())]
        reactants_smiles = Chem.MolToSmiles(mol)
        smiles = Chem.MolToSmiles(
            mol, isomericSmiles=USE_STEREOCHEMISTRY)  # to canonicalize
        # Initialize results object
        if self.celery:
            result = []
        else:
            result = ForwardResult(smiles)
        for i in range(self.start_at, self.end_at):

            # only use templates between the specified boundaries.
            template = prioritized_templates[i]
            if template['count'] > mincount:
                products = self.apply_one_template(mol,
                                                   smiles,
                                                   template,
                                                   singleonly=singleonly,
                                                   stop_if=stop_if)
                if self.celery:
                    for product in products:
                        result.append({
                            'smiles_list': product.smiles_list,
                            'smiles': product.smiles,
                            'edits': product.edits,
                            'template_ids': product.template_ids,
                            'num_examples': product.num_examples
                        })
                else:
                    result.add_products(products)

        return (smiles, result)
示例#2
0
    def get_outcomes(self,
                     smiles,
                     mincount,
                     template_prioritization,
                     start_at=-1,
                     end_at=-1,
                     singleonly=True,
                     stop_if=False,
                     template_count=10000,
                     max_cum_prob=1.0):
        '''
        Each candidate in self.result.products is of type ForwardProduct
        '''
        self.get_template_prioritizers(template_prioritization)
        # Get sorted by popularity during loading.
        if template_prioritization == gc.popularity:
            prioritized_templates = self.templates
        else:
            self.template_prioritizer.set_max_templates(template_count)
            self.template_prioritizer.set_max_cum_prob(max_cum_prob)
            prioritized_templates = self.template_prioritizer.get_priority(
                (self.templates, smiles))
        self.mincount = mincount
        self.start_at = start_at
        self.singleonly = singleonly
        self.stop_if = stop_if

        if end_at == -1 or end_at >= len(self.templates):
            self.end_at = len(self.templates)
        else:
            self.end_at = end_at
        # Define mol to operate on
        mol = Chem.MolFromSmiles(smiles)
        clean_reactant_mapping(mol)
        reactants_smiles = Chem.MolToSmiles(mol)
        smiles = Chem.MolToSmiles(
            mol, isomericSmiles=USE_STEREOCHEMISTRY)  # to canonicalize
        # Initialize results object
        if self.celery:
            result = []
        else:
            result = ForwardResult(smiles)
        for i in range(self.start_at, self.end_at):

            # only use templates between the specified boundaries.
            template = prioritized_templates[i]
            if template['count'] > mincount:
                products = self.apply_one_template(mol,
                                                   smiles,
                                                   template,
                                                   singleonly=singleonly,
                                                   stop_if=stop_if)
                if self.celery:
                    for product in products:
                        result.append({
                            'smiles_list': product.smiles_list,
                            'smiles': product.smiles,
                            'edits': product.edits,
                            'template_ids': product.template_ids,
                            'num_examples': product.num_examples
                        })
                else:
                    result.add_products(products)

        return (smiles, result)