From b7865149a052d0a03eabfd93834faa6e3e0b6ad6 Mon Sep 17 00:00:00 2001 From: Francesco Ricci Date: Tue, 5 Apr 2022 09:23:44 -0700 Subject: [PATCH 1/5] fix dipole units --- pymatgen/io/vasp/outputs.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index 511f6fae7f2..4fb924b37ba 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -3142,6 +3142,17 @@ def p_ion(results, match): micro_pyawk(self.filename, search, self) + # fix polarization units in new versions of vasp + regex = r"^.*Ionic dipole moment: .*" + search = [[regex,None,lambda x,y: x.append(y.group(0))]] + r = micro_pyawk(self.filename,search,[]) + + if "|e|" in r[0]: + self.p_elec *= -1 + self.p_sp1 *= -1 + self.p_sp2 *= -1 + self.p_ion *= -1 + except Exception: raise Exception("LCALCPOL OUTCAR could not be parsed.") From 6d32cb2dd7fa322516d61a81e672213fef802383 Mon Sep 17 00:00:00 2001 From: Francesco Ricci Date: Tue, 5 Apr 2022 09:48:08 -0700 Subject: [PATCH 2/5] spin component fixed --- pymatgen/io/vasp/outputs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index 4fb924b37ba..e47c73fc149 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -3149,9 +3149,10 @@ def p_ion(results, match): if "|e|" in r[0]: self.p_elec *= -1 - self.p_sp1 *= -1 - self.p_sp2 *= -1 - self.p_ion *= -1 + self.p_ion *= -1 + if self.p_sp1: + self.p_sp1 *= -1 + self.p_sp2 *= -1 except Exception: raise Exception("LCALCPOL OUTCAR could not be parsed.") From ece9c86febbb23f98512b83d2464250670af2926 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Apr 2022 16:52:57 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pymatgen/io/vasp/outputs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index e47c73fc149..e9102ad44e7 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -3144,15 +3144,15 @@ def p_ion(results, match): # fix polarization units in new versions of vasp regex = r"^.*Ionic dipole moment: .*" - search = [[regex,None,lambda x,y: x.append(y.group(0))]] - r = micro_pyawk(self.filename,search,[]) + search = [[regex, None, lambda x, y: x.append(y.group(0))]] + r = micro_pyawk(self.filename, search, []) if "|e|" in r[0]: - self.p_elec *= -1 + self.p_elec *= -1 self.p_ion *= -1 if self.p_sp1: - self.p_sp1 *= -1 - self.p_sp2 *= -1 + self.p_sp1 *= -1 + self.p_sp2 *= -1 except Exception: raise Exception("LCALCPOL OUTCAR could not be parsed.") From 5a1bfa3ad6edec9072613fb8e03c504a4f5b3172 Mon Sep 17 00:00:00 2001 From: Francesco Ricci Date: Tue, 5 Apr 2022 16:30:17 -0700 Subject: [PATCH 4/5] test_read_lcalcpol() added --- pymatgen/io/vasp/outputs.py | 5 ++-- pymatgen/io/vasp/tests/test_outputs.py | 37 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index e47c73fc149..00b676bfa10 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -3150,11 +3150,12 @@ def p_ion(results, match): if "|e|" in r[0]: self.p_elec *= -1 self.p_ion *= -1 - if self.p_sp1: + if self.spin and not self.noncollinear: self.p_sp1 *= -1 self.p_sp2 *= -1 - except Exception: + except Exception as ex: + print(ex.args) raise Exception("LCALCPOL OUTCAR could not be parsed.") def read_pseudo_zval(self): diff --git a/pymatgen/io/vasp/tests/test_outputs.py b/pymatgen/io/vasp/tests/test_outputs.py index dc1a41da30d..e54a9977190 100644 --- a/pymatgen/io/vasp/tests/test_outputs.py +++ b/pymatgen/io/vasp/tests/test_outputs.py @@ -1017,6 +1017,43 @@ def test_read_elastic_tensor(self): self.assertAlmostEqual(outcar.data["elastic_tensor"][0][1], 187.8324) self.assertAlmostEqual(outcar.data["elastic_tensor"][3][3], 586.3034) + def test_read_lcalcpol(self): + # outcar with electrons Angst units + folder = "BTO_221_99_polarization/interpolation_6_polarization/" + filepath = self.TEST_FILES_DIR / folder / "OUTCAR" + outcar = Outcar(filepath) + + outcar.read_lcalcpol() + + p_ion = [ 0. , 0. , 19.70306] + p_elec = [ 4.02264, 4.02263, -4.08851] + p_sp1 = [ 2.01124, 2.01124, -2.04426] + p_sp2 = [ 2.01139, 2.01139, -2.04426] + + for i in range(3): + self.assertAlmostEqual(outcar.p_ion[i], p_ion[i]) + self.assertAlmostEqual(outcar.p_elec[i], p_elec[i]) + self.assertAlmostEqual(outcar.p_sp1[i], p_sp1[i]) + self.assertAlmostEqual(outcar.p_sp2[i], p_sp2[i]) + + # outcar with |e| Angst units + filepath = self.TEST_FILES_DIR / "outcar_vasp_6.3.gz" + outcar = Outcar(filepath) + + outcar.read_lcalcpol() + + p_ion = [-79.03374, -0. , -28.44354] + p_elec = [ 9.01127e+00, -1.00000e-05, 3.24308e+00] + p_sp1 = [4.50564, 0. , 1.62154] + p_sp2 = [ 4.50563e+00, -1.00000e-05, 1.62154e+00] + + for i in range(3): + self.assertAlmostEqual(outcar.p_ion[i], p_ion[i]) + self.assertAlmostEqual(outcar.p_elec[i], p_elec[i]) + self.assertAlmostEqual(outcar.p_sp1[i], p_sp1[i]) + self.assertAlmostEqual(outcar.p_sp2[i], p_sp2[i]) + + def test_read_piezo_tensor(self): filepath = self.TEST_FILES_DIR / "OUTCAR.lepsilon.gz" outcar = Outcar(filepath) From 79939cb92a0a8eb639a7c8df64609b6489b2753c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Apr 2022 23:39:08 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pymatgen/io/vasp/outputs.py | 4 ++-- pymatgen/io/vasp/tests/test_outputs.py | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index 29d2fdcc697..aaebb8bc414 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -3151,8 +3151,8 @@ def p_ion(results, match): self.p_elec *= -1 self.p_ion *= -1 if self.spin and not self.noncollinear: - self.p_sp1 *= -1 - self.p_sp2 *= -1 + self.p_sp1 *= -1 + self.p_sp2 *= -1 except Exception as ex: print(ex.args) diff --git a/pymatgen/io/vasp/tests/test_outputs.py b/pymatgen/io/vasp/tests/test_outputs.py index e54a9977190..e556037d7ca 100644 --- a/pymatgen/io/vasp/tests/test_outputs.py +++ b/pymatgen/io/vasp/tests/test_outputs.py @@ -1025,10 +1025,10 @@ def test_read_lcalcpol(self): outcar.read_lcalcpol() - p_ion = [ 0. , 0. , 19.70306] - p_elec = [ 4.02264, 4.02263, -4.08851] - p_sp1 = [ 2.01124, 2.01124, -2.04426] - p_sp2 = [ 2.01139, 2.01139, -2.04426] + p_ion = [0.0, 0.0, 19.70306] + p_elec = [4.02264, 4.02263, -4.08851] + p_sp1 = [2.01124, 2.01124, -2.04426] + p_sp2 = [2.01139, 2.01139, -2.04426] for i in range(3): self.assertAlmostEqual(outcar.p_ion[i], p_ion[i]) @@ -1036,16 +1036,16 @@ def test_read_lcalcpol(self): self.assertAlmostEqual(outcar.p_sp1[i], p_sp1[i]) self.assertAlmostEqual(outcar.p_sp2[i], p_sp2[i]) - # outcar with |e| Angst units + # outcar with |e| Angst units filepath = self.TEST_FILES_DIR / "outcar_vasp_6.3.gz" outcar = Outcar(filepath) outcar.read_lcalcpol() - p_ion = [-79.03374, -0. , -28.44354] - p_elec = [ 9.01127e+00, -1.00000e-05, 3.24308e+00] - p_sp1 = [4.50564, 0. , 1.62154] - p_sp2 = [ 4.50563e+00, -1.00000e-05, 1.62154e+00] + p_ion = [-79.03374, -0.0, -28.44354] + p_elec = [9.01127e00, -1.00000e-05, 3.24308e00] + p_sp1 = [4.50564, 0.0, 1.62154] + p_sp2 = [4.50563e00, -1.00000e-05, 1.62154e00] for i in range(3): self.assertAlmostEqual(outcar.p_ion[i], p_ion[i]) @@ -1053,7 +1053,6 @@ def test_read_lcalcpol(self): self.assertAlmostEqual(outcar.p_sp1[i], p_sp1[i]) self.assertAlmostEqual(outcar.p_sp2[i], p_sp2[i]) - def test_read_piezo_tensor(self): filepath = self.TEST_FILES_DIR / "OUTCAR.lepsilon.gz" outcar = Outcar(filepath)