Skip to content

Commit 13b1473

Browse files
committed
Ensure ordering of starting_magnetization follows order of appearance
1 parent 76d2b55 commit 13b1473

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/koopmans/workflows/_workflow.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,22 @@ def __init__(self,
296296
{k: v for k, v in calculator_parameters['pw'].items() if k.startswith('starting_magnetization')})
297297
if starting_mags:
298298
labels = [a.symbol + str(a.tag) if a.tag > 0 else a.symbol for a in self.atoms]
299-
starting_magmoms: Dict[str, float] = {}
300-
for i, (l, p) in enumerate(self.pseudopotentials.items()):
301-
mag = starting_mags.pop(f'starting_magnetization({i + 1})', 0.0)
299+
starting_magmoms: dict[str, float] = OrderedDict()
300+
i = 0
301+
for label in labels:
302+
if label in starting_magmoms:
303+
continue
304+
i += 1
305+
mag = starting_mags.pop(f'starting_magnetization({i})', 0.0)
302306
if abs(mag) < 1.0:
303307
# If |mag| < 1, QE interprets this as site magnetization *per valence electron*, whereas ASE
304308
# expects simply the site magnetization
309+
p = self.pseudopotentials[label]
305310
valence = p['header']['z_valence']
306-
starting_magmoms[l] = mag * valence
311+
starting_magmoms[label] = mag * valence
307312
else:
308313
# If |mag| >= 1, QE interprets this as site magnetization
309-
starting_magmoms[l] = mag
314+
starting_magmoms[label] = mag
310315
atoms.set_initial_magnetic_moments([starting_magmoms[label] for label in labels])
311316
elif tot_mag != 0:
312317
atoms.set_initial_magnetic_moments([tot_mag / len(atoms) for _ in atoms])

0 commit comments

Comments
 (0)