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: hooks:
- id: black - id: black
language_version: python3.9 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 #- repo: local
# hooks: # hooks:
# - id: pytest-check # - id: pytest-check

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

@ -7,11 +7,14 @@ import sisl
from mpi4py import MPI from mpi4py import MPI
from numpy.linalg import inv from numpy.linalg import inv
from tqdm import tqdm from tqdm import tqdm
from useful import *
from src.grogu_magn.useful import *
def main(): def main():
start_time = timer() start_time = timer() # runtime information
times = dict()
times["start_time"] = timer()
# this cell mimicks an input file # this cell mimicks an input file
fdf = sisl.get_sile("./lat3_791/Fe3GeTe2.fdf") fdf = sisl.get_sile("./lat3_791/Fe3GeTe2.fdf")
@ -28,45 +31,6 @@ def main():
] ]
# human readable definition of magnetic entities # 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 = [ magnetic_entities = [
dict(atom=3, l=2), dict(atom=3, l=2),
dict(atom=4, l=2), dict(atom=4, l=2),
@ -77,11 +41,13 @@ def main():
] ]
# pair information # pair information
# these should all be around -41.9 in the isotropic part
# isotropic should be -82 meV
pairs = [ pairs = [
dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])), # isotropic should be -82 meV dict(ai=0, aj=3, Ruc=np.array([0, 0, 0])),
dict( dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])),
ai=0, aj=2, Ruc=np.array([0, 0, 0]) dict(ai=1, aj=0, Ruc=np.array([0, 0, 0])),
), # these should all be around -41.9 in the isotropic part dict(ai=0, aj=2, Ruc=np.array([0, 0, 0])),
dict(ai=1, 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=0, aj=2, Ruc=np.array([-1, 0, 0])),
dict(ai=1, 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" kdirs = "xy"
ebot = -30 ebot = -30
eset = 50 eset = 50
esetp = 1000 esetp = 10000
# MPI parameters # MPI parameters
comm = MPI.COMM_WORLD comm = MPI.COMM_WORLD
@ -125,7 +91,7 @@ def main():
# unit cell index # unit cell index
uc_in_sc_idx = dh.lattice.sc_index([0, 0, 0]) 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 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}" 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 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): for i, mag_ent in enumerate(magnetic_entities):
parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes
magnetic_entities[i]["orbital_indeces"] = parsed magnetic_entities[i]["orbital_indeces"] = parsed
magnetic_entities[i]["spin_box_indeces"] = blow_up_orbindx( # calculate spin box indexes
parsed magnetic_entities[i]["spin_box_indeces"] = blow_up_orbindx(parsed)
) # calculate spin box indexes # calculate size for Greens function generation
spin_box_shape = len( spin_box_shape = len(mag_ent["spin_box_indeces"])
mag_ent["spin_box_indeces"]
) # calculate size for Greens function generation
mag_ent["energies"] = ( mag_ent["energies"] = (
[] []
@ -232,14 +196,14 @@ def main():
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
mag_ent["Vu1"] = [ # These will be the perturbed potentials from eq. 100
list([]) for _ in range(len(ref_xcf_orientations)) mag_ent["Vu1"] = [list([]) for _ in range(len(ref_xcf_orientations))]
] # These will be the perturbed potentials from eq. 100
mag_ent["Vu2"] = [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: for i in ref_xcf_orientations:
# Greens functions for every quantization axis
mag_ent["Gii"].append( mag_ent["Gii"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128") np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128")
) # Greens functions for every quantization axis )
mag_ent["Gii_tmp"].append( mag_ent["Gii_tmp"].append(
np.zeros((eset, spin_box_shape, spin_box_shape), dtype="complex128") 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) # 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 # in the 3 reference directions, because G_ij and G_ji are both needed
for pair in pairs: for pair in pairs:
spin_box_shape_i, spin_box_shape_j = len( # calculate size for Greens function generation
magnetic_entities[pair["ai"]]["spin_box_indeces"] spin_box_shape_i = len(magnetic_entities[pair["ai"]]["spin_box_indeces"])
), len( spin_box_shape_j = len(magnetic_entities[pair["aj"]]["spin_box_indeces"])
magnetic_entities[pair["aj"]]["spin_box_indeces"]
) # calculate size for Greens function generation
pair["energies"] = [] # we will store the second order energy derivations here 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") 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 kset = make_kset(dirs=kdirs, NUMK=kset) # generate k space sampling
wkset = np.ones(len(kset)) / len(kset) # generate weights for k points 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 = 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) 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 = [] hamiltonians = []
# iterate over the reference directions (quantization axes) # iterate over the reference directions (quantization axes)
@ -296,15 +258,16 @@ def main():
rot_H_XCF_uc = rot_H_XCF[uc_in_sc_idx] rot_H_XCF_uc = rot_H_XCF[uc_in_sc_idx]
# obtain total Hamiltonian with the rotated exchange field # 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( hamiltonians.append(
dict(orient=orient["o"], H=rot_H, rotations=[]) dict(orient=orient["o"], H=rot_H)
) # store orientation and rotated Hamiltonian ) # store orientation and rotated Hamiltonian
for u in orient[ # these are the infinitezimal rotations (for now) perpendicular to the quantization axis
"vw" for u in orient["vw"]:
]: # these are the infinitezimal rotations (for now) perpendicular to the quantization axis
Tu = np.kron(np.eye(NO, dtype=int), tau_u(u)) # section 2.H 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 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"], :] Vu2[:, mag_ent["spin_box_indeces"]][mag_ent["spin_box_indeces"], :]
) )
reference_rotations_time = timer() times["reference_rotations_time"] = timer()
if rank == root_node: if rank == root_node:
print("Number of magnetic entities being calculated: ", len(magnetic_entities)) 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 # sampling the integrand on the contour and the BZ
for k in kpcs[rank]: for k in kpcs[rank]:
wk = wkset[rank] # weight of k point in BZ integral wk = wkset[rank] # weight of k point in BZ integral
for i, hamiltonian_orientation in enumerate( # iterate over reference directions
hamiltonians for i, hamiltonian_orientation in enumerate(hamiltonians):
): # iterate over reference directions
# calculate Greens function # calculate Greens function
H = hamiltonian_orientation["H"] H = hamiltonian_orientation["H"]
HK, SK = hsk(H, ss, dh.sc_off, k) 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["Gij_tmp"][i], pair["Gij"][i], root=root_node)
comm.Reduce(pair["Gji_tmp"][i], pair["Gji"][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: if rank == root_node:
# iterate over the magnetic entities # iterate over the magnetic entities
@ -393,7 +355,7 @@ def main():
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we))) storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the magnetic entities dictionary with the energies # fill up the magnetic entities dictionary with the energies
mag_ent["energies"].append(storage) magnetic_entities[tracker]["energies"].append(storage)
# iterate over the pairs # iterate over the pairs
for tracker, pair in enumerate(pairs): for tracker, pair in enumerate(pairs):
@ -410,109 +372,11 @@ def main():
traced = np.trace((Vui @ Gij @ Vuj @ Gji), axis1=1, axis2=2) traced = np.trace((Vui @ Gij @ Vuj @ Gji), axis1=1, axis2=2)
# evaluation of the contour integral # evaluation of the contour integral
storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we))) storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))
# fill up the pairs dictionary with the energies # fill up the pairs dictionary with the energies
pairs[tracker]["energies"].append(storage) pairs[tracker]["energies"].append(storage)
end_time = timer() times["end_time"] = timer()
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 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"
)
if __name__ == "__main__": if __name__ == "__main__":

@ -22,6 +22,7 @@ from itertools import permutations, product
import numpy as np import numpy as np
from scipy.special import roots_legendre from scipy.special import roots_legendre
from sisl import unit_convert
# Pauli matrices # Pauli matrices
tau_x = np.array([[0, 1], [1, 0]]) 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 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 = "" atomic_indices = ""
atoms = magnetic_entities[pair["ai"]] # iterate over the two magnetic entities in a pair
if "l" not in atoms.keys(): for mag_ent in [magnetic_entities[pair["ai"]], magnetic_entities[pair["aj"]]]:
atoms["l"] = "all" # get atoms of magnetic entity
if isinstance(atoms["atom"], int): atoms_idx = mag_ent["atom"]
atomic_indices += ( # if orbital is not set use all
f"[{atoms['atom']}]{dh.atoms[atoms['atom']].tag}({atoms['l']})" if "l" not in mag_ent.keys():
) mag_ent["l"] = "all"
if isinstance(atoms, list): orbitals = mag_ent["l"]
atomic_indices += [
f"[{atoms['atom']}]{dh.atoms[atom['atom']].tag}({atom['l']})" # if magnetic entity contains one atoms
for atom in atoms["atom"] if isinstance(atoms_idx, int):
] atomic_indices += f"[{atoms_idx}]{dh.atoms[atoms_idx].tag}({orbitals})"
atoms = magnetic_entities[pair["aj"]]
if "l" not in atoms.keys(): # if magnetic entity contains more than one atoms
atoms["l"] = "all" if isinstance(atoms_idx, list):
atomic_indices += " " # iterate over atoms
if isinstance(atoms["atom"], int): atom_group = "{"
atomic_indices += ( for atom_idx in atoms_idx:
f"[{atoms['atom']}]{dh.atoms[atoms['atom']].tag}({atoms['l']})" atom_group += f"[{atom_idx}]{dh.atoms[atom_idx].tag}({orbitals})--"
) # end {} of the atoms in the magnetic entity
if isinstance(atoms, list): atomic_indices += atom_group[:-2] + "}"
atomic_indices += [ # separate magnetic entities
f"[{atoms['atom']}]{dh.atoms[atom['atom']].tag}({atom['l']})" atomic_indices += " "
for atom in atoms["atom"]
]
atomic_indices += f" {pair['Ruc']} d [Ang] Not yet."
return atomic_indices 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 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