-
Notifications
You must be signed in to change notification settings - Fork 48
/
test_fp.py
87 lines (70 loc) · 2.22 KB
/
test_fp.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
import pytest
import datamol as dm
def test_to_fp():
smiles = "CC(=O)Oc1ccccc1C(=O)O"
mol = dm.to_mol(smiles)
assert dm.to_fp(mol).shape[0] == 2048
assert dm.to_fp(mol).sum() == 31
def test_list_fp():
assert set(dm.list_supported_fingerprints().keys()) == {
"atompair",
"atompair-count",
"avalon-count",
"ecfp",
"fcfp",
"ecfp-count",
"erg",
"estate",
"fcfp-count",
"layered",
"maccs",
"pattern",
"rdkit",
"topological",
"topological-count",
"rdkit-count",
}
def test_all_fps():
smiles = "CC(=O)Oc1ccccc1C(=O)O"
mol = dm.to_mol(smiles)
fp_infos = {}
for fp_type in dm.list_supported_fingerprints():
fold_size = None
if fp_type == "rdkit-count":
fold_size = 2048
print(fp_type)
args = {}
args["mol"] = mol
args["as_array"] = True
args["fp_type"] = fp_type
args["fold_size"] = fold_size
fp = dm.to_fp(**args)
fp_infos[fp_type] = dict(size=len(fp), bits_sum=fp.sum())
print(fp_infos)
assert fp_infos == {
"maccs": {"size": 167, "bits_sum": 21},
"ecfp": {"size": 2048, "bits_sum": 31},
"fcfp": {"size": 2048, "bits_sum": 22},
"topological": {"size": 2048, "bits_sum": 18},
"atompair": {"size": 2048, "bits_sum": 68},
"rdkit": {"size": 2048, "bits_sum": 354},
"pattern": {"size": 2048, "bits_sum": 173},
"layered": {"size": 2048, "bits_sum": 335},
"erg": {"size": 315, "bits_sum": 23.4},
"estate": {"size": 79, "bits_sum": 13},
"avalon-count": {"size": 512, "bits_sum": 168},
"ecfp-count": {"size": 2048, "bits_sum": 35},
"fcfp-count": {"size": 2048, "bits_sum": 35},
"topological-count": {"size": 2048, "bits_sum": 19},
"atompair-count": {"size": 2048, "bits_sum": 78},
"rdkit-count": {"size": 2048, "bits_sum": 301},
}
def test_fp_invalid_input():
args = {}
args["mol"] = None
args["radius"] = 3
with pytest.raises(ValueError):
dm.to_fp(**args)
args["mol"] = "dsdsdsd"
with pytest.raises(ValueError):
dm.to_fp(**args)