66from pathlib import Path
77
88import pytest
9+ from Bio .PDB .Model import Model
910from Bio .PDB .PDBParser import PDBParser
1011from Bio .PDB .Residue import Residue
1112from Bio .PDB .Structure import Structure
2223
2324
2425@pytest .fixture
25- def input_pdb_structure ():
26+ def input_model ():
2627 input_f = Path (TEST_DATA , "2oob.pdb" )
2728 parser = PDBParser ()
28- return parser .get_structure (input_f .stem , input_f )
29+ structure = parser .get_structure (input_f .stem , input_f )
30+ assert isinstance (structure , Structure )
31+ return structure .child_list [0 ]
2932
3033
3134@pytest .fixture
@@ -39,13 +42,13 @@ def expected_dataset_json():
3942
4043
4144@pytest .fixture
42- def prodigy_class (input_pdb_structure ):
43- yield Prodigy (struct_obj = input_pdb_structure )
45+ def prodigy_class (input_model ):
46+ yield Prodigy (input_model )
4447
4548
46- def test_calculate_ic (input_pdb_structure ):
49+ def test_calculate_ic (input_model ):
4750
48- result = calculate_ic (struct = input_pdb_structure , d_cutoff = 5.5 )
51+ result = calculate_ic (model = input_model , d_cutoff = 5.5 )
4952
5053 assert len (result ) == 78
5154
@@ -55,11 +58,9 @@ def test_calculate_ic(input_pdb_structure):
5558 assert first_hit [1 ].get_resname () == "LYS"
5659
5760
58- def test_calculate_ic_with_selection (input_pdb_structure ):
61+ def test_calculate_ic_with_selection (input_model ):
5962
60- result = calculate_ic (
61- struct = input_pdb_structure , d_cutoff = 5.5 , selection = {"A" : 0 , "B" : 1 }
62- )
63+ result = calculate_ic (model = input_model , d_cutoff = 5.5 , selection = {"A" : 0 , "B" : 1 })
6364
6465 assert len (result ) == 78
6566
@@ -69,10 +70,10 @@ def test_calculate_ic_with_selection(input_pdb_structure):
6970 assert first_hit [1 ].get_resname () == "LYS"
7071
7172
72- def test_analyse_contacts (input_pdb_structure ):
73+ def test_analyse_contacts (input_model ):
7374
74- res_a = input_pdb_structure [ 0 ] ["A" ][(" " , 931 , " " )]
75- res_b = input_pdb_structure [ 0 ] ["B" ][(" " , 6 , " " )]
75+ res_a = input_model ["A" ][(" " , 931 , " " )]
76+ res_b = input_model ["B" ][(" " , 6 , " " )]
7677 contact = (res_a , res_b )
7778
7879 test_input = [contact ]
@@ -143,10 +144,10 @@ def test_prodigy_print_prediction_quiet(prodigy_class):
143144 Path (outfile .name ).unlink ()
144145
145146
146- def test_prodigy_print_contacts (input_pdb_structure , prodigy_class ):
147+ def test_prodigy_print_contacts (input_model , prodigy_class ):
147148
148- res_a = input_pdb_structure [ 0 ] ["A" ][(" " , 931 , " " )]
149- res_b = input_pdb_structure [ 0 ] ["B" ][(" " , 6 , " " )]
149+ res_a = input_model ["A" ][(" " , 931 , " " )]
150+ res_b = input_model ["B" ][(" " , 6 , " " )]
150151 prodigy_class .ic_network = [(res_a , res_b )]
151152
152153 outfile = tempfile .NamedTemporaryFile (delete = False )
@@ -158,9 +159,9 @@ def test_prodigy_print_contacts(input_pdb_structure, prodigy_class):
158159 Path (outfile .name ).unlink ()
159160
160161
161- def test_print_pymol_script (input_pdb_structure , prodigy_class ):
162- res_a = input_pdb_structure [ 0 ] ["A" ][(" " , 931 , " " )]
163- res_b = input_pdb_structure [ 0 ] ["B" ][(" " , 6 , " " )]
162+ def test_print_pymol_script (input_model , prodigy_class ):
163+ res_a = input_model ["A" ][(" " , 931 , " " )]
164+ res_b = input_model ["B" ][(" " , 6 , " " )]
164165 prodigy_class .ic_network = [(res_a , res_b )]
165166
166167 outfile = tempfile .NamedTemporaryFile (delete = False )
@@ -205,26 +206,31 @@ def test_dataset_prediction(compressed_dataset_f, expected_dataset_json):
205206 parsed_structure = parser .get_structure (s_name , handle )
206207 assert isinstance (parsed_structure , Structure )
207208
208- s = validate_structure (parsed_structure , selection = ["A" , "B" ])
209+ models = validate_structure (parsed_structure , selection = ["A" , "B" ])
209210
210211 # Test for structure object
211- assert isinstance (s , Structure )
212+ # Check if it's a list and all elements are Model objects
213+ assert isinstance (models , list ) and all (
214+ isinstance (item , Model ) for item in models
215+ )
216+ # assert isinstance(s, list[Model])
212217
213218 # run prediction and retrieve result dict
214- prod = Prodigy (s , selection = ["A" , "B" ])
215- prod .predict ()
216- results = prod .as_dict ()
217-
218- # check for equality of prdicted interface residues
219- for k in keys_equal :
220- observed_value = results [k ]
221- expected_value = expected_data [s_name ][k ]
222- assert observed_value == pytest .approx (expected_value )
223-
224- # check that NIS and binding afinity values are within 2% of
225- # expected values and add diffs for summary
226- for k in diffs .keys ():
227- delta = abs (results [k ] / expected_data [s_name ][k ] - 1 )
228- # assume a difference of less then 2%
229- assert delta == pytest .approx (0 , abs = 0.02 )
230- diffs [k ].append (delta )
219+ for m in models :
220+ prod = Prodigy (m , selection = ["A" , "B" ])
221+ prod .predict ()
222+ results = prod .as_dict ()
223+
224+ # check for equality of prdicted interface residues
225+ for k in keys_equal :
226+ observed_value = results [k ]
227+ expected_value = expected_data [s_name ][k ]
228+ assert observed_value == pytest .approx (expected_value )
229+
230+ # check that NIS and binding afinity values are within 2% of
231+ # expected values and add diffs for summary
232+ for k in diffs .keys ():
233+ delta = abs (results [k ] / expected_data [s_name ][k ] - 1 )
234+ # assume a difference of less then 2%
235+ assert delta == pytest .approx (0 , abs = 0.02 )
236+ diffs [k ].append (delta )
0 commit comments