def test_fleurinp_modifier_set_nmmpmat(create_fleurinp): """Tests if set_nmmpmat works on fleurinp modifier works, with right interface""" fleurinp_tmp = create_fleurinp(inpxmlfilefolder2) fm = FleurinpModifier(fleurinp_tmp) fm.set_nmmpmat('Ga-1', orbital=2, spin=1, occStates=[1, 2, 3, 4, 5]) fm.set_nmmpmat('As-2', orbital=1, spin=1, denmat=[[1, -2, 3], [4, -5, 6], [7, -8, 9]]) # Does not validate # Found invalid diagonal element for species Ga-1, spin 1 and l=2 with pytest.raises(ValueError): fm.show(validate=True, display=False) new_fleurinp = fm.freeze() assert 'n_mmp_mat' in new_fleurinp.files
def get_inputs_fixed_configurations(self, index, config): """ Sets up the input for the fixed density matrix calculation. """ remote_data = None if self.ctx.scf_no_ldau_needed: try: fleurinp = self.ctx.scf_no_ldau.outputs.fleurinp remote_data = load_node( self.ctx.scf_no_ldau.outputs.output_scf_wc_para['last_calc_uuid']).outputs.remote_folder except NotExistent: error = 'Fleurinp generated in the SCF calculation is not found.' self.control_end_wc(error) return {}, self.exit_codes.ERROR_SCF_NOLDAU_FAILED else: remote_data = self.inputs.remote if 'fleurinp' not in self.inputs: fleurinp = get_fleurinp_from_remote_data(remote_data, store=True) self.report(f'INFO: generated FleurinpData from {fleurinp.files}') else: fleurinp = self.inputs.fleurinp inputs = self.inputs label = f'Fixed_{index}' description = f'LDA+U with fixed nmmpmat for config {index}' if 'settings' not in inputs: settings = {} else: settings = inputs.settings.get_dict() if 'remove_from_remotecopy_list' not in settings: settings['remove_from_remotecopy_list'] = [] settings['remove_from_remotecopy_list'].append('mixing_history*') self.report(f'INFO: create fleurinp for config {index}') fm = FleurinpModifier(fleurinp) fm.set_inpchanges({'itmax': self.ctx.wf_dict['iterations_fixed'], 'l_linMix': True, 'mixParam': 0.0}) for atom_species, ldau_dict in self.ctx.wf_dict['ldau_dict'].items(): fm.set_species(species_name=atom_species, attributedict={'ldaU': ldau_dict}) for config_index, config_species in config.items(): orbital = config_index.split('-')[-1] atom_species = '-'.join(config_index.split('-')[:-1]) for spin, config_spin in enumerate(config_species): if self.ctx.wf_dict['use_orbital_occupation']: fm.set_nmmpmat(species_name=atom_species, orbital=int(orbital), spin=spin + 1, orbital_occupations=config_spin) else: fm.set_nmmpmat(species_name=atom_species, orbital=int(orbital), spin=spin + 1, state_occupations=config_spin) try: fm.show(display=False, validate=True) except etree.DocumentInvalid: error = ('ERROR: input, inp.xml changes did not validate') self.control_end_wc(error) return self.exit_codes.ERROR_INVALID_INPUT_FILE except ValueError as exc: error = ('ERROR: input, inp.xml changes could not be applied.' f'The following error was raised {exc}') self.control_end_wc(error) return self.exit_codes.ERROR_CHANGING_FLEURINPUT_FAILED fleurinp_fixed = fm.freeze() input_fixed = get_inputs_fleur(inputs.fleur, remote_data, fleurinp_fixed, self.ctx.options, label, description, settings=settings) return input_fixed, None