Beispiel #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 eval_import_file_annotation(self, file_format, sample_file_path,
                                    annotation_file_path, expected_res, user):

        #sample_file_path = 'fragmentation/tests/files/test_import_annotation.mgf'
        with open(sample_file_path, 'rb') as fss:
            fs = FragSample.import_sample(fss, user, 'name', 'file_name')
            fs.wait_import_done()

        #annotation_file_path = 'fragmentation/tests/files/para_annotation.csv'
        with open(annotation_file_path, 'rb') as fa:
            #fs.import_annotation_file(fa)
            fs.import_annotation_file(fa, file_format)

        for er in expected_res:
            m = Molecule.find_from_smiles(er[1])
            self.assertTrue(m)
            fms_search = FragMolSample.objects.filter(frag_sample=fs,
                                                      ion_id=er[0])
            self.assertEqual(fms_search.count(), 1)
            fms = fms_search.first()
            fa_search = FragAnnotationDB.objects.filter(
                molecule=m,
                frag_mol_sample=fms,
                db_source=er[2],
                db_id=er[3],
            )
            self.assertEqual(fa_search.count(), 1, fa_search.count())
    def eval_import_file_annotation(
        self,
        file_format,
        sample_file_path,
        annotation_file_path,
        expected_res,
        user,
        level=None,
    ):

        frag_sample = self.import_annotation_file(file_format,
                                                  sample_file_path,
                                                  annotation_file_path, user)

        for idx, er in enumerate(expected_res):
            m = Molecule.find_from_smiles(er[2])
            self.assertTrue(m)
            fms_search = FragMolSample.objects.filter(frag_sample=frag_sample,
                                                      ion_id=int(er[0]))
            self.assertEqual(fms_search.count(), 1)
            fms = fms_search.first()
            fa_search = FragAnnotationDB.objects.filter(
                molecule=m,
                frag_mol_sample=fms,
                name=er[1],
                db_source=er[3],
                db_id=er[4],
            )
            self.assertEqual(fa_search.count(), 1, fa_search.count())
            if level:
                assert fa_search.first().status_id == level[idx]
Beispiel #4
0
 def test_process_reaction_double_reactants(self):
     r = self.create_reacts([("diels_alder", None)])["diels_alder"]
     smiles = ["C=Cc1c[nH]c(N)n1", "C=CCC"]
     expected_smiles = ["CCC1CCC=C2N=C(N)NC12", "CCC1CC=C2N=C(N)NC2C1"]
     ml = [Molecule.load_from_smiles(sm) for sm in smiles]
     smarts = "[#6:1]=,:[#6:2]-[#6:3]=,:[#6:4].[#6:5]=,:[#6:6]>>[#6:1]1-[#6:2]=,:[#6:3]-[#6:4]-[#6:6]-[#6:5]-1"
     r.load_smarts(smarts)
     for i in range(2):
         rp = ReactProcess.objects.create(reaction=r)
         for m in ml:
             rp.reactants.add(m)
         rp.save()
         rp.run_reaction()
         # Check if molecule has been created
         expected_mols = {
             Molecule.find_from_smiles(sm)
             for sm in expected_smiles
         }
         self.assertEqual(set(rp.products.all()), expected_mols)
         ml.reverse()
Beispiel #5
0
 def test_process_reaction_single_reactant(self):
     r = self.create_reacts([("methylation", "[N,O:1]>>[*:1]-[#6]")
                             ])["methylation"]
     sm = "NC=C(N)C"
     expected_smiles = ["CNC=C(C)N", "CNC(C)=CN"]
     m = Molecule.load_from_smiles(sm)
     m.save()
     # Reaction.reactions_update()
     r = Reaction.objects.get(name="methylation")
     rp = ReactProcess.objects.create(reaction=r)
     rp.reactants.add(m)
     rp.run_reaction()
     # Check if molecule has been created
     expected_mols = {
         Molecule.find_from_smiles(sm)
         for sm in expected_smiles
     }
     self.assertTrue(not False in expected_mols)
     # Check if reaction_product has been created
     self.assertEqual(rp.products.count(), 2)
     for m_exp in expected_mols:
         self.assertTrue(m_exp in rp.products.all())
Beispiel #6
0
 def test_find_from_smiles(self):
     m = Molecule.create_from_smiles("CC")
     self.assertIsNot(Molecule.find_from_smiles("CC"), False)
     self.assertEqual(Molecule.find_from_smiles("CC"), m)
     self.assertFalse(Molecule.find_from_smiles("C"))