diff --git a/aiida_kkr/tools/tools_STM_scan.py b/aiida_kkr/tools/tools_STM_scan.py index a735159d..6b23e567 100644 --- a/aiida_kkr/tools/tools_STM_scan.py +++ b/aiida_kkr/tools/tools_STM_scan.py @@ -71,19 +71,26 @@ def get_r_offset(clust1, clust2, host_structure, add_position): pos2 = np.array(host_structure.sites[ilayer2].position) r_out_of_plane = pos2 - pos1 + # convert from Ang to alat units (used internally in KKR) + 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 + # calculate in-plane vector from da, db inputs da = add_position.get_dict().get('da', 0) db = add_position.get_dict().get('db', 0) cell = np.array(host_structure.cell) r_in_plane = da * cell[0] + db * cell[1] + # convert from Ang to alat units (used internally in KKR) + r_in_plane /= alat + # combine to offset vector r_offset = r_out_of_plane + r_in_plane - # convert from Ang to alat units (used internally in KKR) - alat = get_alat_from_bravais(np.array(host_structure.cell), host_structure.pbc[2]) - r_offset /= alat - return r_offset