Skip to content

Commit 6a5dac2

Browse files
committed
Parse orbital moments in OUTCAR
1 parent d4e253d commit 6a5dac2

File tree

1 file changed

+93
-6
lines changed

1 file changed

+93
-6
lines changed

pymatgen/io/vasp/outputs.py

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,9 @@ def __init__(self, filename):
16371637
mag_x = []
16381638
mag_y = []
16391639
mag_z = []
1640+
orbmom_x = []
1641+
orbmom_y = []
1642+
orbmom_z = []
16401643
header = []
16411644
run_stats = {}
16421645
total_mag = nelect = efermi = e_fr_energy = e_wo_entrp = e0 = None
@@ -1705,9 +1708,12 @@ def __init__(self, filename):
17051708
read_mag_x = False
17061709
read_mag_y = False # for SOC calculations only
17071710
read_mag_z = False
1711+
read_orbmom_x = False # For SOC calculations with LORBMOM=.TRUE.
1712+
read_orbmom_y = False
1713+
read_orbmom_z = False
17081714
all_lines.reverse()
17091715
for clean in all_lines:
1710-
if read_charge or read_mag_x or read_mag_y or read_mag_z:
1716+
if read_charge or read_mag_x or read_mag_y or read_mag_z or read_orbmom_x or read_orbmom_y or read_orbmom_z:
17111717
if clean.startswith("# of ion"):
17121718
header = re.split(r"\s{2,}", clean.strip())
17131719
header.pop(0)
@@ -1724,29 +1730,102 @@ def __init__(self, filename):
17241730
mag_y.append(dict(zip(header, tokens)))
17251731
elif read_mag_z:
17261732
mag_z.append(dict(zip(header, tokens)))
1733+
elif read_orbmom_x:
1734+
orbmom_x.append(dict(zip(header, tokens)))
1735+
elif read_orbmom_y:
1736+
orbmom_y.append(dict(zip(header, tokens)))
1737+
elif read_orbmom_z:
1738+
orbmom_z.append(dict(zip(header, tokens)))
17271739
elif clean.startswith("tot"):
17281740
read_charge = False
17291741
read_mag_x = False
17301742
read_mag_y = False
17311743
read_mag_z = False
1744+
read_orbmom_x = False
1745+
read_orbmom_y = False
1746+
read_orbmom_z = False
17321747
if clean == "total charge":
17331748
charge = []
17341749
read_charge = True
1735-
read_mag_x, read_mag_y, read_mag_z = False, False, False
1750+
read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = (
1751+
False,
1752+
False,
1753+
False,
1754+
False,
1755+
False,
1756+
False,
1757+
)
17361758
elif clean == "magnetization (x)":
17371759
mag_x = []
17381760
read_mag_x = True
1739-
read_charge, read_mag_y, read_mag_z = False, False, False
1761+
read_charge, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = (
1762+
False,
1763+
False,
1764+
False,
1765+
False,
1766+
False,
1767+
False,
1768+
)
17401769
elif clean == "magnetization (y)":
17411770
mag_y = []
17421771
read_mag_y = True
1743-
read_charge, read_mag_x, read_mag_z = False, False, False
1772+
read_charge, read_mag_x, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = (
1773+
False,
1774+
False,
1775+
False,
1776+
False,
1777+
False,
1778+
False,
1779+
)
17441780
elif clean == "magnetization (z)":
17451781
mag_z = []
17461782
read_mag_z = True
1747-
read_charge, read_mag_x, read_mag_y = False, False, False
1783+
read_charge, read_mag_x, read_mag_y, read_orbmom_x, read_orbmom_y, read_orbmom_z = (
1784+
False,
1785+
False,
1786+
False,
1787+
False,
1788+
False,
1789+
False,
1790+
)
1791+
elif clean == "orbital moment (x)":
1792+
orbmom_x = []
1793+
read_orbmom_x = True
1794+
read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_y, read_orbmom_z = (
1795+
False,
1796+
False,
1797+
False,
1798+
False,
1799+
False,
1800+
False,
1801+
)
1802+
elif clean == "orbital moment (y)":
1803+
orbmom_y = []
1804+
read_orbmom_y = True
1805+
read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_z = (
1806+
False,
1807+
False,
1808+
False,
1809+
False,
1810+
False,
1811+
False,
1812+
)
1813+
elif clean == "orbital moment (z)":
1814+
orbmom_z = []
1815+
read_orbmom_z = True
1816+
read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y = (
1817+
False,
1818+
False,
1819+
False,
1820+
False,
1821+
False,
1822+
False,
1823+
)
17481824
elif re.search("electrostatic", clean):
1749-
read_charge, read_mag_x, read_mag_y, read_mag_z = (
1825+
read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = (
1826+
False,
1827+
False,
1828+
False,
17501829
False,
17511830
False,
17521831
False,
@@ -1761,6 +1840,13 @@ def __init__(self, filename):
17611840
mag.append({key: Magmom([mag_x[idx][key], mag_y[idx][key], mag_z[idx][key]]) for key in mag_x[0]})
17621841
else:
17631842
mag = mag_x
1843+
# merge x, y and z components of orbmoms if present (SOC calculation with LORBMOM=.TRUE.)
1844+
orbmom = []
1845+
if orbmom_x and orbmom_y and orbmom_z:
1846+
for idx in range(len(orbmom_x)):
1847+
orbmom.append(
1848+
{key: Magmom([orbmom_x[idx][key], orbmom_y[idx][key], orbmom_z[idx][key]]) for key in orbmom_x[0]}
1849+
)
17641850

17651851
# data from beginning of OUTCAR
17661852
run_stats["cores"] = None
@@ -1780,6 +1866,7 @@ def __init__(self, filename):
17801866

17811867
self.run_stats = run_stats
17821868
self.magnetization = tuple(mag)
1869+
self.orbital_moment = tuple(orbmom)
17831870
self.charge = tuple(charge)
17841871
self.efermi = efermi
17851872
self.nelect = nelect

0 commit comments

Comments
 (0)