added black:jupyter to pre-commit, made the output nicer so it is easier to debug code, experimented with no results... :'(

class-solution
Daniel Pozsar 3 months ago
parent c5ef8787bd
commit a0f1e9ece6

@ -27,6 +27,11 @@ repos:
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black-jupyter
language_version: python3.9
#- repo: local
# hooks:
# - id: pytest-check

@ -24,48 +24,47 @@
"\n",
"# Define MatrixSymbols with specific sizes\n",
"# A = 2x2, B = 3x3, R = 4x4\n",
"AA = MatrixSymbol('AA', 2, 2) # 2x2\n",
"AB = MatrixSymbol('AB', 2, 3) # 2x3\n",
"BA = MatrixSymbol('BA', 3, 2) # 3x2\n",
"AR = MatrixSymbol('AR', 2, 4) # 2x4\n",
"RA = MatrixSymbol('RA', 4, 2) # 4x2\n",
"BB = MatrixSymbol('BB', 3, 3) # 3x3\n",
"BR = MatrixSymbol('BR', 3, 4) # 3x4\n",
"RB = MatrixSymbol('RB', 4, 3) # 4x3\n",
"RR = MatrixSymbol('RR', 4, 4) # 4x4\n",
"AA = MatrixSymbol(\"AA\", 2, 2) # 2x2\n",
"AB = MatrixSymbol(\"AB\", 2, 3) # 2x3\n",
"BA = MatrixSymbol(\"BA\", 3, 2) # 3x2\n",
"AR = MatrixSymbol(\"AR\", 2, 4) # 2x4\n",
"RA = MatrixSymbol(\"RA\", 4, 2) # 4x2\n",
"BB = MatrixSymbol(\"BB\", 3, 3) # 3x3\n",
"BR = MatrixSymbol(\"BR\", 3, 4) # 3x4\n",
"RB = MatrixSymbol(\"RB\", 4, 3) # 4x3\n",
"RR = MatrixSymbol(\"RR\", 4, 4) # 4x4\n",
"\n",
"# Create block matrices VA and VB using BlockMatrix\n",
"# We need to use ZeroMatrix with appropriate dimensions for padding\n",
"VA = BlockMatrix([\n",
"VA = BlockMatrix(\n",
" [\n",
" [AA, 0.5 * AB, 0.5 * AR],\n",
" [0.5 * BA, ZeroMatrix(3, 3), ZeroMatrix(3, 4)],\n",
" [0.5*RA, ZeroMatrix(4,3), ZeroMatrix(4,4)]\n",
"])\n",
" [0.5 * RA, ZeroMatrix(4, 3), ZeroMatrix(4, 4)],\n",
" ]\n",
")\n",
"\n",
"VB = BlockMatrix([\n",
"VB = BlockMatrix(\n",
" [\n",
" [ZeroMatrix(2, 2), 0.5 * AB, ZeroMatrix(2, 4)],\n",
" [0.5 * BA, BB, 0.5 * BR],\n",
" [ZeroMatrix(4,2), 0.5*RB, ZeroMatrix(4,4)]\n",
"])\n",
" [ZeroMatrix(4, 2), 0.5 * RB, ZeroMatrix(4, 4)],\n",
" ]\n",
")\n",
"\n",
"# Define G matrix symbols with matching dimensions\n",
"G_AA = MatrixSymbol('G_AA', 2, 2)\n",
"G_AB = MatrixSymbol('G_AB', 2, 3)\n",
"G_BA = MatrixSymbol('G_BA', 3, 2)\n",
"G_AR = MatrixSymbol('G_AR', 2, 4)\n",
"G_RA = MatrixSymbol('G_RA', 4, 2)\n",
"G_BB = MatrixSymbol('G_BB', 3, 3)\n",
"G_BR = MatrixSymbol('G_BR', 3, 4)\n",
"G_RB = MatrixSymbol('G_RB', 4, 3)\n",
"G_RR = MatrixSymbol('G_RR', 4, 4)\n",
"G_AA = MatrixSymbol(\"G_AA\", 2, 2)\n",
"G_AB = MatrixSymbol(\"G_AB\", 2, 3)\n",
"G_BA = MatrixSymbol(\"G_BA\", 3, 2)\n",
"G_AR = MatrixSymbol(\"G_AR\", 2, 4)\n",
"G_RA = MatrixSymbol(\"G_RA\", 4, 2)\n",
"G_BB = MatrixSymbol(\"G_BB\", 3, 3)\n",
"G_BR = MatrixSymbol(\"G_BR\", 3, 4)\n",
"G_RB = MatrixSymbol(\"G_RB\", 4, 3)\n",
"G_RR = MatrixSymbol(\"G_RR\", 4, 4)\n",
"\n",
"# Create G matrix as a BlockMatrix\n",
"G = BlockMatrix([\n",
" [G_AA, G_AB, G_AR],\n",
" [G_BA, G_BB, G_BR],\n",
" [G_RA, G_RB, G_RR]\n",
"])\n",
"\n",
"G = BlockMatrix([[G_AA, G_AB, G_AR], [G_BA, G_BB, G_BR], [G_RA, G_RB, G_RR]])\n",
"\n",
"\n",
"# Calculate the trace of VA@G@VB@G\n",
@ -92,47 +91,47 @@
],
"source": [
"# Define MatrixSymbols with specific sizes\n",
"AA = MatrixSymbol('AA', 2, 2) # 2x2\n",
"AB = MatrixSymbol('AB', 2, 3) # 2x3\n",
"BA = MatrixSymbol('BA', 3, 2) # 3x2\n",
"BB = MatrixSymbol('BB', 3, 3) # 3x3\n",
"AA = MatrixSymbol(\"AA\", 2, 2) # 2x2\n",
"AB = MatrixSymbol(\"AB\", 2, 3) # 2x3\n",
"BA = MatrixSymbol(\"BA\", 3, 2) # 3x2\n",
"BB = MatrixSymbol(\"BB\", 3, 3) # 3x3\n",
"\n",
"# Create block matrices VA and VB using BlockMatrix\n",
"# R-related terms are replaced with zero matrices\n",
"VA = BlockMatrix([\n",
"VA = BlockMatrix(\n",
" [\n",
" [AA, 0.5 * AB, ZeroMatrix(2, 4)],\n",
" [0.5 * BA, ZeroMatrix(3, 3), ZeroMatrix(3, 4)],\n",
" [ZeroMatrix(4,2), ZeroMatrix(4,3), ZeroMatrix(4,4)]\n",
"])\n",
" [ZeroMatrix(4, 2), ZeroMatrix(4, 3), ZeroMatrix(4, 4)],\n",
" ]\n",
")\n",
"\n",
"VB = BlockMatrix([\n",
"VB = BlockMatrix(\n",
" [\n",
" [ZeroMatrix(2, 2), 0.5 * AB, ZeroMatrix(2, 4)],\n",
" [0.5 * BA, BB, ZeroMatrix(3, 4)],\n",
" [ZeroMatrix(4,2), ZeroMatrix(4,3), ZeroMatrix(4,4)]\n",
"])\n",
" [ZeroMatrix(4, 2), ZeroMatrix(4, 3), ZeroMatrix(4, 4)],\n",
" ]\n",
")\n",
"\n",
"# Define G matrix symbols with matching dimensions (kept original)\n",
"G_AA = MatrixSymbol('G_AA', 2, 2)\n",
"G_AB = MatrixSymbol('G_AB', 2, 3)\n",
"G_BA = MatrixSymbol('G_BA', 3, 2)\n",
"G_AR = MatrixSymbol('G_AR', 2, 4)\n",
"G_RA = MatrixSymbol('G_RA', 4, 2)\n",
"G_BB = MatrixSymbol('G_BB', 3, 3)\n",
"G_BR = MatrixSymbol('G_BR', 3, 4)\n",
"G_RB = MatrixSymbol('G_RB', 4, 3)\n",
"G_RR = MatrixSymbol('G_RR', 4, 4)\n",
"G_AA = MatrixSymbol(\"G_AA\", 2, 2)\n",
"G_AB = MatrixSymbol(\"G_AB\", 2, 3)\n",
"G_BA = MatrixSymbol(\"G_BA\", 3, 2)\n",
"G_AR = MatrixSymbol(\"G_AR\", 2, 4)\n",
"G_RA = MatrixSymbol(\"G_RA\", 4, 2)\n",
"G_BB = MatrixSymbol(\"G_BB\", 3, 3)\n",
"G_BR = MatrixSymbol(\"G_BR\", 3, 4)\n",
"G_RB = MatrixSymbol(\"G_RB\", 4, 3)\n",
"G_RR = MatrixSymbol(\"G_RR\", 4, 4)\n",
"\n",
"# Create G matrix as a BlockMatrix (kept original)\n",
"G = BlockMatrix([\n",
" [G_AA, G_AB, G_AR],\n",
" [G_BA, G_BB, G_BR],\n",
" [G_RA, G_RB, G_RR]\n",
"])\n",
"G = BlockMatrix([[G_AA, G_AB, G_AR], [G_BA, G_BB, G_BR], [G_RA, G_RB, G_RR]])\n",
"\n",
"# Calculate the product and trace\n",
"product = block_collapse(VA @ G @ VB @ G)\n",
"result = trace(product)\n",
"print(result)\n"
"print(result)"
]
},
{
@ -152,39 +151,39 @@
"from sympy import MatrixSymbol, BlockMatrix, ZeroMatrix, trace, block_collapse\n",
"\n",
"# Define MatrixSymbols with specific sizes\n",
"AA = MatrixSymbol('AA', 2, 2) # 2x2\n",
"BB = MatrixSymbol('BB', 3, 3) # 3x3\n",
"AA = MatrixSymbol(\"AA\", 2, 2) # 2x2\n",
"BB = MatrixSymbol(\"BB\", 3, 3) # 3x3\n",
"\n",
"# Create block matrices VA and VB using BlockMatrix with only AA and BB\n",
"VA = BlockMatrix([\n",
"VA = BlockMatrix(\n",
" [\n",
" [AA, ZeroMatrix(2, 3), ZeroMatrix(2, 4)],\n",
" [ZeroMatrix(3, 2), ZeroMatrix(3, 3), ZeroMatrix(3, 4)],\n",
" [ZeroMatrix(4,2), ZeroMatrix(4,3), ZeroMatrix(4,4)]\n",
"])\n",
" [ZeroMatrix(4, 2), ZeroMatrix(4, 3), ZeroMatrix(4, 4)],\n",
" ]\n",
")\n",
"\n",
"VB = BlockMatrix([\n",
"VB = BlockMatrix(\n",
" [\n",
" [ZeroMatrix(2, 2), ZeroMatrix(2, 3), ZeroMatrix(2, 4)],\n",
" [ZeroMatrix(3, 2), BB, ZeroMatrix(3, 4)],\n",
" [ZeroMatrix(4,2), ZeroMatrix(4,3), ZeroMatrix(4,4)]\n",
"])\n",
" [ZeroMatrix(4, 2), ZeroMatrix(4, 3), ZeroMatrix(4, 4)],\n",
" ]\n",
")\n",
"\n",
"# Define G matrix symbols with matching dimensions\n",
"G_AA = MatrixSymbol('G_AA', 2, 2)\n",
"G_AB = MatrixSymbol('G_AB', 2, 3)\n",
"G_BA = MatrixSymbol('G_BA', 3, 2)\n",
"G_AR = MatrixSymbol('G_AR', 2, 4)\n",
"G_RA = MatrixSymbol('G_RA', 4, 2)\n",
"G_BB = MatrixSymbol('G_BB', 3, 3)\n",
"G_BR = MatrixSymbol('G_BR', 3, 4)\n",
"G_RB = MatrixSymbol('G_RB', 4, 3)\n",
"G_RR = MatrixSymbol('G_RR', 4, 4)\n",
"G_AA = MatrixSymbol(\"G_AA\", 2, 2)\n",
"G_AB = MatrixSymbol(\"G_AB\", 2, 3)\n",
"G_BA = MatrixSymbol(\"G_BA\", 3, 2)\n",
"G_AR = MatrixSymbol(\"G_AR\", 2, 4)\n",
"G_RA = MatrixSymbol(\"G_RA\", 4, 2)\n",
"G_BB = MatrixSymbol(\"G_BB\", 3, 3)\n",
"G_BR = MatrixSymbol(\"G_BR\", 3, 4)\n",
"G_RB = MatrixSymbol(\"G_RB\", 4, 3)\n",
"G_RR = MatrixSymbol(\"G_RR\", 4, 4)\n",
"\n",
"# Create G matrix as a BlockMatrix\n",
"G = BlockMatrix([\n",
" [G_AA, G_AB, G_AR],\n",
" [G_BA, G_BB, G_BR],\n",
" [G_RA, G_RB, G_RR]\n",
"])\n",
"G = BlockMatrix([[G_AA, G_AB, G_AR], [G_BA, G_BB, G_BR], [G_RA, G_RB, G_RR]])\n",
"\n",
"# Calculate the product and simplify\n",
"product = block_collapse(VA @ G @ VB @ G)\n",

@ -7,11 +7,14 @@ import sisl
from mpi4py import MPI
from numpy.linalg import inv
from tqdm import tqdm
from useful import *
from src.grogu_magn.useful import *
def main():
start_time = timer()
start_time = timer() # runtime information
times = dict()
times["start_time"] = timer()
# this cell mimicks an input file
fdf = sisl.get_sile("./lat3_791/Fe3GeTe2.fdf")
@ -28,45 +31,6 @@ def main():
]
# human readable definition of magnetic entities
# magnetic_entities = [
# dict(atom=0, ),
# dict(atom=1, ),
# dict(atom=2, ),
# dict(atom=3, l=2),
# dict(atom=4, l=2),
# dict(atom=5, l=2),
# ]
# pairs = [
# dict(ai=3, aj=4, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV
# dict(ai=3, aj=5, Ruc=np.array([0, 0, 0])), # these should all be around -41.9 in the isotropic part
# dict(ai=4, aj=5, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=0, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=1, Ruc=np.array([0, 0, 0])),
# dict(ai=3, aj=2, Ruc=np.array([0, 0, 0])),
# ]
# magnetic_entities = [
# dict(atom=3, l=2),
# dict(atom=4, l=2),
# dict(atom=5, l=2),
# ]
# pair information
# pairs = [
# dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV
# dict(
# ai=0, aj=2, Ruc=np.array([0, 0, 0])
# ), # these should all be around -41.9 in the isotropic part
# dict(ai=1, aj=2, Ruc=np.array([0, 0, 0])),
# dict(ai=0, aj=1, Ruc=np.array([-1, 0, 0])),
# dict(ai=0, aj=2, Ruc=np.array([-1, 0, 0])),
# dict(ai=0, aj=1, Ruc=np.array([1, 0, 0])),
# dict(ai=0, aj=2, Ruc=np.array([1, 0, 0])),
# dict(ai=0, aj=1, Ruc=np.array([0, -1, 0])),
# dict(ai=0, aj=2, Ruc=np.array([0, -1, 0])),
# dict(ai=0, aj=1, Ruc=np.array([0, 1, 0])),
# dict(ai=0, aj=2, Ruc=np.array([0, 1, 0])),
# dict(ai=1, aj=2, Ruc=np.array([-1, 0, 0])),
# ]
magnetic_entities = [
dict(atom=3, l=2),
dict(atom=4, l=2),
@ -77,11 +41,13 @@ def main():
]
# pair information
# these should all be around -41.9 in the isotropic part
# isotropic should be -82 meV
pairs = [
dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV
dict(
ai=0, aj=2, Ruc=np.array([0, 0, 0])
), # these should all be around -41.9 in the isotropic part
dict(ai=0, aj=3, Ruc=np.array([0, 0, 0])),
dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])),
dict(ai=1, aj=0, Ruc=np.array([0, 0, 0])),
dict(ai=0, aj=2, Ruc=np.array([0, 0, 0])),
dict(ai=1, aj=2, Ruc=np.array([0, 0, 0])),
dict(ai=0, aj=2, Ruc=np.array([-1, 0, 0])),
dict(ai=1, aj=2, Ruc=np.array([-1, 0, 0])),
@ -92,7 +58,7 @@ def main():
kdirs = "xy"
ebot = -30
eset = 50
esetp = 1000
esetp = 10000
# MPI parameters
comm = MPI.COMM_WORLD
@ -125,7 +91,7 @@ def main():
# unit cell index
uc_in_sc_idx = dh.lattice.sc_index([0, 0, 0])
setup_time = timer()
times["setup_time"] = timer()
NO = dh.no # shorthand for number of orbitals in the unit cell
@ -213,18 +179,16 @@ def main():
f"Exchange field has non negligible scalar part. Largest value is {max_xcfs}"
)
H_and_XCF_time = timer()
times["H_and_XCF_time"] = timer()
# for every site we have to store 3 Greens function (and the associated _tmp-s) in the 3 reference directions
for i, mag_ent in enumerate(magnetic_entities):
parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes
magnetic_entities[i]["orbital_indeces"] = parsed
magnetic_entities[i]["spin_box_indeces"] = blow_up_orbindx(
parsed
) # calculate spin box indexes
spin_box_shape = len(
mag_ent["spin_box_indeces"]
) # calculate size for Greens function generation
# calculate spin box indexes
magnetic_entities[i]["spin_box_indeces"] = blow_up_orbindx(parsed)
# calculate size for Greens function generation
spin_box_shape = len(mag_ent["spin_box_indeces"])
mag_ent["energies"] = (
[]
@ -232,14 +196,14 @@ def main():
mag_ent["Gii"] = [] # Greens function
mag_ent["Gii_tmp"] = [] # Greens function for parallelization
mag_ent["Vu1"] = [
list([]) for _ in range(len(ref_xcf_orientations))
] # These will be the perturbed potentials from eq. 100
# These will be the perturbed potentials from eq. 100
mag_ent["Vu1"] = [list([]) for _ in range(len(ref_xcf_orientations))]
mag_ent["Vu2"] = [list([]) for _ in range(len(ref_xcf_orientations))]
for i in ref_xcf_orientations:
# Greens functions for every quantization axis
mag_ent["Gii"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128")
) # Greens functions for every quantization axis
)
mag_ent["Gii_tmp"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128")
)
@ -247,11 +211,9 @@ def main():
# for every site we have to store 2x3 Greens function (and the associated _tmp-s)
# in the 3 reference directions, because G_ij and G_ji are both needed
for pair in pairs:
spin_box_shape_i, spin_box_shape_j = len(
magnetic_entities[pair["ai"]]["spin_box_indeces"]
), len(
magnetic_entities[pair["aj"]]["spin_box_indeces"]
) # calculate size for Greens function generation
# calculate size for Greens function generation
spin_box_shape_i = len(magnetic_entities[pair["ai"]]["spin_box_indeces"])
spin_box_shape_j = len(magnetic_entities[pair["aj"]]["spin_box_indeces"])
pair["energies"] = [] # we will store the second order energy derivations here
@ -273,16 +235,16 @@ def main():
np.zeros((eset, spin_box_shape_j, spin_box_shape_i), dtype="complex128")
)
site_and_pair_dictionaries_time = timer()
times["site_and_pair_dictionaries_time"] = timer()
kset = make_kset(dirs=kdirs, NUMK=kset) # generate k space sampling
wkset = np.ones(len(kset)) / len(kset) # generate weights for k points
kpcs = np.array_split(kset, size) # split the k points based on MPI size
kpcs[root_node] = tqdm(kpcs[root_node], desc="k loop", file=stdout)
k_set_time = timer()
times["k_set_time"] = timer()
# this will contain all the data needed to calculate the energy variations upon rotation
# this will contain the three hamiltonians in the reference directions needed to calculate the energy variations upon rotation
hamiltonians = []
# iterate over the reference directions (quantization axes)
@ -296,15 +258,16 @@ def main():
rot_H_XCF_uc = rot_H_XCF[uc_in_sc_idx]
# obtain total Hamiltonian with the rotated exchange field
rot_H = hTRS + rot_H_XCF # equation 76
rot_H = (
hTRS + rot_H_XCF
) # equation 76 #######################################################################################
hamiltonians.append(
dict(orient=orient["o"], H=rot_H, rotations=[])
dict(orient=orient["o"], H=rot_H)
) # store orientation and rotated Hamiltonian
for u in orient[
"vw"
]: # these are the infinitezimal rotations (for now) perpendicular to the quantization axis
# these are the infinitezimal rotations (for now) perpendicular to the quantization axis
for u in orient["vw"]:
Tu = np.kron(np.eye(NO, dtype=int), tau_u(u)) # section 2.H
Vu1 = 1j / 2 * commutator(rot_H_XCF_uc, Tu) # equation 100
@ -318,7 +281,7 @@ def main():
Vu2[:, mag_ent["spin_box_indeces"]][mag_ent["spin_box_indeces"], :]
)
reference_rotations_time = timer()
times["reference_rotations_time"] = timer()
if rank == root_node:
print("Number of magnetic entities being calculated: ", len(magnetic_entities))
@ -339,9 +302,8 @@ def main():
# sampling the integrand on the contour and the BZ
for k in kpcs[rank]:
wk = wkset[rank] # weight of k point in BZ integral
for i, hamiltonian_orientation in enumerate(
hamiltonians
): # iterate over reference directions
# iterate over reference directions
for i, hamiltonian_orientation in enumerate(hamiltonians):
# calculate Greens function
H = hamiltonian_orientation["H"]
HK, SK = hsk(H, ss, dh.sc_off, k)
@ -375,7 +337,7 @@ def main():
comm.Reduce(pair["Gij_tmp"][i], pair["Gij"][i], root=root_node)
comm.Reduce(pair["Gji_tmp"][i], pair["Gji"][i], root=root_node)
green_function_inversion_time = timer()
times["green_function_inversion_time"] = timer()
if rank == root_node:
# iterate over the magnetic entities
@ -393,7 +355,7 @@ def main():
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the magnetic entities dictionary with the energies
mag_ent["energies"].append(storage)
magnetic_entities[tracker]["energies"].append(storage)
# iterate over the pairs
for tracker, pair in enumerate(pairs):
@ -410,109 +372,11 @@ def main():
traced = np.trace((Vui @ Gij @ Vuj @ Gji), axis1=1, axis2=2)
# evaluation of the contour integral
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the pairs dictionary with the energies
pairs[tracker]["energies"].append(storage)
end_time = timer()
print(
"############################### GROGU OUTPUT ###################################"
)
print(
"================================================================================"
)
print("Input file: ")
print(simulation_parameters["path"])
print(
"Number of nodes in the parallel cluster: ",
simulation_parameters["parallel_size"],
)
print(
"================================================================================"
)
try:
print("Cell [Ang]: ")
print(simulation_parameters["geom"].cell)
except:
print("Geometry could not be read.")
print(
"================================================================================"
)
print("DFT axis: ")
print(simulation_parameters["scf_xcf_orientation"])
print("Quantization axis and perpendicular rotation directions:")
for ref in ref_xcf_orientations:
print(ref["o"], " --» ", ref["vw"])
print(
"================================================================================"
)
print("number of k points: ", simulation_parameters["kset"])
print("k point directions: ", simulation_parameters["kdirs"])
print(
"================================================================================"
)
print("Parameters for the contour integral:")
print("Ebot: ", simulation_parameters["ebot"])
print("Eset: ", simulation_parameters["eset"])
print("Esetp: ", simulation_parameters["esetp"])
print(
"================================================================================"
)
print("Atomic informations: ")
print("")
print("")
print("Not yet specified.")
print("")
print("")
print(
"================================================================================"
)
print("Exchange [meV]")
print(
"--------------------------------------------------------------------------------"
)
print("Atom1 Atom2 [i j k] d [Ang]")
print(
"--------------------------------------------------------------------------------"
)
for pair in pairs:
J_iso, J_S, D = calculate_exchange_tensor(pair)
J_iso = J_iso * sisl.unit_convert("eV", "meV")
J_S = J_S * sisl.unit_convert("eV", "meV")
D = D * sisl.unit_convert("eV", "meV")
print(print_atomic_indices(pair, magnetic_entities, dh))
print("Isotropic: ", J_iso)
print("DMI: ", D)
print("Symmetric-anisotropy: ", J_S)
print("")
print(
"================================================================================"
)
print("Runtime information: ")
print("Total runtime: ", end_time - start_time)
print(
"--------------------------------------------------------------------------------"
)
print("Initial setup: ", setup_time - start_time)
print(
f"Hamiltonian conversion and XC field extraction: {H_and_XCF_time - setup_time:.3f} s"
)
print(
f"Pair and site datastructure creatrions: {site_and_pair_dictionaries_time - H_and_XCF_time:.3f} s"
)
print(
f"k set cration and distribution: {k_set_time - site_and_pair_dictionaries_time:.3f} s"
)
print(f"Rotating XC potential: {reference_rotations_time - k_set_time:.3f} s")
print(
f"Greens function inversion: {green_function_inversion_time - reference_rotations_time:.3f} s"
)
print(
f"Calculate energies and magnetic components: {end_time - green_function_inversion_time:.3f} s"
)
times["end_time"] = timer()
print_output(simulation_parameters, magnetic_entities, pairs, dh, times)
if __name__ == "__main__":

@ -22,6 +22,7 @@ from itertools import permutations, product
import numpy as np
from scipy.special import roots_legendre
from sisl import unit_convert
# Pauli matrices
tau_x = np.array([[0, 1], [1, 0]])
@ -226,33 +227,170 @@ def calculate_exchange_tensor(pair):
return J_ii.sum() / 3, np.concatenate([J_ii[:2] - J_ii.sum() / 3, J_S]).flatten(), D
def print_atomic_indices(pair, magnetic_entities, dh):
def print_pair_atomic_indices(pair, magnetic_entities, dh):
atomic_indices = ""
atoms = magnetic_entities[pair["ai"]]
if "l" not in atoms.keys():
atoms["l"] = "all"
if isinstance(atoms["atom"], int):
atomic_indices += (
f"[{atoms['atom']}]{dh.atoms[atoms['atom']].tag}({atoms['l']})"
)
if isinstance(atoms, list):
atomic_indices += [
f"[{atoms['atom']}]{dh.atoms[atom['atom']].tag}({atom['l']})"
for atom in atoms["atom"]
]
atoms = magnetic_entities[pair["aj"]]
if "l" not in atoms.keys():
atoms["l"] = "all"
# iterate over the two magnetic entities in a pair
for mag_ent in [magnetic_entities[pair["ai"]], magnetic_entities[pair["aj"]]]:
# get atoms of magnetic entity
atoms_idx = mag_ent["atom"]
# if orbital is not set use all
if "l" not in mag_ent.keys():
mag_ent["l"] = "all"
orbitals = mag_ent["l"]
# if magnetic entity contains one atoms
if isinstance(atoms_idx, int):
atomic_indices += f"[{atoms_idx}]{dh.atoms[atoms_idx].tag}({orbitals})"
# if magnetic entity contains more than one atoms
if isinstance(atoms_idx, list):
# iterate over atoms
atom_group = "{"
for atom_idx in atoms_idx:
atom_group += f"[{atom_idx}]{dh.atoms[atom_idx].tag}({orbitals})--"
# end {} of the atoms in the magnetic entity
atomic_indices += atom_group[:-2] + "}"
# separate magnetic entities
atomic_indices += " "
if isinstance(atoms["atom"], int):
atomic_indices += (
f"[{atoms['atom']}]{dh.atoms[atoms['atom']].tag}({atoms['l']})"
return atomic_indices
def print_output(simulation_parameters, magnetic_entities, pairs, dh, times):
print(
"##################################################################### GROGU OUTPUT #############################################################################"
)
print(
"================================================================================================================================================================"
)
print("Input file: ")
print(simulation_parameters["path"])
print(
"Number of nodes in the parallel cluster: ",
simulation_parameters["parallel_size"],
)
print(
"================================================================================================================================================================"
)
try:
print("Cell [Ang]: ")
print(simulation_parameters["geom"].cell)
except:
print("Geometry could not be read.")
print(
"================================================================================================================================================================"
)
print("DFT axis: ")
print(simulation_parameters["scf_xcf_orientation"])
print("Quantization axis and perpendicular rotation directions:")
for ref in simulation_parameters["ref_xcf_orientations"]:
print(ref["o"], " --» ", ref["vw"])
print(
"================================================================================================================================================================"
)
print("number of k points: ", simulation_parameters["kset"])
print("k point directions: ", simulation_parameters["kdirs"])
print(
"================================================================================================================================================================"
)
print("Parameters for the contour integral:")
print("Ebot: ", simulation_parameters["ebot"])
print("Eset: ", simulation_parameters["eset"])
print("Esetp: ", simulation_parameters["esetp"])
print(
"================================================================================================================================================================"
)
print("Atomic informations: ")
print(
"----------------------------------------------------------------------------------------------------------------------------------------------------------------"
)
print(
"[atom index]Element(orbitals) x [Ang] y [Ang] z [Ang] Sx Sy Sz Q Lx Ly Lz Jx Jy Jz"
)
print(
"----------------------------------------------------------------------------------------------------------------------------------------------------------------"
)
# iterate over magnetic entities
for mag_ent in magnetic_entities:
# get atoms of magnetic entity
atoms_idx = mag_ent["atom"]
# if orbital is not set use all
if "l" not in mag_ent.keys():
mag_ent["l"] = "all"
orbitals = mag_ent["l"]
# if magnetic entity contains one atom
if isinstance(atoms_idx, int):
# coordinates and tag
x, y, z = dh.xyz[atoms_idx]
print(
f"[{atoms_idx}]{dh.atoms[atoms_idx].tag}({orbitals}) {x} {y} {z}"
)
if isinstance(atoms, list):
atomic_indices += [
f"[{atoms['atom']}]{dh.atoms[atom['atom']].tag}({atom['l']})"
for atom in atoms["atom"]
]
atomic_indices += f" {pair['Ruc']} d [Ang] Not yet."
return atomic_indices
# if magnetic entity contains more than one atoms
if isinstance(atoms_idx, list):
# iterate over atoms
for atom_idx in atoms_idx:
# coordinates and tag
x, y, z = dh.xyz[atom_idx]
print(
f"[{atom_idx}]{dh.atoms[atom_idx].tag}({orbitals}) {x} {y} {z}"
)
print("")
print(
"================================================================================================================================================================"
)
print("Exchange [meV]")
print(
"----------------------------------------------------------------------------------------------------------------------------------------------------------------"
)
print("Magnetic entity1 Magnetic entity2 [i j k] d [Ang]")
print(
"----------------------------------------------------------------------------------------------------------------------------------------------------------------"
)
# iterate over pairs
for pair in pairs:
# calculate magnetic parameters
J_iso, J_S, D = calculate_exchange_tensor(pair)
J_iso = J_iso * unit_convert("eV", "meV")
J_S = J_S * unit_convert("eV", "meV")
D = D * unit_convert("eV", "meV")
# print pair parameters
print(
print_pair_atomic_indices(pair, magnetic_entities, dh),
f" {pair['Ruc']} d [Ang] Not yet.",
)
# print magnetic parameters
print("Isotropic: ", J_iso)
print("DMI: ", D)
print("Symmetric-anisotropy: ", J_S)
print("")
print(
"================================================================================================================================================================"
)
print("Runtime information: ")
print(f"Total runtime: {times['end_time'] - times['start_time']} s")
print(
"----------------------------------------------------------------------------------------------------------------------------------------------------------------"
)
print(f"Initial setup: {times['setup_time'] - times['start_time']} s")
print(
f"Hamiltonian conversion and XC field extraction: {times['H_and_XCF_time'] - times['setup_time']:.3f} s"
)
print(
f"Pair and site datastructure creatrions: {times['site_and_pair_dictionaries_time'] - times['H_and_XCF_time']:.3f} s"
)
print(
f"k set cration and distribution: {times['k_set_time'] - times['site_and_pair_dictionaries_time']:.3f} s"
)
print(
f"Rotating XC potential: {times['reference_rotations_time'] - times['k_set_time']:.3f} s"
)
print(
f"Greens function inversion: {times['green_function_inversion_time'] - times['reference_rotations_time']:.3f} s"
)
print(
f"Calculate energies and magnetic components: {times['end_time'] - times['green_function_inversion_time']:.3f} s"
)

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save