Skip to content

Commit

Permalink
Merge pull request #156 from JuDFTteam/develop-STM
Browse files Browse the repository at this point in the history
Development of STM workchain
  • Loading branch information
PhilippRue authored Nov 28, 2024
2 parents 3144c3a + bf3bbdd commit 84636a1
Show file tree
Hide file tree
Showing 46 changed files with 1,478 additions and 506 deletions.
6 changes: 3 additions & 3 deletions aiida_kkr/calculations/kkr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'IAS-1/PGI-1, Germany. All rights reserved.')
__license__ = 'MIT license, see LICENSE.txt file'

__version__ = '0.13.1'
__version__ = '0.13.2'

__contributors__ = ('Jens Bröder', 'Philipp Rüßmann')

Expand Down Expand Up @@ -1063,8 +1063,8 @@ def _use_initial_noco_angles(self, parameters, structure, tempfolder):
f'Error: theta value out of range (0..180): iatom={iatom}, theta={theta}'
)
# convert fix_dir to boolean if given as integer
if not isinstance(fix_dir, bool):
fix_dir = (fix_dir == 1)
if not isinstance(fix_dir[iatom], bool):
fix_dir[iatom] = (fix_dir[iatom] == 1)
# write line
noco_angle_file.write(f' {theta} {phi} {fix_dir[iatom]}\n')

Expand Down
40 changes: 30 additions & 10 deletions aiida_kkr/calculations/kkrimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class KkrimpCalculation(CalcJob):
_OUT_LMDOS_INTERPOL = u'out_lmdos.interpol.atom=*'
_OUT_MAGNETICMOMENTS = u'out_magneticmoments'
_OUT_ORBITALMOMENTS = u'out_orbitalmoments'
_LDAUPOT = 'ldaupot'
_LDAUPOT = u'ldaupot'

_TEST_RHO2NS = u'test_rho2ns'

# template.product entry point defined in setup.json
_default_parser = u'kkr.kkrimpparser'
Expand Down Expand Up @@ -787,6 +789,10 @@ def _initialize_kkrimp_params(self, params_host, parameters, GFhost_folder, temp
# take care of LLYsimple (i.e. Lloyd in host system)
if 'LLOYD' in runopts:
runflag = self._use_lloyd(runflag, GFhost_folder, tempfolder)
# alternative to Lloyd mode: renormalization factor of energy integration weights
if params_host.get_value('WFAC_RENORM') is not None:
if params_host.get_value('WFAC_RENORM'):
runflag = self._use_lloyd(runflag, GFhost_folder, tempfolder, True)

# now set runflags
params_kkrimp.set_value('RUNFLAG', runflag)
Expand Down Expand Up @@ -824,19 +830,33 @@ def _set_nosoc(self, params_host, GFhost_folder, tempfolder):
for socscl in socscale:
kkrflex_socfac.write(f' {socscl}\n')

def _use_lloyd(self, runflag, GFhost_folder, tempfolder):
def _use_lloyd(self, runflag, GFhost_folder, tempfolder, wfac_renorm=False):
"""Use the LLYsimple version of KKRimp code with the average renormalization factor from the host calculation"""

# add runflag for imp code
runflag.append('LLYsimple')
# also extract renormalization factor and create kkrflex_llyfac file (contains one value only)
with GFhost_folder.open('output.000.txt') as f:
txt = f.readlines()

# find renormalization factor
if wfac_renorm:
# option 1: found wfac_renorm in Kkrhost parent's input parameters
with GFhost_folder.open('inputcard') as f:
txt = f.readlines()
iline = search_string('WFAC_RENORM', txt)
else:
# option 2: host parent is a Lloyd calculation
# extract renormalization factor and create kkrflex_llyfac file (contains one value only)
with GFhost_folder.open('output.000.txt') as f:
txt = f.readlines()
iline = search_string('RENORM_LLY: Renormalization factor of total charge', txt)
if iline >= 0:
llyfac = txt[iline].split()[-1]
# now write kkrflex_llyfac to tempfolder where later on config file is also written
with tempfolder.open(self._KKRFLEX_LLYFAC, 'w') as f2:
f2.writelines([llyfac])

if iline >= 0:
llyfac = txt[iline].split()[-1]
else:
raise ValueError('Failed to extract llyfac in KkrimpCalculation')

# now write kkrflex_llyfac to tempfolder where later on config file is also written
with tempfolder.open(self._KKRFLEX_LLYFAC, 'w') as f2:
f2.writelines([llyfac])
return runflag

def _activate_jij_calc(self, runflag, params_kkrimp, GFhost_folder, tempfolder):
Expand Down
15 changes: 8 additions & 7 deletions aiida_kkr/calculations/voro.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
__copyright__ = (u'Copyright (c), 2017, Forschungszentrum Jülich GmbH, '
'IAS-1/PGI-1, Germany. All rights reserved.')
__license__ = 'MIT license, see LICENSE.txt file'
__version__ = '0.5.3'
__version__ = '0.5.4'
__contributors__ = ('Jens Broeder', 'Philipp Rüßmann')


Expand Down Expand Up @@ -182,7 +182,8 @@ def prepare_for_submission(self, tempfolder):
# Decide what files to copy
local_copy_list = []
if overwrite_potential:
# copy the right files #TODO check first if file, exists and throw
# copy the right files
#TODO check first if file, exists and throw
# warning, now this will throw an error
if found_parent and self._is_KkrCalc(parent_calc):
outfolder = parent_calc.outputs.retrieved # copy from remote folder
Expand All @@ -199,11 +200,11 @@ def prepare_for_submission(self, tempfolder):
filename = self._POTENTIAL_IN_OVERWRITE
local_copy_list.append((outfolder.uuid, file1, filename)) # pylint: disable=possibly-used-before-assignment

# add shapefun to overwrite
if 'shapefun_overwrite' in self.inputs:
shapefun_overwrite = self.inputs.shapefun_overwrite
filename = shapefun_overwrite.filename
local_copy_list.append((shapefun_overwrite.uuid, filename, 'shapefun_overwrite'))
# add shapefun to overwrite
if 'shapefun_overwrite' in self.inputs:
shapefun_overwrite = self.inputs.shapefun_overwrite
filename = shapefun_overwrite.filename
local_copy_list.append((shapefun_overwrite.uuid, filename, 'shapefun_overwrite'))

# Prepare CalcInfo to be returned to aiida
calcinfo = CalcInfo()
Expand Down
25 changes: 19 additions & 6 deletions aiida_kkr/parsers/kkrimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import tarfile
import os
from aiida import __version__ as aiida_core_version
from aiida.orm import Dict
from aiida.common.exceptions import InputValidationError, NotExistent
from aiida.orm import Dict, CalcJobNode
from aiida.common.exceptions import InputValidationError, NotExistent, NotExistentAttributeError
from aiida.parsers.parser import Parser
from aiida_kkr.calculations.kkrimp import KkrimpCalculation
from aiida_kkr.tools.context import open_files_in_context
Expand All @@ -21,8 +21,8 @@
__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.6.0'
__contributors__ = ('Philipp Rüßmann')
__version__ = '0.6.2'
__contributors__ = (u'Philipp Rüßmann', u'Raffaele Aliberti')


class KkrimpParser(Parser):
Expand All @@ -42,7 +42,7 @@ def __init__(self, calc):

# pylint: disable=protected-access
# pylint: disable=unexpected-keyword-arg
def parse(self, debug=False, ignore_nan=True, **kwargs):
def parse(self, debug=False, ignore_nan=True, doscalc=None, **kwargs):
"""
Parse output data folder, store results in database.
Expand All @@ -64,6 +64,19 @@ def parse(self, debug=False, ignore_nan=True, **kwargs):
file_errors = []
files = {}

# Get the node of the parent calculation (useful for the imp calculations)
calc = out_folder.get_incoming(node_class=CalcJobNode).first().node

# figure out if this is a DOS calculation (if not specified in the input already)
if doscalc is None:
parent_host_calc = calc.inputs.host_Greenfunction_folder.get_incoming(node_class=CalcJobNode).first().node
# This parameter discriminates if it is a DOS calc or not
npol = parent_host_calc.inputs.parameters.get_dict().get('NPOL', 1)
doscalc = (npol == 0)

if debug:
print('doscalc = ', doscalc)

# Parse output files of KKRimp calculation

# first get path to files and catch errors if files are not present
Expand Down Expand Up @@ -113,7 +126,7 @@ def parse(self, debug=False, ignore_nan=True, **kwargs):

# now we can parse the output files
success, msg_list, out_dict = KkrimpParserFunctions().parse_kkrimp_outputfile(
out_dict, named_file_handles, debug=debug, ignore_nan=ignore_nan
out_dict, named_file_handles, debug=debug, ignore_nan=ignore_nan, doscalc=doscalc
)

out_dict['parser_errors'] = msg_list
Expand Down
2 changes: 1 addition & 1 deletion aiida_kkr/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .common_workfunctions import (
update_params_wf, prepare_VCA_structure_wf, prepare_2Dcalc_wf, test_and_get_codenode, get_inputs_kkr,
get_inputs_kkrimporter, get_inputs_voronoi, get_inputs_kkrimp, get_parent_paranode,
generate_inputcard_from_structure, check_2Dinput_consistency, structure_from_params, vca_check
generate_inputcard_from_structure, check_2Dinput_consistency, structure_from_params, vca_check, truncate_string
)
from .find_cluster_radius import find_cluster_radius
from .plot_kkr import plot_kkr
Expand Down
4 changes: 0 additions & 4 deletions aiida_kkr/tools/combine_imps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def get_host_structure(impurity_workflow_or_calc):
extract host structure from impurity
"""
#TODO extract host parent no from input but take into account calculation of host GF from inside kkrimp full workflow
print(
f'This is line in the combine impurity tool files at:: /opt/aiida-kkr/aiida_kkr/tools for deburging the line',
end=' '
)
print(f'impurity_workflow_or_calc: {impurity_workflow_or_calc}')
if impurity_workflow_or_calc.process_class == KkrimpCalculation:
host_parent = impurity_workflow_or_calc.inputs.host_Greenfunction_folder
Expand Down
13 changes: 12 additions & 1 deletion aiida_kkr/tools/common_workfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ def get_inputs_kkrimp(
return builder


def truncate_string(string, max_length):
"""
Truncate the length of a string to max_length-3 entries.
The last three characters '...' to indicate the truncation.
"""
if len(string) > max_length:
string = string[:max_length - 3] + '...'
return string


def get_inputs_common(
calculation,
code,
Expand Down Expand Up @@ -381,7 +391,8 @@ def get_inputs_common(
inputs.metadata.description = ''

if label:
inputs.metadata.label = label
# Attention: max label length is 255 characters
inputs.metadata.label = truncate_string(label, 255)
else:
inputs.metadata.label = ''

Expand Down
25 changes: 16 additions & 9 deletions aiida_kkr/tools/imp_cluster_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ def get_scoef_single_imp(host_structure, impinfo_node):
:return: scoef array (positions [x,y,z], layer index, distance to first position in imp cluster)
:type: numpy.array
"""
impinfo = impinfo_node.get_dict()
Rcut = impinfo.get('Rcut', None)
hcut = impinfo.get('hcut', -1.)
cylinder_orient = impinfo.get('cylinder_orient', [0., 0., 1.])
ilayer_center = impinfo.get('ilayer_center', 0)

clust = create_scoef_array(host_structure, Rcut, hcut, cylinder_orient, ilayer_center)
# sort after distance
clust = clust[(clust[:, -1]).argsort()]
# check if we can read it from a node extra
if 'imp_cls' not in impinfo_node.extras:
impinfo = impinfo_node.get_dict()
Rcut = impinfo.get('Rcut', None)
hcut = impinfo.get('hcut', -1.)
cylinder_orient = impinfo.get('cylinder_orient', [0., 0., 1.])
ilayer_center = impinfo.get('ilayer_center', 0)

clust = create_scoef_array(host_structure, Rcut, hcut, cylinder_orient, ilayer_center)
# sort after distance
clust = clust[(clust[:, -1]).argsort()]

# save as extra for second run
impinfo_node.set_extra('imp_cls', clust)
else:
clust = np.array(impinfo_node.extras['imp_cls'])

return clust

Expand Down
Loading

0 comments on commit 84636a1

Please sign in to comment.