-
Notifications
You must be signed in to change notification settings - Fork 24
/
final_eval.py
50 lines (35 loc) · 1.31 KB
/
final_eval.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
import sys
import rdkit
from argparse import ArgumentParser
from rdkit import Chem, DataStructs
from rdkit.Chem import AllChem
import pandas as pd
pred_mols = pd.read_csv('',
header=None).values.reshape(-1)
ref_path = 'actives.txt'
with open(ref_path) as f:
next(f)
true_mols = [line.split(',')[0] for line in f]
print('number of active reference', len(true_mols))
true_mols = [Chem.MolFromSmiles(s) for s in true_mols]
true_mols = [x for x in true_mols if x is not None]
true_fps = [AllChem.GetMorganFingerprintAsBitVect(x, 3, 2048) for x in true_mols]
pred_mols = [Chem.MolFromSmiles(s) for s in pred_mols]
pred_mols = [x for x in pred_mols if x is not None]
pred_fps = [AllChem.GetMorganFingerprintAsBitVect(x, 3, 2048) for x in pred_mols]
fraction_similar = 0
sim_distribution = []
for i in range(len(pred_fps)):
sims = DataStructs.BulkTanimotoSimilarity(pred_fps[i], true_fps)
if max(sims) >= 0.4:
fraction_similar += 1
sim_distribution.append(max(sims))
print('novelty:', 1 - fraction_similar / len(pred_mols))
similarity = 0
for i in range(len(pred_fps)):
sims = DataStructs.BulkTanimotoSimilarity(pred_fps[i], pred_fps[:i])
similarity += sum(sims)
n = len(pred_fps)
n_pairs = n * (n - 1) / 2
diversity = 1 - similarity / n_pairs
print('diversity:', diversity)