Exemplo n.º 1
0
 def load_from_rdkit(self):
     sm = "CCCC"
     mol_rdkit = RDKit.mol_from_smiles(sm)
     self.assertFalse(Molecule.find_from_smiles(sm))
     m = Molecule.load_from_rdkit(mol_rdkit)
     self.assertTrue(Molecule.find_from_smiles(sm))
     self.assertEqual(m.mol_rdkit, mol_rdkit)
     self.assertEqual(m, Molecule.load_from_rdkit(mol_rdkit))
 def run_reaction_(self):
     reaction = self.reaction
     r_smarts = reaction.smarts
     r_smarts = r_smarts.replace("\\", "-").replace("/", "-")
     rx = rdChemReactions.ReactionFromSmarts(r_smarts)
     products_rdkit = []
     if self.reactants.count() == 1:
         reactant = self.format_reactant(self.reactants.all()[0].mol_rdkit)
         products_rdkit = list(rx.RunReactant(reactant, 0))
     elif self.reactants.count() == 2:
         reactants = [
             self.format_reactant(m.mol_rdkit) for m in self.reactants.all()
         ]
         for i in range(2):
             products_rdkit = products_rdkit + list(
                 rx.RunReactants((reactants[i], reactants[1 - i]))
             )
     res = {Molecule.load_from_rdkit(m) for m in list(chain(*products_rdkit))} - {
         False
     }
     self.status_code = ReactProcess.status.DONE
     self.save()
     return res