From 8cc21913ee911aef7718b5ece746624b9ef1036b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20R=C3=BC=C3=9Fmann?= Date: Fri, 10 Nov 2023 13:27:03 +0000 Subject: [PATCH] Small refactoring --- aiida_kkr/calculations/kkrimp.py | 22 +++++------------ aiida_kkr/tools/tools_kkrimp.py | 12 +++++++++ aiida_kkr/workflows/_combine_imps.py | 37 ++++++++++++++++++++-------- tests/workflows/test_combine_imps.py | 13 +++++++--- 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/aiida_kkr/calculations/kkrimp.py b/aiida_kkr/calculations/kkrimp.py index c41dd17d..f4d6b392 100644 --- a/aiida_kkr/calculations/kkrimp.py +++ b/aiida_kkr/calculations/kkrimp.py @@ -11,7 +11,7 @@ from masci_tools.io.kkr_params import kkrparams from .voro import VoronoiCalculation from .kkr import KkrCalculation -from aiida_kkr.tools.tools_kkrimp import modify_potential, make_scoef, write_scoef_full_imp_cls +from aiida_kkr.tools.tools_kkrimp import modify_potential, make_scoef, write_scoef_full_imp_cls, get_imp_info_from_parent from aiida_kkr.tools.common_workfunctions import get_username from aiida_kkr.tools.ldau import get_ldaupot_text from masci_tools.io.common_functions import search_string, get_ef_from_potfile @@ -22,7 +22,7 @@ __copyright__ = (u'Copyright (c), 2018, Forschungszentrum Jülich GmbH, ' 'IAS-1/PGI-1, Germany. All rights reserved.') __license__ = 'MIT license, see LICENSE.txt file' -__version__ = '0.9.0' +__version__ = '0.9.1' __contributors__ = (u'Philipp Rüßmann', u'Fabian Bertoldo') #TODO: implement 'ilayer_center' consistency check @@ -294,26 +294,16 @@ def _get_and_verify_hostfiles(self, tempfolder): else: parent_calc = parent_calcs.first().node # extract impurity_info + found_impurity_inputnode = False if 'impurity_info' in self.inputs: imp_info_inputnode = self.inputs.impurity_info if not isinstance(imp_info_inputnode, Dict): raise InputValidationError('impurity_info not of type Dict') - if 'impurity_info' in parent_calc.get_incoming().all_link_labels(): - imp_info = parent_calc.get_incoming().get_node_by_label('impurity_info') - else: - imp_info = None - if imp_info is None: - raise InputValidationError('host_Greenfunction calculation does not have an input node impurity_info') found_impurity_inputnode = True found_host_parent = True - else: - if 'impurity_info' in parent_calc.get_incoming().all_link_labels(): - imp_info = parent_calc.get_incoming().get_node_by_label('impurity_info') - else: - imp_info = None - if imp_info is None: - raise InputValidationError('host_Greenfunction calculation does not have an input node impurity_info') - found_impurity_inputnode = False + imp_info = get_imp_info_from_parent(parent_calc) + if imp_info is None: + raise InputValidationError('host_Greenfunction calculation does not have an input node impurity_info') # if impurity input is seperate input, check if it is the same as # the one from the parent calc (except for 'Zimp'). If that's not the diff --git a/aiida_kkr/tools/tools_kkrimp.py b/aiida_kkr/tools/tools_kkrimp.py index 0028927d..2ba5e914 100644 --- a/aiida_kkr/tools/tools_kkrimp.py +++ b/aiida_kkr/tools/tools_kkrimp.py @@ -592,3 +592,15 @@ def write_scoef_full_imp_cls(imp_info_node, path, rescale_alat=None): # write scoef file write_scoef(imp_cls, path) + + +def get_imp_info_from_parent(parent_calc): + """ + Returns impurity_info node from inputs to parent_calc calculation node + + Returns None if no input node of this name is found. + """ + imp_info = None + if 'impurity_info' in parent_calc.get_incoming().all_link_labels(): + imp_info = parent_calc.get_incoming().get_node_by_label('impurity_info') + return imp_info diff --git a/aiida_kkr/workflows/_combine_imps.py b/aiida_kkr/workflows/_combine_imps.py index 4b798cae..e5b384fd 100644 --- a/aiida_kkr/workflows/_combine_imps.py +++ b/aiida_kkr/workflows/_combine_imps.py @@ -4,7 +4,7 @@ """ from aiida.engine import WorkChain, if_, ToContext, calcfunction -from aiida.orm import load_node, Dict, WorkChainNode, Int, RemoteData, Bool, ArrayData +from aiida.orm import load_node, Dict, WorkChainNode, Int, RemoteData, Bool, ArrayData, CalcJobNode from aiida_kkr.calculations import KkrCalculation, KkrimpCalculation from aiida_kkr.workflows import kkr_imp_sub_wc, kkr_flex_wc, kkr_imp_wc from aiida_kkr.tools.combine_imps import ( @@ -19,9 +19,12 @@ __copyright__ = (u'Copyright (c), 2020, Forschungszentrum Jülich GmbH, ' 'IAS-1/PGI-1, Germany. All rights reserved.') __license__ = 'MIT license, see LICENSE.txt file' -__version__ = '0.3.1' +__version__ = '0.3.2' __contributors__ = (u'Philipp Rüßmann , Rubel Mozumder') +# activate debug writeout +_debug = False + class combine_imps_wc(WorkChain): """ @@ -130,9 +133,9 @@ def define(cls, spec): workflows or of an `KkrimpCalculation`. Use these output Dict nodes: - * for `kkr_imp_wc`: single_imp_worlfow.outputs.workflow_info - * for `kkr_imp_sub_wc`: single_imp_worlfow.outputs.workflow_info - * for `KkrimpCalculation`: single_imp_worlfow.outputs.output_parameters + * for `kkr_imp_wc`: single_imp_workfow.outputs.workflow_info + * for `kkr_imp_sub_wc`: single_imp_workfow.outputs.workflow_info + * for `KkrimpCalculation`: single_imp_workfow.outputs.output_parameters """ ) @@ -378,12 +381,21 @@ def extract_imps_info_exact_cluster(self): self.report(f'DEBUG: The is the imps_info_in_exact_cluster dict: {imps_info_in_exact_cluster}\n') return imps_info_in_exact_cluster + def get_impinfo_from_hostGF(self, imp_calc): + """ + Extract impurity infor node from the incoming host GF folder + """ + GF_input = imp_calc.inputs.host_Greenfunction_folder + parent_calc = GF_input.get_incoming(node_class=CalcJobNode).first().node + impinfo = parent_calc.inputs.impurity_info + return impinfo + def imps_info_exact_cluster_2imps(self, single_imp1_wc, single_imp2_wc, offset_imp2): """ This construct a python dict keeping info about two single inpurities with respect to the original host structure e.i. before transforming the center to the first impurity position. """ - impinfo1 = single_imp1_wc.inputs.impurity_info - impinfo2 = single_imp2_wc.inputs.impurity_info + impinfo1 = self.get_impinfo_from_hostGF(single_imp1_wc) + impinfo2 = self.get_impinfo_from_hostGF(single_imp2_wc) # imp_info_in_exact_cluster keeps the exact data before creating the cluster will help to add more imps later. imps_info_in_exact_cluster = { 'Zimps': [], @@ -479,13 +491,16 @@ def create_big_cluster(self): # pylint: disable=inconsistent-return-statements imp2 = self.ctx.imp2 single_single = self.ctx.single_vs_single if single_single: - impinfo1 = imp1.inputs.impurity_info + if _debug: + print('DEBUG:', list(imp1.inputs)) + impinfo1 = self.get_impinfo_from_hostGF(imp1) + # impinfo1 = imp1.inputs.impurity_info else: if imp1.process_class == self.__class__: imp1 = imp1.get_outgoing(node_class=kkr_imp_sub_wc).all()[0].node impinfo1 = imp1.inputs.impurity_info self.report(f'DEBUG: impinfo1 : {impinfo1.get_dict()} .') - impinfo2 = imp2.inputs.impurity_info + impinfo2 = self.get_impinfo_from_hostGF(imp2) host_structure = self.ctx.host_structure offset_imp2 = self.inputs.offset_imp2 @@ -592,9 +607,11 @@ def run_gf_writeout(self): #take gf_writeout directly from input to KkrimpCalculation gf_writeout_calc = self.ctx.imp1.inputs.host_Greenfunction_folder.get_incoming(node_class=KkrCalculation ).first().node - if self.ctx.imp1.process_class == kkr_imp_sub_wc: + if (self.ctx.imp1.process_class == kkr_imp_sub_wc or self.ctx.imp1.process_class == KkrimpCalculation): imp1_sub = self.ctx.imp1 else: + if _debug: + print('DEBUG:', self.ctx.imp1, list(self.ctx.imp1.inputs)) imp1_sub = self.ctx.imp1.get_outgoing(node_class=kkr_imp_sub_wc).first().node if gf_writeout_calc is None: gf_writeout_calc = imp1_sub.inputs.remote_data.get_incoming(node_class=KkrCalculation).first().node diff --git a/tests/workflows/test_combine_imps.py b/tests/workflows/test_combine_imps.py index 42934def..0268fdc5 100755 --- a/tests/workflows/test_combine_imps.py +++ b/tests/workflows/test_combine_imps.py @@ -9,6 +9,9 @@ from aiida_kkr.workflows import combine_imps_wc from ..conftest import import_with_migration +# activate debug mode? +_debug = True + def write_graph(node, label=''): #if create_graph_file: @@ -25,11 +28,15 @@ def write_graph(node, label=''): def get_single_imp_inputs(): # import single imp calculations - group_pk = import_with_migration(test_dir / 'data_dir/kkr_imp_wc-nodes-4e7fa222d8fbe143b13363013103a8e3.tar.gz') + group_pk = import_with_migration(test_dir / 'data_dir/kkr_imp_sub_wc-nodes-6227d9003b63b76d1fd41bd5322771b5.tar.gz') + if _debug: + print(group_pk, [i.label for i in load_group(group_pk).nodes]) for node in load_group(group_pk).nodes: - if node.label == 'kkrimp_scf full Cu host_in_host': + if 'KKRimp calculation step 4' in node.label: imp1 = node - imp1_out = imp1.outputs.workflow_info + if _debug: + print(imp1, list(imp1.outputs), list(imp1.inputs)) + imp1_out = imp1.outputs.output_parameters imp2_out = imp1_out # use the same impurity and create a dimer return imp1_out, imp2_out