[d6730e]: / tests / test_datasets.py

Download this file

116 lines (90 with data), 3.5 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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import pytest
import oddt
from oddt.datasets import pdbbind, dude
test_data_dir = os.path.dirname(os.path.abspath(__file__))
def test_pdbbind():
results = {
'core': (['4yef', '10gs'],
[5.35, 6.4]),
'refined': (['1nlp', '1imx', '4yef', '10gs'],
[4.96, 3.52, 5.35, 6.4]),
'general_PL': (['1k9q', '1nlo', '1nlp', '1imx', '4yef', '10gs'],
[3.15, 5.47, 4.96, 3.52, 5.35, 6.4]),
}
with pytest.raises(ValueError):
pdbbind(home=os.path.join(test_data_dir, 'data', 'pdbbind'))
for year in [2007, 2013, 2016]:
pdbbind_db = pdbbind(home=os.path.join(test_data_dir, 'data', 'pdbbind'),
version=year, default_set='core')
for set_name, (ids, activities) in results.items():
if set_name == 'general_PL' and year == 2007:
set_name = 'general'
pdbbind_db.default_set = set_name
assert pdbbind_db.ids == ids
assert pdbbind_db.activities == activities
for pid in pdbbind_db:
assert isinstance(pid.pocket, oddt.toolkit.Molecule)
assert len(pid.pocket.atoms) > 0
assert isinstance(pid.ligand, oddt.toolkit.Molecule)
assert len(pid.ligand.atoms) > 0
if pid.id == '10gs':
assert pid.protein is None
else:
assert isinstance(pid.protein, oddt.toolkit.Molecule)
assert len(pid.protein.atoms) > 0
# reset the pdbbind set
pdbbind_db.default_set = 'refined'
# getting by name
assert pdbbind_db['1imx'].id == '1imx'
# getting by id
assert pdbbind_db[-3].id == '1imx'
assert pdbbind_db[1].id == '1imx'
with pytest.raises(KeyError):
pdbbind_db['xxxx']
with pytest.raises(KeyError):
pdbbind_db[123456]
with pytest.raises(KeyError):
pdbbind_db[-123456]
pid = pdbbind_db['1imx']
# get ligand
ligand = pid.ligand
ligand.removeh()
assert len(ligand.atoms) == 60
# get pocket
pocket = pid.pocket
pocket.removeh()
assert len(pocket.atoms) == 234
# protein do exist
protein = pid.protein
protein.removeh()
assert len(protein.atoms) == 478
def test_dude():
results = {
'fabp4': (1022, 36, 57, 2855),
'inha': (1857, 22, 71, 2318),
}
dude_db = dude(home=os.path.join(test_data_dir, 'data', 'dude'))
for target in dude_db:
if target.dude_id == 'xiap':
# different file names
assert target.protein is None
assert target.ligand is None
assert target.actives is None
assert target.decoys is None
continue
prot_atoms, lig_atoms, num_act, num_dec = results[target.dude_id]
prot = target.protein
prot.removeh()
assert len(prot.atoms) == prot_atoms
lig = target.ligand
lig.removeh()
assert len(lig.atoms) == lig_atoms
assert len(list(target.actives)) == num_act
for a in target.actives:
assert len(a.atoms) > 0
assert len(list(target.decoys)) == num_dec
for d in target.decoys:
assert len(d.atoms) > 0
with pytest.raises(KeyError):
dude_db['xxxx']