Repository navigation
Conversation
…n code _remove_non_conect_bonds() compared only res_id and chain_id to find inter-residue bonds, so a bond between e.g. residues 52 and 52A was treated as intra-residue and not written. Compare residue starts instead, like the PDBx writer does.
padix-key
left a comment
There was a problem hiding this comment.
Good catch! Thank you for the fix 👍
| np.testing.assert_array_equal(actual_bonds, expected_bonds) | ||
|
|
||
|
|
||
| def test_inter_residue_bond_with_ins_code(): |
There was a problem hiding this comment.
Would it be possible to generalize this test? For example we could check that PDBFile.set_structure() adds the same CONECT records as there are in the PDB file downloaded from RCSB. The test assets do contain structures with insertion codes, so this should catch it. If for some reason complete CONECT equivalence is not possible, we could at least compare the number of CONECT records.
Merging this PR will degrade performance by 11.38%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Compare the written CONECT records with the CONECT records of the original file and with the inter-residue bonds of the structure, matched by atom identity since serials are renumbered.
|
Good idea. I replaced the synthetic test with one over every PDB test asset. It checks that the written One thing I found while doing this: the RCSB comparison alone doesn't catch the bug. RCSB only writes The failing "databases" job is the |
Keeping all altlocs and the original atom IDs makes the identity matching unnecessary.
| test_file.set_structure(atoms) | ||
| test_pairs = _conect_pairs(test_file) | ||
|
|
||
| assert _conect_pairs(ref_file) <= test_pairs |
There was a problem hiding this comment.
Shouldn't these two sets be equal?
| assert _conect_pairs(ref_file) <= test_pairs | |
| assert _conect_pairs(ref_file) = test_pairs |
Fixes #945
_remove_non_conect_bonds()found inter-residue bonds by comparingres_idandchain_idonly. Two residues that differ just inins_code(e.g.52and52A) looked like one residue, so a bond between them got noCONECTrecord and was lost when writing a PDB file.This now compares residue starts via
get_residue_starts_for(), the same way_filter_bonds()does for the PDBx writer.Added one small test with a disulfide between
52and52A. It fails onmainand passes here.tests/structure/io/test_pdb.py,test_pdbx.pyandtests/structure/test_bonds.pypass,ruff0.9.7 andpyrightare clean on the changed file.