Skip to content

Commit 71b670a

Browse files
committed
additional test cases for entropy.py this ensures coverage of orientational_entropy_calculation function
1 parent e18092c commit 71b670a

2 files changed

Lines changed: 48 additions & 7 deletions

File tree

CodeEntropy/entropy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def orientational_entropy_calculation(self, neighbours_dict):
822822
# Replaced molecule with neighbour as this is what the for loop uses
823823
S_or_total = 0
824824
for neighbour in neighbours_dict: # we are going through neighbours
825-
if neighbour in []: # water molecules - call POSEIDON functions
825+
if neighbour in ["H2O"]: # water molecules - call POSEIDON functions
826826
pass # TODO temporary until function is written
827827
else:
828828
# the bound ligand is always going to be a neighbour
@@ -835,16 +835,16 @@ def orientational_entropy_calculation(self, neighbours_dict):
835835
f"S_or_component (log(omega)) for neighbour {neighbour}: "
836836
f"{S_or_component}"
837837
)
838-
S_or_component *= self.GAS_CONST
838+
S_or_component *= self._GAS_CONST
839839
logger.debug(
840840
f"S_or_component after multiplying by GAS_CONST for neighbour "
841841
f"{neighbour}: {S_or_component}"
842842
)
843-
S_or_total += S_or_component
844-
logger.debug(
845-
f"S_or_total after adding component for neighbour {neighbour}: "
846-
f"{S_or_total}"
847-
)
843+
S_or_total += S_or_component
844+
logger.debug(
845+
f"S_or_total after adding component for neighbour {neighbour}: "
846+
f"{S_or_total}"
847+
)
848848
# TODO for future releases
849849
# implement a case for molecules with hydrogen bonds but to a lesser
850850
# extent than water

tests/test_CodeEntropy/test_entropy.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import os
23
import shutil
34
import tempfile
@@ -1197,6 +1198,46 @@ def test_orientational_entropy_init(self):
11971198
self.assertEqual(oe._args.temperature, 300)
11981199
self.assertEqual(oe._args.bin_width, 0.1)
11991200

1201+
def test_orientational_entropy_calculation(self):
1202+
"""
1203+
Tests that `orientational_entropy_calculation` correctly computes the total
1204+
orientational entropy for a given dictionary of neighboring species using
1205+
the internal gas constant.
1206+
"""
1207+
# Setup a mock neighbours dictionary
1208+
neighbours_dict = {
1209+
"ligandA": 2,
1210+
"ligandB": 3,
1211+
}
1212+
1213+
# Create an instance of OrientationalEntropy with dummy dependencies
1214+
oe = OrientationalEntropy(None, None, None, None, None)
1215+
1216+
# Run the method
1217+
result = oe.orientational_entropy_calculation(neighbours_dict)
1218+
1219+
# Manually compute expected result using the class's internal gas constant
1220+
expected = (
1221+
math.log(math.sqrt((2**3) * math.pi))
1222+
+ math.log(math.sqrt((3**3) * math.pi))
1223+
) * oe._GAS_CONST
1224+
1225+
# Assert the result is as expected
1226+
self.assertAlmostEqual(result, expected, places=6)
1227+
1228+
def test_orientational_entropy_water_branch_is_covered(self):
1229+
"""
1230+
Tests that the placeholder branch for water molecules is executed to ensure
1231+
coverage of the `if neighbour in [...]` block.
1232+
"""
1233+
neighbours_dict = {"H2O": 1} # Matches the condition exactly
1234+
1235+
oe = OrientationalEntropy(None, None, None, None, None)
1236+
result = oe.orientational_entropy_calculation(neighbours_dict)
1237+
1238+
# Since the logic is skipped, total entropy should be 0.0
1239+
self.assertEqual(result, 0.0)
1240+
12001241

12011242
if __name__ == "__main__":
12021243
unittest.main()

0 commit comments

Comments
 (0)