[d6730e]: / tests / test_descriptors.py

Download this file

55 lines (41 with data), 1.8 kB

 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
import os
import oddt
from oddt.scoring import descriptors
test_data_dir = os.path.dirname(os.path.abspath(__file__))
actives_sdf = os.path.join(test_data_dir, 'data', 'dude', 'xiap',
'actives_docked.sdf')
receptor_pdb = os.path.join(test_data_dir, 'data', 'dude', 'xiap',
'receptor_rdkit.pdb')
def test_atoms_by_type():
mol = next(oddt.toolkit.readfile('sdf', actives_sdf))
for mode, types, num_atoms in (
('atomic_nums',
(6, 7, 8),
(33, 4, 4)),
('atom_types_sybyl',
('C.ar', 'C.2', 'C.3', 'N.3', 'N.am', 'O.3', 'O.2'),
(12, 3, 18, 1, 3, 1, 3)),
('atom_types_ad4',
('A', 'C', 'N', 'OA'),
(12, 21, 4, 4))):
types_dict = descriptors.atoms_by_type(mol.atom_dict, types=types,
mode=mode)
for t, n in zip(types, num_atoms):
assert t in types_dict
assert len(types_dict[t]) == n
def test_close_contacts_descriptor():
ligands = list(oddt.toolkit.readfile('sdf', actives_sdf))
rec = next(oddt.toolkit.readfile('pdb', receptor_pdb))
rec.protein = True
rec.addh()
for cutoff, num_contacts in ((4, 6816), ([4], 6816), ([2, 4], 6816),
([[1, 2], [3, 4]], 6304)):
contacts_descriptor = descriptors.close_contacts_descriptor(
cutoff=cutoff,
ligand_types=[6, 7, 8],
protein_types=[6, 7, 8])
length = len(contacts_descriptor.cutoff) * 9
assert len(contacts_descriptor) == length
contacts = contacts_descriptor.build(ligands, protein=rec)
assert contacts.shape, (len(ligands) == length)
assert contacts.sum() == num_contacts