Coverage for biobb_vs/test/unitests/test_utils/test_bindingsite.py: 100%
49 statements
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 15:52 +0000
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 15:52 +0000
1# type: ignore
2import shutil
3import zipfile
4from pathlib import Path
5import pytest
6from biobb_common.tools import test_fixtures as fx
7from biobb_vs.utils.bindingsite import bindingsite
10class TestBindingSite():
11 def setup_class(self):
12 fx.test_setup(self, 'bindingsite')
14 def teardown_class(self):
15 fx.test_teardown(self)
16 pass
18 def test_bindingsite(self):
19 bindingsite(properties=self.properties, **self.paths)
20 assert fx.not_empty(self.paths['output_pdb_path'])
21 assert fx.equal(self.paths['output_pdb_path'], self.paths['ref_output_pdb_path'])
23 def test_bindingsite_member_without_ca(self):
24 # A cluster member without CA atoms is skipped: the binding site is the same as without it
25 clusters_zip = str(Path(self.properties['path']) / 'clusters_member_without_ca.zip')
26 shutil.copy(self.paths['input_clusters_zip'], clusters_zip)
27 with zipfile.ZipFile(clusters_zip, 'a') as zf:
28 pdb_lines = zf.read('2vgb.pdb').decode().splitlines(keepends=True)
29 zf.writestr('noca.pdb', ''.join(line for line in pdb_lines if not (line.startswith('ATOM') and line[12:16] == ' CA ')))
30 paths = dict(self.paths, input_clusters_zip=clusters_zip,
31 output_pdb_path=str(Path(self.properties['path']) / 'output_bindingsite_member_without_ca.pdb'))
32 bindingsite(properties=self.properties, **paths)
33 assert fx.not_empty(paths['output_pdb_path'])
34 assert fx.equal(paths['output_pdb_path'], paths['ref_output_pdb_path'])
36 def test_bindingsite_all_ligands(self):
37 # max_num_ligands 0 uses all the ligands: the 4 PGA of the test cluster, as the reference
38 paths = dict(self.paths, output_pdb_path=str(Path(self.properties['path']) / 'output_bindingsite_all_ligands.pdb'))
39 bindingsite(properties=dict(self.properties, max_num_ligands=0), **paths)
40 assert fx.not_empty(paths['output_pdb_path'])
41 assert fx.equal(paths['output_pdb_path'], paths['ref_output_pdb_path'])
43 def test_bindingsite_two_chains(self):
44 # Only the first chain of the input structure is used: a copy of it as chain B changes nothing
45 with open(self.paths['input_pdb_path']) as f:
46 atom_lines = [line for line in f if line.startswith(('ATOM', 'HETATM'))]
47 input_pdb = str(Path(self.properties['path']) / 'bindingsite_two_chains.pdb')
48 with open(input_pdb, 'w') as f:
49 f.writelines(atom_lines + [line[:21] + 'B' + line[22:] for line in atom_lines] + ['END\n'])
50 paths = dict(self.paths, input_pdb_path=input_pdb,
51 output_pdb_path=str(Path(self.properties['path']) / 'output_bindingsite_two_chains.pdb'))
52 bindingsite(properties=self.properties, **paths)
53 assert fx.not_empty(paths['output_pdb_path'])
54 assert fx.equal(paths['output_pdb_path'], paths['ref_output_pdb_path'])
56 def test_bindingsite_no_ligand(self):
57 # No cluster member has the ligand: the block stops instead of writing an empty binding site
58 clusters_zip = str(Path(self.properties['path']) / 'clusters_no_ligand.zip')
59 with zipfile.ZipFile(self.paths['input_clusters_zip']) as zin, zipfile.ZipFile(clusters_zip, 'w') as zout:
60 zout.writestr('4ima.pdb', zin.read('4ima.pdb'))
61 paths = dict(self.paths, input_clusters_zip=clusters_zip,
62 output_pdb_path=str(Path(self.properties['path']) / 'output_bindingsite_no_ligand.pdb'))
63 with pytest.raises(SystemExit):
64 bindingsite(properties=self.properties, **paths)
65 assert not Path(paths['output_pdb_path']).exists()