[d6730e]: / tests / test_utils.py

Download this file

66 lines (46 with data), 1.9 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
55
56
57
58
59
60
61
62
63
64
65
import os
import pytest
import oddt
from oddt.utils import check_molecule, chunker, compose_iter
test_data_dir = os.path.dirname(os.path.abspath(__file__))
# common file names
dude_data_dir = os.path.join(test_data_dir, 'data', 'dude', 'xiap')
xiap_crystal_ligand = os.path.join(dude_data_dir, 'crystal_ligand.sdf')
xiap_protein = os.path.join(dude_data_dir, 'receptor_rdkit.pdb')
def test_check_molecule():
with pytest.raises(ValueError, match='Molecule object'):
check_molecule([])
ligand = next(oddt.toolkit.readfile('sdf', xiap_crystal_ligand))
check_molecule(ligand)
# force protein
protein = next(oddt.toolkit.readfile('pdb', xiap_protein))
with pytest.raises(ValueError, match='marked as a protein'):
check_molecule(protein, force_protein=True)
protein.protein = True
check_molecule(protein, force_protein=True)
# force coordinates
mol = oddt.toolkit.readstring('smi', 'c1ccccc1')
with pytest.raises(ValueError, match='3D coordinates'):
check_molecule(mol, force_coords=True)
mol.make3D()
check_molecule(mol, force_coords=True)
# with pytest.raises(ValueError, match='positional'):
# check_molecule(mol, True)
mol = oddt.toolkit.readstring('sdf', '''mol_title
handmade
0 0 0 0 0 0 0 0 0 0999 V2000
M END
''')
with pytest.raises(ValueError, match='has zero atoms'):
check_molecule(mol, non_zero_atoms=True)
def test_func_composition():
def double(x):
return [i * 2 for i in x]
def inc(x):
return [i + 1 for i in x]
assert compose_iter([1], funcs=[double, inc]) == [3]
assert compose_iter([3], funcs=[double, inc]) == [7]
assert compose_iter([10], funcs=[double, inc]) == [21]
def test_chunks():
chunks = chunker('ABCDEFG', 2)
assert list(chunks), [['A', 'B'], ['C', 'D'], ['E', 'F'] == ['G']]