Skip to content

Commit

Permalink
document IC_Residue.ak_set, implement __contains__(AtomKey) for IC_Re…
Browse files Browse the repository at this point in the history
…sidue and Edron
  • Loading branch information
rob-miller committed May 18, 2022
1 parent 372c969 commit cc25a5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Bio/PDB/internal_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,8 @@ class IC_Residue:
atom_coords: AtomKey indexed dict of numpy [4] arrays
**removed**
Use AtomKeys and atomArrayIndex to build if needed
ak_set: set of AtomKeys in dihedra
AtomKeys in all dihedra overlapping this residue (see __contains__())
alt_ids: list of char
AltLoc IDs from PDB file
bfactors: dict
Expand Down Expand Up @@ -2587,6 +2589,18 @@ def __deepcopy__(self, memo):
# still need to update: rnext, rprev, akc, ak_set, di/hedra
return dup

def __contains__(self, ak: "AtomKey") -> bool:
"""Return True if atomkey is in this residue."""
if ak in self.ak_set:
akl = ak.akl
if (
int(akl[0]) == self.rbase[0]
and akl[1] == self.rbase[1]
and akl[2] == self.rbase[2]
):
return True
return False

def rak(self, atm: Union[str, Atom]) -> "AtomKey":
"""Cache calls to AtomKey for this residue."""
try:
Expand Down Expand Up @@ -3929,6 +3943,10 @@ def __deepcopy__(self, memo):
dup.atomkeys = copy.deepcopy(self.atomkeys, memo)
return dup

def __contains__(self, ak: "AtomKey") -> bool:
"""Return True if atomkey is in this edron."""
return ak in self.atomkeys

def is_backbone(self) -> bool:
"""Report True for contains only N, C, CA, O, H atoms."""
return all(ak.is_backbone() for ak in self.atomkeys)
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_PDB_internal_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ def test_seq_as_PIC(self):
msg="covalent radii assignment error for chi1",
)

self.assertTrue(all(ak in rt for ak in chi1.atomkeys))
self.assertFalse(all(ak in rt for ak in psi.atomkeys))
tau = rt.pick_angle("tau")
self.assertEqual(
tau.__repr__(),
Expand Down

0 comments on commit cc25a5b

Please sign in to comment.