Spaces:
Sleeping
Sleeping
saicharan2804
commited on
Commit
·
e0a0e3f
1
Parent(s):
18551e5
Adding synthetic_complexity_score
Browse files- molgenevalmetric.py +9 -15
molgenevalmetric.py
CHANGED
@@ -43,6 +43,7 @@ This is a standalone, importable SCScorer model. It does not have tensorflow as
|
|
43 |
dependency and is a more attractive option for deployment. The calculations are
|
44 |
fast enough that there is no real reason to use GPUs (via tf) instead of CPUs (via np)
|
45 |
'''
|
|
|
46 |
import numpy as np
|
47 |
import time
|
48 |
import rdkit.Chem as Chem
|
@@ -51,9 +52,6 @@ import json
|
|
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,40 +65,36 @@ def sigmoid(x):
|
|
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=os.path.join('model.ckpt-10654.as_numpy.json.gz'), FP_rad=FP_rad, FP_len=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)
|
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,
|
96 |
-
|
97 |
-
|
98 |
-
self.mol_to_fp = MethodType(mol_to_fp, self)
|
99 |
|
100 |
self._restored = True
|
101 |
return self
|
102 |
|
103 |
-
|
104 |
def smi_to_fp(self, smi):
|
105 |
if not smi:
|
106 |
return np.zeros((self.FP_len,), dtype=np.float32)
|
|
|
43 |
dependency and is a more attractive option for deployment. The calculations are
|
44 |
fast enough that there is no real reason to use GPUs (via tf) instead of CPUs (via np)
|
45 |
'''
|
46 |
+
|
47 |
import numpy as np
|
48 |
import time
|
49 |
import rdkit.Chem as Chem
|
|
|
52 |
import gzip
|
53 |
import six
|
54 |
|
|
|
|
|
|
|
55 |
import os
|
56 |
project_root = os.path.dirname(os.path.dirname(__file__))
|
57 |
|
|
|
65 |
return 1 / (1 + np.exp(-x))
|
66 |
|
67 |
class SCScorer():
|
|
|
|
|
68 |
def __init__(self, score_scale=score_scale):
|
69 |
self.vars = []
|
70 |
self.score_scale = score_scale
|
71 |
self._restored = False
|
72 |
|
73 |
def restore(self, weight_path=os.path.join('model.ckpt-10654.as_numpy.json.gz'), FP_rad=FP_rad, FP_len=FP_len):
|
74 |
+
self.FP_len = FP_len; self.FP_rad = FP_rad
|
|
|
75 |
self._load_vars(weight_path)
|
76 |
+
# print('Restored variables from {}'.format(weight_path))
|
77 |
|
78 |
if 'uint8' in weight_path or 'counts' in weight_path:
|
79 |
+
def mol_to_fp(self, mol):
|
80 |
if mol is None:
|
81 |
return np.array((self.FP_len,), dtype=np.uint8)
|
82 |
+
fp = AllChem.GetMorganFingerprint(mol, self.FP_rad, useChirality=True) # uitnsparsevect
|
83 |
fp_folded = np.zeros((self.FP_len,), dtype=np.uint8)
|
84 |
for k, v in six.iteritems(fp.GetNonzeroElements()):
|
85 |
fp_folded[k % self.FP_len] += v
|
86 |
return np.array(fp_folded)
|
87 |
else:
|
88 |
+
def mol_to_fp(self, mol):
|
89 |
if mol is None:
|
90 |
return np.zeros((self.FP_len,), dtype=np.float32)
|
91 |
+
return np.array(AllChem.GetMorganFingerprintAsBitVect(mol, self.FP_rad, nBits=self.FP_len,
|
92 |
+
useChirality=True), dtype=np.bool_)
|
93 |
+
self.mol_to_fp = mol_to_fp
|
|
|
94 |
|
95 |
self._restored = True
|
96 |
return self
|
97 |
|
|
|
98 |
def smi_to_fp(self, smi):
|
99 |
if not smi:
|
100 |
return np.zeros((self.FP_len,), dtype=np.float32)
|