|
a |
|
b/tests/test_utils.py |
|
|
1 |
import os |
|
|
2 |
import pytest |
|
|
3 |
|
|
|
4 |
import oddt |
|
|
5 |
from oddt.utils import check_molecule, chunker, compose_iter |
|
|
6 |
|
|
|
7 |
test_data_dir = os.path.dirname(os.path.abspath(__file__)) |
|
|
8 |
|
|
|
9 |
# common file names |
|
|
10 |
dude_data_dir = os.path.join(test_data_dir, 'data', 'dude', 'xiap') |
|
|
11 |
xiap_crystal_ligand = os.path.join(dude_data_dir, 'crystal_ligand.sdf') |
|
|
12 |
xiap_protein = os.path.join(dude_data_dir, 'receptor_rdkit.pdb') |
|
|
13 |
|
|
|
14 |
|
|
|
15 |
def test_check_molecule(): |
|
|
16 |
with pytest.raises(ValueError, match='Molecule object'): |
|
|
17 |
check_molecule([]) |
|
|
18 |
|
|
|
19 |
ligand = next(oddt.toolkit.readfile('sdf', xiap_crystal_ligand)) |
|
|
20 |
check_molecule(ligand) |
|
|
21 |
|
|
|
22 |
# force protein |
|
|
23 |
protein = next(oddt.toolkit.readfile('pdb', xiap_protein)) |
|
|
24 |
with pytest.raises(ValueError, match='marked as a protein'): |
|
|
25 |
check_molecule(protein, force_protein=True) |
|
|
26 |
|
|
|
27 |
protein.protein = True |
|
|
28 |
check_molecule(protein, force_protein=True) |
|
|
29 |
|
|
|
30 |
# force coordinates |
|
|
31 |
mol = oddt.toolkit.readstring('smi', 'c1ccccc1') |
|
|
32 |
with pytest.raises(ValueError, match='3D coordinates'): |
|
|
33 |
check_molecule(mol, force_coords=True) |
|
|
34 |
|
|
|
35 |
mol.make3D() |
|
|
36 |
check_molecule(mol, force_coords=True) |
|
|
37 |
|
|
|
38 |
# with pytest.raises(ValueError, match='positional'): |
|
|
39 |
# check_molecule(mol, True) |
|
|
40 |
|
|
|
41 |
mol = oddt.toolkit.readstring('sdf', '''mol_title |
|
|
42 |
handmade |
|
|
43 |
|
|
|
44 |
0 0 0 0 0 0 0 0 0 0999 V2000 |
|
|
45 |
M END |
|
|
46 |
''') |
|
|
47 |
with pytest.raises(ValueError, match='has zero atoms'): |
|
|
48 |
check_molecule(mol, non_zero_atoms=True) |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
def test_func_composition(): |
|
|
52 |
def double(x): |
|
|
53 |
return [i * 2 for i in x] |
|
|
54 |
|
|
|
55 |
def inc(x): |
|
|
56 |
return [i + 1 for i in x] |
|
|
57 |
|
|
|
58 |
assert compose_iter([1], funcs=[double, inc]) == [3] |
|
|
59 |
assert compose_iter([3], funcs=[double, inc]) == [7] |
|
|
60 |
assert compose_iter([10], funcs=[double, inc]) == [21] |
|
|
61 |
|
|
|
62 |
|
|
|
63 |
def test_chunks(): |
|
|
64 |
chunks = chunker('ABCDEFG', 2) |
|
|
65 |
assert list(chunks), [['A', 'B'], ['C', 'D'], ['E', 'F'] == ['G']] |