Skip to content

Commit

Permalink
Fixes for more complicated system (Fe trimer)
Browse files Browse the repository at this point in the history
- fix offset position (removed modulo 1 in `tools/tools_STM_scan.py`->`get_r_offset`)
- removed code duplication by `self.get_tip_position_dict(da, db)` in `workflows/kkr_STM.py`
- corrected confusing names of functions (combine_potentials`->`combine_imp_info` and `combine_nodes`->`combine_potentials`)
- corrected deduplication checking of cluster positions (`pos_exists_already` needed `clust_offset` input instead of position without layer offset)
  • Loading branch information
PhilippRue committed Oct 4, 2024
1 parent e0e7f2a commit c823109
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 56 deletions.
6 changes: 3 additions & 3 deletions aiida_kkr/tools/tools_STM_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@PhilippRue

PhilippRue Oct 4, 2024

Author Member

these lines lead to the breakdown of the workflow for a more complicated unit cell (Fe trimer system)

# 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)
Expand Down
95 changes: 42 additions & 53 deletions aiida_kkr/workflows/kkr_STM.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

This comment has been minimized.

Copy link
@PhilippRue

PhilippRue Oct 4, 2024

Author Member

old name was confusing: here actually the imp_info nodes are combined, not the potnetials!

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)
Expand All @@ -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):

This comment has been minimized.

Copy link
@PhilippRue

PhilippRue Oct 4, 2024

Author Member

old name was confusing: here the potential nodes are combined, new name reflects this

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):
"""
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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]:

This comment has been minimized.

Copy link
@PhilippRue

PhilippRue Oct 4, 2024

Author Member

old version always compared with a cluster that only had (0,0,0) as position because there was no offset included

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

Expand Down

0 comments on commit c823109

Please sign in to comment.