Skip to content

Commit a6ac3c5

Browse files
committed
Do not lookup bonds for hetero residues
1 parent a541322 commit a6ac3c5

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/biotite/structure/bonds.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,7 @@ def connect_via_residue_names(atoms, bint inter_residue=True,
17351735
cdef np.ndarray atom_names = atoms.atom_name
17361736
cdef np.ndarray atom_names_in_res
17371737
cdef np.ndarray res_names = atoms.res_name
1738+
cdef np.ndarray hetero = atoms.hetero
17381739
cdef str atom_name1, atom_name2
17391740
cdef int64[:] atom_indices1, atom_indices2
17401741
cdef dict bond_dict_for_res
@@ -1745,6 +1746,10 @@ def connect_via_residue_names(atoms, bint inter_residue=True,
17451746
curr_start_i = residue_starts[res_i]
17461747
next_start_i = residue_starts[res_i+1]
17471748

1749+
# Skip lookup for ligands
1750+
if hetero[curr_start_i]:
1751+
continue
1752+
17481753
if custom_bond_dict is None:
17491754
bond_dict_for_res = bonds_in_residue(res_names[curr_start_i])
17501755
else:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
HETATM 704 C7 LIG B 101 -17.432 24.497 -0.918 1.00 26.28 C
2+
HETATM 705 C8 LIG B 101 -17.432 24.497 -0.918 1.00 26.28 C
3+
HETATM 706 C13 LIG B 101 -17.432 24.497 -0.918 1.00 26.28 C
4+
HETATM 707 C14 LIG B 101 -17.432 24.497 -0.918 1.00 26.28 C
5+
HETATM 708 C15 LIG B 101 -17.432 24.497 -0.918 1.00 26.28 C
6+
CONECT 704 705
7+
CONECT 705 704 706
8+
CONECT 706 705 707
9+
CONECT 707 706 708
10+
CONECT 708 707

tests/structure/io/test_pdb.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,13 @@ def test_bond_parsing():
468468
pdb_file = pdb.PDBFile.read(path)
469469
atoms = pdb.get_structure(pdb_file, model=1, include_bonds=True)
470470

471+
# TODO get input on this modification
472+
atoms = atoms[~atoms.hetero]
471473
test_bonds = atoms.bonds
472474
test_bonds.remove_bond_order()
473475

474476
ref_bonds = struc.connect_via_residue_names(atoms)
475477
ref_bonds.remove_bond_order()
476-
477478
assert test_bonds.as_set() == ref_bonds.as_set()
478479

479480

@@ -572,3 +573,26 @@ def test_setting_incompatible_structure(annotation, value, warning_only):
572573
else:
573574
with pytest.raises(struc.BadStructureError):
574575
pdb_file.set_structure(atoms)
576+
577+
578+
def test_hetatm_intra_residue_bonds():
579+
"""
580+
Expect that HETATM intra-residues bonds are only parsed from CONECT records
581+
and not looked up via residue names.
582+
"""
583+
expected_bonds = np.array(
584+
[
585+
[0, 1, 0],
586+
[1, 2, 0],
587+
[2, 3, 0],
588+
[3, 4, 0],
589+
],
590+
dtype=np.uint32,
591+
)
592+
path = join(data_dir("structure"), "hetatm/ligand.pdb")
593+
594+
pdb_file = pdb.PDBFile.read(path)
595+
structure = pdb.get_structure(pdb_file, model=1, include_bonds=True)
596+
actual_bonds = structure.bonds.as_array()
597+
598+
np.testing.assert_array_equal(actual_bonds, expected_bonds)

0 commit comments

Comments
 (0)