Skip to content

Commit

Permalink
Merge pull request #2486 from fraricci/fix_dipole_units
Browse files Browse the repository at this point in the history
Fix dipole moments units for VASP 6.3
  • Loading branch information
mkhorton authored Apr 20, 2022
2 parents ec9eb7c + 79939cb commit bb259c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3142,7 +3142,20 @@ def p_ion(results, match):

micro_pyawk(self.filename, search, self)

except Exception:
# 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_ion *= -1
if self.spin and not self.noncollinear:
self.p_sp1 *= -1
self.p_sp2 *= -1

except Exception as ex:
print(ex.args)
raise Exception("LCALCPOL OUTCAR could not be parsed.")

def read_pseudo_zval(self):
Expand Down
36 changes: 36 additions & 0 deletions pymatgen/io/vasp/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,42 @@ 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, 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.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])
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)
Expand Down

0 comments on commit bb259c6

Please sign in to comment.