Skip to content

Commit

Permalink
Use self.info.spin to determine spin type for Mulliken charges
Browse files Browse the repository at this point in the history
  • Loading branch information
ahkole committed Mar 14, 2024
1 parent af95fd7 commit fece834
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/sisl/io/siesta/stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sisl._common import Opt
from sisl._internal import set_module
from sisl.messages import deprecation, warn
from sisl.physics import Spin
from sisl.unit.siesta import unit_convert
from sisl.utils import PropertyDict
from sisl.utils.cmd import *
Expand All @@ -34,6 +35,20 @@ def _ensure_atoms(atoms):
return atoms


def _parse_spin(attr, match):
spin_string = match.group(1)
if spin_string == "none":
return Spin.UNPOLARIZED
elif spin_string == "collinear":
return Spin.POLARIZED
elif spin_string == "non-collinear":
return Spin.NONCOLINEAR
elif "spin-orbit" in spin_string:
return Spin.SPINORBIT
else:
assert False # Should never reach here


@set_module("sisl.io.siesta")
class stdoutSileSiesta(SileSiesta):
"""Output file from Siesta
Expand All @@ -48,6 +63,11 @@ class stdoutSileSiesta(SileSiesta):
lambda attr, match: lambda: True,
default=lambda: False,
),
_A(
"spin",
r".*Spin configuration\s*=\s*(\S+)\s*",
_parse_spin,
),
]

@deprecation(
Expand Down Expand Up @@ -1259,26 +1279,13 @@ def try_parse_int(s):
atom_charges.append(charge)

# Determine with which spin type we are dealing
IDX_NON_POL = 0
IDX_POL = 1
IDX_NC = 2
search_keys_spin = [
"Qatom", # if we find Qatom and no "mulliken: Spin UP" we are dealing with spin unpolarized
"mulliken: Spin UP",
"Svec",
]
loc = self.fh.tell()
ret = self.step_to(
search_keys_spin, case=True, ret_index=True, allow_reread=False
)
self.fh.seek(loc)
if ret[2] == IDX_NON_POL:
if self.info.spin == Spin.UNPOLARIZED:
# No spin components so just parse charge
atom_charges = []
atom_idx = []
header = ["e"]
_parse_spin_pol()
elif ret[2] == IDX_POL:
elif self.info.spin == Spin.POLARIZED:
# Parse both spin polarizations
atom_charges_pol = []
header = ["e", "Sz"]
Expand All @@ -1294,7 +1301,7 @@ def try_parse_int(s):
atom_q = atom_charges_pol_array[0, :] + atom_charges_pol_array[1, :]
atom_s = atom_charges_pol_array[0, :] - atom_charges_pol_array[1, :]
atom_charges[:] = np.stack((atom_q, atom_s), axis=-1)
elif ret[2] == IDX_NC:
elif self.info.spin == Spin.NONCOLINEAR or self.info.spin == Spin.SPINORBIT:
# Parse as long as we find new species
atom_charges = []
atom_idx = []
Expand Down

0 comments on commit fece834

Please sign in to comment.