Skip to content

Commit 73442cf

Browse files
committed
Made sure band structure plotting works for spin polarized systems
1 parent dd10185 commit 73442cf

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/koopmans/workflows/_koopmans_dfpt.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from pathlib import Path
1111
from typing import Dict
1212

13+
import numpy as np
14+
1315
from koopmans import pseudopotentials, utils
1416
from koopmans.bands import Bands
1517
from koopmans.calculators import (KoopmansHamCalculator, PWCalculator,
@@ -280,20 +282,29 @@ def _run(self):
280282
self, dft_ham_files=dft_ham_files, koopmans_ham_files=koopmans_ham_files)
281283
ui_workflow.run(subdirectory='postproc' + spin_suffix)
282284

283-
# Plotting
284-
self.plot_bandstructure()
285+
# Plotting
286+
if self._perform_ham_calc:
287+
self.plot_bandstructure()
285288

286289
def plot_bandstructure(self):
287290
if not all(self.atoms.pbc):
288291
return
289292

290293
# Identify the relevant calculators
291-
kc_ham_calc = [c for c in self.calculations if isinstance(c, KoopmansHamCalculator)][-1]
294+
n_calc = 2 if self.parameters.spin_polarized else 1
295+
kc_ham_calcs = [c for c in self.calculations if isinstance(c, KoopmansHamCalculator)][-n_calc:]
292296

293297
# Plot the bandstructure if the band path has been specified
294-
bs = kc_ham_calc.results['band structure']
295-
if bs.path.path:
296-
super().plot_bandstructure(bs.subtract_reference())
298+
bandstructures = [c.results['band structure'] for c in kc_ham_calcs]
299+
ref = max([b.reference for b in bandstructures])
300+
bs_to_plot = bandstructures[0].subtract_reference(ref)
301+
if not bs_to_plot.path.path:
302+
return
303+
304+
if self.parameters.spin_polarized:
305+
bs_to_plot._energies = np.append(bs_to_plot._energies, bandstructures[1]._energies - ref, axis=0)
306+
307+
super().plot_bandstructure(bs_to_plot)
297308

298309
def new_calculator(self, calc_presets, **kwargs):
299310
return internal_new_calculator(self, calc_presets, **kwargs)

src/koopmans/workflows/_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ def plot_bandstructure(self,
15291529
if isinstance(bs, BandStructure):
15301530
bs = [bs]
15311531
if isinstance(bsplot_kwargs, dict):
1532-
bsplot_kwargs = [bsplot_kwargs]
1532+
bsplot_kwargs = [bsplot_kwargs for _ in bs]
15331533
if len(bs) != len(bsplot_kwargs):
15341534
raise ValueError('The `bs` and `bsplot_kwargs` arguments to `plot_bandstructure()` should be the same '
15351535
'length')

0 commit comments

Comments
 (0)