Skip to content

Commit 8fd9a48

Browse files
committed
added edge case unit test
1 parent c6cba70 commit 8fd9a48

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

‎tests/unit/CodeEntropy/levels/test_axes.py‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ def _select_atoms(q):
12691269

12701270
u.atoms.select_atoms.side_effect = _select_atoms
12711271
u.atoms.principal_axes.return_value = np.eye(3)
1272-
monkeypatch.setattr(ax, "get_chain", backbone_atom)
1272+
monkeypatch.setattr(ax, "get_chain", lambda residue, first, last: [backbone_atom])
12731273
monkeypatch.setattr(
12741274
ax,
12751275
"get_custom_residue_moment_of_inertia",
@@ -1639,3 +1639,49 @@ def _sel(q):
16391639

16401640
with pytest.raises(ValueError):
16411641
ax.get_UA_axes(u, index=0, res_position=None)
1642+
1643+
1644+
def get_residue_bonded_axes_terminal_2_points(monkeypatch):
1645+
ax = AxesCalculator()
1646+
u = MagicMock()
1647+
u.dimensions = np.array([10.0, 10.0, 10.0, 90, 90, 90])
1648+
monkeypatch.setattr("CodeEntropy.levels.axes.make_whole", lambda _ag: None)
1649+
residue = u.select_atoms("resindex 0")
1650+
residue.__len__.return_value = 3
1651+
uas = _FakeAtomGroup(
1652+
[
1653+
_atom(index=0, mass=12.0, pos=[1, 0, 0]),
1654+
_atom(index=1, mass=12.0, pos=[0, 1, 0]),
1655+
]
1656+
)
1657+
1658+
def _select_atoms(q):
1659+
if q == "mass 2 to 999":
1660+
return uas
1661+
if q.startswith("(mass 2 to 999) and bonded"):
1662+
# the bonded atom
1663+
return [uas[1]]
1664+
if q.startswith("resindex 0 and (bonded resindex"):
1665+
# edge atom
1666+
return [uas[2]]
1667+
1668+
u.atoms.principal_axes.return_value = np.eye(3)
1669+
u.atoms.select_atoms.side_effect = _select_atoms
1670+
residue.select_atoms.side_effect = _select_atoms
1671+
1672+
monkeypatch.setattr(
1673+
ax,
1674+
"get_custom_residue_moment_of_inertia",
1675+
lambda center_of_mass, positions, masses, custom_rot_axes, dimensions: np.array(
1676+
[1, 1, 1]
1677+
),
1678+
)
1679+
1680+
trans_axes, rot_axes, rot_center, moi = ax.get_residue_axes(
1681+
u, index=0, relative_index=0
1682+
)
1683+
1684+
assert np.allclose(trans_axes, np.eye(3))
1685+
assert rot_axes.shape == (3, 3)
1686+
assert np.allclose(rot_center, [1, 1, 0])
1687+
assert np.allclose(moi, np.array([1, 1, 1]))

0 commit comments

Comments
 (0)