TB2J 0.9.0.1__tar.gz → 0.9.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/PKG-INFO +1 -1
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/Jdownfolder.py +110 -24
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/Jtensor.py +1 -1
- tb2j-0.9.0.2/TB2J/abacus/MAE.py +320 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/abacus_wrapper.py +20 -2
- tb2j-0.9.0.2/TB2J/abacus/occupations.py +278 -0
- tb2j-0.9.0.2/TB2J/abacus/test_density_matrix.py +38 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/green.py +2 -13
- tb2j-0.9.0.2/TB2J/mathutils/__init__.py +1 -0
- tb2j-0.9.0.2/TB2J/mathutils/fermi.py +22 -0
- tb2j-0.9.0.2/TB2J/mathutils/kR_convert.py +90 -0
- tb2j-0.9.0.2/TB2J/mathutils/lowdin.py +12 -0
- tb2j-0.9.0.2/TB2J/mathutils/rotate_spin.py +35 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/pauli.py +17 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/utils.py +82 -1
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J.egg-info/PKG-INFO +1 -1
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J.egg-info/SOURCES.txt +8 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/TB2J_downfold.py +8 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/setup.py +1 -1
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/LICENSE +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/README.md +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/Oiju.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/Oiju_epc.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/__init__.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/__init__.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/abacus_api.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/gen_exchange_abacus.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/orbital_api.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/stru_api.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/test_read_HRSR.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/abacus/test_read_stru.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/basis.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/citation.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/contour.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/density_matrix.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/epc.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/exchange.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/exchangeCL2.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/exchange_pert.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/exchange_qspace.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/external/__init__.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/external/p_tqdm.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/gpaw_wrapper.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/greentest.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_exchange/__init__.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_exchange/io_exchange.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_exchange/io_multibinit.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_exchange/io_tomsasd.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_exchange/io_txt.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_exchange/io_uppasd.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_exchange/io_vampire.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/io_merge.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/kpoints.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/manager.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/mathutils.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/myTB.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/orbmap.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/pert.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/plot.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/rotate_atoms.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/rotate_siestaDM.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/sisl_wrapper.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/__init__.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/base_parser.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/constants.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/hamiltonian.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/hamiltonian_terms.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/plot.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/qsolver.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/spin_api.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/spin_xml.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/spinham/supercell.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/tensor_rotate.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/utest.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/versioninfo.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/wannier/__init__.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/wannier/w90_parser.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J/wannier/w90_tb_parser.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J.egg-info/dependency_links.txt +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J.egg-info/requires.txt +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/TB2J.egg-info/top_level.txt +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/TB2J_eigen.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/TB2J_magnon.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/TB2J_magnon_dos.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/TB2J_merge.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/TB2J_rotate.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/TB2J_rotateDM.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/abacus2J.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/siesta2J.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/scripts/wann2J.py +0 -0
- {TB2J-0.9.0.1 → tb2j-0.9.0.2}/setup.cfg +0 -0
@@ -17,9 +17,23 @@ def ind_to_indn(ind, n=3):
|
|
17
17
|
return indn
|
18
18
|
|
19
19
|
|
20
|
+
class JR_model:
|
21
|
+
def __init__(self, JR, Rlist):
|
22
|
+
self.JR = JR
|
23
|
+
self.Rlist = Rlist
|
24
|
+
self.nR = len(Rlist)
|
25
|
+
|
26
|
+
def get_Jq(self, q):
|
27
|
+
Jq = np.zeros(self.JR[0].shape, dtype=complex)
|
28
|
+
for iR, R in enumerate(self.Rlist):
|
29
|
+
phase = np.exp(2.0j * np.pi * np.dot(q, R))
|
30
|
+
Jq += self.JR[iR] * phase
|
31
|
+
return Jq
|
32
|
+
|
33
|
+
|
20
34
|
class JDownfolder:
|
21
35
|
def __init__(self, JR, Rlist, iM, iL, qmesh, iso_only=False):
|
22
|
-
self.
|
36
|
+
self.model = JR_model(JR, Rlist)
|
23
37
|
self.Rlist = Rlist
|
24
38
|
self.nR = len(Rlist)
|
25
39
|
self.nM = len(iM)
|
@@ -34,25 +48,18 @@ class JDownfolder:
|
|
34
48
|
self.nLn = self.nL * 3
|
35
49
|
self.iso_only = iso_only
|
36
50
|
|
37
|
-
def get_Jq(self, q):
|
38
|
-
Jq = np.zeros(self.JR[0].shape, dtype=complex)
|
39
|
-
for iR, R in enumerate(self.Rlist):
|
40
|
-
phase = np.exp(2.0j * np.pi * np.dot(q, R))
|
41
|
-
Jq += self.JR[iR] * phase
|
42
|
-
return Jq
|
43
|
-
|
44
51
|
def get_JR(self):
|
45
52
|
JR_downfolded = np.zeros((self.nR, self.nMn, self.nMn), dtype=float)
|
46
53
|
Jq_downfolded = np.zeros((self.nqpt, self.nMn, self.nMn), dtype=complex)
|
47
54
|
self.iMn = ind_to_indn(self.iM, n=3)
|
48
55
|
self.iLn = ind_to_indn(self.iL, n=3)
|
49
56
|
for iq, q in enumerate(self.qpts):
|
50
|
-
Jq = self.get_Jq(q)
|
57
|
+
Jq = self.model.get_Jq(q)
|
51
58
|
Jq_downfolded[iq] = self.downfold_oneq(Jq)
|
52
59
|
for iR, R in enumerate(self.Rlist):
|
53
60
|
phase = np.exp(-2.0j * np.pi * np.dot(q, R))
|
54
61
|
JR_downfolded[iR] += np.real(Jq_downfolded[iq] * phase / self.nqpt)
|
55
|
-
return JR_downfolded
|
62
|
+
return JR_downfolded, self.Rlist
|
56
63
|
|
57
64
|
def downfold_oneq(self, J):
|
58
65
|
JMM = J[np.ix_(self.iMn, self.iMn)]
|
@@ -63,17 +70,80 @@ class JDownfolder:
|
|
63
70
|
return Jn
|
64
71
|
|
65
72
|
|
73
|
+
class PWFDownfolder:
|
74
|
+
def __init__(self, JR, Rlist, iM, iL, qmesh, atoms=None, iso_only=False, **kwargs):
|
75
|
+
from lawaf.interfaces.magnon.magnon_downfolder import (
|
76
|
+
MagnonWrapper,
|
77
|
+
MagnonDownfolder,
|
78
|
+
)
|
79
|
+
|
80
|
+
model = MagnonWrapper(JR, Rlist, atoms)
|
81
|
+
wann = MagnonDownfolder(model)
|
82
|
+
# Downfold the band structure.
|
83
|
+
index_basis = []
|
84
|
+
for i in iM:
|
85
|
+
index_basis += list(range(i * 3, i * 3 + 3))
|
86
|
+
params = dict(
|
87
|
+
method="projected",
|
88
|
+
# method="maxprojected",
|
89
|
+
kmesh=qmesh,
|
90
|
+
nwann=len(index_basis),
|
91
|
+
selected_basis=index_basis,
|
92
|
+
# anchors={(0, 0, 0): (-1, -2, -3, -4)},
|
93
|
+
# anchors={(0, 0, 0): ()},
|
94
|
+
# use_proj=True,
|
95
|
+
enhance_Amn=2.0,
|
96
|
+
)
|
97
|
+
params.update(kwargs)
|
98
|
+
wann.set_parameters(**params)
|
99
|
+
print("begin downfold")
|
100
|
+
ewf = wann.downfold()
|
101
|
+
ewf.save_hr_pickle("downfolded_JR.pickle")
|
102
|
+
|
103
|
+
# Plot the band structure.
|
104
|
+
wann.plot_band_fitting(
|
105
|
+
# kvectors=np.array([[0, 0, 0], [0.5, 0, 0],
|
106
|
+
# [0.5, 0.5, 0], [0, 0, 0],
|
107
|
+
# [.5, .5, .5]]),
|
108
|
+
# knames=['$\Gamma$', 'X', 'M', '$\Gamma$', 'R'],
|
109
|
+
cell=model.atoms.cell,
|
110
|
+
supercell_matrix=None,
|
111
|
+
npoints=100,
|
112
|
+
efermi=None,
|
113
|
+
erange=None,
|
114
|
+
fullband_color="blue",
|
115
|
+
downfolded_band_color="green",
|
116
|
+
marker="o",
|
117
|
+
ax=None,
|
118
|
+
savefig="downfold_band.png",
|
119
|
+
show=True,
|
120
|
+
)
|
121
|
+
self.JR_downfolded = ewf.HwannR
|
122
|
+
self.Rlist = ewf.Rlist
|
123
|
+
|
124
|
+
def get_JR(self):
|
125
|
+
return self.JR_downfolded, self.Rlist
|
126
|
+
|
127
|
+
|
66
128
|
class JDownfolder_pickle:
|
67
129
|
def __init__(
|
68
|
-
self,
|
130
|
+
self,
|
131
|
+
inpath,
|
132
|
+
metals,
|
133
|
+
ligands,
|
134
|
+
outpath,
|
135
|
+
qmesh=[7, 7, 7],
|
136
|
+
iso_only=False,
|
137
|
+
method="pwf",
|
138
|
+
**kwargs
|
69
139
|
):
|
70
140
|
self.exc = SpinIO.load_pickle(path=inpath, fname="TB2J.pickle")
|
71
141
|
|
72
142
|
self.iso_only = (self.exc.dmi_ddict is None) or iso_only
|
73
|
-
|
74
143
|
self.metals = metals
|
75
144
|
self.ligands = ligands
|
76
145
|
self.outpath = outpath
|
146
|
+
self.method = method
|
77
147
|
|
78
148
|
# read atomic structure
|
79
149
|
self.atoms = self.exc.atoms
|
@@ -83,7 +153,8 @@ class JDownfolder_pickle:
|
|
83
153
|
self.Rcut = None
|
84
154
|
self._build_atom_index()
|
85
155
|
self._prepare_distance()
|
86
|
-
self._downfold()
|
156
|
+
Jd, Rlist = self._downfold(**kwargs)
|
157
|
+
self._Jd_to_exchange(Jd, Rlist)
|
87
158
|
|
88
159
|
def _build_atom_index(self):
|
89
160
|
self.magnetic_elements = self.metals
|
@@ -101,18 +172,33 @@ class JDownfolder_pickle:
|
|
101
172
|
self.nL = len(self.iL)
|
102
173
|
self.nsite = self.nM + self.nL
|
103
174
|
|
104
|
-
def _downfold(self):
|
175
|
+
def _downfold(self, **kwargs):
|
105
176
|
JR2 = self.exc.get_full_Jtensor_for_Rlist(asr=True)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
177
|
+
if self.method == "lowdin":
|
178
|
+
d = JDownfolder(
|
179
|
+
JR2,
|
180
|
+
self.exc.Rlist,
|
181
|
+
iM=self.iM,
|
182
|
+
iL=self.iL,
|
183
|
+
qmesh=self.qmesh,
|
184
|
+
iso_only=self.iso_only,
|
185
|
+
)
|
186
|
+
Jd, Rlist = d.get_JR()
|
187
|
+
else:
|
188
|
+
d = PWFDownfolder(
|
189
|
+
JR2,
|
190
|
+
self.exc.Rlist,
|
191
|
+
iM=self.iM,
|
192
|
+
iL=self.iL,
|
193
|
+
qmesh=self.qmesh,
|
194
|
+
atoms=self.atoms,
|
195
|
+
iso_only=self.iso_only,
|
196
|
+
**kwargs
|
197
|
+
)
|
198
|
+
Jd, Rlist = d.get_JR()
|
199
|
+
return Jd, Rlist
|
115
200
|
|
201
|
+
def _Jd_to_exchange(self, Jd, Rlist):
|
116
202
|
self._prepare_distance()
|
117
203
|
self._prepare_index_spin()
|
118
204
|
self.Jdict = {}
|
@@ -123,7 +209,7 @@ class JDownfolder_pickle:
|
|
123
209
|
self.DMIdict = {}
|
124
210
|
self.Janidict = {}
|
125
211
|
|
126
|
-
for iR, R in enumerate(
|
212
|
+
for iR, R in enumerate(Rlist):
|
127
213
|
for i, ispin in enumerate(self.index_spin):
|
128
214
|
for j, jspin in enumerate(self.index_spin):
|
129
215
|
if ispin >= 0 and jspin >= 0:
|
@@ -79,7 +79,7 @@ def combine_J_tensor(Jiso=0.0, D=np.zeros(3), Jani=np.zeros((3, 3), dtype=float)
|
|
79
79
|
:param Jani: 3x3 matrix anisotropic exchange
|
80
80
|
:returns: A 3x3 matrix, the exchange paraemter in tensor form.
|
81
81
|
"""
|
82
|
-
Jtensor = np.zeros((3, 3), dtype=
|
82
|
+
Jtensor = np.zeros((3, 3), dtype=complex)
|
83
83
|
if Jiso is not None:
|
84
84
|
Jtensor += np.eye(3, dtype=float) * Jiso
|
85
85
|
if Jani is not None:
|
@@ -0,0 +1,320 @@
|
|
1
|
+
import numpy as np
|
2
|
+
from TB2J.abacus.abacus_wrapper import AbacusWrapper, AbacusParser
|
3
|
+
from TB2J.mathutils.rotate_spin import rotate_Matrix_from_z_to_axis
|
4
|
+
from TB2J.kpoints import monkhorst_pack
|
5
|
+
from TB2J.mathutils.fermi import fermi
|
6
|
+
from TB2J.mathutils.kR_convert import R_to_k
|
7
|
+
from scipy.linalg import eigh
|
8
|
+
from copy import deepcopy
|
9
|
+
from scipy.spatial.transform import Rotation
|
10
|
+
import matplotlib.pyplot as plt
|
11
|
+
from pathlib import Path
|
12
|
+
from TB2J.abacus.occupations import Occupations
|
13
|
+
|
14
|
+
# TODO List:
|
15
|
+
# - [x] Add the class AbacusSplitSOCWrapper
|
16
|
+
# - [x] Add the function to rotate the XC part
|
17
|
+
# - [x] Compute the band energy at arbitrary angle
|
18
|
+
|
19
|
+
|
20
|
+
def get_occupation(evals, kweights, nel, width=0.1):
|
21
|
+
occ = Occupations(nel=nel, width=width, wk=kweights, nspin=2)
|
22
|
+
return occ.occupy(evals)
|
23
|
+
|
24
|
+
|
25
|
+
def get_density_matrix(evals=None, evecs=None, kweights=None, nel=None, width=0.1):
|
26
|
+
occ = get_occupation(evals, kweights, nel, width=width)
|
27
|
+
rho = np.einsum("kib, kb, kjb -> kij", evecs, occ, evecs.conj())
|
28
|
+
return rho
|
29
|
+
|
30
|
+
|
31
|
+
def spherical_to_cartesian(theta, phi, normalize=True):
|
32
|
+
"""
|
33
|
+
Convert spherical coordinates to cartesian
|
34
|
+
"""
|
35
|
+
x = np.sin(theta) * np.cos(phi)
|
36
|
+
y = np.sin(theta) * np.sin(phi)
|
37
|
+
z = np.cos(theta)
|
38
|
+
vec = np.array([x, y, z])
|
39
|
+
if normalize:
|
40
|
+
vec = vec / np.linalg.norm(vec)
|
41
|
+
return vec
|
42
|
+
|
43
|
+
|
44
|
+
class AbacusSplitSOCWrapper(AbacusWrapper):
|
45
|
+
"""
|
46
|
+
Abacus wrapper with Hamiltonian split to SOC and non-SOC parts
|
47
|
+
"""
|
48
|
+
|
49
|
+
def __init__(self, *args, **kwargs):
|
50
|
+
HR_soc = kwargs.pop("HR_soc", None)
|
51
|
+
# nbasis = HR_soc.shape[1]
|
52
|
+
# kwargs["nbasis"] = nbasis
|
53
|
+
super().__init__(*args, **kwargs)
|
54
|
+
self._HR_copy = deepcopy(self._HR)
|
55
|
+
self.HR_soc = HR_soc
|
56
|
+
self.soc_lambda = 1.0
|
57
|
+
self.nel = 16
|
58
|
+
self.width = 0.1
|
59
|
+
|
60
|
+
@property
|
61
|
+
def HR(self):
|
62
|
+
return self._HR + self.HR_soc * self.soc_lambda
|
63
|
+
|
64
|
+
def rotate_HR_xc(self, axis):
|
65
|
+
"""
|
66
|
+
Rotate SOC part of Hamiltonian
|
67
|
+
"""
|
68
|
+
for iR, R in enumerate(self.Rlist):
|
69
|
+
self._HR[iR] = rotate_Matrix_from_z_to_axis(self._HR_copy[iR], axis)
|
70
|
+
|
71
|
+
def rotate_Hk_xc(self, axis):
|
72
|
+
"""
|
73
|
+
Rotate SOC part of Hamiltonian
|
74
|
+
"""
|
75
|
+
for ik in range(len(self._Hk)):
|
76
|
+
self._Hk[ik] = rotate_Matrix_from_z_to_axis(self._Hk_copy[ik], axis)
|
77
|
+
|
78
|
+
def get_density_matrix(self, kpts, kweights=None):
|
79
|
+
rho = np.zeros((len(kpts), self.nbasis, self.nbasis), dtype=complex)
|
80
|
+
evals, evecs = self.solve_all(kpts)
|
81
|
+
occ = get_occupation(evals, kweights, self.nel, width=self.width)
|
82
|
+
rho = np.einsum(
|
83
|
+
"kib, kb, kjb -> kij", evecs, occ, evecs.conj()
|
84
|
+
) # should multiply S to the the real DM.
|
85
|
+
return rho
|
86
|
+
|
87
|
+
def rotate_DM(self, rho, axis):
|
88
|
+
"""
|
89
|
+
Rotate the density matrix
|
90
|
+
"""
|
91
|
+
for ik in range(len(rho)):
|
92
|
+
rho[ik] = rotate_Matrix_from_z_to_axis(rho[ik], axis)
|
93
|
+
return rho
|
94
|
+
|
95
|
+
|
96
|
+
class RotateHam:
|
97
|
+
def __init__(self, model, kmesh, gamma=True):
|
98
|
+
self.model = model
|
99
|
+
self.kpts = monkhorst_pack(kmesh, gamma_center=gamma)
|
100
|
+
self.kweights = np.ones(len(self.kpts), dtype=float) / len(self.kpts)
|
101
|
+
|
102
|
+
def get_band_energy2(self):
|
103
|
+
for ik, kpt in enumerate(self.kpts):
|
104
|
+
Hk, Sk = self.model.gen_ham(kpt)
|
105
|
+
evals, evecs = eigh(Hk, Sk)
|
106
|
+
rho = np.einsum(
|
107
|
+
"ib, b, jb -> ij",
|
108
|
+
evecs,
|
109
|
+
fermi(evals, self.model.efermi, width=0.05),
|
110
|
+
evecs.conj(),
|
111
|
+
)
|
112
|
+
eband1 = np.sum(evals * fermi(evals, self.model.efermi, width=0.05))
|
113
|
+
eband2 = np.trace(Hk @ rho)
|
114
|
+
print(eband1, eband2)
|
115
|
+
|
116
|
+
def get_band_energy(self, dm=False):
|
117
|
+
evals, evecs = self.model.solve_all(self.kpts)
|
118
|
+
occ = get_occupation(
|
119
|
+
evals, self.kweights, self.model.nel, width=self.model.width
|
120
|
+
)
|
121
|
+
eband = np.sum(evals * occ * self.kweights[:, np.newaxis])
|
122
|
+
# * fermi(evals, self.model.efermi, width=0.05)
|
123
|
+
if dm:
|
124
|
+
density_matrix = self.model.get_density_matrix(evecs)
|
125
|
+
return eband, density_matrix
|
126
|
+
else:
|
127
|
+
return eband
|
128
|
+
|
129
|
+
def calc_ref(self):
|
130
|
+
# calculate the Hk_ref, Sk_ref, Hk_soc_ref, and rho_ref
|
131
|
+
self.Sk_ref = R_to_k(self.kpts, self.model.Rlist, self.model.SR)
|
132
|
+
self.Hk_xc_ref = R_to_k(self.kpts, self.model.Rlist, self.model._HR_copy)
|
133
|
+
self.Hk_soc_ref = R_to_k(self.kpts, self.model.Rlist, self.model.HR_soc)
|
134
|
+
self.rho_ref = np.zeros(
|
135
|
+
(len(self.kpts), self.model.nbasis, self.model.nbasis), dtype=complex
|
136
|
+
)
|
137
|
+
|
138
|
+
evals = np.zeros((len(self.kpts), self.model.nbasis), dtype=float)
|
139
|
+
evecs = np.zeros(
|
140
|
+
(len(self.kpts), self.model.nbasis, self.model.nbasis), dtype=complex
|
141
|
+
)
|
142
|
+
|
143
|
+
for ik, kpt in enumerate(self.kpts):
|
144
|
+
# evals, evecs = eigh(self.Hk_xc_ref[ik]+self.Hk_soc_ref[ik], self.Sk_ref[ik])
|
145
|
+
evals[ik], evecs[ik] = eigh(self.Hk_xc_ref[ik], self.Sk_ref[ik])
|
146
|
+
occ = get_occupation(
|
147
|
+
evals, self.kweights, self.model.nel, width=self.model.width
|
148
|
+
)
|
149
|
+
# occ = fermi(evals, self.model.efermi, width=self.model.width)
|
150
|
+
self.rho_ref = np.einsum("kib, kb, kjb -> kij", evecs, occ, evecs.conj())
|
151
|
+
|
152
|
+
def get_band_energy_from_rho(self, axis):
|
153
|
+
"""
|
154
|
+
This is wrong!! Should use second order perturbation theory to get the band energy instead.
|
155
|
+
"""
|
156
|
+
eband = 0.0
|
157
|
+
for ik, k in enumerate(self.kpts):
|
158
|
+
rho = rotate_Matrix_from_z_to_axis(self.rho_ref[ik], axis)
|
159
|
+
Hk_xc = rotate_Matrix_from_z_to_axis(self.Hk_xc_ref[ik], axis)
|
160
|
+
Hk_soc = self.Hk_soc_ref[ik]
|
161
|
+
Htot = Hk_xc + Hk_soc * self.model.soc_lambda
|
162
|
+
# Sk = self.Sk_ref[ik]
|
163
|
+
# evals, evecs = eigh(Htot, Sk)
|
164
|
+
# rho2= np.einsum("ib, b, jb -> ij", evecs, fermi(evals, self.model.efermi, width=0.05), evecs.conj())
|
165
|
+
if ik == 0 and False:
|
166
|
+
pass
|
167
|
+
# print(f"{evecs[:4,0:4].real=}")
|
168
|
+
# print(f"{evals[:4]=}")
|
169
|
+
# print(f"{Hk_xc[:4,0:4].real=}")
|
170
|
+
# print(f"{Htot[:4,0:4].real=}")
|
171
|
+
# print(f"{Sk[:4,0:4].real=}")
|
172
|
+
# print(f"{rho[:4,0:4].real=}")
|
173
|
+
# print(f"{rho2[:4,0:4].real=}")
|
174
|
+
# eband1 = np.sum(evals * fermi(evals, self.model.efermi, width=0.05))
|
175
|
+
# eband2 = np.trace(Htot @ rho2).real
|
176
|
+
# eband3 = np.trace(Htot @ rho).real
|
177
|
+
# print(eband1, eband2, eband3)
|
178
|
+
e_soc = np.trace(Hk_soc @ rho) * self.kweights[ik] * self.model.soc_lambda
|
179
|
+
eband += e_soc
|
180
|
+
return eband
|
181
|
+
|
182
|
+
def get_band_energy_vs_angles(
|
183
|
+
self,
|
184
|
+
thetas,
|
185
|
+
psis,
|
186
|
+
):
|
187
|
+
es = []
|
188
|
+
# es2 = []
|
189
|
+
# e,rho = self.model.get_band_energy(dm=True)
|
190
|
+
# self.calc_ref()
|
191
|
+
# thetas = np.linspace(*angle_range, npoints)
|
192
|
+
for i, theta, phi in enumerate(zip(thetas, psis)):
|
193
|
+
axis = spherical_to_cartesian(theta, phi)
|
194
|
+
self.model.rotate_HR_xc(axis)
|
195
|
+
# self.get_band_energy2()
|
196
|
+
e = self.get_band_energy()
|
197
|
+
es.append(e)
|
198
|
+
# es2.append(e2)
|
199
|
+
return es
|
200
|
+
|
201
|
+
|
202
|
+
def get_model_energy(model, kmesh, gamma=True):
|
203
|
+
ham = RotateHam(model, kmesh, gamma=gamma)
|
204
|
+
return ham.get_band_energy()
|
205
|
+
|
206
|
+
|
207
|
+
class AbacusSplitSOCParser:
|
208
|
+
"""
|
209
|
+
Abacus parser with Hamiltonian split to SOC and non-SOC parts
|
210
|
+
"""
|
211
|
+
|
212
|
+
def __init__(self, outpath_nosoc=None, outpath_soc=None, binary=False):
|
213
|
+
self.outpath_nosoc = outpath_nosoc
|
214
|
+
self.outpath_soc = outpath_soc
|
215
|
+
self.binary = binary
|
216
|
+
self.parser_nosoc = AbacusParser(outpath=outpath_nosoc, binary=binary)
|
217
|
+
self.parser_soc = AbacusParser(outpath=outpath_soc, binary=binary)
|
218
|
+
spin1 = self.parser_nosoc.read_spin()
|
219
|
+
spin2 = self.parser_soc.read_spin()
|
220
|
+
if spin1 != "noncollinear" or spin2 != "noncollinear":
|
221
|
+
raise ValueError("Spin should be noncollinear")
|
222
|
+
|
223
|
+
def parse(self):
|
224
|
+
nbasis, Rlist, HR, SR = self.parser_nosoc.Read_HSR_noncollinear()
|
225
|
+
nbasis2, Rlist2, HR2, SR2 = self.parser_soc.Read_HSR_noncollinear()
|
226
|
+
# print(HR[0])
|
227
|
+
HR_soc = HR2 - HR
|
228
|
+
model = AbacusSplitSOCWrapper(HR, SR, Rlist, nbasis, nspin=2, HR_soc=HR_soc)
|
229
|
+
model.efermi = self.parser_soc.efermi
|
230
|
+
model.basis = self.parser_nosoc.basis
|
231
|
+
model.atoms = self.parser_nosoc.atoms
|
232
|
+
return model
|
233
|
+
|
234
|
+
|
235
|
+
def abacus_get_MAE(
|
236
|
+
path_nosoc, path_soc, kmesh, thetas, psis, gamma=True, outfile="MAE.txt"
|
237
|
+
):
|
238
|
+
"""Get MAE from Abacus with magnetic force theorem. Two calculations are needed. First we do an calculation with SOC but the soc_lambda is set to 0. Save the density. The next calculatin we start with the density from the first calculation and set the SOC prefactor to 1. With the information from the two calcualtions, we can get the band energy with magnetic moments in the direction, specified in two list, thetas, and phis."""
|
239
|
+
parser = AbacusSplitSOCParser(
|
240
|
+
outpath_nosoc=path_nosoc, outpath_soc=path_soc, binary=False
|
241
|
+
)
|
242
|
+
model = parser.parse()
|
243
|
+
ham = RotateHam(model, kmesh, gamma=gamma)
|
244
|
+
es = []
|
245
|
+
for theta, psi in zip(thetas, psis):
|
246
|
+
axis = spherical_to_cartesian(theta, psi)
|
247
|
+
model.rotate_HR_xc(axis)
|
248
|
+
e = ham.get_band_energy()
|
249
|
+
es.append(ham.get_band_energy())
|
250
|
+
if outfile:
|
251
|
+
with open(outfile, "w") as f:
|
252
|
+
f.write("theta, psi, energy\n")
|
253
|
+
for theta, psi, e in zip(thetas, psis, es):
|
254
|
+
f.write(f"{theta}, {psi}, {e}\n")
|
255
|
+
return es
|
256
|
+
|
257
|
+
|
258
|
+
def test_AbacusSplitSOCWrapper():
|
259
|
+
# path = Path("~/projects/2D_Fe").expanduser()
|
260
|
+
path = Path("~/projects/TB2Jflows/examples/2D_Fe/Fe_z").expanduser()
|
261
|
+
outpath_nosoc = f"{path}/soc0/OUT.ABACUS"
|
262
|
+
outpath_soc = f"{path}/soc1/OUT.ABACUS"
|
263
|
+
parser = AbacusSplitSOCParser(
|
264
|
+
outpath_nosoc=outpath_nosoc, outpath_soc=outpath_soc, binary=False
|
265
|
+
)
|
266
|
+
model = parser.parse()
|
267
|
+
kmesh = [6, 6, 1]
|
268
|
+
|
269
|
+
r = RotateHam(model, kmesh)
|
270
|
+
# thetas, es = r.get_band_energy_vs_theta(angle_range=(0, np.pi*2), rotation_axis="z", initial_direction=(1,0,0), npoints=21)
|
271
|
+
thetas, es, es2 = r.get_band_energy_vs_theta(
|
272
|
+
angle_range=(0, np.pi * 2),
|
273
|
+
rotation_axis="y",
|
274
|
+
initial_direction=(0, 0, 1),
|
275
|
+
npoints=11,
|
276
|
+
)
|
277
|
+
# print the table of thetas and es, es2
|
278
|
+
print("theta, e, e2")
|
279
|
+
for theta, e, e2 in zip(thetas, es, es2):
|
280
|
+
print(f"{theta=}, {e=}, {e2=}")
|
281
|
+
|
282
|
+
plt.plot(thetas / np.pi, es - es[0], marker="o")
|
283
|
+
plt.plot(thetas / np.pi, es2 - es2[0], marker=".")
|
284
|
+
plt.savefig("E_along_z_x_z.png")
|
285
|
+
plt.show()
|
286
|
+
|
287
|
+
|
288
|
+
def abacus_get_MAE_cli():
|
289
|
+
import argparse
|
290
|
+
|
291
|
+
parser = argparse.ArgumentParser(
|
292
|
+
description="Get MAE from Abacus with magnetic force theorem. Two calculations are needed. First we do an calculation with SOC but the soc_lambda is set to 0. Save the density. The next calculatin we start with the density from the first calculation and set the SOC prefactor to 1. With the information from the two calcualtions, we can get the band energy with magnetic moments in the direction, specified in two list, thetas, and phis. "
|
293
|
+
)
|
294
|
+
parser.add_argument("path_nosoc", type=str, help="Path to the calculation with ")
|
295
|
+
parser.add_argument("path_soc", type=str, help="Path to the SOC calculation")
|
296
|
+
parser.add_argument("thetas", type=float, nargs="+", help="Thetas")
|
297
|
+
parser.add_argument("psis", type=float, nargs="+", help="Phis")
|
298
|
+
parser.add_argument("kmesh", type=int, nargs=3, help="K-mesh")
|
299
|
+
parser.add_argument(
|
300
|
+
"--gamma", action="store_true", help="Use Gamma centered kpoints"
|
301
|
+
)
|
302
|
+
parser.add_argument(
|
303
|
+
"--outfile",
|
304
|
+
type=str,
|
305
|
+
help="The angles and the energey will be saved in this file.",
|
306
|
+
)
|
307
|
+
args = parser.parse_args()
|
308
|
+
abacus_get_MAE(
|
309
|
+
args.path_nosoc,
|
310
|
+
args.path_soc,
|
311
|
+
args.kmesh,
|
312
|
+
args.thetas,
|
313
|
+
args.psis,
|
314
|
+
gamma=args.gamma,
|
315
|
+
outfile=args.outfile,
|
316
|
+
)
|
317
|
+
|
318
|
+
|
319
|
+
if __name__ == "__main__":
|
320
|
+
abacus_get_MAE_cli()
|
@@ -16,10 +16,10 @@ from TB2J.abacus.stru_api import read_abacus, read_abacus_out
|
|
16
16
|
|
17
17
|
class AbacusWrapper(AbstractTB):
|
18
18
|
def __init__(self, HR, SR, Rlist, nbasis, nspin=1):
|
19
|
-
self.R2kfactor =
|
19
|
+
self.R2kfactor = 2j * np.pi
|
20
20
|
self.is_orthogonal = False
|
21
21
|
self._name = "ABACUS"
|
22
|
-
self.
|
22
|
+
self._HR = HR
|
23
23
|
self.SR = SR
|
24
24
|
self.Rlist = Rlist
|
25
25
|
self.nbasis = nbasis
|
@@ -27,6 +27,14 @@ class AbacusWrapper(AbstractTB):
|
|
27
27
|
self.norb = nbasis * nspin
|
28
28
|
self._build_Rdict()
|
29
29
|
|
30
|
+
@property
|
31
|
+
def HR(self):
|
32
|
+
return self._HR
|
33
|
+
|
34
|
+
@HR.setter
|
35
|
+
def set_HR(self, HR):
|
36
|
+
self._HR = HR
|
37
|
+
|
30
38
|
def _build_Rdict(self):
|
31
39
|
if hasattr(self, "Rdict"):
|
32
40
|
pass
|
@@ -62,6 +70,8 @@ class AbacusWrapper(AbstractTB):
|
|
62
70
|
S = self.SR[iR] * phase
|
63
71
|
# Sk += S + S.conjugate().T
|
64
72
|
Sk += S
|
73
|
+
# Hk = (Hk + Hk.conj().T)/2
|
74
|
+
# Sk = (Sk + Sk.conj().T)/2
|
65
75
|
elif convention == 1:
|
66
76
|
# TODO: implement the first convention (the r convention)
|
67
77
|
raise NotImplementedError("convention 1 is not implemented yet.")
|
@@ -74,6 +84,14 @@ class AbacusWrapper(AbstractTB):
|
|
74
84
|
Hk, Sk = self.gen_ham(k, convention=convention)
|
75
85
|
return eigh(Hk, Sk)
|
76
86
|
|
87
|
+
def solve_all(self, kpts, convention=2):
|
88
|
+
nk = len(kpts)
|
89
|
+
evals = np.zeros((nk, self.nbasis), dtype=float)
|
90
|
+
evecs = np.zeros((nk, self.nbasis, self.nbasis), dtype=complex)
|
91
|
+
for ik, k in enumerate(kpts):
|
92
|
+
evals[ik], evecs[ik] = self.solve(k, convention=convention)
|
93
|
+
return evals, evecs
|
94
|
+
|
77
95
|
def HSE_k(self, kpt, convention=2):
|
78
96
|
H, S = self.gen_ham(tuple(kpt), convention=convention)
|
79
97
|
evals, evecs = eigh(H, S)
|