diff --git a/qiskit_nature/second_q/problems/electronic_structure_result.py b/qiskit_nature/second_q/problems/electronic_structure_result.py index 71b7718ed9..03491f83e6 100644 --- a/qiskit_nature/second_q/problems/electronic_structure_result.py +++ b/qiskit_nature/second_q/problems/electronic_structure_result.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2022. +# (C) Copyright IBM 2020, 2023. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -162,6 +162,8 @@ def total_dipole_moment(self) -> Optional[List[float]]: def total_dipole_moment_in_debye(self) -> Optional[List[float]]: """Returns total dipole of moment in Debye""" tdm = self.total_dipole_moment + if tdm is None: + return None return [dip / DEBYE if dip is not None else None for dip in tdm] @property diff --git a/releasenotes/notes/fix-debye-dipole-0154e964da22910d.yaml b/releasenotes/notes/fix-debye-dipole-0154e964da22910d.yaml new file mode 100644 index 0000000000..de9657b9db --- /dev/null +++ b/releasenotes/notes/fix-debye-dipole-0154e964da22910d.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixes a bug when printing the :attr:`~qiskit_nature.second_q.problems.ElectronicStructureResult.total_dipole_moment_in_debye` diff --git a/test/second_q/problems/test_electronic_structure_result.py b/test/second_q/problems/test_electronic_structure_result.py index 10e88419e3..4c9db12a78 100644 --- a/test/second_q/problems/test_electronic_structure_result.py +++ b/test/second_q/problems/test_electronic_structure_result.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021, 2022. +# (C) Copyright IBM 2021, 2023. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -12,9 +12,9 @@ """Tests for the ElectronicStructureResult.""" -import unittest import contextlib import io +import unittest from itertools import zip_longest from test import QiskitNatureTestCase @@ -80,6 +80,12 @@ def test_print_complex_dipole(self): """ self._assert_printed_result(res) + def test_print_debye_dipole(self): + """Test printing debye dipoles.""" + res = ElectronicStructureResult() + res.computed_dipole_moment = None + self.assertIsNone(res.total_dipole_moment_in_debye) + if __name__ == "__main__": unittest.main()