@@ -805,7 +805,7 @@ def test_frequency_calculation_0(self):
805805
806806 Ensures that the method returns 0 when the input eigenvalue (lambda) is zero.
807807 """
808- lambdas = 0
808+ lambdas = [ 0 ]
809809 temp = 298
810810
811811 run_manager = RunManager ("mock_folder" )
@@ -815,7 +815,7 @@ def test_frequency_calculation_0(self):
815815 )
816816 frequencies = ve .frequency_calculation (lambdas , temp )
817817
818- assert frequencies == 0
818+ assert np . allclose ( frequencies , [ 0.0 ])
819819
820820 def test_frequency_calculation_positive (self ):
821821 """
@@ -842,30 +842,75 @@ def test_frequency_calculation_positive(self):
842842 [1899594266400.4016 , 2013894687315.6213 , 2195940987139.7097 ]
843843 )
844844
845- def test_frequency_calculation_negative (self ):
845+ def test_frequency_calculation_filters_invalid (self ):
846846 """
847- Test `frequency_calculation` with a negative eigenvalue .
847+ Test `frequency_calculation` filters out invalid eigenvalues .
848848
849- Ensures that the method raises a `ValueError` when any eigenvalue is negative ,
850- as this is physically invalid for frequency calculations .
849+ Ensures that negative, complex, and near-zero eigenvalues are excluded ,
850+ and frequencies are calculated only for valid ones .
851851 """
852- lambdas = np .array ([585495.0917897299 , - 658074.5130064893 , 782425.305888707 ])
852+ lambdas = np .array (
853+ [585495.0917897299 , - 658074.5130064893 , 0.0 , 782425.305888707 ]
854+ )
853855 temp = 298
854856
855857 # Create a mock RunManager and set return value for get_KT2J
856- run_manager = RunManager ( "temp_folder" )
857- run_manager .get_KT2J
858+ run_manager = MagicMock ( )
859+ run_manager .get_KT2J . return_value = 2.479e-21 # example value in Joules
858860
859861 # Instantiate VibrationalEntropy with mocks
860862 ve = VibrationalEntropy (
861863 run_manager , MagicMock (), MagicMock (), MagicMock (), MagicMock (), MagicMock ()
862864 )
863865
864- # Assert that ValueError is raised due to negative eigenvalue
865- with self .assertRaises (ValueError ) as context :
866- ve .frequency_calculation (lambdas , temp )
866+ # Call the method
867+ frequencies = ve .frequency_calculation (lambdas , temp )
868+
869+ # Expected: only two valid eigenvalues used
870+ expected_lambdas = np .array ([585495.0917897299 , 782425.305888707 ])
871+ expected_frequencies = (
872+ 1
873+ / (2 * np .pi )
874+ * np .sqrt (expected_lambdas / run_manager .get_KT2J .return_value )
875+ )
876+
877+ # Assert frequencies match expected
878+ np .testing .assert_allclose (frequencies , expected_frequencies , rtol = 1e-5 )
879+
880+ def test_frequency_calculation_filters_invalid_with_warning (self ):
881+ """
882+ Test `frequency_calculation` filters out invalid eigenvalues and logs a warning.
867883
868- self .assertIn ("Negative eigenvalues" , str (context .exception ))
884+ Ensures that negative, complex, and near-zero eigenvalues are excluded,
885+ and a warning is logged about the exclusions.
886+ """
887+ lambdas = np .array (
888+ [585495.0917897299 , - 658074.5130064893 , 0.0 , 782425.305888707 ]
889+ )
890+ temp = 298
891+
892+ run_manager = MagicMock ()
893+ run_manager .get_KT2J .return_value = 2.479e-21 # example value
894+
895+ ve = VibrationalEntropy (
896+ run_manager , MagicMock (), MagicMock (), MagicMock (), MagicMock (), MagicMock ()
897+ )
898+
899+ with self .assertLogs ("CodeEntropy.entropy" , level = "WARNING" ) as cm :
900+ frequencies = ve .frequency_calculation (lambdas , temp )
901+
902+ # Check that warning was logged
903+ warning_messages = "\n " .join (cm .output )
904+ self .assertIn ("invalid eigenvalues excluded" , warning_messages )
905+
906+ # Check that only valid frequencies are returned
907+ expected_lambdas = np .array ([585495.0917897299 , 782425.305888707 ])
908+ expected_frequencies = (
909+ 1
910+ / (2 * np .pi )
911+ * np .sqrt (expected_lambdas / run_manager .get_KT2J .return_value )
912+ )
913+ np .testing .assert_allclose (frequencies , expected_frequencies , rtol = 1e-5 )
869914
870915 def test_vibrational_entropy_calculation_force_not_highest (self ):
871916 """
0 commit comments