Beispiel #1
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 import_organism_from_csv(csv_file, add_Hs=True):
     with open(csv_file) as csv_handle:
         dict_reader = csv.DictReader(csv_handle, delimiter=',')
         compound_list = []
         for row in dict_reader:
             name = row["name"]
             inchi = row["inchi"]
             if inchi is None or inchi == "None" or inchi == "":
                 pass
             else:
                 try:
                     if name.startswith("InChI"):
                         compound = Compound(InChI=inchi,
                                             heavy_standardisation=True,
                                             force_add_H=add_Hs)
                     else:
                         compound = Compound(InChI=inchi,
                                             name=name,
                                             heavy_standardisation=True,
                                             force_add_H=add_Hs)
                     if not compound.in_list(compound_list,
                                             main_layer=False):
                         compound_list.append(compound)
                 except ChemConversionError as e:
                     logging.error(
                         "For compound {} with inchi {}: error ChemConversionError"
                         .format(name, inchi))
     organism = ChemicalCompoundState(compound_list, main_layer=False)
     return (organism)
Beispiel #3
0
    def load_AppendObject(self, object):
	Compound.load_AppendObject(self, object)
	length = len(self.objects)
	if length > 2 and length & 1:
	    # last object was a control object
	    if len(self.objects[-2].objects) == 0:
		self.objects[-2].Recompute(self.objects[-3], self.objects[-1])
Beispiel #4
0
 def test_add_compound_to_state_no(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     compound = Compound(csmile)
     compound_2 = Compound(csmile)
     state = ChemicalCompoundState(compound, organism=Test_organism_H)
     state._add_compound_to_state(compound_2)
     assert len(state) == 1
Beispiel #5
0
 def test_cloning(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     compound = Compound(csmile)
     cloned_compound = compound.clone()
     different_python_object = (id(compound) != id(cloned_compound))
     identical_chemical_object = (compound.eq_full_inchi_key(cloned_compound))
     assert (different_python_object and identical_chemical_object)
Beispiel #6
0
 def load_AppendObject(self, object):
     Compound.load_AppendObject(self, object)
     length = len(self.objects)
     if length > 2 and length & 1:
         # last object was a control object
         if len(self.objects[-2].objects) == 0:
             self.objects[-2].Recompute(self.objects[-3], self.objects[-1])
Beispiel #7
0
 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
    def test_expand_90191(self):
        csmile_90191 = "[H][O][C]([H])([H])[C]([H])([O][H])[C]([H])([H])[H]"
        compound_1 = Compound("[H+]", name="1")
        compound_6 = 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][P](=[O])([O][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]",
            name='6')
        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]",
            name="10")
        compound_909 = Compound("[H][O][C]([H])([C]([H])=[O])[C]([H])([H])[H]",
                                name=909)
        # compound_2345 = Compound("[H][C](=[O])[C]([H])=[C]([H])[H]", name = "2345")
        compound_90191 = Compound(csmile_90191)
        resulting_state_95713 = ChemicalCompoundState(
            [compound_1, compound_10, compound_909], organism=Test_organism_H)
        resulting_state_903108 = ChemicalCompoundState(
            [compound_1, compound_6, compound_909], organism=Test_organism_H)
        root_state = ChemicalCompoundState(compound_90191,
                                           organism=Test_organism_H)
        root_node = MCTS_node(root_state)
        root_node.expand()

        result_95713 = (root_node.children[0].state == resulting_state_95713 or
                        root_node.children[0].state == resulting_state_903108)
        result_903108 = (root_node.children[1].state == resulting_state_903108
                         or root_node.children[1].state
                         == resulting_state_95713)
        assert (result_95713 and result_903108)
 def test_expand_821(self):
     csmile_821 = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     csmile_90191 = "[H][O][C]([H])([H])[C]([H])([O][H])[C]([H])([H])[H]"
     compound = Compound(csmile_821, "821")
     compound_1 = Compound("[H+]", name="1")
     compound_6 = 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][P](=[O])([O][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]",
         name='6')
     compound_2345 = Compound("[H][C](=[O])[C]([H])=[C]([H])[H]",
                              name="2345")
     compound_90191 = Compound(csmile_90191, "90191")
     resulting_state_94682 = ChemicalCompoundState([compound_90191],
                                                   organism=Test_organism_H)
     resulting_state_117465 = ChemicalCompoundState(
         [compound_1, compound_6, compound_2345], organism=Test_organism_H)
     root_state = ChemicalCompoundState(compound, organism=Test_organism_H)
     root_node = MCTS_node(root_state, chemical_score=True)
     root_node.expand()
     for child in root_node.children:
         if child.move.rid == "MNXR94682_MNXM821":
             i_94682 = root_node.children.index(child)
         if child.move.rid == "MNXR117465_MNXM821":
             i_117465 = root_node.children.index(child)
     result_94682 = (
         root_node.children[i_94682].state == resulting_state_94682)
     result_117465 = (
         root_node.children[i_117465].state == resulting_state_117465)
     assert (result_94682 and result_117465)
Beispiel #10
0
 def test_check_sanitized_state_not(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     unstandardised = "C(=O)CC"
     compound = Compound(csmile)
     compound_ns = Compound(unstandardised)
     state = ChemicalCompoundState(
         [compound, compound_ns], main_layer=True)  # state is not sanitised
     assert state._check_sanitized_state()
Beispiel #11
0
 def test_compound_in_state_yes(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     unstandardised = "C(=O)CC"
     compound = Compound(csmile)
     compound_ns = Compound(unstandardised)
     state = ChemicalCompoundState(
         [compound], organism=Test_organism_H)  # state is not sanitised
     assert state.compound_in_state(compound_ns)
Beispiel #12
0
 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
Beispiel #13
0
 def test_naming(self):
     InChI_key = "BQJCRHHNABKAKU-UHFFFAOYSA-N"
     # Remark: we are not generating standard InChI keys or InChIs.
     # It's okay as long as we're consistent
     canonical_smiles = "CN1CCC23C4C1CC5=C2C(=C(C=C5)O)OC3C(C=C4)O"
     morphine = Compound(canonical_smiles)
     morphine.naming("morphine")
     assert morphine.name == 'morphine'
Beispiel #14
0
 def test_check_sanitized_state_yes(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     csmile_2 = "[H][O][C]([H])([H])[C]([H])([O][H])[C]([H])([H])[H]"
     compound = Compound(csmile)
     compound_2 = Compound(csmile_2)
     state = ChemicalCompoundState([compound,
                                    compound_2])  # state is not sanitised
     assert state._check_sanitized_state()
Beispiel #15
0
 def test_compound_in_state_no(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     csmile_2 = "[H][O][C]([H])([H])[C]([H])([O][H])[C]([H])([H])[H]"
     compound = Compound(csmile)
     compound_2 = Compound(csmile_2)
     state = ChemicalCompoundState(
         [compound], organism=Test_organism_H)  # state is not sanitised
     assert not state.compound_in_state(compound_2)
    def __init__(self, jobsDir, elements, potFile, alat):
        numElements = len(elements.split())

        if numElements != 5:
            print('Expecting 5 elements, but ' + numElements
                  + ' (' + elements + ') were inputted.')
            nmod.nexit()

        Compound.__init__(self, jobsDir, elements, potFile, alat)
Beispiel #17
0
 def test_GetResults_from_InChI_Key_fraction(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     chassis_2_smile = "[H][O][C](=[O])[C](=[O])[C]([H])([H])[C]([H])([O][H])[C]([H])([O][H])[C]([H])([H])[H]"
     outside_compound = Compound(csmile)
     chassis_2 = Compound(chassis_2_smile)
     state_chassis = ChemicalCompoundState([chassis_2, outside_compound],
                                           organism=Test_organism_H)
     assert state_chassis.GetResults_from_InChI_Keys(
         rewarding=Basic_Rollout_Reward) == 1 / 2
Beispiel #18
0
 def test_equal_two(slef):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     csmile_2 = "[H][O][C]([H])([H])[C]([H])([O][H])[C]([H])([H])[H]"
     compound = Compound(csmile)
     compound_2 = Compound(csmile_2)
     state = ChemicalCompoundState([compound, compound_2],
                                   organism=Test_organism_H)
     state_2 = ChemicalCompoundState([compound, compound_2],
                                     organism=Test_organism_H)
     assert state == state_2
Beispiel #19
0
 def test_equal_two_from_addition(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     csmile_2 = "[H][O][C]([H])([H])[C]([H])([O][H])[C]([H])([H])[H]"
     compound = Compound(csmile)
     compound_2 = Compound(csmile_2)
     state = ChemicalCompoundState(compound, organism=Test_organism_H)
     state_2 = ChemicalCompoundState(compound_2, organism=Test_organism_H)
     state._add_compound_to_state(compound_2)
     state_2._add_compound_to_state(compound)
     assert state == state_2
Beispiel #20
0
 def test_GetResults_from_InChI_Key_reward(self):
     chassis_1_smile = "[H+]"
     chassis_2_smile = "[H][O][C](=[O])[C](=[O])[C]([H])([H])[C]([H])([O][H])[C]([H])([O][H])[C]([H])([H])[H]"
     chassis_1 = Compound(chassis_1_smile)
     chassis_2 = Compound(chassis_2_smile)
     state_chassis = ChemicalCompoundState([chassis_1, chassis_2],
                                           organism=Test_organism_H)
     assert state_chassis.GetResults_from_InChI_Keys(
         rewarding=Basic_Rollout_Reward
     ) == Basic_Rollout_Reward.full_state_reward
Beispiel #21
0
 def test_remove_cmps(self):
     chassis_1_smile = "[H+]"
     chassis_2_smile = "[H][O][C](=[O])[C](=[O])[C]([H])([H])[C]([H])([O][H])[C]([H])([O][H])[C]([H])([H])[H]"
     chassis_1 = Compound(chassis_1_smile)
     chassis_2 = Compound(chassis_2_smile)
     state_chassis = ChemicalCompoundState([chassis_1, chassis_2],
                                           organism=Test_organism_H)
     present_in_state = state_chassis.compound_in_state(chassis_1)
     state_chassis.remove_cmpd_from_state(chassis_1)
     present_in_state_after = state_chassis.compound_in_state(chassis_1)
     assert present_in_state and not present_in_state_after
Beispiel #22
0
 def test_compound_in_chassis_state(self):
     compound_1 = Compound("[H+]")
     compound_6 = 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][P](=[O])([O][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]"
     )
     compound_3459 = Compound(
         "[H][O][C](=[O])[C](=[O])[C]([H])([H])[C]([H])([O][H])[C]([H])([O][H])[C]([H])([H])[H]"
     )
     chassis_metabolites = ChemicalCompoundState(
         [compound_1, compound_6, compound_3459], organism=Test_organism_H)
     assert chassis_metabolites.compound_in_state(compound_1)
Beispiel #23
0
    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])
Beispiel #24
0
 def test_node_rollout_terminal(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]"
     )
     compound_6 = 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][P](=[O])([O][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]",
         name='6')
     state_1 = ChemicalCompoundState([compound_10, compound_6],
                                     organism=Test_organism_H)
     node_1 = MCTS_node(state_1)
     rolled_state = node_1.rollout()
     assert (rolled_state == node_1.state)
Beispiel #25
0
 def test_terminal_state_true_unavailable_moves(self):
     compound_1 = Compound("[H+]", name="1")
     compound_6 = 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][P](=[O])([O][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]",
         name='6')
     compound_2345 = Compound("[H][C](=[O])[C]([H])=[C]([H])[H]",
                              name="2345")
     state = ChemicalCompoundState(
         [compound_1, compound_6, compound_2345],
         organism=Test_organism_H)  # state is not sanitised
     node = MCTS_node(state)
     assert node.moves == []
Beispiel #26
0
 def test_GetResultsForBiosensors_present(self):
     chassis_1_smile = "[H+]"
     chassis_1 = Compound(chassis_1_smile)
     benzoate = Compound(
         InChI="InChI=1S/C7H6O2/c8-7(9)6-4-2-1-3-5-6/h1-5H,(H,8,9)/p-1")
     benzoate_chassis = ChemicalCompoundState([benzoate, chassis_1],
                                              organism=detectable_cmpds_H)
     retrosynthesis = benzoate_chassis.GetResults_from_InChI_Keys(
         rewarding=Basic_Rollout_Reward)
     biosensor = benzoate_chassis.GetResultsForBiosensors(
         rewarding=Basic_Rollout_Reward)
     assert retrosynthesis == 0.5 and biosensor == 2
Beispiel #27
0
    def test_rave_update(self):
        compound_1 = Compound("[H+]")
        compound_6 = 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][P](=[O])([O][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]")
        move = Move(rsmart = "rsmart",
                    rid = "rid",
                    compound_id= "compound_id",
                    product_list = [compound_1, compound_6])

        move.update(5, visit_number = 10)
        move.update(0.2, 10)
        assert move.RAVE_total_score == 52
        assert move.RAVE_visits == 20
Beispiel #28
0
 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
Beispiel #29
0
 def test_node_unexpanded(self):
     csmile_821 = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     compound_821 = Compound(csmile_821, "821")
     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]",
         name="10")
     compound_909 = Compound("[H][O][C]([H])([C]([H])=[O])[C]([H])([H])[H]",
                             name="909")
     state_1 = ChemicalCompoundState(
         [compound_821, compound_10, compound_909],
         organism=Test_organism_H)
     node_1 = MCTS_node(state_1)
     assert (node_1.children == [])
Beispiel #30
0
 def test_expand_1_6_2345_empty_children(self):
     compound_1 = Compound("[H+]", name="1")
     compound_6 = 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][P](=[O])([O][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]",
         name='6')
     compound_2345 = Compound("[H][C](=[O])[C]([H])=[C]([H])[H]",
                              name="2345")
     state = ChemicalCompoundState(
         [compound_1, compound_6, compound_2345],
         organism=Test_organism_H)  # state is not sanitised
     node = MCTS_node(state)
     node.expand()
     assert node.children == []
Beispiel #31
0
 def test_saving_and_loading(self):
     compound_1 = Compound("[H+]")
     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]"
     )
     compound_909 = Compound("[H][O][C]([H])([C]([H])=[O])[C]([H])([H])[H]")
     chassis_1_10_909 = ChemicalCompoundState(
         [compound_1, compound_10, compound_909], organism=Test_organism_H)
     chassis_1_10_909.save(folder_address="tests/generated_jsons/pickles")
     chassis_load = unpickle("BOPG_BSAB_GPRL",
                             type="state",
                             folder_address="tests/data")
     assert chassis_1_10_909 == chassis_load
Beispiel #32
0
 def test_terminal_state_true_chassis(self):
     compound_1 = Compound("[H+]", name="1")
     compound_6 = 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][P](=[O])([O][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]",
         name='6')
     compound_3459 = Compound(
         "[H][O][C](=[O])[C](=[O])[C]([H])([H])[C]([H])([O][H])[C]([H])([O][H])[C]([H])([H])[H]",
         name='3459')
     state = ChemicalCompoundState(
         [compound_1, compound_6, compound_3459],
         organism=Test_organism_H)  # state is not sanitised
     node = MCTS_node(state)
     assert node.terminal == True
 def load(self):
     # parse the JSON cache file and store in a dictionary 'compound_dict'
     self.compound_dict = {}
     self.compound_ids = []
     if os.path.exists(CACHE_FNAME):
         for d in json.load(open(CACHE_FNAME, 'r')):
             self.compound_ids.append(d['id'])
             self.compound_dict[d['id']] = Compound.from_json_dict(d)
 def load(self):
     # parse the JSON cache file and store in a dictionary 'compound_dict'
     self.compound_dict = {}
     self.compound_ids = []
     if os.path.exists(self.cache_fname):
         for d in json.load(gzip.open(self.cache_fname, 'r')):
             self.compound_ids.append(d['compound_id'])
             self.compound_dict[d['compound_id']] = Compound.from_json_dict(d)
    def get_compound(self, compound_id):
        if compound_id not in self.compound_dict:
            logging.debug('Cache miss: %s' % str(compound_id))
            inchi = self.compound_id2inchi[compound_id]
            comp = Compound.from_inchi('KEGG', compound_id, inchi)
            self.add(comp)

        logging.debug('Cache hit: %s' % str(compound_id))
        return self.compound_dict[compound_id]
 def get_kegg_compound(self, cid):
     compound_id = 'C%05d' % cid
     if compound_id in self.compound_dict:
         return self.compound_dict[compound_id]
     else:
         logging.info('Downloading structure and calculating pKa for: ' + compound_id)
         comp = Compound.from_kegg(cid)
         self.compound_dict[comp.compound_id] = comp
         self.need_to_update_cache_file = True
         return comp
 def get_kegg_additions(self):
     # fields are: name, cid, inchi
     for row in csv.DictReader(open(KEGG_ADDITIONS_TSV_FNAME, 'r'), delimiter='\t'):
         cid = int(row['cid'])
         compound_id = 'C%05d' % cid
         inchi = row['inchi']
         # if the compound_id is not in the cache, or its InChI has changed,
         # recalculate the Compound() and add/replace in cache
         if (compound_id not in self.compound_dict) or \
            (inchi != self.compound_dict[compound_id].inchi):
             logging.info('Calculating pKa for additional compound: ' + compound_id)
             pKas, majorMSpH7, nHs, zs = Compound.get_species_pka(inchi)
             comp = Compound('KEGG', compound_id, inchi,
                             pKas, majorMSpH7, nHs, zs)
             self.compound_dict[comp.compound_id] = comp
             self.need_to_update_cache_file = True
Beispiel #38
0
    def __init__(self, steps = 2, start = None, end = None,
		 duplicate = None):
	if duplicate is not None:
	    self.steps = duplicate.steps
	    Compound.__init__(self, duplicate = duplicate)
	else:
	    self.steps = steps
	    if start is not None:
		Compound.__init__(self, self.compute_blend(start, end))
	    else:
		Compound.__init__(self)
Beispiel #39
0
    def __init__(self, text = None, path = None, model = PATHTEXT_ROTATE,
		 start_pos = 0.0, duplicate = None, _blended_text = None):
	if duplicate is not None:
	    Compound.__init__(self, duplicate = duplicate)
	    self.text = self.objects[0]
	    self.path = self.objects[1]
	else:
            if _blended_text is not None:
                self.text = _blended_text
                self.path = path
                Compound.__init__(self, [self.text, self.path])
            elif text is not None:
		self.text = InternalPathText(text.Text(),
                                             start_pos = start_pos,
                                             model = model,
                                             duplicate = text)
		self.path = path
		Compound.__init__(self, [self.text, self.path])
	    else:
		# we're being loaded
		self.text = self.path = None
		Compound.__init__(self)
Beispiel #40
0
    def __init__(self, steps = 0, start = None, end = None, duplicate = None):
	# Three different ways to instantiate this class:
	#
	# 1. Duplicating a BlendGroup: duplicate is not None.
	#
	# 2. Creating a BlendGroup from two normal graphics objects:
	#    start and end are not None.
	#
	# 3. Creating a BlendGroup from an sk file: steps is 0.

	if duplicate is not None:
	    # case 1
	    Compound.__init__(self, duplicate = duplicate)
	    #self.Connect()
	elif start is not None:
	    # case 2
	    inter = BlendInterpolation(steps, start, end)
	    Compound.__init__(self, [start, inter, end])
	    #self.Connect()
	else:
	    # case 3
	    Compound.__init__(self)
Beispiel #41
0
    def load_AppendObject(self, object):
	Compound.load_AppendObject(self, object)
	if len(self.objects) == 2:
	    self.text, self.path = self.objects
Beispiel #42
0
    def end_change_children(self, ignore_child_changes = 0):
	if self.child_has_changed and not ignore_child_changes:
	    self.document.AddAfterHandler(self.recompute, (), self.depth())
	self.child_has_changed = 0
	return Compound.end_change_children(self)
Beispiel #43
0
    def begin_change_children(self):
	self.child_has_changed = 0
	return Compound.begin_change_children(self)
Beispiel #44
0
import sys, logging
sys.path.append('../python')
from compound import Compound

logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)

for cid in [282]:
    comp = Compound.from_kegg(cid)
    print comp
    print "C%05d: ddG0_prime = %.2f" % (cid, comp.transform(7.0, 0.2, 300))