Skip to content

Commit

Permalink
fix: printing debye-dipole-moment (qiskit-community#1057)
Browse files Browse the repository at this point in the history
* fix: printing debye-dipole-moment

* fix copyright

* Update qiskit_nature/second_q/problems/electronic_structure_result.py

---------

Co-authored-by: Max Rossmannek <[email protected]>
  • Loading branch information
wltr-tlrc and mrossinek authored Feb 10, 2023
1 parent dbe573b commit 1ed64c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/fix-debye-dipole-0154e964da22910d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fixes a bug when printing the :attr:`~qiskit_nature.second_q.problems.ElectronicStructureResult.total_dipole_moment_in_debye`
10 changes: 8 additions & 2 deletions test/second_q/problems/test_electronic_structure_result.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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()

0 comments on commit 1ed64c8

Please sign in to comment.