Skip to content

Commit 7474d90

Browse files
authored
Do not lookup bonds for hetero residues (#820)
* Disable bond lookup for hetero atoms * Build non-hetero bond dict for pdbs
1 parent a541322 commit 7474d90

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/biotite/structure/io/pdb/file.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@
66
__author__ = "Patrick Kunzmann, Daniel Bauer, Claude J. Rogers"
77
__all__ = ["PDBFile"]
88

9+
import itertools
910
import warnings
1011
from collections import namedtuple
1112
import numpy as np
1213
from biotite.file import InvalidFileError, TextFile
1314
from biotite.structure.atoms import AtomArray, AtomArrayStack, repeat
14-
from biotite.structure.bonds import BondList, connect_via_residue_names
15+
from biotite.structure.bonds import (
16+
BondList,
17+
connect_via_residue_names,
18+
)
1519
from biotite.structure.box import unitcell_from_vectors, vectors_from_unitcell
1620
from biotite.structure.error import BadStructureError
1721
from biotite.structure.filter import (
1822
filter_first_altloc,
1923
filter_highest_occupancy_altloc,
2024
filter_solvent,
2125
)
26+
from biotite.structure.info.bonds import bonds_in_residue
2227
from biotite.structure.io.pdb.hybrid36 import (
2328
decode_hybrid36,
2429
encode_hybrid36,
@@ -544,7 +549,16 @@ def get_structure(
544549
# Read bonds
545550
if include_bonds:
546551
bond_list = self._get_bonds(atom_id)
547-
bond_list = bond_list.merge(connect_via_residue_names(array))
552+
# Create bond dict containing only non-hetero residues (+ water)
553+
custom_bond_dict = {
554+
res_name: bonds_in_residue(res_name)
555+
for res_name in itertools.chain(
556+
np.unique(array[..., ~array.hetero].res_name), ["HOH"]
557+
)
558+
}
559+
bond_list = bond_list.merge(
560+
connect_via_residue_names(array, custom_bond_dict=custom_bond_dict)
561+
)
548562
array.bonds = bond_list
549563

550564
return array
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: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ def test_bond_parsing():
473473

474474
ref_bonds = struc.connect_via_residue_names(atoms)
475475
ref_bonds.remove_bond_order()
476-
477476
assert test_bonds.as_set() == ref_bonds.as_set()
478477

479478

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

0 commit comments

Comments
 (0)