From 482775f19e11ae77e7ee9835ee23068da11c52cb Mon Sep 17 00:00:00 2001 From: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:27:41 +0800 Subject: [PATCH] Fix: qe/pw/scf unit conversion is not consistent with dpdata (#725) ## Summary by CodeRabbit - **New Features** - Introduced a configuration file for sodium SCF calculations, enhancing quantum mechanical simulations. - Added a new test class to verify properties of sodium systems, improving test coverage. - **Bug Fixes** - Improved logic for block extraction and stress block handling to enhance robustness. - **Tests** - Updated energy validation method to use relative comparisons for more accurate results. --------- Signed-off-by: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com> Co-authored-by: Han Wang Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dpdata/qe/scf.py | 10 +++++++--- tests/test_qe_pw_scf.py | 6 +++--- tests/test_qe_pw_scf_energy_bug.py | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dpdata/qe/scf.py b/dpdata/qe/scf.py index 7b6a70aa..341261d2 100755 --- a/dpdata/qe/scf.py +++ b/dpdata/qe/scf.py @@ -7,9 +7,13 @@ from dpdata.utils import open_file -ry2ev = 13.605693009 -bohr2ang = 0.52917721067 -kbar2evperang3 = 1e3 / 1.602176621e6 +from .traj import ( + kbar2evperang3, + ry2ev, +) +from .traj import ( + length_convert as bohr2ang, +) _QE_BLOCK_KEYWORDS = [ "ATOMIC_SPECIES", diff --git a/tests/test_qe_pw_scf.py b/tests/test_qe_pw_scf.py index a38e2d05..7fe803b9 100644 --- a/tests/test_qe_pw_scf.py +++ b/tests/test_qe_pw_scf.py @@ -161,11 +161,11 @@ def test_virial(self): def test_energy(self): ref_energy = -219.74425946528794 - self.assertAlmostEqual(self.system_ch4.data["energies"][0], ref_energy) + self.assertAlmostEqual(self.system_ch4.data["energies"][0] / ref_energy, 1.0) ref_energy = -30007.651851226798 - self.assertAlmostEqual(self.system_h2o.data["energies"][0], ref_energy) + self.assertAlmostEqual(self.system_h2o.data["energies"][0] / ref_energy, 1.0) ref_energy = -219.7153691367526562 - self.assertAlmostEqual(self.system_ch4_2.data["energies"][0], ref_energy) + self.assertAlmostEqual(self.system_ch4_2.data["energies"][0] / ref_energy, 1.0) class TestPWSCFLabeledOutput(unittest.TestCase, TestPWSCFSinglePointEnergy): diff --git a/tests/test_qe_pw_scf_energy_bug.py b/tests/test_qe_pw_scf_energy_bug.py index b66ce924..a513dc7c 100644 --- a/tests/test_qe_pw_scf_energy_bug.py +++ b/tests/test_qe_pw_scf_energy_bug.py @@ -8,7 +8,7 @@ class TestPWSCFSinglePointEnergy: def test_energy(self): ref_energy = -296.08379065679094669 - self.assertAlmostEqual(self.system_al.data["energies"][0], ref_energy) + self.assertAlmostEqual(self.system_al.data["energies"][0] / ref_energy, 1.0) class TestPWSCFLabeledOutput(unittest.TestCase, TestPWSCFSinglePointEnergy):