コード例 #1
0
 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
コード例 #2
0
 def new_frag_mol_sim(self, smiles='N=C([NH3+])', adduct='M+'):
     fs = FragCommonTests.new_frag_sim()
     m = Molecule.load_from_smiles(smiles)
     return fs.create_frag_mol_sim(molecule=m, adduct=adduct), fs
コード例 #3
0
 def test_load_from_smiles(self):
     m = Molecule.create_from_smiles("CCC")
     self.assertIsNot(Molecule.load_from_smiles("CCC"), False)
     self.assertIsNot(Molecule.load_from_smiles("CCCC"), False)
     self.assertFalse(Molecule.load_from_smiles("HHOHH"))
コード例 #4
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"))
コード例 #5
0
 def test_smiles(self):
     sm_init = "C(C)(C)(C)(C)"
     sm_target = RDKit.mol_to_smiles(RDKit.mol_from_smiles(sm_init))
     m = Molecule.create_from_smiles(sm_init)
     self.assertEqual(m.smiles(), sm_target)
コード例 #6
0
 def gen_all_molecules(self):
     file_path = self.item_path() + '/metwork_all_molecules.csv'
     query_set = self.molecules.all()
     Molecule.gen_molecules(file_path, query_set)
コード例 #7
0
    def test_mass_selection(self):
        u = get_user_model().objects.create(email='*****@*****.**')
        methylation = Reaction.objects.create(user=u,
                                              name='methylation',
                                              smarts='[N,O:1]>>[*:1]-[#6]')
        methylation.run_reaction([Molecule.load_from_smiles('CCO')])
        methylation_modified = Reaction.objects.create(
            user=u, name='methylation_modified', smarts='[N,O:1]>>IC(I)C[*:1]')
        methylation_modified.run_reaction([Molecule.load_from_smiles('CCO')])
        diels_alder = Reaction.objects.create(
            user=u,
            name='diels_alder',
            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'
        )
        diels_alder.run_reaction([
            Molecule.load_from_smiles('C=Cc1c[nH]c(N)n1'),
            Molecule.load_from_smiles('C=C')
        ])
        diels_alder_modified = Reaction.objects.create(
            user=u,
            name='diels_alder_modified',
            smarts=
            '[#6:1]=,:[#6:2]-[#6:3]=,:[#6:4]-[H].[#6:5]=,:[#6:6]>>[#6]-[#6:2]-1=,:[#6:3]-[#6:4]-[#6:6]-[#6:5]-[#6:1]-1'
        )
        diels_alder_modified.run_reaction([
            Molecule.load_from_smiles('C=Cc1c[nH]c(N)n1'),
            Molecule.load_from_smiles('C=C')
        ])
        for r in [methylation, diels_alder, diels_alder_modified]:
            r.status_code = Reaction.status.ACTIVE
            r.save()

        sample_folder = 'fragmentation/tests/files/test_annotation_project/'
        sample_file_path = sample_folder + 'test_annotation_project.mgf'
        anno_file_path = sample_folder + 'anno_1.csv'

        with open(sample_file_path, 'rb') as fss:
            fs = FragSample.import_sample(fss, u, energy=2)

        # Import annotation
        with open(anno_file_path, 'rb') as f_annot:
            fs.import_annotation_file(f_annot)

        p = SampleAnnotationProject.objects.create(\
            user = u,
            depth_total = 3,
            depth_last_match = 0)
        p.save()
        p.update_frag_sample(fs)
        p.select_reactions_by_mass()

        self.assertIn(methylation, p.reactions())
        self.assertNotIn(methylation_modified, p.reactions())
        self.assertIn(diels_alder, p.reactions())
        self.assertNotIn(diels_alder_modified, p.reactions())

        # test frag_sample.gen_mass_delta reevaluation
        # when new reaction added
        methylation_modified.status_code = Reaction.status.ACTIVE
        methylation_modified.save()
        self.assertNotIn(methylation_modified, p.reactions())
        p.select_reactions_by_mass()
        self.assertIn(methylation_modified, p.reactions())
コード例 #8
0
 def test_load_from_smiles(self):
     m = Molecule.create_from_smiles('CCC')
     self.assertIsNot(Molecule.load_from_smiles('CCC'), False)
     self.assertIsNot(Molecule.load_from_smiles('CCCC'), False)
     self.assertFalse(Molecule.load_from_smiles('HHOHH'))
コード例 #9
0
 def test_mass_delta(self):
     r = self.create_reacts([("methylation", "[N,O:1]>>[*:1]-[#6]")
                             ])["methylation"]
     m = Molecule.load_from_smiles("CCO")
     rp = r.run_reaction([m])
     self.assertEqual(round(rp.mass_delta(), 6), 14.01565)
コード例 #10
0
 def test_mass_delta(self):
     r = self.create_reacts([('methylation', '[N,O:1]>>[*:1]-[#6]')
                             ])['methylation']
     m = Molecule.load_from_smiles('CCO')
     rp = r.run_reaction([m])
     self.assertEqual(round(rp.mass_delta(), 6), 14.01565)