From 86053462669b3a3a419e68bd63368fed51f85b0c Mon Sep 17 00:00:00 2001 From: bastonero Date: Wed, 5 Jul 2023 12:38:04 +0000 Subject: [PATCH] `PhononWorkChain`: smearing for magnetic metals When the system was detected as metallic, a fixed occupations was set. This produces bad results for metals, where `smearing` should be used. --- .gitignore | 1 + src/aiida_vibroscopy/workflows/phonons/base.py | 9 ++++++++- tests/conftest.py | 1 + tests/workflows/phonons/test_phonon.py | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ebd4717..bef3044 100644 --- a/.gitignore +++ b/.gitignore @@ -113,3 +113,4 @@ _aiida_* # Autogenerated API docs docs/source/reference/api/aiida_vibroscopy docs/source/reference/cli +tox.ini diff --git a/src/aiida_vibroscopy/workflows/phonons/base.py b/src/aiida_vibroscopy/workflows/phonons/base.py index a94cbfb..2911285 100644 --- a/src/aiida_vibroscopy/workflows/phonons/base.py +++ b/src/aiida_vibroscopy/workflows/phonons/base.py @@ -283,6 +283,7 @@ def set_ctx_variables(self): parameters = self.inputs.scf.pw.parameters.get_dict() nspin = parameters.get('SYSTEM', {}).get('nspin', 1) self.ctx.is_magnetic = (nspin != 1) + self.ctx.is_insulator = True self.ctx.plus_hubbard = False self.ctx.old_plus_hubbard = False @@ -365,6 +366,12 @@ def inspect_base_supercell(self): self.report(f'base supercell scf failed with exit status {workchain.exit_status}') return self.exit_codes.ERROR_FAILED_BASE_SCF + parameters = workchain.outputs.output_parameters.dict + if parameters.occupations == 'smearing': + bands = workchain.outputs.output_band + fermi_energy = parameters.fermi_energy + self.ctx.is_insulator, _ = orm.find_bandgap(bands, fermi_energy=fermi_energy) + def run_forces(self): """Run an scf for each supercell with displacements.""" if self.ctx.plus_hubbard or self.ctx.old_plus_hubbard: @@ -398,7 +405,7 @@ def run_forces(self): parameters.setdefault('SYSTEM', {}) parameters.setdefault('ELECTRONS', {}) - if self.ctx.is_magnetic: + if self.ctx.is_magnetic and self.ctx.is_insulator: parameters['SYSTEM']['occupations'] = 'fixed' for name in ('smearing', 'degauss', 'starting_magnetization'): diff --git a/tests/conftest.py b/tests/conftest.py index 5a6e9f5..0197303 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -454,6 +454,7 @@ def _generate_base_scf_workchain_node(exit_status=0, with_trajectory=False): # Add output Dict parameters = orm.Dict({ + 'occupations': 'fixed', 'number_of_bands': 5, 'total_magnetization': 1, 'volume': 10, diff --git a/tests/workflows/phonons/test_phonon.py b/tests/workflows/phonons/test_phonon.py index 4685faf..a848650 100644 --- a/tests/workflows/phonons/test_phonon.py +++ b/tests/workflows/phonons/test_phonon.py @@ -88,6 +88,7 @@ def test_setup(generate_workchain_phonon): process.setup() assert process.ctx.is_magnetic == False + assert process.ctx.is_insulator == True assert process.ctx.plus_hubbard == False assert process.ctx.old_plus_hubbard == False assert 'preprocess_data' in process.ctx @@ -212,6 +213,7 @@ def test_inspect_base_supercell( process.ctx.scf_supercell_0 = generate_base_scf_workchain_node(exit_status=exit_status) result = process.inspect_base_supercell() assert result == expected_result + assert process.ctx.is_insulator @pytest.mark.usefixtures('aiida_profile')