diff --git a/src/sisl/io/siesta/stdout.py b/src/sisl/io/siesta/stdout.py index 25bb8e247..b350986cb 100644 --- a/src/sisl/io/siesta/stdout.py +++ b/src/sisl/io/siesta/stdout.py @@ -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 * @@ -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 @@ -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( @@ -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"] @@ -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 = []