Exemplo n.º 1
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
Exemplo n.º 2
0
 def test_pickling_and_saving(self):
     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)
     state_1 = ChemicalCompoundState(
         [compound_6, compound_10, compound_909], organism=Test_organism_H)
     node_1 = MCTS_node(state_1)
     node_1.save(folder_address="tests/generated_jsons/pickles")
     node_2 = unpickle("6_10_909-0-0",
                       type="node",
                       folder_address="tests/generated_jsons/pickles")
     assert (node_1 == node_2)
Exemplo n.º 3
0
    def test_pickling_unpickling(self):
        csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
        compound = Compound(csmile, name="821")
        state = ChemicalCompoundState(
            [compound],
            organism=Test_organism_H,
            representation=Test_representation)  # state is not sanitised
        state_bis = ChemicalCompoundState(
            [compound],
            organism=Test_organism_H,
            representation=Test_representation)  # state is not sanitised

        test_Tree = Tree(root_state=state,
                         itermax=10000,
                         parallel=False,
                         Rollout_policy="Rollout_policy_first",
                         UCT_policy="Biochemical_UCT_1")
        test_Tree.run_search()
        test_Tree.save("test", folder_address="tests/generated_jsons/pickles")
        loaded_tree = unpickle(file_name='test',
                               type='tree',
                               folder_address="tests/generated_jsons/pickles")
        assert test_Tree == loaded_tree
Exemplo n.º 4
0
 def test_biosensor(self):
     organism = detectable_cmpds_H
     inchi = "InChI=1S/C6H11NO2/c8-6(9)5-3-1-2-4-7-5/h5,7H,1-4H2,(H,8,9)"
     compound = Compound(InChI=inchi, name="pipecolate")
     present_in_state_detectable = organism.compound_in_state(compound)
     if present_in_state_detectable:
         logging.warning(
             "Removed compound from the detectable set to force enzymatic detection"
         )
         organism.remove_cmpd_from_state(compound)
     rules, biological_scoring = get_rules_and_score(
         full_rules_forward_H=full_rules_forward_H,
         full_rules_retro_H=full_rules_retro_H,
         full_rules_forward_no_H=full_rules_forward_no_H,
         full_rules_retro_no_H=full_rules_retro_no_H,
         add_Hs=True,
         retro=False,
         diameters=[10, 12, 14, 16],
         small=False,
         c_name=None,
         filtering_EC=["1.5.3.7", "1.5.3"])
     state = ChemicalCompoundState([compound])  # state is not sanitised
     test_Tree = Tree(root_state=state,
                      itermax=1000,
                      parallel=False,
                      Rollout_policy="Rollout_policy_first",
                      UCT_policy="Biochemical_UCT_1",
                      available_rules=rules,
                      organism=organism,
                      biological_scorer=biological_scoring,
                      folder_to_save="tests/generated_jsons")
     test_Tree.run_search()
     loaded_tree = unpickle(file_name='pipecolate_test',
                            type='tree',
                            folder_address="tests/data")
     same_states = test_Tree.equality_visited_states(loaded_tree)
     assert same_states
Exemplo n.º 5
0
 def test_unstandardised_pickle(self):
     csmile = "C(=O)CC"
     compound = Compound(csmile)
     compound.save("test", folder_address = "tests/generated_jsons/pickles")
     loaded = unpickle("test", folder_address = "tests/generated_jsons/pickles")
     assert compound.eq_full_inchi_key(loaded)
Exemplo n.º 6
0
 def test_simple_pickle(self):
     csmile = "[H][C](=[O])[C]([H])([H])[C]([H])([H])[H]"
     compound = Compound(csmile)
     compound.save("test", folder_address = "tests/generated_jsons/pickles")
     loaded = unpickle("test", folder_address = "tests/generated_jsons/pickles")
     assert compound.eq_full_inchi_key(loaded)
Exemplo n.º 7
0
                except ChemConversionError as e:
                    logging.error("For compound {} with inchi {}: error ChemConversionError".format(name, inchi))
    organism = ChemicalCompoundState(compound_list, main_layer = False)
    # organism.set_main_layer(True)
    return(organism)


organisms_data_path = "{}/organisms".format(data_path)
if not os.path.exists(organisms_data_path):
    os.mkdir(organisms_data_path)

if not os.path.exists(organisms_data_path + '/state_iML1515_chassis_H.pkl'):
    logging.error("Please run calculate_organisms script")
    raise NotReady


Test_organism_H = unpickle(file_name = "{}".format('Test_organism_H'), type = 'state', folder_address = organisms_data_path)
ecoli_chassis_H = unpickle(file_name = "{}".format('iML1515_chassis_H'), type = 'state', folder_address = organisms_data_path)
detectable_cmpds_H = unpickle(file_name = "{}".format('detectable_cmpds_H'), type = 'state', folder_address = organisms_data_path)
core_ecoli_H = unpickle(file_name = "{}".format('core_ecoli_H'), type = 'state', folder_address = organisms_data_path)
bsubtilis_H = unpickle(file_name = "{}".format('bsubtilis_H'), type = 'state', folder_address = organisms_data_path)
iJO1366_chassis_H = unpickle(file_name = "{}".format('iJO1366_chassis_H'), type = 'state', folder_address = organisms_data_path)


Test_organism_noH = unpickle(file_name = "{}".format('Test_organism_noH'), type = 'state', folder_address = organisms_data_path)
ecoli_chassis_noH = unpickle(file_name = "{}".format('iML1515_chassis_noH'), type = 'state', folder_address = organisms_data_path)
detectable_cmpds_noH = unpickle(file_name = "{}".format('detectable_cmpds_noH'), type = 'state', folder_address = organisms_data_path)
core_ecoli_noH = unpickle(file_name = "{}".format('core_ecoli_noH'), type = 'state', folder_address = organisms_data_path)
bsubtilis_noH = unpickle(file_name = "{}".format('bsubtilis_noH'), type = 'state', folder_address = organisms_data_path)
iJO1366_chassis_noH = unpickle(file_name = "{}".format('iJO1366_chassis_noH'), type = 'state', folder_address = organisms_data_path)