Skip to content

Commit 6b4a2d8

Browse files
committed
updated unit tests
1 parent 9a8aae0 commit 6b4a2d8

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

CodeEntropy/levels/axes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def get_UA_axes(self, data_container, index: int, res_position):
225225
If axis construction fails.
226226
"""
227227
index = int(index) # bead index
228-
heavy_atoms = data_container.atoms.select_atoms("mass 2 to 999")
228+
heavy_atoms = data_container.select_atoms("mass 2 to 999")
229229
# use the same customPI trans axes as the residue level
230230
if len(heavy_atoms) > 1:
231231
if len(data_container.residues) == 1:
@@ -240,7 +240,7 @@ def get_UA_axes(self, data_container, index: int, res_position):
240240
index_next = residue.resid + 1
241241
# the .resid attribute gives 1-indexing
242242
# substract 1 to match indexing later
243-
second_edge = data_container.atoms.select_atoms(
243+
second_edge = data_container.select_atoms(
244244
f"resindex {residue.resid - 1} and "
245245
f"bonded resindex {index_next - 1}"
246246
)
@@ -254,7 +254,7 @@ def get_UA_axes(self, data_container, index: int, res_position):
254254
residue = data_container.residues[1]
255255
index_prev = residue.resid - 1
256256
index_next = residue.resid + 1
257-
edge_set = data_container.atoms.select_atoms(
257+
edge_set = data_container.select_atoms(
258258
f"resindex {residue.resid - 1} and "
259259
f"(bonded resindex {index_next - 1} or "
260260
f"resindex {index_prev - 1})"
@@ -266,7 +266,7 @@ def get_UA_axes(self, data_container, index: int, res_position):
266266
# last resid
267267
residue = data_container.residues[1]
268268
index_prev = residue.resid - 1
269-
first_edge = data_container.atoms.select_atoms(
269+
first_edge = data_container.select_atoms(
270270
f"resindex {residue.resid - 1} and "
271271
f"bonded resindex {index_prev - 1}"
272272
)
@@ -283,6 +283,7 @@ def get_UA_axes(self, data_container, index: int, res_position):
283283
last = heavy_atom
284284
else:
285285
last_index -= 1
286+
286287
edges = [first_edge.atoms[0], last]
287288
backbone = self.get_chain(residue, first_edge.atoms[0], last)
288289

tests/unit/CodeEntropy/levels/test_axes.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_get_UA_axes_raises_when_bonded_axes_fail(monkeypatch):
213213
heavy_atoms = [heavy_atom]
214214

215215
def _sel(q):
216-
if q == "prop mass > 1.1":
216+
if q == "mass 2 to 999":
217217
return heavy_atoms
218218
if q.startswith("index "):
219219
ag = MagicMock()
@@ -650,8 +650,18 @@ def center_of_mass(self, *args, **kwargs):
650650
def __getitem__(self, idx):
651651
return system_atom
652652

653+
def principal_axes(self, *args, **kwargs):
654+
return np.eye(3)
655+
656+
def select_atoms(self, q):
657+
if q == "mass 2 to 999":
658+
return heavy_atoms
659+
if q.startswith("index "):
660+
return heavy_atom_selection
661+
653662
data_container = MagicMock()
654663
data_container.atoms = _Atoms()
664+
data_container.residues.__len__.return_value = 1
655665
data_container.dimensions = np.array([10.0, 10.0, 10.0, 90, 90, 90], dtype=float)
656666
_FakeAtomGroup.atoms = heavy_atom_selection
657667

@@ -671,12 +681,6 @@ def _select_atoms(q):
671681
)
672682
monkeypatch.setattr(ax, "get_UA_masses", lambda _ag: [12.0, 12.0])
673683

674-
got_tensor = MagicMock(return_value=np.eye(3))
675-
monkeypatch.setattr(ax, "get_moment_of_inertia_tensor", got_tensor)
676-
677-
got_custom_axes = MagicMock(return_value=(np.eye(3), np.array([3.0, 2.0, 1.0])))
678-
monkeypatch.setattr(ax, "get_custom_principal_axes", got_custom_axes)
679-
680684
trans_axes, rot_axes, center, moi = ax.get_UA_axes(
681685
data_container, index=0, res_position=None
682686
)
@@ -685,8 +689,6 @@ def _select_atoms(q):
685689
assert rot_axes.shape == (3, 3)
686690
assert np.allclose(center, np.array([0.0, 0.0, 0.0]))
687691
assert moi.shape == (3,)
688-
got_tensor.assert_called_once()
689-
got_custom_axes.assert_called_once()
690692

691693

692694
def test_get_bonded_axes_returns_none_none_if_custom_axes_none(monkeypatch):

0 commit comments

Comments
 (0)