Skip to content

Commit

Permalink
Merge Issue124 fix (#125)
Browse files Browse the repository at this point in the history
* Fixed ResidueSelection iterator to include chain

* Add test for ResidueSelection iterator
  • Loading branch information
mtessmer authored Feb 5, 2024
1 parent 800520e commit 4a34167
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/chilife/MolSys.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,8 @@ def __len__(self):
return len(self.first_ix)

def __iter__(self):
for resnum in self.resnums:
mask = self.molsys.resnums == resnum
for resnum, segid in zip(self.resnums, self.segids):
mask = (self.molsys.resnums == resnum) * (self.molsys.segids == segid)
yield Residue(self.molsys, mask)


Expand Down
12 changes: 11 additions & 1 deletion tests/test_MolSys.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,14 @@ def test_from_atomsel():

np.testing.assert_equal(new_prot.positions, atomsel.positions)
np.testing.assert_equal(new_prot.ix + 435, atomsel.ix)
assert len(new_prot.trajectory) == len(atomsel.universe.trajectory)
assert len(new_prot.trajectory) == len(atomsel.universe.trajectory)


def test_ResidueSelection_iter():
prot = MolSys.from_pdb('test_data/1a2w.pdb')
chain_B = prot.select_atoms('chain B')
for res in chain_B.residues:
assert res.chain == 'B'
assert np.all(res.atoms.chains == 'B')


0 comments on commit 4a34167

Please sign in to comment.