Skip to content

Commit

Permalink
working version of the STM_wf
Browse files Browse the repository at this point in the history
  • Loading branch information
Raff-physics committed May 29, 2024
1 parent 72af668 commit 47baf2c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
48 changes: 27 additions & 21 deletions aiida_kkr/tools/tools_STM_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ def offset_clust2(clust1, clust2, host_structure, add_position):
return clust2_offset


def get_imp_info_add_position(host_calc, imp_info, add_position):
def get_imp_info_add_position(add_position, host_structure, imp_info):
"""
Create combined impurity info node for the original
imp cluster + an additional (STM tip) position
"""

# extract host structure
host_structure = find_parent_structure(host_calc)
# host_structure = find_parent_structure(host_calc)

# convert imp info to cls form
imp_info_cls, clust1 = convert_to_imp_cls(host_structure, imp_info)
Expand All @@ -138,14 +138,14 @@ def get_imp_info_add_position(host_calc, imp_info, add_position):


@engine.calcfunction
def get_imp_info_add_position_cf(host_remote, imp_info, add_position):
def get_imp_info_add_position_cf(add_position, host_structure, imp_info):
"""
Create a new impurty info node that combines the impurity cluster
of an original calculation and an STM scanning position.
"""

# then combine the imp info
imp_info_combined = get_imp_info_add_position(host_remote, imp_info, add_position)
imp_info_combined = get_imp_info_add_position(add_position, host_structure, imp_info)

return imp_info_combined

Expand All @@ -154,7 +154,7 @@ def get_imp_info_add_position_cf(host_remote, imp_info, add_position):
# combine potentials


def extract_host_potential(add_position, host_remote):
def extract_host_potential(add_position, host_calc):
"""
Extract the potential of the position in the host that matches the additional position
"""
Expand All @@ -163,7 +163,7 @@ def extract_host_potential(add_position, host_remote):
ilayer = add_position['ilayer']

# get host calculation from remote
host_calc = host_remote.get_incoming(node_class=orm.CalcJobNode).first().node
#host_calc = host_remote.get_incoming(node_class=orm.CalcJobNode).first().node

# read potential from host's retrieved node
with host_calc.outputs.retrieved.open('out_potential') as _f:
Expand All @@ -183,12 +183,12 @@ def extract_host_potential(add_position, host_remote):
return pot_add


def add_host_potential_to_imp(add_position, host_remote, imp_potential_node):
def add_host_potential_to_imp(add_position, host_calc, imp_potential_node):
"""
combine host potential with impurity potential
"""
# get add potential from host
pot_add = extract_host_potential(add_position, host_remote)
pot_add = extract_host_potential(add_position, host_calc)

# get impurity potential and convert to list
pot_imp = imp_potential_node.get_content().split('\n')
Expand All @@ -200,15 +200,15 @@ def add_host_potential_to_imp(add_position, host_remote, imp_potential_node):
return pot_combined


def create_combined_potential_node(add_position, host_remote, imp_potential_node):
def create_combined_potential_node(add_position, host_calc, imp_potential_node):
"""
Combine impurity potential with an additional potential from the host for
the STM tip position (additional position)
"""
import io

# combine potential texts
pot_combined = add_host_potential_to_imp(add_position, host_remote, imp_potential_node)
pot_combined = add_host_potential_to_imp(add_position, host_calc, imp_potential_node)

# convert to byte string and put into SinglefilData node
pot_combined_string = ''
Expand All @@ -218,17 +218,17 @@ def create_combined_potential_node(add_position, host_remote, imp_potential_node

return pot_combined_node


@engine.calcfunction
def create_combined_potential_node_cf(add_position, host_remote, imp_potential_node):
def create_combined_potential_node_cf(add_position, host_calc, imp_potential_node):
"""
Calcfunction that combines the impurity potential with an addition potential site from the host
"""

pot_combined_node = create_combined_potential_node(add_position, host_remote, imp_potential_node)
pot_combined_node = create_combined_potential_node(add_position, host_calc, imp_potential_node)

return pot_combined_node


#####################################################################
# STM pathfinder

Expand All @@ -237,9 +237,8 @@ def STM_pathfinder(host_structure):
#from aiida_kkr.tools import find_parent_structure
from ase.spacegroup import Spacegroup
"""This function is used to help visualize the scanned positions
and the symmetries that are present in the system
and the symmetries that are present in the system
"""

"""
inputs::
host_struture : RemoteData : The Remote data contains all the information needed to create the path to scan
Expand Down Expand Up @@ -289,7 +288,16 @@ def symmetry_finder(struc_info):
supp_struc = struc.clone()

# If the structure is not periodic in every direction we force it to be.
supp_struc.pbc = (True, True, True)
if not supp_struc.pbc[2]:
# find film thickness
zs = np.array([i.position[2] for i in supp_struc.sites])
z = zs.max() - zs.min() + 5 # add 5 to have a unit cell larger than the considered film thickness
# set third bravais vector along z direction
cell = supp_struc.cell
cell[2] = [0, 0, z]
supp_struc.set_cell(cell)
# change periodic boundary conditions to periodic
supp_struc.pbc = (True, True, True)

# ASE struc
ase_struc = supp_struc.get_ase()
Expand Down Expand Up @@ -342,10 +350,8 @@ def lattice_generation(x_len, y_len, rot, vec):

for i in range(-x_len, x_len + 1):
for j in range(-y_len, y_len + 1):
if (
(lattice_points[i][j][0] > 0 or math.isclose(lattice_points[i][j][0],0, abs_tol=1e-3)) and
(lattice_points[i][j][1] > 0 or math.isclose(lattice_points[i][j][1],0, abs_tol=1e-3))
):
if ((lattice_points[i][j][0] > 0 or math.isclose(lattice_points[i][j][0], 0, abs_tol=1e-3)) and
(lattice_points[i][j][1] > 0 or math.isclose(lattice_points[i][j][1], 0, abs_tol=1e-3))):
for element in rot[1:]:
point = np.dot(element, lattice_points[i][j])
if point[0] >= 0 and point[1] >= 0:
Expand Down Expand Up @@ -458,4 +464,4 @@ def find_linear_combination_coefficients(plane_vectors, vectors):

indices = sorted(indices, key=itemgetter(0, 1))

return indices
return indices
1 change: 1 addition & 0 deletions aiida_kkr/workflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
from ._decimation import kkr_decimation_wc
from .jijs import kkr_jij_wc
from .imp_BdG import kkrimp_BdG_wc
from .kkr_STM import kkr_STM_wc
9 changes: 8 additions & 1 deletion aiida_kkr/workflows/kkr_STM.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def combine_potentials(self, host_structure, impurity_to_combine, da, db):
imp_info = self.inputs.imp_info #(impurity to combine)
#host_remote = self.inputs.host_remote

combined_imp_info = get_imp_info_add_position(tip_position, host_structure, imp_info)
combined_imp_info = get_imp_info_add_position(Dict(tip_position), host_structure, imp_info)
# Since the objects in AiiDA are immutable we have to create a new dictionary and then convert
# it to the right AiiDA type

Expand Down Expand Up @@ -424,6 +424,9 @@ def STM_lmdos_run(self):
# Check if the kkrflex files are already given in the outputs
if 'kkrflex_files' in self.inputs:
builder.gf_dos_remote = self.inputs.kkrflex_files
message = f'Remote host function is given in the outputs from the node: {self.inputs.kkrflex_files}'
print(message)
self.report(message)
else:
builder.kkr = self.inputs.kkr # needed to evaluate the kkr_flex files in the DOS step

Expand All @@ -440,6 +443,7 @@ def STM_lmdos_run(self):
if 'BdG' in self.inputs:
if 'params_kkr_overwrite' in self.inputs.BdG:
builder.BdG.params_overwrite = self.inputs.BdG.params_kkr_overwrite


self.ctx.kkrimp_params_dict = Dict(
dict={
Expand Down Expand Up @@ -482,6 +486,9 @@ def STM_lmdos_run(self):
calc = self.submit(builder)
message = f"""INFO: running DOS step for an STM measurement (pk: {calc.pk}) at position
(ilayer: {self.inputs.tip_position['ilayer']}, da: {x}, db: {y} )"""

if self.inputs.BdG.params_kkr_overwrite:
message = f"""INFO: runnig DOS step (pk: {calc.pk}) BdG is present"""

print(message)
self.report(message)
Expand Down

0 comments on commit 47baf2c

Please sign in to comment.