ezpzbz / aiida-catmat

Collection of AiiDA WorkChains Developed in CATMAT project
MIT License
3 stars 1 forks source link

[BUG] issue in structure sort when spin sign changes during the workchain #44

Closed ezpzbz closed 4 years ago

ezpzbz commented 4 years ago

context

We do generate INCAR in each stage to have updated information of the structure after previous stage. However, one thing that I am not checking currently is the sign of spin. When we generate structure, we do the structure soring so the species would be sorted and we would not have problem in constructing the hubbard parameters section of INCAR. However, I just realized that we may face structures where the sign of spin would change during the calculations and chages the sorted structure. This will in turn result in having incosistent order of hubbard parameters and therefore crash of parser.

solution

We need to run a sanity check when forming the LDAU tags. The solution that so far I came up with is:

  1. Before constructing the LDAU tag, compare spins of provided structure and its sorted version.
  2. If they are identical, pass! If they are different, take the sorted structure, update structure, and construct the hubbard tag based on updated structure.

To do the check:

import functools
structure_pmg = structure.get_pymatgen_structure(add_spin=True)
structure_pmg_sorted = structure.get_pymatgen_structure(add_spin=True)
structure_pmg_sorted.sort()
species = structure_pmg.species
species_sorted = structure_pmg_sorted.species
spin = []
for s in species:
      spin1.append(getattr(s, "spin", 0))
spin_sorted = []
for s in species_sorted:
      spin_sorted.append(getattr(s, "spin", 0))
if functools.reduce(lambda i, j : i and j, map(lambda m, k: m == k, spin, spin_sorted), True) :
        print ("The lists are identical")
else :
        print ("The lists are not identical")