-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest.py
153 lines (110 loc) · 3.91 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import os
import sys
import random
import pickle
import numpy as np
from timeit import default_timer as timer
from mhfp.encoder import MHFPEncoder
from mhfp.lsh_forest import LSHForest
from rdkit.Chem import AllChem
# config = mstmap.LayoutConfiguration()
# # config.merger = mstmap.Merger.Solar
# # print(config)
# # TODO: Fails for disconnected components!
# u = mstmap.VectorUint([0, 1, 2, 3, 4])
# v = mstmap.VectorUint([1, 2, 0, 4, 3])
# w = mstmap.VectorFloat([1.0, 1.0, 1.0, 2.0, 6.0])
# x, y = mstmap.layout(5, u, v, config, w)
# print(x)
# print(y)
enc = MHFPEncoder(512)
fps = []
if not os.path.isfile('fps.dat'):
with open('drugbank.smi', 'r') as f:
i = 0
for line in f:
smiles = line.split()[0].strip()
mol = AllChem.MolFromSmiles(smiles)
if mol:
fps.append(enc.encode_mol(mol))
i += 1
if i > 2000: break
pickle.dump(fps, open('fps.dat', 'wb'))
else:
fps = pickle.load(open('fps.dat', 'rb'))
m = enc.encode("N=C(N)NCCC[C@H](NC(=O)[C@@H]1CCCN1C(=O)[C@H](N)Cc1ccccc1)C(=O)N1CCC[C@H]1C(=O)NCC(=O)NCC(=O)NCC(=O)NCC(=O)N[C@@H](CC(=O)N)C(=O)NCC(=O)N[C@@H](CC(=O)O)C(=O)N[C@@H](Cc1ccccc1)C(=O)N[C@@H](CCC(=O)O)C(=O)N[C@@H](CCC(=O)O)C(=O)N[C@@H]([C@@H](C)CC)C(=O)N1CCC[C@H]1C(=O)N[C@@H](CCC(=O)O)C(=O)N[C@@H](CCC(=O)O)C(=O)N[C@@H](Cc1ccc(O)cc1)C(=O)N[C@@H](CC(C)C)C(=O)O")
n = enc.encode("O=C(N1[C@@H](CCC1)C(=O)NNC(=O)N)[C@@H](NC(=O)[C@@H](NC(=O)[C@H](NC(=O)[C@@H](NC(=O)[C@@H](NC(=O)[C@@H](NC(=O)[C@@H](NC(=O)[C@H]1NC(=O)CC1)Cc1[nH]cnc1)Cc1c2c([nH]c1)cccc2)CO)Cc1ccc(O)cc1)COC(C)(C)C)CC(C)C)CCCN=C(N)N")
q = enc.encode("[C@@H](C(=O)NCC(=O)N[C@@H](C(=O)N[C@@H](C)C(=O)N[C@@H](C(=O)N[C@H](C(=O)N[C@@H](C(=O)N[C@H](C(=O)N[C@@H](C(=O)N[C@H](C(=O)N[C@@H](C(=O)N[C@H](C(=O)N[C@@H](C(=O)N[C@H](C(=O)NCCO)Cc1c2c(cccc2)[nH]c1)CC(C)C)Cc1c[nH]c2c1cccc2)CC(C)C)Cc1c[nH]c2c1cccc2)CC(C)C)Cc1c[nH]c2c1cccc2)C(C)C)C(C)C)C(C)C)CC(C)C)(C(C)C)NC=O")
r = enc.encode('CNCNCNCNC')
lf_classic = LSHForest(512, 64)
for i, e in enumerate(fps):
lf_classic.add(i, e)
lf_classic.index()
start = timer()
result = lf_classic.query(r, 5)
end = timer()
print(end - start)
print(result)
# import os
# import sys
# import random
# import pickle
# from timeit import default_timer as timer
# from mhfp.encoder import MHFPEncoder
# from mhfp.lsh_forest import LSHForest
# from mstmap import mstmap
# from rdkit.Chem import AllChem
# # config = mstmap.LayoutConfiguration()
# # # config.merger = mstmap.Merger.Solar
# # # print(config)
# # # TODO: Fails for disconnected components!
# # u = mstmap.VectorUint([0, 1, 2, 3, 4])
# # v = mstmap.VectorUint([1, 2, 0, 4, 3])
# # w = mstmap.VectorFloat([1.0, 1.0, 1.0, 2.0, 6.0])
# # x, y = mstmap.layout(5, u, v, config, w)
# # print(x)
# # print(y)
# fps = []
# enc = MHFPEncoder(128)
# if not os.path.isfile('fps.dat'):
# with open('drugbank.smi', 'r') as f:
# i = 0
# for line in f:
# smiles = line.split()[0].strip()
# mol = AllChem.MolFromSmiles(smiles)
# if mol:
# fps.append(enc.encode_mol(mol))
# i += 1
# if i > 3: break
# pickle.dump(fps, open('fps.dat', 'wb'))
# else:
# fps = pickle.load(open('fps.dat', 'rb'))
# m = enc.encode("CNCNCNCNCNCNC")
# n = enc.encode("CCCCCCCCCCCCC")
# q = enc.encode("CCCCCCCCCCCCO")
# start = timer()
# lf_classic = LSHForest(128, 8)
# for i, fp in enumerate(fps):
# lf_classic.add(i, m)
# lf_classic.index()
# end = timer()
# print(end - start)
# start = timer()
# for _ in range(1000):
# result = lf_classic.query(q, 5)
# end = timer()
# print(end - start)
# print(result)
# start = timer()
# lf = mstmap.LSHForest()
# for i, fp in enumerate(fps):
# lf.add(i, mstmap.VectorUint(m))
# lf.index()
# end = timer()
# print(end - start)
# start = timer()
# for _ in range(1000):
# result = lf.query(mstmap.VectorUint(q), 5)
# end = timer()
# print(end - start)
# print(result)