You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grogu/test.ipynb

1133 lines
152 KiB

3 months ago
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[Daniels-Air:55387] shmem: mmap: an error occurred while determining whether or not /var/folders/yh/dx7xl94n3g52ts3td8qcxjcc0000gn/T//ompi.Daniels-Air.501/jf.0/1750007808/sm_segment.Daniels-Air.501.684f0000.0 could be created.\n"
]
},
{
"data": {
"text/plain": [
"'0.14.3'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
3 months ago
"source": [
"from tqdm import tqdm\n",
"from sys import getsizeof\n",
"from timeit import default_timer as timer\n",
"\n",
3 months ago
"import numpy as np\n",
"import sisl\n",
"import sisl.viz\n",
"from src.grogu_magn.useful import *\n",
3 months ago
"from mpi4py import MPI\n",
"import pickle\n",
3 months ago
"from numpy.linalg import inv\n",
"import warnings\n",
"\n",
"\"\"\" \n",
"# Some input parsing\n",
"parser = argparse.ArgumentParser()\n",
"parser.add_argument('--kset' , dest = 'kset' , default = 2 , type=int , help = 'k-space resolution of Jij calculation')\n",
"parser.add_argument('--kdirs' , dest = 'kdirs' , default = 'xyz' , help = 'Definition of k-space dimensionality')\n",
"parser.add_argument('--eset' , dest = 'eset' , default = 42 , type=int , help = 'Number of energy points on the contour')\n",
"parser.add_argument('--eset-p' , dest = 'esetp' , default = 10 , type=int , help = 'Parameter tuning the distribution on the contour')\n",
"parser.add_argument('--input' , dest = 'infile' , required = True , help = 'Input file name')\n",
"parser.add_argument('--output' , dest = 'outfile', required = True , help = 'Output file name')\n",
"parser.add_argument('--Ebot' , dest = 'Ebot' , default = -20.0 , type=float, help = 'Bottom energy of the contour')\n",
"parser.add_argument('--npairs' , dest = 'npairs' , default = 1 , type=int , help = 'Number of unitcell pairs in each direction for Jij calculation')\n",
"parser.add_argument('--adirs' , dest = 'adirs' , default = False , help = 'Definition of pair directions')\n",
"parser.add_argument('--use-tqdm', dest = 'usetqdm', default = 'not' , help = 'Use tqdm for progressbars or not')\n",
"parser.add_argument('--cutoff' , dest = 'cutoff' , default = 100.0 , type=float, help = 'Real space cutoff for pair generation in Angs')\n",
"parser.add_argument('--pairfile', dest = 'pairfile', default = False , help = 'File to read pair information')\n",
"args = parser.parse_args()\n",
"\"\"\"\n",
"# runtime information\n",
"times = dict()\n",
"times[\"start_time\"] = timer()\n",
"########################\n",
3 months ago
"# it works if data is in downloads folder\n",
"########################\n",
"sisl.__version__"
3 months ago
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-12.806878959999999"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dat = sisl.io.siesta.eigSileSiesta(\n",
" \"/Users/danielpozsar/Downloads/nojij/Fe3GeTe2/monolayer/soc/lat3_791/Fe3GeTe2.EIG\"\n",
")\n",
"siesta_eigs = dat.read_data()\n",
"siesta_eigs.min()"
]
},
{
"cell_type": "code",
"execution_count": 3,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"================================================================================================================================================================\n",
"Input file: \n",
"/Users/danielpozsar/Downloads/nojij/Fe3GeTe2/monolayer/soc/lat3_791/Fe3GeTe2.fdf\n",
"Output file: \n",
"./Fe3GeTe2.pickle\n",
"Number of nodes in the parallel cluster: 1\n",
"================================================================================================================================================================\n",
"Cell [Ang]: \n",
"[[ 3.79100000e+00 0.00000000e+00 0.00000000e+00]\n",
" [-1.89550000e+00 3.28310231e+00 0.00000000e+00]\n",
" [ 1.25954923e-15 2.18160327e-15 2.05700000e+01]]\n",
"================================================================================================================================================================\n",
"DFT axis: \n",
"[0 0 1]\n",
"Quantization axis and perpendicular rotation directions:\n",
"[1 0 0] --» [array([0, 1, 0]), array([0, 0, 1])]\n",
"[0 1 0] --» [array([1, 0, 0]), array([0, 0, 1])]\n",
"[0 0 1] --» [array([1, 0, 0]), array([0, 1, 0])]\n",
"================================================================================================================================================================\n",
"Parameters for the contour integral:\n",
"Number of k points: 20\n",
"k point directions: xy\n",
"Ebot: -13\n",
"Eset: 100\n",
"Esetp: 10000\n",
"================================================================================================================================================================\n",
"Setup done. Elapsed time: 3.879105916 s\n",
"================================================================================================================================================================\n"
]
}
],
3 months ago
"source": [
"################################################################################\n",
"#################################### INPUT #####################################\n",
"################################################################################\n",
"path = (\n",
" \"/Users/danielpozsar/Downloads/nojij/Fe3GeTe2/monolayer/soc/lat3_791/Fe3GeTe2.fdf\"\n",
")\n",
"outfile = \"./Fe3GeTe2\"\n",
"\n",
3 months ago
"# this information needs to be given at the input!!\n",
"scf_xcf_orientation = np.array([0, 0, 1]) # z\n",
3 months ago
"# list of reference directions for around which we calculate the derivatives\n",
"# o is the quantization axis, v and w are two axes perpendicular to it\n",
"# at this moment the user has to supply o,v,w on the input.\n",
3 months ago
"# we can have some default for this\n",
"ref_xcf_orientations = [\n",
" dict(o=np.array([1, 0, 0]), vw=[np.array([0, 1, 0]), np.array([0, 0, 1])]),\n",
" dict(o=np.array([0, 1, 0]), vw=[np.array([1, 0, 0]), np.array([0, 0, 1])]),\n",
" dict(o=np.array([0, 0, 1]), vw=[np.array([1, 0, 0]), np.array([0, 1, 0])]),\n",
"]\n",
"magnetic_entities = [\n",
" dict(atom=3, l=2),\n",
" dict(atom=4, l=2),\n",
" dict(atom=5, l=2),\n",
"]\n",
"pairs = [\n",
" dict(ai=0, aj=1, Ruc=np.array([0, 0, 0])),\n",
" dict(ai=0, aj=2, Ruc=np.array([0, 0, 0])),\n",
" dict(ai=1, aj=2, Ruc=np.array([0, 0, 0])),\n",
" dict(ai=0, aj=2, Ruc=np.array([-1, -1, 0])),\n",
" dict(ai=1, aj=2, Ruc=np.array([-1, -1, 0])),\n",
" dict(ai=0, aj=2, Ruc=np.array([-1, 0, 0])),\n",
" dict(ai=1, aj=2, Ruc=np.array([-1, 0, 0])),\n",
"]\n",
3 months ago
"# Brilloun zone sampling and Green function contour integral\n",
"kset = 20\n",
"kdirs = \"xy\"\n",
"ebot = -13\n",
"eset = 100\n",
"esetp = 10000\n",
"################################################################################\n",
"#################################### INPUT #####################################\n",
"################################################################################\n",
3 months ago
"\n",
"# MPI parameters\n",
"comm = MPI.COMM_WORLD\n",
"size = comm.Get_size()\n",
"rank = comm.Get_rank()\n",
"root_node = 0\n",
"\n",
"# rename outfile\n",
"if not outfile.endswith(\".pickle\"):\n",
" outfile += \".pickle\"\n",
"\n",
"simulation_parameters = dict(\n",
" path=path,\n",
" outpath=outfile,\n",
" scf_xcf_orientation=scf_xcf_orientation,\n",
" ref_xcf_orientations=ref_xcf_orientations,\n",
" kset=kset,\n",
" kdirs=kdirs,\n",
" ebot=ebot,\n",
" eset=eset,\n",
" esetp=esetp,\n",
" parallel_size=size,\n",
")\n",
"\n",
"# digestion of the input\n",
"# read sile\n",
"fdf = sisl.get_sile(path)\n",
"# read in hamiltonian\n",
"dh = fdf.read_hamiltonian()\n",
"simulation_parameters[\"cell\"] = fdf.read_geometry().cell\n",
"\n",
"# unit cell index\n",
"uc_in_sc_idx = dh.lattice.sc_index([0, 0, 0])\n",
"\n",
"if rank == root_node:\n",
" print_parameters(simulation_parameters)\n",
" times[\"setup_time\"] = timer()\n",
" print(f\"Setup done. Elapsed time: {times['setup_time']} s\")\n",
" print(\n",
" \"================================================================================================================================================================\"\n",
" )"
3 months ago
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"xyz[-3:]: red, green, blue\n",
"2.745163300331324\n",
"2.5835033632437767\n",
"2.583501767937866\n",
"2.583541444641373\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMUAAAGyCAYAAADksXO/AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZA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LdCFQpnyawKZ9GLlBvbM/l6qHGtXDex1/YNceWaNxN6V2S8qmY/WFowDA8fWRLJcH7D5dcC602Y/N0EQBLGkIFGsCTseH8G1dz5a96K0b6yCa+98FF94/VlzJox9/etfx8c//nE8+eSTKBaLOPPMM/H1r38d73jHOxJXIr/61a9i+/btdf16enrmZF8EQRDEEibrimRxJVA63GSQBsafNULaxq1zvkWC6CS2xYEq8KuRcTxvZXHxBw5aSALddCiVIaZl5CottKUEN3cKGHsaOLIHOPoUcPhJM2b0dybtecCs9+N/AD7wLPlZIwiCIBKQKNYAqTS237ur2ffi2H7vLlyyaV3Hr1KOjIzgLW95C2655Ra8+tWvxsTEBH7wgx/UXZscGRnB6173Ovzt3/4tXvWqVzXsRxAEQRDT0uiKZFNBLMbk/o5viSDmmledeQz+7sE9+H//96Mo2ALrBvJY25/D2v481vXnTT5g8rX9Oazpy8OxeLe3vfBQKnmFM3FSLX0lNH5ttNLkumiztoxyWNcqe48XvIsEMYIgCKIOEsUa8MieI4krk2k0gJGxCh7ZcwTnPX9lR9ceGRmB7/t41atehec973kAgNNPP71hv1e/+tXYsGFDw34
"text/plain": [
"<Figure size 1500x500 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABNoAAAHACAYAAAB0/gUQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABJqUlEQVR4nO3de5xVdb0//tcAMnhjytABPJPXEq9AmoTZV7FJUvNIvzKzjhBftcvRfhmlSV6wUilNIxXlpJmpecR7nfSHEUf0dKQ8IpyjpR4vIHgZ1KPOACrIzP79MYfRkYszsGb2zPB8+lgPnM9aa+/3Z8Nen/15zdprVZRKpVIAAAAAgI3Sq9wFAAAAAEBPIGgDAAAAgAII2gAAAACgAII2AAAAACiAoA0AA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qKiEbtMXNN799Vs663Hpr59QCXdnNN6//GmylUvM2AECPtDpsS5J/+Zdk3rxkm22EbLA+t922/t9Vr1qV3HRT8c8raCtKRUVy7LGt2444QsgG6/PGG+tfXyoly5d3Ti3QlbXlfeC9AgA92ruvErHDDsnuu5enFugOli9/7/uFvflm8c8raCvK6muyvdPkyW9fsw1Y0z77rP9XDH36JMOGdVo50GUNH/72lY/Xpnfv5m0AgB5p9TXZ3mnevLev2QasaejQt2+AsDa9enXMGaGCtiK888YH++yTvPRS62u2Cdtg7U4+ef2/Yli1qvkezLCpO/749X+Kbmxs3gYA6HHefeODhx9ObrllzRskAK197Wvrv1JRU1PzlLRograNtWxZ85Uo331NtnffIOGWW8paJnRJX/hC8sUvNn/1uqLi7fbVZ7mdd17z+wo2dTfeuPb2d75v/vmfO6cWAKDTlErN12d7940P3n2DhLPOKnel0PUMGZJccEHz/7/zi1Srp5//z/+T/MM/FP+8graNtdVWzWHAsGGtb3zwzhskjB6dfOYz5awSuqZevZLrr08uuyzZZZe32z/60eabIHz/++WrDbqSM85ofo9MnJjsuefb7Xvv3fw+2XXX5nUAQI9SUdE83dxllzVvfLA6bNtzz445Kwd6glNPTX772+RjH3u7baedmu82etNN6786y4aqKJVKpeIftntraGhIVVVV6uvr079//7bt9NZbyWabrX3dqlXr/2Iw0PzruoaG5iPdVluVuxoKtkHH1R5sg16Pd44lDQ3Nn7y33nrNdQCbIOPMmrwmPcv6hnofA6Btli9vfr/079/6iyFt1dbjqrdjUdYVsiWOetAWFRVJVVW5q4Cu651jybsHduMMAPRo6xvqfQyAttlyy855Hl8dBQAAAIACCNoAAAAAoACCNgAAAAAogKANAAAAAAogaAMAAACAAgjaAAAAAKAAgjYAAAAAKICgDQAAAAAKIGgDAAAAgAKUNWi77777cuSRR2bw4MGpqKjIHXfc0Wr9bbfdlkMPPTQf+MAHUlFRkfnz57/nY15zzTWpqKhotfTr169jOgBAl2acAQAAOlNZg7bly5dn6NChmTp16jrXH3jggfnJT37Srsft379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/f/9svvnma92nsrIylZWVnVEeAOvhjDYAAIAuZOTIkZk1a1artpkzZ2bkyJFlqgiAthK0AQAAdKBly5Zl/vz5mT9/fpJkwYIFmT9/fhYtWpSk+WufY8eObdn+61//ep5++umcdtppeeyxx3L55Zfnpptuyre//e1ylA9AOwjaAAAAOtCDDz6Y4cOHZ/jw4UmSCRMmZPjw4Tn77LOTJC+88EJL6JYkO+20U+68887MnDkzQ4cOzUUXXZSrrroqo0ePLkv9ALSda7QBAAB0oIMPPjilUmmd66+55pq17jNv3rwOrAqAjuC
"text/plain": [
"<Figure size 1500x500 with 3 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"plt.figure(figsize=(15, 5))\n",
"plt.subplot(121)\n",
"plt.plot(np.sort(dh.eigh()), marker=\"o\", linestyle=\" \", label=\"sisl\")\n",
"plt.plot(np.sort(siesta_eigs[0, 0]), marker=\"o\", linestyle=\" \", label=\"siesta\")\n",
"plt.ylim(None, 10)\n",
"plt.xlim(None, 75)\n",
"plt.legend()\n",
"plt.grid()\n",
"plt.subplot(122)\n",
"DOS = sisl.physics.electron.DOS(np.linspace(-15, 85, 1000), dh.eigh())\n",
"plt.plot(DOS, np.linspace(-15, 85, 1000))\n",
"DOS = sisl.physics.electron.DOS(np.linspace(-15, 85, 1000), siesta_eigs[0, 0])\n",
"plt.plot(DOS, np.linspace(-15, 85, 1000))\n",
"plt.ylim(None, 10)\n",
"\n",
"coords = dh.xyz[-3:]\n",
"\n",
"shift = np.array([-1, 0, 0]) @ simulation_parameters[\"cell\"]\n",
"\n",
"\n",
"plt.figure(figsize=(15, 5))\n",
"plt.subplot(131)\n",
"plt.scatter(coords[:, 0], coords[:, 2], color=[\"r\", \"g\", \"b\"])\n",
"plt.scatter(\n",
" (coords + shift)[:, 0], (coords + shift)[:, 2], color=[\"r\", \"g\", \"b\"], marker=\"x\"\n",
")\n",
"plt.xlabel(\"x\")\n",
"plt.ylabel(\"z\")\n",
"plt.subplot(132)\n",
"plt.scatter(coords[:, 1], coords[:, 2], color=[\"r\", \"g\", \"b\"])\n",
"plt.scatter(\n",
" (coords + shift)[:, 1], (coords + shift)[:, 2], color=[\"r\", \"g\", \"b\"], marker=\"x\"\n",
")\n",
"plt.xlabel(\"y\")\n",
"plt.ylabel(\"z\")\n",
"plt.subplot(133)\n",
"plt.scatter(coords[:, 0], coords[:, 1], color=[\"r\", \"g\", \"b\"])\n",
"plt.scatter(\n",
" (coords + shift)[:, 0], (coords + shift)[:, 1], color=[\"r\", \"g\", \"b\"], marker=\"x\"\n",
")\n",
"plt.xlabel(\"x\")\n",
"plt.ylabel(\"y\")\n",
"print(\"xyz[-3:]: red, green, blue\")\n",
"\n",
"print(np.linalg.norm(coords[0] - coords[1]))\n",
"print(np.linalg.norm(coords[0] - coords[2]))\n",
"print(np.linalg.norm(coords[2] - coords[1]))\n",
"print(np.linalg.norm(coords[0] - (coords + shift)[2]))"
]
},
{
"cell_type": "code",
"execution_count": 5,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hamiltonian and exchange field rotated. Elapsed time: 4.926466833 s\n",
"================================================================================================================================================================\n"
]
}
],
3 months ago
"source": [
"NO = dh.no # shorthand for number of orbitals in the unit cell\n",
3 months ago
"\n",
3 months ago
"# preprocessing Hamiltonian and overlap matrix elements\n",
"h11 = dh.tocsr(dh.M11r)\n",
"h11 += dh.tocsr(dh.M11i) * 1.0j\n",
"h11 = h11.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype(\"complex128\")\n",
3 months ago
"\n",
"h22 = dh.tocsr(dh.M22r)\n",
"h22 += dh.tocsr(dh.M22i) * 1.0j\n",
"h22 = h22.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype(\"complex128\")\n",
3 months ago
"\n",
"h12 = dh.tocsr(dh.M12r)\n",
"h12 += dh.tocsr(dh.M12i) * 1.0j\n",
"h12 = h12.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype(\"complex128\")\n",
3 months ago
"\n",
"h21 = dh.tocsr(dh.M21r)\n",
"h21 += dh.tocsr(dh.M21i) * 1.0j\n",
"h21 = h21.toarray().reshape(NO, dh.n_s, NO).transpose(0, 2, 1).astype(\"complex128\")\n",
3 months ago
"\n",
"sov = (\n",
" dh.tocsr(dh.S_idx)\n",
" .toarray()\n",
" .reshape(NO, dh.n_s, NO)\n",
" .transpose(0, 2, 1)\n",
" .astype(\"complex128\")\n",
")\n",
3 months ago
"\n",
"\n",
3 months ago
"# Reorganization of Hamiltonian and overlap matrix elements to SPIN BOX representation\n",
"U = np.vstack(\n",
" [np.kron(np.eye(NO, dtype=int), [1, 0]), np.kron(np.eye(NO, dtype=int), [0, 1])]\n",
")\n",
3 months ago
"# This is the permutation that transforms ud1ud2 to u12d12\n",
"# That is this transforms FROM SPIN BOX to ORBITAL BOX => U\n",
"# the inverse transformation is U.T u12d12 to ud1ud2\n",
"# That is FROM ORBITAL BOX to SPIN BOX => U.T\n",
"\n",
3 months ago
"# From now on everything is in SPIN BOX!!\n",
"hh, ss = np.array(\n",
" [\n",
" U.T @ np.block([[h11[:, :, i], h12[:, :, i]], [h21[:, :, i], h22[:, :, i]]]) @ U\n",
" for i in range(dh.lattice.nsc.prod())\n",
" ]\n",
"), np.array(\n",
" [\n",
" U.T\n",
" @ np.block([[sov[:, :, i], sov[:, :, i] * 0], [sov[:, :, i] * 0, sov[:, :, i]]])\n",
" @ U\n",
" for i in range(dh.lattice.nsc.prod())\n",
" ]\n",
")\n",
"\n",
"\n",
"# symmetrizing Hamiltonian and overlap matrix to make them hermitian\n",
3 months ago
"for i in range(dh.lattice.sc_off.shape[0]):\n",
" j = dh.lattice.sc_index(-dh.lattice.sc_off[i])\n",
" h1, h1d = hh[i], hh[j]\n",
" hh[i], hh[j] = (h1 + h1d.T.conj()) / 2, (h1d + h1.T.conj()) / 2\n",
" s1, s1d = ss[i], ss[j]\n",
" ss[i], ss[j] = (s1 + s1d.T.conj()) / 2, (s1d + s1.T.conj()) / 2\n",
3 months ago
"\n",
"# identifying TRS and TRB parts of the Hamiltonian\n",
"TAUY = np.kron(np.eye(NO), tau_y)\n",
"hTR = np.array([TAUY @ hh[i].conj() @ TAUY for i in range(dh.lattice.nsc.prod())])\n",
"hTRS = (hh + hTR) / 2\n",
"hTRB = (hh - hTR) / 2\n",
3 months ago
"\n",
"# extracting the exchange field\n",
"traced = [spin_tracer(hTRB[i]) for i in range(dh.lattice.nsc.prod())] # equation 77\n",
"XCF = np.array(\n",
" [\n",
" np.array([f[\"x\"] for f in traced]),\n",
" np.array([f[\"y\"] for f in traced]),\n",
" np.array([f[\"z\"] for f in traced]),\n",
" ]\n",
") # equation 77\n",
3 months ago
"\n",
3 months ago
"# Check if exchange field has scalar part\n",
"max_xcfs = abs(np.array(np.array([f[\"c\"] for f in traced]))).max()\n",
"if max_xcfs > 1e-12:\n",
" warnings.warn(\n",
" f\"Exchange field has non negligible scalar part. Largest value is {max_xcfs}\"\n",
" )\n",
"\n",
"if rank == root_node:\n",
" times[\"H_and_XCF_time\"] = timer()\n",
" print(\n",
" f\"Hamiltonian and exchange field rotated. Elapsed time: {times['H_and_XCF_time']} s\"\n",
" )\n",
" print(\n",
" \"================================================================================================================================================================\"\n",
" )"
3 months ago
]
},
{
"cell_type": "code",
"execution_count": 6,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Site and pair dictionaries created. Elapsed time: 4.962375291 s\n",
"================================================================================================================================================================\n"
]
}
],
3 months ago
"source": [
3 months ago
"# for every site we have to store 3 Greens function (and the associated _tmp-s) in the 3 reference directions\n",
"for mag_ent in magnetic_entities:\n",
" parsed = parse_magnetic_entity(dh, **mag_ent) # parse orbital indexes\n",
" mag_ent[\"orbital_indeces\"] = parsed\n",
" mag_ent[\"spin_box_indeces\"] = blow_up_orbindx(parsed) # calculate spin box indexes\n",
" # if orbital is not set use all\n",
" if \"l\" not in mag_ent.keys():\n",
" mag_ent[\"l\"] = \"all\"\n",
" if isinstance(mag_ent[\"atom\"], int):\n",
" mag_ent[\"tags\"] = [\n",
" f\"[{mag_ent['atom']}]{dh.atoms[mag_ent['atom']].tag}({mag_ent['l']})\"\n",
" ]\n",
" mag_ent[\"xyz\"] = [dh.xyz[mag_ent[\"atom\"]]]\n",
" if isinstance(mag_ent[\"atom\"], list):\n",
" mag_ent[\"tags\"] = []\n",
" mag_ent[\"xyz\"] = []\n",
" # iterate over atoms\n",
" for atom_idx in mag_ent[\"atom\"]:\n",
" mag_ent[\"tags\"].append(\n",
" f\"[{atom_idx}]{dh.atoms[atom_idx].tag}({mag_ent['l']})\"\n",
" )\n",
" mag_ent[\"xyz\"].append(dh.xyz[atom_idx])\n",
"\n",
" # calculate size for Greens function generation\n",
" spin_box_shape = len(mag_ent[\"spin_box_indeces\"])\n",
"\n",
" mag_ent[\"energies\"] = [] # we will store the second order energy derivations here\n",
"\n",
" # These will be the perturbed potentials from eq. 100\n",
" mag_ent[\"Vu1\"] = [] # so they are independent in memory\n",
" mag_ent[\"Vu2\"] = []\n",
"\n",
" mag_ent[\"Gii\"] = [] # Greens function\n",
" mag_ent[\"Gii_tmp\"] = [] # Greens function for parallelization\n",
3 months ago
" for i in ref_xcf_orientations:\n",
" # Rotations for every quantization axis\n",
" mag_ent[\"Vu1\"].append([])\n",
" mag_ent[\"Vu2\"].append([])\n",
" # Greens functions for every quantization axis\n",
" mag_ent[\"Gii\"].append(\n",
" np.zeros((eset, spin_box_shape, spin_box_shape), dtype=\"complex128\")\n",
" )\n",
" mag_ent[\"Gii_tmp\"].append(\n",
" np.zeros((eset, spin_box_shape, spin_box_shape), dtype=\"complex128\")\n",
" )\n",
"\n",
"# for every site we have to store 2x3 Greens function (and the associated _tmp-s)\n",
"# in the 3 reference directions, because G_ij and G_ji are both needed\n",
3 months ago
"for pair in pairs:\n",
" # calculate distance\n",
" xyz_ai = magnetic_entities[pair[\"ai\"]][\"xyz\"]\n",
" xyz_aj = magnetic_entities[pair[\"aj\"]][\"xyz\"]\n",
" xyz_aj = xyz_aj + pair[\"Ruc\"] @ simulation_parameters[\"cell\"]\n",
" pair[\"dist\"] = np.linalg.norm(xyz_ai - xyz_aj)\n",
"\n",
" # calculate size for Greens function generation\n",
" spin_box_shape_i = len(magnetic_entities[pair[\"ai\"]][\"spin_box_indeces\"])\n",
" spin_box_shape_j = len(magnetic_entities[pair[\"aj\"]][\"spin_box_indeces\"])\n",
" pair[\"tags\"] = []\n",
" for mag_ent in [magnetic_entities[pair[\"ai\"]], magnetic_entities[pair[\"aj\"]]]:\n",
" tag = \"\"\n",
" # get atoms of magnetic entity\n",
" atoms_idx = mag_ent[\"atom\"]\n",
" orbitals = mag_ent[\"l\"]\n",
"\n",
" # if magnetic entity contains one atoms\n",
" if isinstance(atoms_idx, int):\n",
" tag += f\"[{atoms_idx}]{dh.atoms[atoms_idx].tag}({orbitals})\"\n",
"\n",
" # if magnetic entity contains more than one atoms\n",
" if isinstance(atoms_idx, list):\n",
" # iterate over atoms\n",
" atom_group = \"{\"\n",
" for atom_idx in atoms_idx:\n",
" atom_group += f\"[{atom_idx}]{dh.atoms[atom_idx].tag}({orbitals})--\"\n",
" # end {} of the atoms in the magnetic entity\n",
" tag += atom_group[:-2] + \"}\"\n",
" pair[\"tags\"].append(tag)\n",
" pair[\"energies\"] = [] # we will store the second order energy derivations here\n",
"\n",
" pair[\"Gij\"] = [] # Greens function\n",
" pair[\"Gji\"] = []\n",
" pair[\"Gij_tmp\"] = [] # Greens function for parallelization\n",
" pair[\"Gji_tmp\"] = []\n",
" for i in ref_xcf_orientations:\n",
" # Greens functions for every quantization axis\n",
" pair[\"Gij\"].append(\n",
" np.zeros((eset, spin_box_shape_i, spin_box_shape_j), dtype=\"complex128\")\n",
" )\n",
" pair[\"Gij_tmp\"].append(\n",
" np.zeros((eset, spin_box_shape_i, spin_box_shape_j), dtype=\"complex128\")\n",
" )\n",
" pair[\"Gji\"].append(\n",
" np.zeros((eset, spin_box_shape_j, spin_box_shape_i), dtype=\"complex128\")\n",
" )\n",
" pair[\"Gji_tmp\"].append(\n",
" np.zeros((eset, spin_box_shape_j, spin_box_shape_i), dtype=\"complex128\")\n",
" )\n",
"\n",
"if rank == root_node:\n",
" times[\"site_and_pair_dictionaries_time\"] = timer()\n",
" print(\n",
" f\"Site and pair dictionaries created. Elapsed time: {times['site_and_pair_dictionaries_time']} s\"\n",
" )\n",
" print(\n",
" \"================================================================================================================================================================\"\n",
" )"
3 months ago
]
},
{
"cell_type": "code",
"execution_count": 7,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"k loop: 0%| | 0/400 [00:00<?, ?it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"k set created. Elapsed time: 4.990981666 s\n",
"================================================================================================================================================================\n"
]
}
],
3 months ago
"source": [
"kset = make_kset(dirs=kdirs, NUMK=kset) # generate k space sampling\n",
"wkset = np.ones(len(kset)) / len(kset) # generate weights for k points\n",
"kpcs = np.array_split(kset, size) # split the k points based on MPI size\n",
"kpcs[root_node] = tqdm(kpcs[root_node], desc=\"k loop\")\n",
"\n",
"if rank == root_node:\n",
" times[\"k_set_time\"] = timer()\n",
" print(f\"k set created. Elapsed time: {times['k_set_time']} s\")\n",
" print(\n",
" \"================================================================================================================================================================\"\n",
" )"
3 months ago
]
},
{
"cell_type": "code",
"execution_count": 8,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Rotations done perpendicular to quantization axis. Elapsed time: 5.319766625 s\n",
"================================================================================================================================================================\n"
]
}
],
3 months ago
"source": [
"# this will contain the three hamiltonians in the reference directions needed to calculate the energy variations upon rotation\n",
3 months ago
"hamiltonians = []\n",
3 months ago
"\n",
3 months ago
"# iterate over the reference directions (quantization axes)\n",
"for i, orient in enumerate(ref_xcf_orientations):\n",
" # obtain rotated exchange field\n",
" R = RotMa2b(scf_xcf_orientation, orient[\"o\"])\n",
" rot_XCF = np.einsum(\"ij,jklm->iklm\", R, XCF)\n",
" rot_H_XCF = sum(\n",
" [np.kron(rot_XCF[i], tau) for i, tau in enumerate([tau_x, tau_y, tau_z])]\n",
" )\n",
3 months ago
" rot_H_XCF_uc = rot_H_XCF[uc_in_sc_idx]\n",
"\n",
3 months ago
" # obtain total Hamiltonian with the rotated exchange field\n",
" rot_H = (\n",
" hTRS + rot_H_XCF\n",
" ) # equation 76 #######################################################################################\n",
3 months ago
"\n",
" hamiltonians.append(\n",
" dict(orient=orient[\"o\"], H=rot_H)\n",
" ) # store orientation and rotated Hamiltonian\n",
"\n",
" # these are the rotations (for now) perpendicular to the quantization axis\n",
" for u in orient[\"vw\"]:\n",
" Tu = np.kron(np.eye(NO, dtype=int), tau_u(u)) # section 2.H\n",
3 months ago
"\n",
" Vu1 = 1j / 2 * commutator(rot_H_XCF_uc, Tu) # equation 100\n",
" Vu2 = 1 / 8 * commutator(commutator(Tu, rot_H_XCF_uc), Tu) # equation 100\n",
3 months ago
"\n",
3 months ago
" for mag_ent in magnetic_entities:\n",
" idx = mag_ent[\"spin_box_indeces\"]\n",
" # fill up the perturbed potentials (for now) based on the on-site projections\n",
" mag_ent[\"Vu1\"][i].append(Vu1[:, idx][idx, :])\n",
" mag_ent[\"Vu2\"][i].append(Vu2[:, idx][idx, :])\n",
"\n",
"if rank == root_node:\n",
" times[\"reference_rotations_time\"] = timer()\n",
" print(\n",
" f\"Rotations done perpendicular to quantization axis. Elapsed time: {times['reference_rotations_time']} s\"\n",
" )\n",
" print(\n",
" \"================================================================================================================================================================\"\n",
" )"
3 months ago
]
},
{
"cell_type": "code",
"execution_count": 9,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting matrix inversions\n",
"Total number of k points: 400\n",
"Number of energy samples per k point: 100\n",
"Total number of directions: 3\n",
"Total number of matrix inversions: 120000\n",
"The shape of the Hamiltonian and the Greens function is 84x84=7056\n",
"Memory taken by a single Hamiltonian is: 0.015625 KB\n",
"Expected memory usage per matrix inversion: 0.5 KB\n",
"Expected memory usage per k point for parallel inversion: 150.0 KB\n",
"Expected memory usage on root node: 58.59375 MB\n",
"================================================================================================================================================================\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"k loop: 100%|██████████| 400/400 [04:23<00:00, 1.52it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calculated Greens functions. Elapsed time: 268.00303675 s\n",
"================================================================================================================================================================\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
3 months ago
"source": [
3 months ago
"if rank == root_node:\n",
" print(\"Starting matrix inversions\")\n",
" print(f\"Total number of k points: {kset.shape[0]}\")\n",
" print(f\"Number of energy samples per k point: {eset}\")\n",
" print(f\"Total number of directions: {len(hamiltonians)}\")\n",
" print(\n",
" f\"Total number of matrix inversions: {kset.shape[0] * len(hamiltonians) * eset}\"\n",
" )\n",
" print(f\"The shape of the Hamiltonian and the Greens function is {NO}x{NO}={NO*NO}\")\n",
" # https://stackoverflow.com/questions/70746660/how-to-predict-memory-requirement-for-np-linalg-inv\n",
" # memory is O(64 n**2) for complex matrices\n",
" memory_size = getsizeof(hamiltonians[0][\"H\"].base) / 1024\n",
" print(\n",
" f\"Memory taken by a single Hamiltonian is: {getsizeof(hamiltonians[0]['H'].base) / 1024} KB\"\n",
" )\n",
" print(f\"Expected memory usage per matrix inversion: {memory_size * 32} KB\")\n",
" print(\n",
" f\"Expected memory usage per k point for parallel inversion: {memory_size * len(hamiltonians) * eset * 32} KB\"\n",
" )\n",
" print(\n",
" f\"Expected memory usage on root node: {len(np.array_split(kset, size)[0]) * memory_size * len(hamiltonians) * eset * 32 / 1024} MB\"\n",
" )\n",
" print(\n",
" \"================================================================================================================================================================\"\n",
" )\n",
"\n",
3 months ago
"comm.Barrier()\n",
"# ----------------------------------------------------------------------\n",
3 months ago
"\n",
"# make energy contour\n",
3 months ago
"# we are working in eV now !\n",
"# and sisl shifts E_F to 0 !\n",
"cont = make_contour(emin=ebot, enum=eset, p=esetp)\n",
3 months ago
"eran = cont.ze\n",
"\n",
"# ----------------------------------------------------------------------\n",
3 months ago
"# sampling the integrand on the contour and the BZ\n",
"for k in kpcs[rank]:\n",
" wk = wkset[rank] # weight of k point in BZ integral\n",
" # iterate over reference directions\n",
" for i, hamiltonian_orientation in enumerate(hamiltonians):\n",
" # calculate Greens function\n",
3 months ago
" H = hamiltonian_orientation[\"H\"]\n",
" HK, SK = hsk(H, ss, dh.sc_off, k)\n",
" # Gk = inv(SK * eran.reshape(eset, 1, 1) - HK)\n",
"\n",
" # solve Greens function sequentially for the energies, because of memory bound\n",
" Gk = np.zeros(shape=(eset, HK.shape[0], HK.shape[1]), dtype=\"complex128\")\n",
" for j in range(eset):\n",
" Gk[j] = inv(SK * eran[j] - HK)\n",
"\n",
3 months ago
" # store the Greens function slice of the magnetic entities (for now) based on the on-site projections\n",
" for mag_ent in magnetic_entities:\n",
" mag_ent[\"Gii_tmp\"][i] += (\n",
" Gk[:, mag_ent[\"spin_box_indeces\"], :][:, :, mag_ent[\"spin_box_indeces\"]]\n",
" * wk\n",
" )\n",
3 months ago
"\n",
" for pair in pairs:\n",
" # add phase shift based on the cell difference\n",
" phase = np.exp(1j * 2 * np.pi * k @ pair[\"Ruc\"].T)\n",
"\n",
3 months ago
" # get the pair orbital sizes from the magnetic entities\n",
" ai = magnetic_entities[pair[\"ai\"]][\"spin_box_indeces\"]\n",
" aj = magnetic_entities[pair[\"aj\"]][\"spin_box_indeces\"]\n",
"\n",
" # store the Greens function slice of the magnetic entities (for now) based on the on-site projections\n",
" pair[\"Gij_tmp\"][i] += Gk[:, ai][..., aj] * phase * wk\n",
" pair[\"Gji_tmp\"][i] += Gk[:, aj][..., ai] / phase * wk\n",
3 months ago
"\n",
"# summ reduce partial results of mpi nodes\n",
"for i in range(len(hamiltonians)):\n",
" for mag_ent in magnetic_entities:\n",
" comm.Reduce(mag_ent[\"Gii_tmp\"][i], mag_ent[\"Gii\"][i], root=root_node)\n",
3 months ago
"\n",
3 months ago
" for pair in pairs:\n",
" comm.Reduce(pair[\"Gij_tmp\"][i], pair[\"Gij\"][i], root=root_node)\n",
" comm.Reduce(pair[\"Gji_tmp\"][i], pair[\"Gji\"][i], root=root_node)\n",
"\n",
"if rank == root_node:\n",
" times[\"green_function_inversion_time\"] = timer()\n",
" print(\n",
" f\"Calculated Greens functions. Elapsed time: {times['green_function_inversion_time']} s\"\n",
" )\n",
" print(\n",
" \"================================================================================================================================================================\"\n",
" )"
3 months ago
]
},
{
"cell_type": "code",
"execution_count": 10,
3 months ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Magnetic entities integrated.\n",
"Pairs integrated.\n",
"Magnetic parameters calculated.\n",
"##################################################################### GROGU OUTPUT #############################################################################\n",
"================================================================================================================================================================\n",
"Input file: \n",
"/Users/danielpozsar/Downloads/nojij/Fe3GeTe2/monolayer/soc/lat3_791/Fe3GeTe2.fdf\n",
"Output file: \n",
"./Fe3GeTe2.pickle\n",
"Number of nodes in the parallel cluster: 1\n",
"================================================================================================================================================================\n",
"Cell [Ang]: \n",
"[[ 3.79100000e+00 0.00000000e+00 0.00000000e+00]\n",
" [-1.89550000e+00 3.28310231e+00 0.00000000e+00]\n",
" [ 1.25954923e-15 2.18160327e-15 2.05700000e+01]]\n",
"================================================================================================================================================================\n",
"DFT axis: \n",
"[0 0 1]\n",
"Quantization axis and perpendicular rotation directions:\n",
"[1 0 0] --» [array([0, 1, 0]), array([0, 0, 1])]\n",
"[0 1 0] --» [array([1, 0, 0]), array([0, 0, 1])]\n",
"[0 0 1] --» [array([1, 0, 0]), array([0, 1, 0])]\n",
"================================================================================================================================================================\n",
"Parameters for the contour integral:\n",
"Number of k points: 20\n",
"k point directions: xy\n",
"Ebot: -13\n",
"Eset: 100\n",
"Esetp: 10000\n",
"================================================================================================================================================================\n",
"Atomic information: \n",
"----------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
"[atom index]Element(orbitals) x [Ang] y [Ang] z [Ang] Sx Sy Sz Q Lx Ly Lz Jx Jy Jz\n",
"----------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
"[3]Fe(2) -7.339158738013707e-06 4.149278510690423e-06 11.657585837928032\n",
"\n",
"[4]Fe(2) -7.326987662162937e-06 4.158274523275774e-06 8.912422537596708\n",
"\n",
"[5]Fe(2) 1.8954667088117545 1.0943913231921656 10.285002698393109\n",
"\n",
"================================================================================================================================================================\n",
"Exchange [meV]\n",
"----------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
"Magnetic entity1 Magnetic entity2 [i j k] d [Ang]\n",
"----------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
"[3]Fe(2) [4]Fe(2) [0 0 0] d [Ang] 2.745163300331324\n",
"Isotropic: -61.498296406506675\n",
"DMI: [-9.32930006e-01 -6.96988637e-04 -1.36689594e-06]\n",
"Symmetric-anisotropy: [ 3.64026416e-01 -9.75305726e-05 1.03837928e-05 -9.75305726e-05\n",
" 2.98408661e+00 -2.59876808e-05 1.03837928e-05 -2.59876808e-05\n",
" -3.34811302e+00]\n",
"J: [-6.11342700e+01 -9.75305726e-05 1.03837928e-05 -9.75305726e-05\n",
" -5.85142098e+01 -2.59876808e-05 1.03837928e-05 -2.59876808e-05\n",
" -6.48464094e+01]\n",
"Energies for debugging: \n",
"array([[-6.21997924e-02, -9.32904018e-04, 9.32955993e-04,\n",
" -6.14479990e-02],\n",
" [-6.74930265e-02, 6.86604844e-07, -7.07372430e-07,\n",
" -6.66882231e-02],\n",
" [-5.55804206e-02, 9.61636767e-08, 9.88974686e-08,\n",
" -5.55803169e-02]])\n",
"J_ii for debugging: (check if this is the same as in calculate_exchange_tensor)\n",
"array([-0.06668822, -0.05558042, -0.06219979])\n",
"Test J_xx = E(y,z) = E(z,y)\n",
"-0.06668822305594396 -0.055580316925466514\n",
"\n",
"[3]Fe(2) [5]Fe(2) [0 0 0] d [Ang] 2.5835033632437767\n",
"Isotropic: -60.54618555554936\n",
"DMI: [ 3.78486756e+00 -6.14165405e+00 5.59099134e-04]\n",
"Symmetric-anisotropy: [ 0.20417082 0.07119707 -0.09312132 0.07119707 0.01235531 -0.04251649\n",
" -0.09312132 -0.04251649 -0.21652613]\n",
"J: [-6.03420147e+01 7.11970660e-02 -9.31213222e-02 7.11970660e-02\n",
" -6.05338303e+01 -4.25164858e-02 -9.31213222e-02 -4.25164858e-02\n",
" -6.07627117e+01]\n",
"Energies for debugging: \n",
"array([[-6.08726017e-02, 3.82738404e-03, -3.74235107e-03,\n",
" -6.11758535e-02],\n",
" [-6.06528217e-02, 6.23477538e-03, -6.04853273e-03,\n",
" -6.08746935e-02],\n",
" [-5.98918070e-02, -7.06379668e-05, -7.17561651e-05,\n",
" -5.98093360e-02]])\n",
"J_ii for debugging: (check if this is the same as in calculate_exchange_tensor)\n",
"array([-0.06087469, -0.05989181, -0.0608726 ])\n",
"Test J_xx = E(y,z) = E(z,y)\n",
"-0.06087469345892933 -0.05980933600539501\n",
"\n",
"[4]Fe(2) [5]Fe(2) [0 0 0] d [Ang] 2.583501767937866\n",
"Isotropic: -60.54212757392337\n",
"DMI: [-3.79967167e+00 6.15419703e+00 5.59764090e-04]\n",
"Symmetric-anisotropy: [ 0.20573682 0.0711945 0.08981327 0.0711945 0.0059668 0.03643624\n",
" 0.08981327 0.03643624 -0.21170362]\n",
"J: [-6.03363908e+01 7.11945020e-02 8.98132684e-02 7.11945020e-02\n",
" -6.05361608e+01 3.64362362e-02 8.98132684e-02 3.64362362e-02\n",
" -6.07538312e+01]\n",
"Energies for debugging: \n",
"array([[-6.08690792e-02, -3.83610790e-03, 3.76323543e-03,\n",
" -6.11804573e-02],\n",
" [-6.06385832e-02, -6.24401030e-03, 6.06438376e-03,\n",
" -6.08633835e-02],\n",
" [-5.98918643e-02, -7.06347379e-05, -7.17542661e-05,\n",
" -5.98093980e-02]])\n",
"J_ii for debugging: (check if this is the same as in calculate_exchange_tensor)\n",
"array([-0.06086338, -0.05989186, -0.06086908])\n",
"Test J_xx = E(y,z) = E(z,y)\n",
"-0.0608633834990491 -0.059809398001364436\n",
"\n",
"[3]Fe(2) [5]Fe(2) [-1 -1 0] d [Ang] 2.5834973202859075\n",
"Isotropic: -60.53930274234898\n",
"DMI: [-7.20262359e+00 3.30922312e-04 -5.12682125e-04]\n",
"Symmetric-anisotropy: [-4.62470099e-02 -1.05109909e-04 1.11455444e-04 -1.05109909e-04\n",
" 2.54462404e-01 1.15662485e-01 1.11455444e-04 1.15662485e-01\n",
" -2.08215394e-01]\n",
"J: [-6.05855498e+01 -1.05109909e-04 1.11455444e-04 -1.05109909e-04\n",
" -6.02848403e+01 1.15662485e-01 1.11455444e-04 1.15662485e-01\n",
" -6.07475181e+01]\n",
"Energies for debugging: \n",
"array([[-6.06216770e-02, -7.31828608e-03, 7.08696111e-03,\n",
" -6.08002127e-02],\n",
" [-6.08733593e-02, -4.42377757e-07, 2.19466868e-07,\n",
" -6.12370668e-02],\n",
" [-5.97694679e-02, -4.07572216e-07, 6.17792035e-07,\n",
" -5.99340327e-02]])\n",
"J_ii for debugging: (check if this is the same as in calculate_exchange_tensor)\n",
"array([-0.06123707, -0.05976947, -0.06062168])\n",
"Test J_xx = E(y,z) = E(z,y)\n",
"-0.061237066792013795 -0.05993403271250145\n",
"\n",
"[4]Fe(2) [5]Fe(2) [-1 -1 0] d [Ang] 2.583495745338251\n",
"Isotropic: -60.54260994469562\n",
"DMI: [ 7.20261281e+00 -7.79978899e-04 -5.10345027e-04]\n",
"Symmetric-anisotropy: [-4.49940133e-02 -1.04644259e-04 1.76885445e-05 -1.04644259e-04\n",
" 2.57575083e-01 -1.15643556e-01 1.76885445e-05 -1.15643556e-01\n",
" -2.12581070e-01]\n",
"J: [-6.05876040e+01 -1.04644259e-04 1.76885445e-05 -1.04644259e-04\n",
" -6.02850349e+01 -1.15643556e-01 1.76885445e-05 -1.15643556e-01\n",
" -6.07551910e+01]\n",
"Energies for debugging: \n",
"array([[-6.06219750e-02, 7.31825637e-03, -7.08696926e-03,\n",
" -6.08004936e-02],\n",
" [-6.08884070e-02, 7.62290354e-07, -7.97667443e-07,\n",
" -6.12410736e-02],\n",
" [-5.97695761e-02, -4.05700767e-07, 6.14989286e-07,\n",
" -5.99341343e-02]])\n",
"J_ii for debugging: (check if this is the same as in calculate_exchange_tensor)\n",
"array([-0.06124107, -0.05976958, -0.06062198])\n",
"Test J_xx = E(y,z) = E(z,y)\n",
"-0.06124107359965607 -0.059934134316324196\n",
"\n",
"[3]Fe(2) [5]Fe(2) [-1 0 0] d [Ang] 2.583541444641373\n",
"Isotropic: -60.53142529259683\n",
"DMI: [ 3.79939696e+00 6.14174265e+00 -4.60077462e-05]\n",
"Symmetric-anisotropy: [ 0.2042796 -0.07107711 0.09303406 -0.07107711 0.01020684 -0.03654049\n",
" 0.09303406 -0.03654049 -0.21448644]\n",
"J: [-6.03271457e+01 -7.10771078e-02 9.30340570e-02 -7.10771078e-02\n",
" -6.05212185e+01 -3.65404867e-02 9.30340570e-02 -3.65404867e-02\n",
" -6.07459117e+01]\n",
"Energies for debugging: \n",
"array([[-6.08543628e-02, 3.83593745e-03, -3.76285647e-03,\n",
" -6.11652643e-02],\n",
" [-6.06374606e-02, -6.23477670e-03, 6.04870859e-03,\n",
" -6.08592084e-02],\n",
" [-5.98771726e-02, 7.10311000e-05, 7.11231155e-05,\n",
" -5.97950830e-02]])\n",
"J_ii for debugging: (check if this is the same as in calculate_exchange_tensor)\n",
"array([-0.06085921, -0.05987717, -0.06085436])\n",
"Test J_xx = E(y,z) = E(z,y)\n",
"-0.06085920839939711 -0.059795082988255574\n",
"\n",
"[4]Fe(2) [5]Fe(2) [-1 0 0] d [Ang] 2.5835398672184064\n",
"Isotropic: -60.52706082282313\n",
"DMI: [-3.78470017e+00 -6.15374066e+00 -4.69844827e-05]\n",
"Symmetric-anisotropy: [ 0.2054248 -0.07107452 -0.08989469 -0.07107452 0.00801517 0.04261804\n",
" -0.08989469 0.04261804 -0.21343998]\n",
"J: [-6.03216360e+01 -7.10745234e-02 -8.98946890e-02 -7.10745234e-02\n",
" -6.05190457e+01 4.26180387e-02 -8.98946890e-02 4.26180387e-02\n",
" -6.07405008e+01]\n",
"Energies for debugging: \n",
"array([[-6.08579041e-02, -3.82731821e-03, 3.74208213e-03,\n",
" -6.11607909e-02],\n",
" [-6.06230975e-02, 6.24363535e-03, -6.06384598e-03,\n",
" -6.08480575e-02],\n",
" [-5.98773004e-02, 7.10275389e-05, 7.11215079e-05,\n",
" -5.97952145e-02]])\n",
"J_ii for debugging: (check if this is the same as in calculate_exchange_tensor)\n",
"array([-0.06084806, -0.0598773 , -0.0608579 ])\n",
"Test J_xx = E(y,z) = E(z,y)\n",
"-0.060848057523824294 -0.05979521451219277\n",
"\n",
"================================================================================================================================================================\n",
"Runtime information: \n",
"Total runtime: 264.50463125 s\n",
"----------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
"Initial setup: 0.17141095800000006 s\n",
"Hamiltonian conversion and XC field extraction: 1.047 s\n",
"Pair and site datastructure creatrions: 0.036 s\n",
"k set cration and distribution: 0.029 s\n",
"Rotating XC potential: 0.329 s\n",
"Greens function inversion: 262.683 s\n",
"Calculate energies and magnetic components: 0.209 s\n"
]
}
],
3 months ago
"source": [
"if rank == root_node:\n",
" # iterate over the magnetic entities\n",
" for tracker, mag_ent in enumerate(magnetic_entities):\n",
" # iterate over the quantization axes\n",
" for i, Gii in enumerate(mag_ent[\"Gii\"]):\n",
" storage = []\n",
" # iterate over the first and second order local perturbations\n",
" for Vu1, Vu2 in zip(mag_ent[\"Vu1\"][i], mag_ent[\"Vu2\"][i]):\n",
3 months ago
" # The Szunyogh-Lichtenstein formula\n",
" traced = np.trace((Vu2 @ Gii + 0.5 * Gii @ Vu1 @ Gii), axis1=1, axis2=2)\n",
3 months ago
" # evaluation of the contour integral\n",
" storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))\n",
"\n",
" # fill up the magnetic entities dictionary with the energies\n",
" magnetic_entities[tracker][\"energies\"].append(storage)\n",
" # convert to np array\n",
" magnetic_entities[tracker][\"energies\"] = np.array(\n",
" magnetic_entities[tracker][\"energies\"]\n",
" )\n",
" print(\"Magnetic entities integrated.\")\n",
"\n",
" # iterate over the pairs\n",
" for tracker, pair in enumerate(pairs):\n",
" # iterate over the quantization axes\n",
" for i, (Gij, Gji) in enumerate(zip(pair[\"Gij\"], pair[\"Gji\"])):\n",
" site_i = magnetic_entities[pair[\"ai\"]]\n",
" site_j = magnetic_entities[pair[\"aj\"]]\n",
"\n",
" storage = []\n",
" # iterate over the first order local perturbations in all possible orientations for the two sites\n",
" for Vui in site_i[\"Vu1\"][i]:\n",
" for Vuj in site_j[\"Vu1\"][i]:\n",
" # The Szunyogh-Lichtenstein formula\n",
" traced = np.trace((Vui @ Gij @ Vuj @ Gji), axis1=1, axis2=2)\n",
" # evaluation of the contour integral\n",
" storage.append(np.trapz(-1 / np.pi * np.imag(traced * cont.we)))\n",
" # fill up the pairs dictionary with the energies\n",
" pairs[tracker][\"energies\"].append(storage)\n",
" # convert to np array\n",
" pairs[tracker][\"energies\"] = np.array(pairs[tracker][\"energies\"])\n",
"\n",
" print(\"Pairs integrated.\")\n",
"\n",
" # calculate magnetic parameters\n",
" for pair in pairs:\n",
" J_iso, J_S, D, J = calculate_exchange_tensor(pair)\n",
" pair[\"J_iso\"] = J_iso * sisl.unit_convert(\"eV\", \"meV\")\n",
" pair[\"J_S\"] = J_S * sisl.unit_convert(\"eV\", \"meV\")\n",
" pair[\"D\"] = D * sisl.unit_convert(\"eV\", \"meV\")\n",
" pair[\"J\"] = J * sisl.unit_convert(\"eV\", \"meV\")\n",
"\n",
" print(\"Magnetic parameters calculated.\")\n",
"\n",
" times[\"end_time\"] = timer()\n",
" print(\n",
" \"##################################################################### GROGU OUTPUT #############################################################################\"\n",
" )\n",
"\n",
" print_parameters(simulation_parameters)\n",
" print_atoms_and_pairs(magnetic_entities, pairs)\n",
" print_runtime_information(times)\n",
"\n",
" # remove clutter from magnetic entities and pair information\n",
" for pair in pairs:\n",
" del pair[\"Gij\"]\n",
" del pair[\"Gij_tmp\"]\n",
" del pair[\"Gji\"]\n",
" del pair[\"Gji_tmp\"]\n",
" for mag_ent in magnetic_entities:\n",
" del mag_ent[\"Gii\"]\n",
" del mag_ent[\"Gii_tmp\"]\n",
" del mag_ent[\"Vu1\"]\n",
" del mag_ent[\"Vu2\"]\n",
" # create output dictionary with all the relevant data\n",
" results = dict(\n",
" parameters=simulation_parameters,\n",
" magnetic_entities=magnetic_entities,\n",
" pairs=pairs,\n",
" runtime=times,\n",
" )\n",
" # save dictionary\n",
" with open(outfile, \"wb\") as output_file:\n",
" pickle.dump(results, output_file)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (3105939143.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[11], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m ========================================\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"========================================\n",
" \n",
"Atom Angstrom\n",
"# Label, x y z Sx Sy Sz #Q Lx Ly Lz Jx Jy Jz\n",
"--------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
"Te1 1.8955 1.0943 13.1698 -0.0000 0.0000 -0.1543 # 5.9345 -0.0000 0.0000 -0.0537 -0.0000 0.0000 -0.2080 \n",
"Te2 1.8955 1.0943 7.4002 0.0000 -0.0000 -0.1543 # 5.9345 0.0000 -0.0000 -0.0537 0.0000 -0.0000 -0.2080 \n",
"Ge3 -0.0000 2.1887 10.2850 0.0000 0.0000 -0.1605 # 3.1927 -0.0000 0.0000 0.0012 0.0000 0.0000 -0.1593 \n",
"Fe4 -0.0000 0.0000 11.6576 0.0001 -0.0001 2.0466 # 8.3044 0.0000 -0.0000 0.1606 0.0001 -0.0001 2.2072 \n",
"Fe5 -0.0000 0.0000 8.9124 -0.0001 0.0001 2.0466 # 8.3044 -0.0000 0.0000 0.1606 -0.0001 0.0001 2.2072 \n",
"Fe6 1.8955 1.0944 10.2850 0.0000 0.0000 1.5824 # 8.3296 -0.0000 -0.0000 0.0520 -0.0000 0.0000 1.6344 \n",
"==================================================================================================================================\n",
" \n",
"Exchange meV\n",
"--------------------------------------------------------------------------------\n",
"# at1 at2 i j k # d (Ang)\n",
"--------------------------------------------------------------------------------\n",
"Fe4 Fe5 0 0 0 # 2.7452\n",
"Isotropic -82.0854\n",
"DMI 0.12557 -0.00082199 6.9668e-08\n",
"Symmetric-anisotropy -0.60237 -0.83842 -0.00032278 -1.2166e-05 -3.3923e-05\n",
"--------------------------------------------------------------------------------\n",
"Fe4 Fe6 0 0 0 # 2.5835\n",
"Isotropic -41.9627\n",
"DMI 1.1205 -1.9532 0.0018386\n",
"Symmetric-anisotropy 0.26007 -0.00013243 0.12977 -0.069979 -0.042066\n",
"--------------------------------------------------------------------------------\n"
]
3 months ago
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
3 months ago
}
},
"nbformat": 4,
"nbformat_minor": 2
}