|
|
@ -21,15 +21,57 @@
|
|
|
|
import numpy as np
|
|
|
|
import numpy as np
|
|
|
|
from numpy.linalg import inv
|
|
|
|
from numpy.linalg import inv
|
|
|
|
|
|
|
|
|
|
|
|
from grogupy.utils import blow_up_orbindx, commutator, parse_magnetic_entity
|
|
|
|
from grogupy.magnetism import blow_up_orbindx, parse_magnetic_entity
|
|
|
|
|
|
|
|
from grogupy.utils import commutator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parallel_Gk(HK, SK, eran, eset):
|
|
|
|
def parallel_Gk(HK, SK, eran, eset):
|
|
|
|
|
|
|
|
"""Calculates the Greens function by inversion.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It calculates the Greens function on all the energy levels at the same time.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
HK : (NO, NO), np.array_like
|
|
|
|
|
|
|
|
Hamiltonian at a given k point
|
|
|
|
|
|
|
|
SK : (NO, NO), np.array_like
|
|
|
|
|
|
|
|
Overlap Matrix at a given k point
|
|
|
|
|
|
|
|
eran : (eset) np.array_like
|
|
|
|
|
|
|
|
Energy sample along the contour
|
|
|
|
|
|
|
|
eset : int
|
|
|
|
|
|
|
|
Number of energy samples along the contour
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
Gk : (eset, NO, NO), np.array_like
|
|
|
|
|
|
|
|
Green's function at a given k point
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Calculates the Greens function on all the energy levels
|
|
|
|
return inv(SK * eran.reshape(eset, 1, 1) - HK)
|
|
|
|
return inv(SK * eran.reshape(eset, 1, 1) - HK)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sequential_GK(HK, SK, eran, eset):
|
|
|
|
def sequential_GK(HK, SK, eran, eset):
|
|
|
|
|
|
|
|
"""Calculates the Greens function by inversion.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It calculates sequentially over the energy levels.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
HK : (NO, NO), np.array_like
|
|
|
|
|
|
|
|
Hamiltonian at a given k point
|
|
|
|
|
|
|
|
SK : (NO, NO), np.array_like
|
|
|
|
|
|
|
|
Overlap Matrix at a given k point
|
|
|
|
|
|
|
|
eran : (eset) np.array_like
|
|
|
|
|
|
|
|
Energy sample along the contour
|
|
|
|
|
|
|
|
eset : int
|
|
|
|
|
|
|
|
Number of energy samples along the contour
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
Gk : (eset, NO, NO), np.array_like
|
|
|
|
|
|
|
|
Green's function at a given k point
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# creates an empty holder
|
|
|
|
Gk = np.zeros(shape=(eset, HK.shape[0], HK.shape[1]), dtype="complex128")
|
|
|
|
Gk = np.zeros(shape=(eset, HK.shape[0], HK.shape[1]), dtype="complex128")
|
|
|
|
|
|
|
|
# fills the holder sequentially by the Greens function on a given energy
|
|
|
|
for j in range(eset):
|
|
|
|
for j in range(eset):
|
|
|
|
Gk[j] = inv(SK * eran[j] - HK)
|
|
|
|
Gk[j] = inv(SK * eran[j] - HK)
|
|
|
|
|
|
|
|
|
|
|
@ -37,14 +79,19 @@ def sequential_GK(HK, SK, eran, eset):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calc_Vu(H, Tu):
|
|
|
|
def calc_Vu(H, Tu):
|
|
|
|
"""_summary_
|
|
|
|
"""Calculates the local perturbation in case of a spin rotation.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
H (_type_): _description_
|
|
|
|
H : (NO, NO) np.array_like
|
|
|
|
Tu (_type_): _description_
|
|
|
|
Hamiltonian
|
|
|
|
|
|
|
|
Tu : (NO, NO) array_like
|
|
|
|
|
|
|
|
Rotation around u
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
_type_: _description_
|
|
|
|
Vu1 : (NO, NO) np.array_like
|
|
|
|
|
|
|
|
First order perturbed matrix
|
|
|
|
|
|
|
|
Vu2 : (NO, NO) np.array_like
|
|
|
|
|
|
|
|
Second order perturbed matrix
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
Vu1 = 1j / 2 * commutator(H, Tu) # equation 100
|
|
|
|
Vu1 = 1j / 2 * commutator(H, Tu) # equation 100
|
|
|
@ -54,15 +101,24 @@ def calc_Vu(H, Tu):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_clutter_for_save(pairs, magnetic_entities):
|
|
|
|
def remove_clutter_for_save(pairs, magnetic_entities):
|
|
|
|
"""_summary_
|
|
|
|
"""Removes unimportant data from the dictionaries.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It is used before saving to throw away data that
|
|
|
|
|
|
|
|
is not needed for post processing.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
pairs (_type_): _description_
|
|
|
|
pairs : dict
|
|
|
|
magnetic_entities (_type_): _description_
|
|
|
|
Contains all the pair information
|
|
|
|
|
|
|
|
magnetic_entities : dict
|
|
|
|
|
|
|
|
Contains all the magnetic entity information
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
_type_: _description_
|
|
|
|
pairs : dict
|
|
|
|
|
|
|
|
Contains all the reduced pair information
|
|
|
|
|
|
|
|
magnetic_entities : dict
|
|
|
|
|
|
|
|
Contains all the reduced magnetic entity information
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
# remove clutter from magnetic entities and pair information
|
|
|
|
# remove clutter from magnetic entities and pair information
|
|
|
|
for pair in pairs:
|
|
|
|
for pair in pairs:
|
|
|
|
del pair["Gij"]
|
|
|
|
del pair["Gij"]
|
|
|
@ -79,14 +135,22 @@ def remove_clutter_for_save(pairs, magnetic_entities):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_hh_ss(dh):
|
|
|
|
def build_hh_ss(dh):
|
|
|
|
"""_summary_
|
|
|
|
"""It builds the Hamiltonian and Overlap matrix from the sisl.dh class.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It restructures the data in the SPIN BOX representation, where NS is
|
|
|
|
|
|
|
|
the number of supercells and NO is the number of orbitals.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
dh (_type_): _description_
|
|
|
|
dh : sisl.physics.Hamiltonian
|
|
|
|
|
|
|
|
Hamiltonian read in by sisl
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
_type_: _description_
|
|
|
|
hh : (NS, NO, NO) np.array_like
|
|
|
|
|
|
|
|
Hamiltonian in SPIN BOX representation
|
|
|
|
|
|
|
|
ss : (NS, NO, NO) np.array_like
|
|
|
|
|
|
|
|
Overlap matrix in SPIN BOX representation
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
NO = dh.no # shorthand for number of orbitals in the unit cell
|
|
|
|
NO = dh.no # shorthand for number of orbitals in the unit cell
|
|
|
|
|
|
|
|
|
|
|
|
# preprocessing Hamiltonian and overlap matrix elements
|
|
|
|
# preprocessing Hamiltonian and overlap matrix elements
|
|
|
@ -142,23 +206,35 @@ def build_hh_ss(dh):
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return hh, ss, NO
|
|
|
|
return hh, ss
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup_pairs_and_magnetic_entities(
|
|
|
|
def setup_pairs_and_magnetic_entities(
|
|
|
|
magnetic_entities, pairs, dh, simulation_parameters
|
|
|
|
magnetic_entities, pairs, dh, simulation_parameters
|
|
|
|
):
|
|
|
|
):
|
|
|
|
"""_summary_
|
|
|
|
"""It creates the complete structure of the dictionaries and fills some basic data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It creates orbital indexes, spin box indexes, coordinates and tags for magnetic entities.
|
|
|
|
|
|
|
|
Furthermore it creates the structures for the energies, the perturbed potentials and
|
|
|
|
|
|
|
|
the Greens function calculation. It dose the same for the pairs.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
magnetic_entities (_type_): _description_
|
|
|
|
pairs : dict
|
|
|
|
pairs (_type_): _description_
|
|
|
|
Contains the initial pair information
|
|
|
|
dh (_type_): _description_
|
|
|
|
magnetic_entities : dict
|
|
|
|
simulation_parameters (_type_): _description_
|
|
|
|
Contains the initial magnetic entity information
|
|
|
|
|
|
|
|
dh : sisl.physics.Hamiltonian
|
|
|
|
|
|
|
|
Hamiltonian read in by sisl
|
|
|
|
|
|
|
|
simulation_parameters : dict
|
|
|
|
|
|
|
|
A set of parameters from the simulation
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
_type_: _description_
|
|
|
|
pairs : dict
|
|
|
|
|
|
|
|
Contains the initial information and the complete structure
|
|
|
|
|
|
|
|
magnetic_entities : dict
|
|
|
|
|
|
|
|
Contains the initial information and the complete structure
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
# for every site we have to store 3 Greens function (and the associated _tmp-s) in the 3 reference directions
|
|
|
|
# for every site we have to store 3 Greens function (and the associated _tmp-s) in the 3 reference directions
|
|
|
|
for mag_ent in magnetic_entities:
|
|
|
|
for mag_ent in magnetic_entities:
|
|
|
|
parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes
|
|
|
|
parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes
|
|
|
@ -169,11 +245,14 @@ def setup_pairs_and_magnetic_entities(
|
|
|
|
# if orbital is not set use all
|
|
|
|
# if orbital is not set use all
|
|
|
|
if "l" not in mag_ent.keys():
|
|
|
|
if "l" not in mag_ent.keys():
|
|
|
|
mag_ent["l"] = "all"
|
|
|
|
mag_ent["l"] = "all"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# tag creation for one atom
|
|
|
|
if isinstance(mag_ent["atom"], int):
|
|
|
|
if isinstance(mag_ent["atom"], int):
|
|
|
|
mag_ent["tags"] = [
|
|
|
|
mag_ent["tags"] = [
|
|
|
|
f"[{mag_ent['atom']}]{dh.atoms[mag_ent['atom']].tag}({mag_ent['l']})"
|
|
|
|
f"[{mag_ent['atom']}]{dh.atoms[mag_ent['atom']].tag}({mag_ent['l']})"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
mag_ent["xyz"] = [dh.xyz[mag_ent["atom"]]]
|
|
|
|
mag_ent["xyz"] = [dh.xyz[mag_ent["atom"]]]
|
|
|
|
|
|
|
|
# tag creation for more atoms
|
|
|
|
if isinstance(mag_ent["atom"], list):
|
|
|
|
if isinstance(mag_ent["atom"], list):
|
|
|
|
mag_ent["tags"] = []
|
|
|
|
mag_ent["tags"] = []
|
|
|
|
mag_ent["xyz"] = []
|
|
|
|
mag_ent["xyz"] = []
|
|
|
@ -187,9 +266,8 @@ def setup_pairs_and_magnetic_entities(
|
|
|
|
# calculate size for Greens function generation
|
|
|
|
# calculate size for Greens function generation
|
|
|
|
spin_box_shape = len(mag_ent["spin_box_indices"])
|
|
|
|
spin_box_shape = len(mag_ent["spin_box_indices"])
|
|
|
|
|
|
|
|
|
|
|
|
mag_ent["energies"] = (
|
|
|
|
# we will store the second order energy derivations here
|
|
|
|
[]
|
|
|
|
mag_ent["energies"] = []
|
|
|
|
) # we will store the second order energy derivations here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# These will be the perturbed potentials from eq. 100
|
|
|
|
# These will be the perturbed potentials from eq. 100
|
|
|
|
mag_ent["Vu1"] = [] # so they are independent in memory
|
|
|
|
mag_ent["Vu1"] = [] # so they are independent in memory
|
|
|
@ -197,7 +275,7 @@ def setup_pairs_and_magnetic_entities(
|
|
|
|
|
|
|
|
|
|
|
|
mag_ent["Gii"] = [] # Greens function
|
|
|
|
mag_ent["Gii"] = [] # Greens function
|
|
|
|
mag_ent["Gii_tmp"] = [] # Greens function for parallelization
|
|
|
|
mag_ent["Gii_tmp"] = [] # Greens function for parallelization
|
|
|
|
for i in simulation_parameters["ref_xcf_orientations"]:
|
|
|
|
for _ in simulation_parameters["ref_xcf_orientations"]:
|
|
|
|
# Rotations for every quantization axis
|
|
|
|
# Rotations for every quantization axis
|
|
|
|
mag_ent["Vu1"].append([])
|
|
|
|
mag_ent["Vu1"].append([])
|
|
|
|
mag_ent["Vu2"].append([])
|
|
|
|
mag_ent["Vu2"].append([])
|
|
|
@ -227,6 +305,7 @@ def setup_pairs_and_magnetic_entities(
|
|
|
|
# calculate size for Greens function generation
|
|
|
|
# calculate size for Greens function generation
|
|
|
|
spin_box_shape_i = len(magnetic_entities[pair["ai"]]["spin_box_indices"])
|
|
|
|
spin_box_shape_i = len(magnetic_entities[pair["ai"]]["spin_box_indices"])
|
|
|
|
spin_box_shape_j = len(magnetic_entities[pair["aj"]]["spin_box_indices"])
|
|
|
|
spin_box_shape_j = len(magnetic_entities[pair["aj"]]["spin_box_indices"])
|
|
|
|
|
|
|
|
# tag generation
|
|
|
|
pair["tags"] = []
|
|
|
|
pair["tags"] = []
|
|
|
|
for mag_ent in [magnetic_entities[pair["ai"]], magnetic_entities[pair["aj"]]]:
|
|
|
|
for mag_ent in [magnetic_entities[pair["ai"]], magnetic_entities[pair["aj"]]]:
|
|
|
|
tag = ""
|
|
|
|
tag = ""
|
|
|
@ -253,7 +332,7 @@ def setup_pairs_and_magnetic_entities(
|
|
|
|
pair["Gji"] = []
|
|
|
|
pair["Gji"] = []
|
|
|
|
pair["Gij_tmp"] = [] # Greens function for parallelization
|
|
|
|
pair["Gij_tmp"] = [] # Greens function for parallelization
|
|
|
|
pair["Gji_tmp"] = []
|
|
|
|
pair["Gji_tmp"] = []
|
|
|
|
for i in simulation_parameters["ref_xcf_orientations"]:
|
|
|
|
for _ in simulation_parameters["ref_xcf_orientations"]:
|
|
|
|
# Greens functions for every quantization axis
|
|
|
|
# Greens functions for every quantization axis
|
|
|
|
pair["Gij"].append(
|
|
|
|
pair["Gij"].append(
|
|
|
|
np.zeros(
|
|
|
|
np.zeros(
|
|
|
@ -284,14 +363,19 @@ def setup_pairs_and_magnetic_entities(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def onsite_projection(matrix, idx1, idx2):
|
|
|
|
def onsite_projection(matrix, idx1, idx2):
|
|
|
|
"""_summary_
|
|
|
|
"""It produces the slices of a matrix for the on site projection.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The slicing is along the last two axes as these contains the orbital indexing.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
matrix (_type_): _description_
|
|
|
|
matrix : (..., :, :) np.array_like
|
|
|
|
idx (_type_): _description_
|
|
|
|
Some matrix
|
|
|
|
|
|
|
|
idx : np.array_like
|
|
|
|
|
|
|
|
The indexes of the orbitals
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
_type_: _description_
|
|
|
|
np.array_like
|
|
|
|
|
|
|
|
Reduced matrix based on the projection
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
return matrix[..., idx1, :][..., idx2]
|
|
|
|
return matrix[..., idx1, :][..., idx2]
|
|
|
|