Spaces:
Sleeping
Sleeping
saicharan2804
commited on
Commit
·
9ebf1eb
1
Parent(s):
e0d6a40
Adding synthetic_complexity_score
Browse files- molgenevalmetric.py +26 -20
molgenevalmetric.py
CHANGED
@@ -51,6 +51,9 @@ import json
|
|
51 |
import gzip
|
52 |
import six
|
53 |
|
|
|
|
|
|
|
54 |
import os
|
55 |
project_root = os.path.dirname(os.path.dirname(__file__))
|
56 |
|
@@ -64,32 +67,35 @@ def sigmoid(x):
|
|
64 |
return 1 / (1 + np.exp(-x))
|
65 |
|
66 |
class SCScorer():
|
|
|
|
|
67 |
def __init__(self, score_scale=score_scale):
|
68 |
self.vars = []
|
69 |
self.score_scale = score_scale
|
70 |
self._restored = False
|
71 |
|
72 |
-
def restore(self, weight_path=
|
73 |
-
self.FP_len = FP_len
|
|
|
74 |
self._load_vars(weight_path)
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
return np.
|
90 |
-
|
91 |
-
|
92 |
-
self.mol_to_fp = mol_to_fp
|
93 |
|
94 |
self._restored = True
|
95 |
return self
|
|
|
51 |
import gzip
|
52 |
import six
|
53 |
|
54 |
+
from types import MethodType
|
55 |
+
|
56 |
+
|
57 |
import os
|
58 |
project_root = os.path.dirname(os.path.dirname(__file__))
|
59 |
|
|
|
67 |
return 1 / (1 + np.exp(-x))
|
68 |
|
69 |
class SCScorer():
|
70 |
+
self.mol_to_fp = MethodType(mol_to_fp, self)
|
71 |
+
|
72 |
def __init__(self, score_scale=score_scale):
|
73 |
self.vars = []
|
74 |
self.score_scale = score_scale
|
75 |
self._restored = False
|
76 |
|
77 |
+
def restore(self, weight_path='model.ckpt-10654.as_numpy.json.gz', FP_rad, FP_len):
|
78 |
+
self.FP_len = FP_len
|
79 |
+
self.FP_rad = FP_rad
|
80 |
self._load_vars(weight_path)
|
81 |
+
|
82 |
+
if 'uint8' in weight_path or 'counts' in weight_path:
|
83 |
+
def mol_to_fp(mol):
|
84 |
+
if mol is None:
|
85 |
+
return np.array((self.FP_len,), dtype=np.uint8)
|
86 |
+
fp = AllChem.GetMorganFingerprint(mol, self.FP_rad, useChirality=True) # uint sparse vector
|
87 |
+
fp_folded = np.zeros((self.FP_len,), dtype=np.uint8)
|
88 |
+
for k, v in six.iteritems(fp.GetNonzeroElements()):
|
89 |
+
fp_folded[k % self.FP_len] += v
|
90 |
+
return np.array(fp_folded)
|
91 |
+
else:
|
92 |
+
def mol_to_fp(mol):
|
93 |
+
if mol is None:
|
94 |
+
return np.zeros((self.FP_len,), dtype=np.float32)
|
95 |
+
return np.array(AllChem.GetMorganFingerprintAsBitVect(mol, self.FP_rad, nBits=self.FP_len, useChirality=True), dtype=np.bool_)
|
96 |
+
|
97 |
+
# Set the mol_to_fp method for the instance
|
98 |
+
self.mol_to_fp = MethodType(mol_to_fp, self)
|
99 |
|
100 |
self._restored = True
|
101 |
return self
|