Skip to content

Commit 3ed442c

Browse files
committed
add unit test for _compute_ft_entropy function within entropy/vibrational.py
1 parent c71ee1d commit 3ed442c

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎CodeEntropy/entropy/nodes/vibrational.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def run(self, shared_data: MutableMapping[str, Any], **_: Any) -> Dict[str, Any]
7878
ua_frame_counts=ua_frame_counts,
7979
reporter=reporter,
8080
n_frames_default=shared_data.get("n_frames", 0),
81-
highest=highest, # IMPORTANT: matches main
81+
highest=highest,
8282
)
8383
self._store_results(results, group_id, level, pair)
8484
self._log_molecule_level_results(
@@ -89,7 +89,6 @@ def run(self, shared_data: MutableMapping[str, Any], **_: Any) -> Dict[str, Any]
8989
if level in ("residue", "polymer"):
9090
gi = gid2i[group_id]
9191

92-
# FT only applies at the highest level (same as main)
9392
if combined and highest and ft_cov is not None:
9493
ft_key = "res" if level == "residue" else "poly"
9594
ftmat = self._get_indexed_matrix(ft_cov.get(ft_key, []), gi)
@@ -219,7 +218,6 @@ def _compute_force_torque_entropy(
219218
np.asarray(tmat), atol=self._zero_atol
220219
)
221220

222-
# If filtering removes everything, behave like "no data"
223221
if f.size == 0 or t.size == 0:
224222
return EntropyPair(trans=0.0, rot=0.0)
225223

@@ -247,7 +245,6 @@ def _compute_ft_entropy(
247245
if ft.size == 0:
248246
return EntropyPair(trans=0.0, rot=0.0)
249247

250-
# FT is only used at highest level in main branch
251248
s_trans = ve.vibrational_entropy_calculation(
252249
ft, "forcetorqueTRANS", temp, highest_level=True
253250
)

‎tests/unit/CodeEntropy/entropy/nodes/test_vibrational_node.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,19 @@ def test_run_unknown_level_raises(shared_groups):
364364

365365
with pytest.raises(ValueError):
366366
node.run(shared_groups)
367+
368+
369+
def test_compute_ft_entropy_returns_zeros_when_filtered_ft_matrix_is_empty(monkeypatch):
370+
node = VibrationalEntropyNode()
371+
ve = MagicMock()
372+
373+
monkeypatch.setattr(
374+
node._mat_ops,
375+
"filter_zero_rows_columns",
376+
lambda _arr, atol: np.empty((0, 0), dtype=float),
377+
)
378+
379+
out = node._compute_ft_entropy(ve=ve, temp=298.0, ftmat=np.eye(6))
380+
381+
assert out == EntropyPair(trans=0.0, rot=0.0)
382+
ve.vibrational_entropy_calculation.assert_not_called()

0 commit comments

Comments
 (0)