Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippRue committed Nov 10, 2023
1 parent 85e046c commit 8cc2191
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
22 changes: 6 additions & 16 deletions aiida_kkr/calculations/kkrimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions aiida_kkr/tools/tools_kkrimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 27 additions & 10 deletions aiida_kkr/workflows/_combine_imps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
"""
)

Expand Down Expand Up @@ -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': [],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions tests/workflows/test_combine_imps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 8cc2191

Please sign in to comment.