diff --git a/aiida_kkr/tools/tools_STM_scan.py b/aiida_kkr/tools/tools_STM_scan.py index 14f42f57..630c234b 100644 --- a/aiida_kkr/tools/tools_STM_scan.py +++ b/aiida_kkr/tools/tools_STM_scan.py @@ -80,9 +80,9 @@ def get_r_offset(clust1, clust2, host_structure, add_position): alat = get_alat_from_bravais(np.array(host_structure.cell), host_structure.pbc[2]) r_out_of_plane /= alat - # remove spurious offsets that might be there due to the choice of the unit cell positions - r_out_of_plane = np.round(r_out_of_plane, 7) - r_out_of_plane[:2] %= 1 # modulo 1 for x and y coordinate + # # remove spurious offsets that might be there due to the choice of the unit cell positions + # r_out_of_plane = np.round(r_out_of_plane, 7) + # r_out_of_plane[:2] %= 1 # modulo 1 for x and y coordinate # calculate in-plane vector from da, db inputs da = add_position.get_dict().get('da', 0) diff --git a/aiida_kkr/workflows/kkr_STM.py b/aiida_kkr/workflows/kkr_STM.py index 99db63d0..c7945b5f 100644 --- a/aiida_kkr/workflows/kkr_STM.py +++ b/aiida_kkr/workflows/kkr_STM.py @@ -188,19 +188,13 @@ def define(cls, spec): cls.results ) - def combine_potentials(self, host_structure, impurity_to_combine, da, db): + def combine_imp_info(self, host_structure, impurity_to_combine, da, db): from aiida_kkr.tools.tools_STM_scan import get_imp_info_add_position import numpy as np # TO DO: optimize this call, only need append from numpy """ Here we want to combine the impurity information and the host information """ - tip_position = { - } # Since the objects in AiiDA are immutable we have to create a new dictionary and then convert - # it to the right AiiDA type - - tip_position['ilayer'] = self.inputs.tip_position['ilayer'] - tip_position['da'] = da - tip_position['db'] = db + tip_position = self.get_tip_position_dict(da, db) imp_info = self.inputs.imp_info #(impurity to combine) combined_imp_info = get_imp_info_add_position(Dict(tip_position), host_structure, imp_info) @@ -227,23 +221,25 @@ def combine_potentials(self, host_structure, impurity_to_combine, da, db): return new_combined_imp_info - def combine_nodes(self, host_calc, node_to_combine, da, db): + def combine_potentials(self, host_calc, node_to_combine, da, db): from aiida_kkr.tools.tools_STM_scan import create_combined_potential_node """ Here we create a combined potential node from the host potential (no impurity) and from the impurity potential """ - # Since the objects in AiiDA are immutable we have to create a new dictionary and then convert - # it to the right AiiDA type + tip_position = self.get_tip_position_dict(da, db) + combined_potential_node = create_combined_potential_node(tip_position, host_calc, node_to_combine) + return combined_potential_node + + def get_tip_position_dict(self, da, db): + # Since the objects in AiiDA are immutable we have to create a new dictionary + # and then convert it to the right AiiDA type tip_position = {} - # for now we require that the z position remains the same. tip_position['ilayer'] = self.inputs.tip_position['ilayer'] tip_position['da'] = da tip_position['db'] = db - - combined_node = create_combined_potential_node(tip_position, host_calc, node_to_combine) - return combined_node + return tip_position def start(self): """ @@ -344,11 +340,11 @@ def impurity_cluster_evaluation(self): from aiida_kkr.tools.imp_cluster_tools import pos_exists_already from aiida_kkr.tools.tools_STM_scan import get_imp_cls_add, convert_to_imp_cls, offset_clust2 - #if _VERBOSE_: - # from time import time - # - # # measure time at start - # t_start = time() + if _VERBOSE_: + from time import time + + # measure time at start + t_start = time() # Here we create an impurity cluster that has inside all the positions on which the STM will scan @@ -362,9 +358,9 @@ def impurity_cluster_evaluation(self): # now find all the positions we need to scan coeff = self.get_scanning_positions(host_remote) - #if _VERBOSE_: - # # timing counters - # t_imp_info, t_pot = 0., 0. + if _VERBOSE_: + # timing counters + t_imp_info, t_pot = 0., 0. _, imp_clust = convert_to_imp_cls(host_structure, impurity_info) @@ -380,52 +376,45 @@ def impurity_cluster_evaluation(self): for element in coeff: - #if _VERBOSE_: - # t0 = time() + if _VERBOSE_: + t0 = time() # Check if the position is already in the cluster - tmp_pos = {} - tmp_pos['ilayer'] = self.inputs.tip_position['ilayer'] - tmp_pos['da'] = element[0] - tmp_pos['db'] = element[1] - - message = f'position to be embedded {tmp_pos}' - + # for this we need to first get the position + tmp_pos = self.get_tip_position_dict(element[0], element[1]) _, tmp_clust = get_imp_cls_add(host_structure, tmp_pos) - #clust_offset = offset_clust2(imp_clust, tmp_clust, host_structure, Dict(tmp_pos)) + clust_offset = offset_clust2(imp_clust, tmp_clust, host_structure, Dict(tmp_pos)) - #if _VERBOSE_: - # t_cluster_offset += time()-t0 + if _VERBOSE_: + t_cluster_offset += time() - t0 - if pos_exists_already(imp_clust, tmp_clust)[0]: - message = f'The position {tmp_pos} is already present in the system' + if pos_exists_already(imp_clust[:, :3], clust_offset[:, :3])[0]: + message = f'INFO: The position {tmp_pos} is already present in the system, skipping it' self.report(message) continue # If the position exists already skip the embedding else: # Aggregation of the impurity potential - tmp_imp_info = self.combine_potentials(host_structure, impurity_info_aux, element[0], element[1]) + tmp_imp_info = self.combine_imp_info(host_structure, impurity_info_aux, element[0], element[1]) impurity_info_aux = tmp_imp_info - message = 'imp info has been embedded' - self.report(message) - - #if _VERBOSE_: - # t_imp_info += time() - t0 - # t0 = time() + if _VERBOSE_: + self.report('imp info has been embedded') + t_imp_info += time() - t0 + t0 = time() # Aggregation the impurity nodes - tmp_imp_pot = self.combine_nodes(host_calc, imp_potential_node_aux, element[0], element[1]) + tmp_imp_pot = self.combine_potentials(host_calc, imp_potential_node_aux, element[0], element[1]) imp_potential_node_aux = tmp_imp_pot - message = 'imp pot has been embedded' - self.report(message) - - #if _VERBOSE_: - # t_pot += time() - t0 + if _VERBOSE_: + self.report('imp potential has been added') + t_pot += time() - t0 - #if _VERBOSE_: - # # report elapsed time for cluster generation - # self.report(f'time for cluster generation (s): {time()-t_start}, cluster generation={t_cluster_offset}, imp_info={t_imp_info}, pot={t_pot}') + if _VERBOSE_: + # report elapsed time for cluster generation + self.report( + f'time for cluster generation (s): {time()-t_start}, cluster generation={t_cluster_offset}, imp_info={t_imp_info}, pot={t_pot}' + ) return impurity_info_aux, imp_potential_node_aux