forked from jinhojsk515/spmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_property.py
36 lines (30 loc) · 1.03 KB
/
calc_property.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
from rdkit import Chem
import torch
import rdkit
from rdkit import RDLogger
from inspect import getmembers, isfunction
from rdkit.Chem import Descriptors
import time
from collections import OrderedDict
with open('./property_name.txt', 'r') as f:
names = [n.strip() for n in f.readlines()][:53]
descriptor_dict = OrderedDict()
for n in names:
if n == 'QED':
descriptor_dict[n] = lambda x: Chem.QED.qed(x)
else:
descriptor_dict[n] = getattr(Descriptors, n)
def calculate_property(smiles):
RDLogger.DisableLog('rdApp.*')
mol = Chem.MolFromSmiles(smiles)
output = []
for i, descriptor in enumerate(descriptor_dict):
# print(descriptor)
output.append(descriptor_dict[descriptor](mol))
return torch.tensor(output, dtype=torch.float)
if __name__ == '__main__':
st = time.time()
output = calculate_property('Cc1cccc(CNNC(=O)C2(Cc3ccccc3CN=[N+]=[N-])N=C(c3ccc(OCCCO)cc3)OC2c2ccc(Br)cc2)c1')
print(output, output.size())
print(time.time() - st)
print(rdkit.__version__)