diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index 9af84743be7..26b113f489e 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -1637,6 +1637,9 @@ def __init__(self, filename): mag_x = [] mag_y = [] mag_z = [] + orbmom_x = [] + orbmom_y = [] + orbmom_z = [] header = [] run_stats = {} total_mag = nelect = efermi = e_fr_energy = e_wo_entrp = e0 = None @@ -1705,9 +1708,12 @@ def __init__(self, filename): read_mag_x = False read_mag_y = False # for SOC calculations only read_mag_z = False + read_orbmom_x = False # For SOC calculations with LORBMOM=.TRUE. + read_orbmom_y = False + read_orbmom_z = False all_lines.reverse() for clean in all_lines: - if read_charge or read_mag_x or read_mag_y or read_mag_z: + 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: if clean.startswith("# of ion"): header = re.split(r"\s{2,}", clean.strip()) header.pop(0) @@ -1724,29 +1730,102 @@ def __init__(self, filename): mag_y.append(dict(zip(header, tokens))) elif read_mag_z: mag_z.append(dict(zip(header, tokens))) + elif read_orbmom_x: + orbmom_x.append(dict(zip(header, tokens))) + elif read_orbmom_y: + orbmom_y.append(dict(zip(header, tokens))) + elif read_orbmom_z: + orbmom_z.append(dict(zip(header, tokens))) elif clean.startswith("tot"): read_charge = False read_mag_x = False read_mag_y = False read_mag_z = False + read_orbmom_x = False + read_orbmom_y = False + read_orbmom_z = False if clean == "total charge": charge = [] read_charge = True - read_mag_x, read_mag_y, read_mag_z = False, False, False + read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = ( + False, + False, + False, + False, + False, + False, + ) elif clean == "magnetization (x)": mag_x = [] read_mag_x = True - read_charge, read_mag_y, read_mag_z = False, False, False + read_charge, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = ( + False, + False, + False, + False, + False, + False, + ) elif clean == "magnetization (y)": mag_y = [] read_mag_y = True - read_charge, read_mag_x, read_mag_z = False, False, False + read_charge, read_mag_x, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = ( + False, + False, + False, + False, + False, + False, + ) elif clean == "magnetization (z)": mag_z = [] read_mag_z = True - read_charge, read_mag_x, read_mag_y = False, False, False + read_charge, read_mag_x, read_mag_y, read_orbmom_x, read_orbmom_y, read_orbmom_z = ( + False, + False, + False, + False, + False, + False, + ) + elif clean == "orbital moment (x)": + orbmom_x = [] + read_orbmom_x = True + read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_y, read_orbmom_z = ( + False, + False, + False, + False, + False, + False, + ) + elif clean == "orbital moment (y)": + orbmom_y = [] + read_orbmom_y = True + read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_z = ( + False, + False, + False, + False, + False, + False, + ) + elif clean == "orbital moment (z)": + orbmom_z = [] + read_orbmom_z = True + read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y = ( + False, + False, + False, + False, + False, + False, + ) elif re.search("electrostatic", clean): - read_charge, read_mag_x, read_mag_y, read_mag_z = ( + read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y, read_orbmom_z = ( + False, + False, + False, False, False, False, @@ -1761,6 +1840,13 @@ def __init__(self, filename): mag.append({key: Magmom([mag_x[idx][key], mag_y[idx][key], mag_z[idx][key]]) for key in mag_x[0]}) else: mag = mag_x + # merge x, y and z components of orbmoms if present (SOC calculation with LORBMOM=.TRUE.) + orbmom = [] + if orbmom_x and orbmom_y and orbmom_z: + for idx in range(len(orbmom_x)): + orbmom.append( + {key: Magmom([orbmom_x[idx][key], orbmom_y[idx][key], orbmom_z[idx][key]]) for key in orbmom_x[0]} + ) # data from beginning of OUTCAR run_stats["cores"] = None @@ -1780,6 +1866,7 @@ def __init__(self, filename): self.run_stats = run_stats self.magnetization = tuple(mag) + self.orbital_moment = tuple(orbmom) self.charge = tuple(charge) self.efermi = efermi self.nelect = nelect