Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippRue committed Jun 1, 2018
2 parents 251bcc6 + c9b39f6 commit 74236b8
Show file tree
Hide file tree
Showing 40 changed files with 38,457 additions and 609 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ coverage.xml
.hypothesis/
aiida_kkr/tests/coverage
aiida_kkr/tests/inputcard
aiida_kkr/tests/input.temp_unsorted.txt
aiida_kkr/tests/input.temp.txt
aiida_kkr/tests/config.cfg


# Translations
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
AiiDA plugin for the KKR codes plus workflows and utility.


# Documentation

# Installation

```shell
Expand All @@ -17,4 +15,6 @@ $ verdi quicksetup # better to set up a new profile
$ verdi calculation plugins # should now show kkr.* entrypoints
```

# Usage
# Usage and Documentation

See http://aiida-kkr.readthedocs.io for user's guide and API reference.
196 changes: 154 additions & 42 deletions aiida_kkr/calculations/kkr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
from aiida.orm import DataFactory
from aiida.common.exceptions import UniquenessError
from aiida_kkr.tools.common_workfunctions import (generate_inputcard_from_structure,
check_2Dinput_consistency, update_params_wf)
check_2Dinput_consistency, update_params_wf,
vca_check)
from aiida_kkr.tools.tools_kkrimp import make_scoef

#define aiida structures from DataFactory of aiida
RemoteData = DataFactory('remote')
ParameterData = DataFactory('parameter')
StructureData = DataFactory('structure')
ArrayData = DataFactory('array')


__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.4"
__version__ = "0.6"
__contributors__ = ("Jens Broeder", "Philipp Rüßmann")


Expand Down Expand Up @@ -77,6 +80,9 @@ def _init_internal_params(self):
self._COMPLEXDOS = 'complex.dos'
self._DOS_ATOM = 'dos.atom%i'
self._LMDOS = 'lmdos.%2i.%i.dat'
# qdos files
self._QVEC = 'qvec.dat'
self._QDOS_ATOM = 'qdos.%2i.%i.dat'
# kkrflex files for impurity calculation
self._KKRFLEX_GREEN = 'kkrflex_green'
self._KKRFLEX_TMAT = 'kkrflex_tmat'
Expand Down Expand Up @@ -136,6 +142,13 @@ def _use_methods(cls):
"of impurity cluster in scoef file that is "
"automatically created).")
},
"kpath": {
'valid_types': ArrayData,
'additional_parameter': None,
'linkname': 'kpath',
'docstring': ("Use a ArrayDataNode that specifies the kpath for which"
"a bandstructure calculation should be performed.")
},
})
return use_dict

Expand Down Expand Up @@ -173,6 +186,13 @@ def _prepare_for_submission(self, tempfolder, inputdict):
except KeyError:
raise InputValidationError("No code specified for this calculation")

# get qdos inputs
try:
kpath = inputdict.pop(self.get_linkname('kpath'))
found_kpath = True
except KeyError:
found_kpath = False

try:
parent_calc_folder = inputdict.pop(self.get_linkname('parent_folder'))
except KeyError:
Expand Down Expand Up @@ -250,27 +270,12 @@ def _prepare_for_submission(self, tempfolder, inputdict):
if inputdict:
self.logger.error('KkrCalculation: Unknown inputs for structure lookup')
raise ValidationError("Unknown inputs")


# for VCA: check if input structure and parameter node define VCA structure
vca_structure = vca_check(structure, parameters)

###################################

# Check for 2D case
twoDimcheck, msg = check_2Dinput_consistency(structure, parameters)
if not twoDimcheck:
raise InputValidationError(msg)

# set shapes array either from parent voronoi run or read from inputcard in kkrimporter calculation
if parent_calc.get_parser_name() != 'kkr.kkrimporterparser':
# get shapes array from voronoi parent
shapes = voro_parent.res.shapes
else:
# extract shapes from input parameters node constructed by kkrimporter calculation
shapes = voro_parent.inp.parameters.get_dict().get('<SHAPE>')

# Prepare inputcard from Structure and input parameter data
input_filename = tempfolder.get_abs_path(self._INPUT_FILE_NAME)
natom, nspin, newsosol = generate_inputcard_from_structure(parameters, structure, input_filename, parent_calc, shapes=shapes)

# prepare scoef file if impurity_info was given
write_scoef = False
runopt = parameters.get_dict().get('RUNOPT', None)
Expand All @@ -285,34 +290,93 @@ def _prepare_for_submission(self, tempfolder, inputdict):
write_scoef = True
runopt = parameters.get_dict().get('RUNOPT', [])
runopt.append('KKRFLEX')
parameters = update_params_wf(parameters, ParameterData(dict={'RUNOPT':runopt, 'nodename': '', 'nodedesc':''}))
parameters = update_params_wf(parameters, ParameterData(dict={'RUNOPT':runopt, 'nodename': 'update_KKRFLEX', 'nodedesc':'Update Parameter node with KKRFLEX runopt'}))
if found_imp_info and write_scoef:
# TODO check completeness of impurity info!
# TODO implement this!
# placeholder: take Fabian's functions later on
scoef = [' 13\n',
' 0.0000000000000000000E+00 0.0000000000000000000E+00 0.0000000000000000000E+00 1 29.0 0.000000000E+00\n',
' 0.2220446049250313081E-14 -0.7071067811865453523E+00 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 0.2220446049250313081E-14 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 0.2220446049250313081E-14 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' 0.2220446049250313081E-14 0.7071067811865497932E+00 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 -0.7071067811865453523E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 -0.7071067811865453523E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 0.7071067811865497932E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 0.7071067811865497932E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' 0.2220446049250313081E-14 -0.7071067811865453523E+00 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 0.2220446049250313081E-14 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 0.2220446049250313081E-14 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n',
' 0.2220446049250313081E-14 0.7071067811865497932E+00 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n']
scoef_filename = os.path.join(tempfolder.get_abs_path(''), self._SCOEF)
self.logger.info('Writing scoef file {}'.format(scoef_filename))
with open(scoef_filename, 'w') as file:
file.writelines(scoef)
imp_info_dict = imp_info.get_dict()
Rcut = imp_info_dict.get('Rcut', None)
hcut = imp_info_dict.get('hcut', -1.)
cylinder_orient = imp_info_dict.get('cylinder_orient', [0., 0., 1.])
ilayer_center = imp_info_dict.get('ilayer_center', 0)
for i in range(len(cylinder_orient)):
try:
len(cylinder_orient[i])
vec_shape = False
except TypeError:
vec_shape = True
if ilayer_center > len(structure.sites) - 1:
raise IndexError('Index of the reference site is out of range! Possible values: 0 to {}.'.format(len(structure.sites) - 1))
elif Rcut < 0:
raise ValueError('Cutoff radius has to be positive!')
elif vec_shape == False or len(cylinder_orient) != 3:
raise TypeError('Input orientation vector ({}) has the wrong shape! It needs to be a 3D-vector!'.format(cylinder_orient))
else:
print('Input parameters for make_scoef read in correctly!')
make_scoef(structure, Rcut, scoef_filename, hcut, cylinder_orient, ilayer_center)
elif write_scoef:
self.logger.info('Need to write scoef file but no impurity_info given!')
raise ValidationError('Found RUNOPT KKRFLEX but no impurity_info in inputs')

# qdos option, ensure low T, E-contour, qdos run option and write qvec.dat file
if found_kpath:
# check qdos settings
change_values = []
runopt = parameters.get_dict().get('RUNOPT')
if runopt is None: runopt = []
runopt = [i.strip() for i in runopt]
if 'qdos' not in runopt:
runopt.append('qdos')
change_values.append(['RUNOPT', runopt])
tempr = parameters.get_dict().get('TEMPR')
if tempr>100.:
change_values.append(['TEMPR', 50.])
N1 = parameters.get_dict().get('TEMPR')
if N1>0:
change_values.append(['NPT1', 0])
N2 = parameters.get_dict().get('NPT2')
if N2 is None:
change_values.append(['NPT2', 100])
N3 = parameters.get_dict().get('NPT3')
if N3>0.:
change_values.append(['NPT3', 0])
NPOL = parameters.get_dict().get('NPOL')
if NPOL>0.:
change_values.append(['NPOL', 0])
if change_values != []:
new_params = {'nodename': 'changed_params_qdos', 'nodedesc': 'Changed parameters to mathc qdos mode. Changed values: {}'.format(change_values)}
for key, val in change_values:
new_params[key] = val
new_params_node = ParameterData(dict=new_params)
parameters = update_params_wf(parameters, new_params_node)
# write qvec.dat file
if 'kpath' not in kpath.get_arraynames():
raise InputValidationError("kpath input node needs to contain an array called 'kpath'")
kpath_array = kpath.get_array('kpath')
qvec = ['%i\n'%len(kpath_array)]
qvec+=['%e %e %e\n'%(kpt[0], kpt[1], kpt[2]) for kpt in kpath_array]
qvecpath = tempfolder.get_abs_path(self._QVEC)
with open(qvecpath, 'w') as file:
file.writelines(qvec)

# Check for 2D case
twoDimcheck, msg = check_2Dinput_consistency(structure, parameters)
if not twoDimcheck:
raise InputValidationError(msg)

# set shapes array either from parent voronoi run or read from inputcard in kkrimporter calculation
if parent_calc.get_parser_name() != 'kkr.kkrimporterparser':
# get shapes array from voronoi parent
shapes = voro_parent.res.shapes
else:
# extract shapes from input parameters node constructed by kkrimporter calculation
shapes = voro_parent.inp.parameters.get_dict().get('<SHAPE>')

# Prepare inputcard from Structure and input parameter data
input_filename = tempfolder.get_abs_path(self._INPUT_FILE_NAME)

use_alat_input = parameters.get_dict().get('use_input_alat', False)
natom, nspin, newsosol = generate_inputcard_from_structure(parameters, structure, input_filename, parent_calc, shapes=shapes, vca_structure=vca_structure, use_input_alat=use_alat_input)


#################
# Decide what files to copy based on settings to the code (e.g. KKRFLEX option needs scoef)
Expand Down Expand Up @@ -356,7 +420,40 @@ def _prepare_for_submission(self, tempfolder, inputdict):
local_copy_list.append((
os.path.join(outfolderpath, file1),
os.path.join(filename)))


# for set-ef option:
ef_set = parameters.get_dict().get('ef_set', None)
if ef_set is not None:
print('local copy list before change: {}'.format(local_copy_list))
print("found 'ef_set' in parameters: change EF of potential to this value")
potcopy_info = [i for i in local_copy_list if i[1]==self._POTENTIAL][0]
with open(potcopy_info[0]) as file:
# change potential and copy list
local_copy_list.remove(potcopy_info)
pot_new_name = tempfolder.get_abs_path(self._POTENTIAL+'_new_ef')
local_copy_list.append((pot_new_name, self._POTENTIAL))

# change potential
txt = file.readlines()
potstart = []
for iline in range(len(txt)):
line = txt[iline]
if 'exc:' in line:
potstart.append(iline)
for ipotstart in potstart:
tmpline = txt[ipotstart+3]
tmpline = tmpline.split()
newline = '%10.5f%20.14f%20.14f\n'%(float(tmpline[0]), ef_set, float(tmpline[-1]))
txt[ipotstart+3] = newline
# write new file
pot_new_ef = open(pot_new_name, 'w')
pot_new_ef.writelines(txt)
pot_new_ef.close()


# TODO different copy lists, depending on the keywors input
print('local copy list: {}'.format(local_copy_list))
self.logger.info('local copy list: {}'.format(local_copy_list))


Expand Down Expand Up @@ -401,7 +498,6 @@ def _prepare_for_submission(self, tempfolder, inputdict):
add_files.append(self._DOS_ATOM%(iatom+1))
for ispin in range(nspin):
add_files.append((self._LMDOS%(iatom+1, ispin+1)).replace(' ','0'))
print(add_files)
calcinfo.retrieve_list += add_files

# 2. KKRFLEX calculation
Expand All @@ -417,6 +513,22 @@ def _prepare_for_submission(self, tempfolder, inputdict):
print('adding files for KKRFLEX output', add_files)
calcinfo.retrieve_list += add_files

# 3. qdos claculation
retrieve_qdos_files = False
if 'RUNOPT' in parameters.get_dict().keys():
runopts = parameters.get_dict()['RUNOPT']
if runopts is not None :
stripped_run_opts = [i.strip() for i in runopts]
if 'qdos' in stripped_run_opts:
retrieve_qdos_files = True
if retrieve_qdos_files:
print('adding files for qdos output', self._QDOS_ATOM, self._QVEC)
add_files = [self._QVEC]
for iatom in range(natom):
for ispin in range(nspin):
add_files.append((self._QDOS_ATOM%(iatom+1, ispin+1)).replace(' ','0'))
calcinfo.retrieve_list += add_files


codeinfo = CodeInfo()
codeinfo.cmdline_params = []
Expand Down
31 changes: 10 additions & 21 deletions aiida_kkr/calculations/kkrimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,26 +436,15 @@ def _get_pot_and_shape(self, imp_info, shapefun_path, shapes, impurity_potential
"""
write shapefun from impurity info and host shapefun and copy imp. potential
"""
# TODO implement this!
# placeholder: take Fabian's functions later on
scoef = [' 13\n',
' 0.0000000000000000000E+00 0.0000000000000000000E+00 0.0000000000000000000E+00 1 29.0 0.000000000E+00\n',
' 0.2220446049250313081E-14 -0.7071067811865453523E+00 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 0.2220446049250313081E-14 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 0.2220446049250313081E-14 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' 0.2220446049250313081E-14 0.7071067811865497932E+00 -0.7071067811865453523E+00 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 -0.7071067811865453523E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 -0.7071067811865453523E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 0.7071067811865497932E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 0.7071067811865497932E+00 0.2220446049250313081E-14 1 29.0 0.100000000E+01\n',
' 0.2220446049250313081E-14 -0.7071067811865453523E+00 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n',
' -0.7071067811865453523E+00 0.2220446049250313081E-14 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n',
' 0.7071067811865497932E+00 0.2220446049250313081E-14 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n',
' 0.2220446049250313081E-14 0.7071067811865497932E+00 0.7071067811865497932E+00 1 29.0 0.100000000E+01\n']
# use scoef, shapes and shapefun_path to create shapefun for this impurity
scoef_filename = os.path.join(tempfolder.get_abs_path(''), KkrCalculation()._SCOEF)
with open(scoef_filename, 'w') as file:
file.writelines(scoef)


scoef_filename = os.path.join(tempfolder.get_abs_path(''), self._SCOEF)
imp_info_dict = imp_info.get_dict()
Rcut = imp_info_dict.get('Rcut', None)
hcut = imp_info_dict.get('hcut', -1.)
cylinder_orient = imp_info_dict.get('cylinder_orient', [0., 0., 1.])
ilayer_center = imp_info_dict.get('ilayer_center', 0)
make_scoef(structure, Rcut, scoef_filename, hcut, cylinder_orient, ilayer_center)

# create impurity shapefun
shapefun_new_path = tempfolder.get_abs_path(self._SHAPEFUN)
Expand Down Expand Up @@ -486,4 +475,4 @@ def _check_key_setting_consistency(self, params_kkrimp, key, val):

if not param_ok:
raise ValueError('Trying to set key "{}" with value "{}" which is in conflict to previous settings!'.format(key, val))


Loading

0 comments on commit 74236b8

Please sign in to comment.