def test_stoechiometry_3(self):
     ongoing_cmp_inchi = "InChI=1S/C15H12O4/c16-11-8-13(18)15(14(19)9-11)12(17)7-6-10-4-2-1-3-5-10/h1-9,16,18-19H"
     compound = Compound(InChI = ongoing_cmp_inchi, max_moves = 5)
     moves = compound.obtain_applicable_transformation_with_move(available_rules = full_rules_retro_H, chemical_scorer = "SubandprodChemicalScorer")
     move_1_stoechio = moves[4].stoechiometry == {'LTYOQGRJFJAKNA-UHFFFAOYSA-N': 3, 'JVNVHNHITFVWIX-UHFFFAOYSA-N': 1}
     move_2_stoechio = moves[0].stoechiometry == {'JFRPZSBKZZVAHT-UHFFFAOYSA-N': 1}
     assert move_1_stoechio and move_2_stoechio
Exemple #2
0
    def test_GetMoves_state_and_compound(self):
        compound_10 = Compound(
            "[H][N]=[C]([O][H])[C]1=[C]([H])[N]([C]2([H])[O][C]([H])([C]([H])([H])[O][P](=[O])([O][H])[O][P](=[O])([O][H])[O][C]([H])([H])[C]3([H])[O][C]([H])([n]4[c]([H])[n][c]5[c]([N]([H])[H])[n][c]([H])[n][c]54)[C]([H])([O][H])[C]3([H])[O][H])[C]([H])([O][H])[C]2([H])[O][H])[C]([H])=[C]([H])[C]1([H])[H]"
        )
        state_test_10 = ChemicalCompoundState(
            compound_10,
            organism=Test_organism_H,
            available_rules=applicable_rules_mixed_dict)
        moves_compound = compound_10.obtain_applicable_transformation_with_move(
            available_rules=applicable_rules_mixed_dict)
        print("moves_compound: {}".format(moves_compound))
        del compound_10
        compound_10 = Compound(
            "[H][N]=[C]([O][H])[C]1=[C]([H])[N]([C]2([H])[O][C]([H])([C]([H])([H])[O][P](=[O])([O][H])[O][P](=[O])([O][H])[O][C]([H])([H])[C]3([H])[O][C]([H])([n]4[c]([H])[n][c]5[c]([N]([H])[H])[n][c]([H])[n][c]54)[C]([H])([O][H])[C]3([H])[O][H])[C]([H])([O][H])[C]2([H])[O][H])[C]([H])=[C]([H])[C]1([H])[H]"
        )
        state_test_10 = ChemicalCompoundState(
            compound_10,
            organism=Test_organism_H,
            available_rules=applicable_rules_mixed_dict)

        moves_state = state_test_10.GetMoves(top_x=10)
        print("moves_state: {}".format(moves_state))
        identicial_moves = len(moves_state) == len(moves_compound)
        for move in moves_state:
            identicial_moves = identicial_moves and move.in_list(
                moves_compound, main_layer=False)
        assert identicial_moves
 def test_obtain_applicable_transformation_with_moves(self):
     one_set_one_product_compound = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     one_set_one_product_matches = ['MNXR94682_MNXM821', 'MNXR117465_MNXM821']
     compound = Compound(one_set_one_product_compound)
     moves = compound.obtain_applicable_transformation_with_move(available_rules = applicable_rules_10_dict)
     # issue with rule and reaction IDs
     for move in moves:
         assert move.rid in one_set_one_product_matches
    def test_apply_transformation_sets_different_products_parallel(self):

        # set_1 = ['[H]OC([H])([H])C([H])(O[H])C([H])([H])[H]']
        # set_2 = ['[H]C(=O)C([H])=C([H])[H]', '[H+]', '[H]N=C(O[H])C1=C([H])N(C2([H])OC([H])(C([H])([H])OP(=O)(O[H])OP(=O)(O[H])OC([H])([H])C3([H])OC([H])(n4c([H])nc5c(N([H])[H])nc([H])nc54)C([H])(OP(=O)(O[H])O[H])C3([H])O[H])C([H])(O[H])C2([H])O[H])C([H])=C([H])C1([H])[H]']
        set_test_compound = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
        compound = Compound(set_test_compound, single_worker = True)
        moves = compound.obtain_applicable_transformation_with_move(available_rules = applicable_rules_10_dict)
        move_1 = moves[0]
        product_set_1 = compound.apply_transformation_with_move(move_1)
        move_2 = moves[1]
        product_set_2 = compound.apply_transformation_with_move(move_2)
        assert set([product.name for product in product_set_1]) != set([product.name for product in product_set_2])
 def test_similarity_substrate_and_product_equal_1(self):
     one_set_one_product_compound = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     compound = Compound(one_set_one_product_compound)
     moves = compound.obtain_applicable_transformation_with_move(available_rules = applicable_rules_10_dict_sim)
     move = moves[1]
     original_substrates_list = applicable_rules_10_dict_sim[move.rid]["substrate_ECFP"]
     original_product_list = applicable_rules_10_dict_sim[move.rid]["products_ECFP"]
     scorer = SubandprodChemicalScorer
     score = scorer.calculate(compound,
                         products = move.product_list,
                         original_substrates_list = original_substrates_list,
                         original_products_list_list = original_product_list)
     assert score == 1
    def test_similarity_substrate_and_product_different_1(self):
        one_set_one_product_compound = "[H]N=C(O[H])C1=C([H])N(C2([H])OC([H])(C([H])([H])OP(=O)(O[H])OP(=O)(O[H])OC([H])([H])C3([H])OC([H])(n4c([H])nc5c(N([H])[H])nc([H])nc54)C([H])(OP(=O)(O[H])O[H])C3([H])O[H])C([H])(O[H])C2([H])O[H])C([H])=C([H])C1([H])[H]"

        compound = Compound(one_set_one_product_compound)
        moves = compound.obtain_applicable_transformation_with_move(available_rules = applicable_rules_mixed_dict_sim)
        move = moves[0]
        original_substrates_list = applicable_rules_mixed_dict_sim[move.rid]["substrate_ECFP"]
        original_product_list = applicable_rules_mixed_dict_sim[move.rid]["products_ECFP"]
        scorer = SubandprodChemicalScorer
        score = scorer.calculate(compound,
                            products = move.product_list,
                            original_substrates_list = original_substrates_list,
                            original_products_list_list = original_product_list)
        assert round(score, 2) == 0.24
 def test_rule_with_timeout(self):
     ongoing_cmp_inchi = "InChI=1S/C53H78O4/c1-41(2)19-11-20-42(3)21-12-22-43(4)23-13-24-44(5)25-14-26-45(6)27-15-28-46(7)29-16-30-47(8)31-17-32-48(9)33-18-34-49(10)39-40-57-53(56)51-37-35-50(36-38-51)52(54)55/h19,21,23,25,27,29,31,33,35-39H,11-18,20,22,24,26,28,30,32,34,40H2,1-10H3,(H,54,55)"
     compound = Compound(InChI = ongoing_cmp_inchi, max_moves = 10)
     move_rid_list = ["RR-02-dbef5e1eacd20afc-06-F",
                     "RR-02-98f27ab4082414aa-02-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F",
                     "RR-02-fa79f7a2d3a06ca5-04-F"]
     moves = compound.obtain_applicable_transformation_with_move(available_rules = full_rules_retro_H, chemical_scorer = "SubandprodChemicalScorer")
     all_found = True
     for move in moves:
         found = move.rid in move_rid_list
         all_found = all_found and found
     assert all_found
    def test_apply_transformation_sets_parallel(self):

        set_1 = [Compound('[H]OC([H])([H])C([H])(O[H])C([H])([H])[H]').name]
        set_2 = [Compound('[H]C(=O)C([H])=C([H])[H]').name, Compound('[H+]').name, Compound('[H]N=C(O[H])C1=C([H])N(C2([H])OC([H])(C([H])([H])OP(=O)(O[H])OP(=O)(O[H])OC([H])([H])C3([H])OC([H])(n4c([H])nc5c(N([H])[H])nc([H])nc54)C([H])(OP(=O)(O[H])O[H])C3([H])O[H])C([H])(O[H])C2([H])O[H])C([H])=C([H])C1([H])[H]').name]
        set_test_compound = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
        compound = Compound(set_test_compound, single_worker = True)
        moves = compound.obtain_applicable_transformation_with_move(available_rules = applicable_rules_10_dict)
        found_set_1 = False
        found_set_2 = False
        all_found = True
        for move in moves:
            products = compound.apply_transformation_with_move(move)
            if set([product.name for product in products]) == set(set_1):
                found_set_1 = True
            elif set([product.name for product in products]) == set(set_2):
                found_set_2 = True
            else:
                all_found = False

        assert (found_set_1 and found_set_2 and len(moves) == 2)
 def test_obtain_applicable_transformation_with_move_none(self):
     unmatched_substrate = "[H][C](=[O])[C]([H])=[C]([H])[H]"
     compound = Compound(unmatched_substrate)
     moves = compound.obtain_applicable_transformation_with_move(available_rules = applicable_rules_10_dict)
     assert moves == []