TB2J 0.9.4rc0__py3-none-any.whl → 0.9.6rc0__py3-none-any.whl
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/MAE.py +108 -24
- TB2J/anisotropy.py +672 -0
- TB2J/contour.py +8 -0
- TB2J/exchange.py +43 -103
- TB2J/exchangeCL2.py +11 -13
- TB2J/exchange_params.py +213 -0
- TB2J/green.py +62 -27
- TB2J/interfaces/__init__.py +12 -0
- TB2J/interfaces/abacus/__init__.py +4 -0
- TB2J/{abacus → interfaces/abacus}/abacus_api.py +3 -3
- TB2J/{abacus → interfaces/abacus}/abacus_wrapper.py +11 -7
- TB2J/{abacus → interfaces/abacus}/gen_exchange_abacus.py +6 -3
- TB2J/{abacus → interfaces/abacus}/orbital_api.py +4 -4
- TB2J/{abacus → interfaces/abacus}/stru_api.py +11 -11
- TB2J/{abacus → interfaces/abacus}/test_read_HRSR.py +0 -1
- TB2J/{abacus → interfaces/abacus}/test_read_stru.py +5 -3
- TB2J/interfaces/gpaw_interface.py +54 -0
- TB2J/interfaces/lawaf_interface.py +129 -0
- TB2J/interfaces/manager.py +23 -0
- TB2J/interfaces/siesta_interface.py +174 -0
- TB2J/interfaces/wannier90_interface.py +115 -0
- TB2J/io_exchange/io_exchange.py +21 -7
- TB2J/io_merge.py +2 -1
- TB2J/mathutils/fermi.py +11 -6
- TB2J/mathutils/lowdin.py +12 -2
- TB2J/mathutils/rotate_spin.py +222 -4
- TB2J/pauli.py +38 -2
- TB2J/symmetrize_J.py +120 -0
- TB2J/utils.py +82 -1
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/abacus2J.py +5 -4
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/siesta2J.py +21 -4
- TB2J-0.9.6rc0.data/scripts/wann2J.py +96 -0
- {TB2J-0.9.4rc0.dist-info → TB2J-0.9.6rc0.dist-info}/METADATA +4 -3
- {TB2J-0.9.4rc0.dist-info → TB2J-0.9.6rc0.dist-info}/RECORD +46 -46
- {TB2J-0.9.4rc0.dist-info → TB2J-0.9.6rc0.dist-info}/WHEEL +1 -1
- TB2J-0.9.6rc0.dist-info/entry_points.txt +3 -0
- TB2J/abacus/MAE.py +0 -320
- TB2J/abacus/__init__.py +0 -1
- TB2J/abacus/occupations.py +0 -278
- TB2J/cut_cell.py +0 -82
- TB2J/io_exchange/io_pickle.py +0 -0
- TB2J/manager.py +0 -441
- TB2J/mathutils.py +0 -12
- TB2J/patch.py +0 -50
- TB2J/spinham/h_matrix.py +0 -68
- TB2J/spinham/obtain_J.py +0 -79
- TB2J/supercell.py +0 -532
- TB2J-0.9.4rc0.data/scripts/wann2J.py +0 -194
- TB2J/{abacus → interfaces/abacus}/test_density_matrix.py +1 -1
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/TB2J_downfold.py +0 -0
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/TB2J_eigen.py +0 -0
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/TB2J_magnon.py +0 -0
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/TB2J_magnon_dos.py +0 -0
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/TB2J_merge.py +0 -0
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/TB2J_rotate.py +0 -0
- {TB2J-0.9.4rc0.data → TB2J-0.9.6rc0.data}/scripts/TB2J_rotateDM.py +0 -0
- {TB2J-0.9.4rc0.dist-info → TB2J-0.9.6rc0.dist-info}/LICENSE +0 -0
- {TB2J-0.9.4rc0.dist-info → TB2J-0.9.6rc0.dist-info}/top_level.txt +0 -0
TB2J/manager.py
DELETED
@@ -1,441 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from TB2J.myTB import MyTB, merge_tbmodels_spin
|
3
|
-
import numpy as np
|
4
|
-
from TB2J.exchange import ExchangeNCL
|
5
|
-
from TB2J.exchangeCL2 import ExchangeCL2
|
6
|
-
from TB2J.exchange_qspace import ExchangeCLQspace
|
7
|
-
from TB2J.utils import read_basis, auto_assign_basis_name
|
8
|
-
from ase.io import read
|
9
|
-
|
10
|
-
# from TB2J.sisl_wrapper import SislWrapper
|
11
|
-
try:
|
12
|
-
from HamiltonIO.siesta import SislWrapper
|
13
|
-
except ImportError:
|
14
|
-
print(
|
15
|
-
"Cannot import SislWrapper from HamiltonIO.siesta. Please install HamiltonIO first."
|
16
|
-
)
|
17
|
-
from TB2J.sisl_wrapper import SislWrapper
|
18
|
-
from TB2J.gpaw_wrapper import GPAWWrapper
|
19
|
-
from TB2J.wannier import parse_atoms
|
20
|
-
|
21
|
-
|
22
|
-
def gen_exchange(
|
23
|
-
path,
|
24
|
-
colinear=True,
|
25
|
-
groupby="spin",
|
26
|
-
posfile=None,
|
27
|
-
prefix_up="wannier90.up",
|
28
|
-
prefix_dn="wannier90.dn",
|
29
|
-
prefix_SOC="wannier90",
|
30
|
-
min_hopping_norm=1e-4,
|
31
|
-
max_distance=None,
|
32
|
-
efermi=0,
|
33
|
-
magnetic_elements=[],
|
34
|
-
kmesh=[4, 4, 4],
|
35
|
-
emin=-12.0,
|
36
|
-
emax=0.0,
|
37
|
-
nz=100,
|
38
|
-
exclude_orbs=[],
|
39
|
-
Rcut=None,
|
40
|
-
ne=None,
|
41
|
-
use_cache=False,
|
42
|
-
np=1,
|
43
|
-
output_path="TB2J_results",
|
44
|
-
wannier_type="wannier90",
|
45
|
-
qspace=False,
|
46
|
-
orb_decomposition=False,
|
47
|
-
write_density_matrix=False,
|
48
|
-
description="",
|
49
|
-
):
|
50
|
-
try:
|
51
|
-
fname = os.path.join(path, posfile)
|
52
|
-
print(f"Reading atomic structure from file {fname}.")
|
53
|
-
atoms = read(os.path.join(path, posfile))
|
54
|
-
except Exception:
|
55
|
-
print(
|
56
|
-
f"Cannot read atomic structure from file {fname}. Trying to read from Wannier input."
|
57
|
-
)
|
58
|
-
if colinear:
|
59
|
-
fname = os.path.join(path, f"{prefix_up}.win")
|
60
|
-
else:
|
61
|
-
fname = os.path.join(path, f"{prefix_SOC}.win")
|
62
|
-
|
63
|
-
print(f"Reading atomic structure from file {fname}.")
|
64
|
-
atoms = parse_atoms(fname)
|
65
|
-
|
66
|
-
basis_fname = os.path.join(path, "basis.txt")
|
67
|
-
if colinear:
|
68
|
-
if wannier_type.lower() == "wannier90":
|
69
|
-
print("Reading Wannier90 hamiltonian: spin up.")
|
70
|
-
tbmodel_up = MyTB.read_from_wannier_dir(
|
71
|
-
path=path, prefix=prefix_up, atoms=atoms, nls=False
|
72
|
-
)
|
73
|
-
print("Reading Wannier90 hamiltonian: spin down.")
|
74
|
-
tbmodel_dn = MyTB.read_from_wannier_dir(
|
75
|
-
path=path, prefix=prefix_dn, atoms=atoms, nls=False
|
76
|
-
)
|
77
|
-
if os.path.exists(basis_fname):
|
78
|
-
basis = read_basis(basis_fname)
|
79
|
-
else:
|
80
|
-
basis, _ = auto_assign_basis_name(
|
81
|
-
tbmodel_up.xred,
|
82
|
-
atoms,
|
83
|
-
write_basis_file=os.path.join(output_path, "assigned_basis.txt"),
|
84
|
-
)
|
85
|
-
elif wannier_type.lower() == "banddownfolder":
|
86
|
-
print("Reading Banddownfolder hamiltonian: spin up.")
|
87
|
-
tbmodel_up = MyTB.load_banddownfolder(
|
88
|
-
path=path, prefix=prefix_up, atoms=atoms, nls=False
|
89
|
-
)
|
90
|
-
print("Reading Banddownfolder hamiltonian: spin down.")
|
91
|
-
tbmodel_dn = MyTB.load_banddownfolder(
|
92
|
-
path=path, prefix=prefix_dn, atoms=atoms, nls=False
|
93
|
-
)
|
94
|
-
|
95
|
-
basis, _ = auto_assign_basis_name(
|
96
|
-
tbmodel_up.xred,
|
97
|
-
atoms,
|
98
|
-
write_basis_file=os.path.join(output_path, "assigned_basis.txt"),
|
99
|
-
)
|
100
|
-
else:
|
101
|
-
raise ValueError("wannier_type should be Wannier90 or banddownfolder.")
|
102
|
-
|
103
|
-
print("Starting to calculate exchange.")
|
104
|
-
description = f""" Input from collinear Wannier90 data.
|
105
|
-
Tight binding data from {path}.
|
106
|
-
Prefix of wannier function files:{prefix_up} and {prefix_dn}.
|
107
|
-
Warning: Please check if the noise level of Wannier function Hamiltonian to make sure it is much smaller than the exchange values.
|
108
|
-
\n"""
|
109
|
-
if not qspace:
|
110
|
-
exchange = ExchangeCL2(
|
111
|
-
tbmodels=(tbmodel_up, tbmodel_dn),
|
112
|
-
atoms=atoms,
|
113
|
-
basis=basis,
|
114
|
-
efermi=efermi,
|
115
|
-
magnetic_elements=magnetic_elements,
|
116
|
-
kmesh=kmesh,
|
117
|
-
emin=emin,
|
118
|
-
emax=emax,
|
119
|
-
nz=nz,
|
120
|
-
exclude_orbs=exclude_orbs,
|
121
|
-
Rcut=Rcut,
|
122
|
-
ne=ne,
|
123
|
-
np=np,
|
124
|
-
use_cache=use_cache,
|
125
|
-
output_path=output_path,
|
126
|
-
write_density_matrix=write_density_matrix,
|
127
|
-
description=description,
|
128
|
-
)
|
129
|
-
else:
|
130
|
-
exchange = ExchangeCLQspace(
|
131
|
-
tbmodels=(tbmodel_up, tbmodel_dn),
|
132
|
-
atoms=atoms,
|
133
|
-
basis=basis,
|
134
|
-
efermi=efermi,
|
135
|
-
magnetic_elements=magnetic_elements,
|
136
|
-
kmesh=kmesh,
|
137
|
-
emin=emin,
|
138
|
-
emax=emax,
|
139
|
-
nz=nz,
|
140
|
-
exclude_orbs=exclude_orbs,
|
141
|
-
Rcut=Rcut,
|
142
|
-
ne=ne,
|
143
|
-
np=np,
|
144
|
-
use_cache=use_cache,
|
145
|
-
output_path=output_path,
|
146
|
-
write_density_matrix=write_density_matrix,
|
147
|
-
description=description,
|
148
|
-
)
|
149
|
-
|
150
|
-
exchange.run(path=output_path)
|
151
|
-
print("All calculation finsihed. The results are in TB2J_results directory.")
|
152
|
-
|
153
|
-
elif colinear and wannier_type.lower() == "banddownfolder":
|
154
|
-
print("Reading Wannier90 hamiltonian: spin up.")
|
155
|
-
tbmodel_up = MyTB.read_from_wannier_dir(
|
156
|
-
path=path, prefix=prefix_up, atoms=atoms, groupby=None, nls=False
|
157
|
-
)
|
158
|
-
print("Reading Wannier90 hamiltonian: spin down.")
|
159
|
-
tbmodel_dn = MyTB.read_from_wannier_dir(
|
160
|
-
path=path, prefix=prefix_dn, atoms=atoms, groupby=None, nls=False
|
161
|
-
)
|
162
|
-
tbmodel = merge_tbmodels_spin(tbmodel_up, tbmodel_dn)
|
163
|
-
basis, _ = auto_assign_basis_name(
|
164
|
-
tbmodel.xred,
|
165
|
-
atoms,
|
166
|
-
write_basis_file=os.path.join(output_path, "assigned_basis.txt"),
|
167
|
-
)
|
168
|
-
description = f""" Input from collinear BandDownfolder data.
|
169
|
-
Tight binding data from {path}.
|
170
|
-
Prefix of wannier function files:{prefix_up} and {prefix_dn}.
|
171
|
-
Warning: Please check if the noise level of Wannier function Hamiltonian to make sure it is much smaller than the exchange values.
|
172
|
-
\n"""
|
173
|
-
print("Starting to calculate exchange.")
|
174
|
-
exchange = ExchangeCL2(
|
175
|
-
tbmodels=tbmodel,
|
176
|
-
atoms=atoms,
|
177
|
-
basis=basis,
|
178
|
-
efermi=efermi,
|
179
|
-
magnetic_elements=magnetic_elements,
|
180
|
-
kmesh=kmesh,
|
181
|
-
emin=emin,
|
182
|
-
emax=emax,
|
183
|
-
nz=nz,
|
184
|
-
exclude_orbs=exclude_orbs,
|
185
|
-
Rcut=Rcut,
|
186
|
-
ne=ne,
|
187
|
-
np=np,
|
188
|
-
use_cache=use_cache,
|
189
|
-
output_path=output_path,
|
190
|
-
write_density_matrix=write_density_matrix,
|
191
|
-
description=description,
|
192
|
-
)
|
193
|
-
exchange.run(path=output_path)
|
194
|
-
print("All calculation finsihed. The results are in TB2J_results directory.")
|
195
|
-
else:
|
196
|
-
print("Reading Wannier90 hamiltonian: non-colinear spin.")
|
197
|
-
groupby = groupby.lower().strip()
|
198
|
-
if groupby not in ["spin", "orbital"]:
|
199
|
-
raise ValueError("groupby can only be spin or orbital.")
|
200
|
-
tbmodel = MyTB.read_from_wannier_dir(
|
201
|
-
path=path, prefix=prefix_SOC, atoms=atoms, groupby=groupby, nls=True
|
202
|
-
)
|
203
|
-
if os.path.exists(basis_fname):
|
204
|
-
print("The use of basis file is deprecated. It will be ignored.")
|
205
|
-
# basis = read_basis(basis_fname)
|
206
|
-
else:
|
207
|
-
basis, _ = auto_assign_basis_name(
|
208
|
-
tbmodel.xred,
|
209
|
-
atoms,
|
210
|
-
write_basis_file=os.path.join(output_path, "assigned_basis.txt"),
|
211
|
-
)
|
212
|
-
description = f""" Input from non-collinear Wannier90 data.
|
213
|
-
Tight binding data from {path}.
|
214
|
-
Prefix of wannier function files:{prefix_SOC}.
|
215
|
-
Warning: Please check if the noise level of Wannier function Hamiltonian to make sure it is much smaller than the exchange values.
|
216
|
-
The DMI component parallel to the spin orientation, the Jani which has the component of that orientation should be disregarded
|
217
|
-
e.g. if the spins are along z, the xz, yz, zz, zx, zy components and the z component of DMI.
|
218
|
-
If you need these component, try to do three calculations with spin along x, y, z, or use structure with z rotated to x, y and z. And then use TB2J_merge.py to get the full set of parameters.
|
219
|
-
|
220
|
-
\n"""
|
221
|
-
print("Starting to calculate exchange.")
|
222
|
-
exchange = ExchangeNCL(
|
223
|
-
tbmodels=tbmodel,
|
224
|
-
atoms=atoms,
|
225
|
-
basis=basis,
|
226
|
-
efermi=efermi,
|
227
|
-
magnetic_elements=magnetic_elements,
|
228
|
-
kmesh=kmesh,
|
229
|
-
emin=emin,
|
230
|
-
emax=emax,
|
231
|
-
nz=nz,
|
232
|
-
exclude_orbs=exclude_orbs,
|
233
|
-
Rcut=Rcut,
|
234
|
-
ne=ne,
|
235
|
-
np=np,
|
236
|
-
use_cache=use_cache,
|
237
|
-
description=description,
|
238
|
-
output_path=output_path,
|
239
|
-
write_density_matrix=write_density_matrix,
|
240
|
-
orb_decomposition=orb_decomposition,
|
241
|
-
)
|
242
|
-
print("\n")
|
243
|
-
exchange.run(path=output_path)
|
244
|
-
print(f"All calculation finsihed. The results are in {output_path} directory.")
|
245
|
-
|
246
|
-
|
247
|
-
def gen_exchange_siesta(
|
248
|
-
fdf_fname,
|
249
|
-
magnetic_elements=[],
|
250
|
-
include_orbs=None,
|
251
|
-
kmesh=[5, 5, 5],
|
252
|
-
emin=-12.0,
|
253
|
-
emax=0.0,
|
254
|
-
nz=100,
|
255
|
-
exclude_orbs=[],
|
256
|
-
Rcut=None,
|
257
|
-
ne=None,
|
258
|
-
np=1,
|
259
|
-
use_cache=False,
|
260
|
-
output_path="TB2J_results",
|
261
|
-
orb_decomposition=False,
|
262
|
-
description="",
|
263
|
-
):
|
264
|
-
try:
|
265
|
-
import sisl
|
266
|
-
except:
|
267
|
-
raise ImportError("sisl cannot be imported. Please install sisl first.")
|
268
|
-
|
269
|
-
from packaging import version
|
270
|
-
|
271
|
-
if version.parse(sisl.__version__) <= version.parse("0.10.0"):
|
272
|
-
raise ImportError(
|
273
|
-
f"sisl version is {sisl.__version__}, but should be larger than 0.10.0."
|
274
|
-
)
|
275
|
-
|
276
|
-
include_orbs = {}
|
277
|
-
if isinstance(magnetic_elements, str):
|
278
|
-
magnetic_elements = [magnetic_elements]
|
279
|
-
for element in magnetic_elements:
|
280
|
-
if "_" in element:
|
281
|
-
elem = element.split("_")[0]
|
282
|
-
orb = element.split("_")[1:]
|
283
|
-
include_orbs[elem] = orb
|
284
|
-
else:
|
285
|
-
include_orbs[element] = None
|
286
|
-
magnetic_elements = list(include_orbs.keys())
|
287
|
-
|
288
|
-
fdf = sisl.get_sile(fdf_fname)
|
289
|
-
# geom = fdf.read_geometry()
|
290
|
-
H = fdf.read_hamiltonian()
|
291
|
-
geom = H.geometry
|
292
|
-
if H.spin.is_colinear:
|
293
|
-
print("Reading Siesta hamiltonian: colinear spin.")
|
294
|
-
tbmodel_up = SislWrapper(fdf_fname=None, sisl_hamiltonian=H, spin=0, geom=geom)
|
295
|
-
tbmodel_dn = SislWrapper(fdf_fname=None, sisl_hamiltonian=H, spin=1, geom=geom)
|
296
|
-
basis = dict(zip(tbmodel_up.orbs, list(range(tbmodel_up.norb))))
|
297
|
-
print("Starting to calculate exchange.")
|
298
|
-
description = f""" Input from collinear Siesta data.
|
299
|
-
working directory: {os.getcwd()}
|
300
|
-
fdf_fname: {fdf_fname}.
|
301
|
-
\n"""
|
302
|
-
exchange = ExchangeCL2(
|
303
|
-
tbmodels=(tbmodel_up, tbmodel_dn),
|
304
|
-
atoms=tbmodel_up.atoms,
|
305
|
-
basis=basis,
|
306
|
-
efermi=0.0,
|
307
|
-
magnetic_elements=magnetic_elements,
|
308
|
-
include_orbs=include_orbs,
|
309
|
-
kmesh=kmesh,
|
310
|
-
emin=emin,
|
311
|
-
emax=emax,
|
312
|
-
nz=nz,
|
313
|
-
exclude_orbs=exclude_orbs,
|
314
|
-
Rcut=Rcut,
|
315
|
-
ne=ne,
|
316
|
-
np=np,
|
317
|
-
use_cache=use_cache,
|
318
|
-
output_path=output_path,
|
319
|
-
description=description,
|
320
|
-
)
|
321
|
-
exchange.run(path=output_path)
|
322
|
-
print("\n")
|
323
|
-
print(f"All calculation finsihed. The results are in {output_path} directory.")
|
324
|
-
|
325
|
-
elif H.spin.is_colinear and False:
|
326
|
-
print(
|
327
|
-
"Reading Siesta hamiltonian: colinear spin. Treat as non-colinear. For testing only."
|
328
|
-
)
|
329
|
-
tbmodel = SislWrapper(H, spin="merge", geom=geom)
|
330
|
-
basis = dict(zip(tbmodel.orbs, list(range(tbmodel.nbasis))))
|
331
|
-
print("Starting to calculate exchange.")
|
332
|
-
description = f""" Input from collinear Siesta data.
|
333
|
-
working directory: {os.getcwd()}
|
334
|
-
fdf_fname: {fdf_fname}.
|
335
|
-
\n"""
|
336
|
-
exchange = ExchangeNCL(
|
337
|
-
tbmodels=tbmodel,
|
338
|
-
atoms=tbmodel.atoms,
|
339
|
-
basis=basis,
|
340
|
-
efermi=0.0,
|
341
|
-
magnetic_elements=magnetic_elements,
|
342
|
-
include_orbs=include_orbs,
|
343
|
-
kmesh=kmesh,
|
344
|
-
emin=emin,
|
345
|
-
emax=emax,
|
346
|
-
nz=nz,
|
347
|
-
exclude_orbs=exclude_orbs,
|
348
|
-
Rcut=Rcut,
|
349
|
-
ne=ne,
|
350
|
-
np=np,
|
351
|
-
use_cache=use_cache,
|
352
|
-
description=description,
|
353
|
-
output_path=output_path,
|
354
|
-
orb_decomposition=orb_decomposition,
|
355
|
-
)
|
356
|
-
exchange.run(path=output_path)
|
357
|
-
print("\n")
|
358
|
-
print(f"All calculation finsihed. The results are in {output_path} directory.")
|
359
|
-
|
360
|
-
elif H.spin.is_spinorbit or H.spin.is_noncolinear:
|
361
|
-
print("Reading Siesta hamiltonian: non-colinear spin.")
|
362
|
-
tbmodel = SislWrapper(fdf_fname=None, sisl_hamiltonian=H, spin=None, geom=geom)
|
363
|
-
basis = dict(zip(tbmodel.orbs, list(range(tbmodel.nbasis))))
|
364
|
-
print("Starting to calculate exchange.")
|
365
|
-
description = f""" Input from non-collinear Siesta data.
|
366
|
-
working directory: {os.getcwd()}
|
367
|
-
fdf_fname: {fdf_fname}.
|
368
|
-
Warning: The DMI component parallel to the spin orientation, the Jani which has the component of that orientation should be disregarded
|
369
|
-
e.g. if the spins are along z, the xz, yz, zz, zx, zy components and the z component of DMI.
|
370
|
-
If you need these component, try to do three calculations with spin along x, y, z, or use structure with z rotated to x, y and z. And then use TB2J_merge.py to get the full set of parameters.
|
371
|
-
\n"""
|
372
|
-
exchange = ExchangeNCL(
|
373
|
-
tbmodels=tbmodel,
|
374
|
-
atoms=tbmodel.atoms,
|
375
|
-
basis=basis,
|
376
|
-
efermi=0.0,
|
377
|
-
magnetic_elements=magnetic_elements,
|
378
|
-
include_orbs=include_orbs,
|
379
|
-
kmesh=kmesh,
|
380
|
-
emin=emin,
|
381
|
-
emax=emax,
|
382
|
-
nz=nz,
|
383
|
-
exclude_orbs=exclude_orbs,
|
384
|
-
Rcut=Rcut,
|
385
|
-
ne=ne,
|
386
|
-
np=np,
|
387
|
-
use_cache=use_cache,
|
388
|
-
description=description,
|
389
|
-
output_path=output_path,
|
390
|
-
orb_decomposition=orb_decomposition,
|
391
|
-
)
|
392
|
-
exchange.run(path=output_path)
|
393
|
-
print("\n")
|
394
|
-
print(f"All calculation finsihed. The results are in {output_path} directory.")
|
395
|
-
|
396
|
-
|
397
|
-
def gen_exchange_gpaw(
|
398
|
-
gpw_fname,
|
399
|
-
magnetic_elements=[],
|
400
|
-
kmesh=[3, 3, 3],
|
401
|
-
emin=-12.0,
|
402
|
-
emax=0.0,
|
403
|
-
nz=50,
|
404
|
-
exclude_orbs=[],
|
405
|
-
Rcut=None,
|
406
|
-
use_cache=False,
|
407
|
-
output_path="TB2J_results",
|
408
|
-
description="",
|
409
|
-
):
|
410
|
-
print("Reading from GPAW data and calculate electronic structure.")
|
411
|
-
model = GPAWWrapper(gpw_fname=gpw_fname)
|
412
|
-
efermi = model.calc.get_fermi_level()
|
413
|
-
print(f"Fermi Energy: {efermi}")
|
414
|
-
poses = np.vstack([model.positions, model.positions])
|
415
|
-
basis, _ = auto_assign_basis_name(
|
416
|
-
poses,
|
417
|
-
model.atoms,
|
418
|
-
write_basis_file=os.path.join(output_path, "assigned_basis.txt"),
|
419
|
-
)
|
420
|
-
|
421
|
-
if model.calc.get_spin_polarized():
|
422
|
-
print("Starting to calculate exchange.")
|
423
|
-
exchange = ExchangeNCL(
|
424
|
-
tbmodels=model,
|
425
|
-
atoms=model.atoms,
|
426
|
-
efermi=efermi,
|
427
|
-
basis=basis,
|
428
|
-
magnetic_elements=magnetic_elements,
|
429
|
-
kmesh=kmesh,
|
430
|
-
emin=emin,
|
431
|
-
emax=emax,
|
432
|
-
nz=nz,
|
433
|
-
exclude_orbs=exclude_orbs,
|
434
|
-
Rcut=Rcut,
|
435
|
-
use_cache=use_cache,
|
436
|
-
output_path=output_path,
|
437
|
-
description=description,
|
438
|
-
)
|
439
|
-
exchange.run(path=output_path)
|
440
|
-
print("\n")
|
441
|
-
print(f"All calculation finsihed. The results are in {output_path} directory.")
|
TB2J/mathutils.py
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import numpy as np
|
2
|
-
from scipy.linalg import inv, eigh
|
3
|
-
|
4
|
-
|
5
|
-
def Lowdin(S):
|
6
|
-
"""
|
7
|
-
Calculate S^(-1/2).
|
8
|
-
Which is used in lowind's symmetric orthonormalization.
|
9
|
-
psi_prime = S^(-1/2) psi
|
10
|
-
"""
|
11
|
-
eigval, eigvec = eigh(S)
|
12
|
-
return eigvec @ np.diag(np.sqrt(1.0 / eigval)) @ (eigvec.T.conj())
|
TB2J/patch.py
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
import types
|
2
|
-
from unittest import mock
|
3
|
-
|
4
|
-
class A(object):#but seems to work for old style objects too
|
5
|
-
def funcx(self,x):
|
6
|
-
print("x1=",x)
|
7
|
-
print("called from", self)
|
8
|
-
|
9
|
-
def method(self,x):
|
10
|
-
print("xmethod=",x)
|
11
|
-
print("called from", self)
|
12
|
-
|
13
|
-
def patch_me(target):
|
14
|
-
def method(target,x):
|
15
|
-
print("x=",x)
|
16
|
-
print("called from", target)
|
17
|
-
target.method = types.MethodType(method,target)
|
18
|
-
|
19
|
-
def method(self,x):
|
20
|
-
print("x=",x)
|
21
|
-
print("called from", self)
|
22
|
-
|
23
|
-
@mock.patch("__main__.A")
|
24
|
-
def funcx(self,x):
|
25
|
-
print("new x=",x)
|
26
|
-
print("called from", self)
|
27
|
-
|
28
|
-
A.method=method
|
29
|
-
#add more if needed
|
30
|
-
a = A()
|
31
|
-
print(A.__dict__)
|
32
|
-
print(a)
|
33
|
-
#out: <__main__.A object at 0x2b73ac88bfd0>
|
34
|
-
|
35
|
-
@mock.patch("__main__.a")
|
36
|
-
def funcx(self,x):
|
37
|
-
print("x=",x)
|
38
|
-
print("called from", self)
|
39
|
-
|
40
|
-
a.funcx(3)
|
41
|
-
patch_me(a) #patch instance
|
42
|
-
a.method=method
|
43
|
-
#a.method(5)
|
44
|
-
#out: x= 5
|
45
|
-
#out: called from <__main__.A object at 0x2b73ac88bfd0>
|
46
|
-
patch_me(A)
|
47
|
-
|
48
|
-
a.method(6) #can patch class too
|
49
|
-
#out: x= 6
|
50
|
-
#out: called from <class '__main__.A'>
|
TB2J/spinham/h_matrix.py
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
import numpy as np
|
2
|
-
import matplotlib.pyplot as plt
|
3
|
-
import aiida
|
4
|
-
from aiida_tb2j.data import ExchangeData
|
5
|
-
|
6
|
-
def plot_dispersion(bands, kpoint_labels, color='blue', title=None):
|
7
|
-
|
8
|
-
fig, axs = plt.subplots(1, 1, constrained_layout=True)
|
9
|
-
fig.set_size_inches(6, 6/1.618)
|
10
|
-
|
11
|
-
'''
|
12
|
-
Plot the bands
|
13
|
-
'''
|
14
|
-
kpoints = np.arange(len(bands))
|
15
|
-
axs.plot(kpoints, bands, color=color, linewidth=1.5)
|
16
|
-
|
17
|
-
'''
|
18
|
-
Plot the symmetry points
|
19
|
-
'''
|
20
|
-
bmin = bands.min(); bmax = bands.max()
|
21
|
-
ymin = bmin - 0.05*np.abs(bmin-bmax); ymax = bmax + 0.05*np.abs(bmax-bmin);
|
22
|
-
axs.set_xticks(kpoint_labels[0], kpoint_labels[1], fontsize=10)
|
23
|
-
axs.vlines(x=kpoint_labels[0], ymin=ymin, ymax=ymax, color='black', linewidth=0.5)
|
24
|
-
axs.set_xlim([0, len(kpoints)])
|
25
|
-
axs.set_ylim([ymin, ymax])
|
26
|
-
|
27
|
-
if title is not None:
|
28
|
-
plt.title(title, fontsize=10)
|
29
|
-
|
30
|
-
plt.show()
|
31
|
-
|
32
|
-
|
33
|
-
if __name__ == "__main__":
|
34
|
-
|
35
|
-
from argparse import ArgumentParser
|
36
|
-
|
37
|
-
parser = ArgumentParser()
|
38
|
-
parser.add_argument('-f', '--pickle_filename', type=str, help="Path of the 'TB2J.pickle' file.", required=True)
|
39
|
-
args = parser.parse_args()
|
40
|
-
|
41
|
-
'''
|
42
|
-
Right now the implementation depends on AiiDA and so we must create and load an AiiDA profile,
|
43
|
-
even if we do not store any information on a data base.
|
44
|
-
'''
|
45
|
-
aiida.load_profile()
|
46
|
-
'''
|
47
|
-
Create an ExchangeData object with the informations from the TB2J.pickle file
|
48
|
-
'''
|
49
|
-
exchange = ExchangeData.load_tb2j(pickle_file=args.pickle_filename, isotropic=False, pbc=(True, True, True))
|
50
|
-
'''
|
51
|
-
Compute the magnon band structure along a high symmetry path generated with
|
52
|
-
the ASE package. The informations is stored in an AiiDA BandsData object.
|
53
|
-
Here tol is the symmetry tolerance to determine the space group of the system.
|
54
|
-
They are in units of eV
|
55
|
-
'''
|
56
|
-
magnon_data = exchange.get_magnon_bands(npoints=300, tol=1e-1, with_DMI=True, with_Jani=True)
|
57
|
-
magnon_bands = 1000*magnon_data.get_bands() # Convert to meV
|
58
|
-
raw_labels = [(k, '$\Gamma$') if s == 'GAMMA' else (k, s) for k, s in magnon_data.labels]
|
59
|
-
kpoint_labels = list( zip( *raw_labels ) )
|
60
|
-
plot_dispersion(magnon_bands, kpoint_labels, color='blue', title='Magnon Bands')
|
61
|
-
'''
|
62
|
-
We can also obtain the dynamical matrix h instead of the actual magnon bands. The result
|
63
|
-
is stored in a numpy array with shape (number of kpoints, 2*natoms, 2*natoms)
|
64
|
-
'''
|
65
|
-
kpoints = magnon_data.get_kpoints() # The shape of the kpoints must be (nkpoints, 3)
|
66
|
-
h_matrix = 1000*exchange._H_matrix(kpoints, with_DMI=True, with_Jani=True) # Convert to meV
|
67
|
-
h_dispersion = np.linalg.eigvalsh(h_matrix) # We can also get the eigenvectors with np.linalg.eigh
|
68
|
-
plot_dispersion(h_dispersion, kpoint_labels, color='red', title='h matrix dispersion')
|
TB2J/spinham/obtain_J.py
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
import numpy as np
|
2
|
-
from aiida_tb2j.data import ExchangeData
|
3
|
-
from aiida_tb2j.data.exchange import get_rotation_arrays
|
4
|
-
from itertools import combinations_with_replacement
|
5
|
-
|
6
|
-
ux, uy, uz = np.eye(3).reshape((3, 1, 3))
|
7
|
-
|
8
|
-
def combine_arrays(u, v):
|
9
|
-
|
10
|
-
return np.concatenate([u*v, np.roll(u, -1, axis=-1)*v, np.roll(v, -1, axis=-1)*u], axis=-1)
|
11
|
-
|
12
|
-
def get_coefficients(magmoms, indices):
|
13
|
-
|
14
|
-
i, j = indices
|
15
|
-
|
16
|
-
U, V = zip(*[get_rotation_arrays(magmoms, u=u) for u in [ux, uy, uz]])
|
17
|
-
U = np.stack(U).swapaxes(0, 1)
|
18
|
-
V = np.stack(V).swapaxes(0, 1)
|
19
|
-
|
20
|
-
uc = combine_arrays(U[i], U[j].conj())
|
21
|
-
ur = combine_arrays(U[i], U[j])
|
22
|
-
uc2 = combine_arrays(U[i].conj(), U[j])
|
23
|
-
u = np.concatenate([uc, ur, uc2], axis=1)
|
24
|
-
|
25
|
-
return u, V
|
26
|
-
|
27
|
-
def get_C(H0, u, V):
|
28
|
-
|
29
|
-
n = int(H0.shape[-1]/2)
|
30
|
-
upi = np.triu_indices(n)
|
31
|
-
dig = np.diag_indices(n)
|
32
|
-
|
33
|
-
i, j = upi
|
34
|
-
AB0 = H0[:, [i, i, i+n], [j, j+n, j+n]]
|
35
|
-
AB0 = np.swapaxes(AB0, 0, 2).reshape(len(i), 9)
|
36
|
-
J0_flat = np.linalg.solve(u, AB0)
|
37
|
-
|
38
|
-
J0 = np.empty((n, n, 3, 3), dtype=complex)
|
39
|
-
J0[*upi] = J0_flat[:, [0, 6, 5, 3, 1, 7, 8, 4, 2]].reshape(-1, 3, 3)
|
40
|
-
J0 += J0.swapaxes(0, 1)
|
41
|
-
J0[*dig] = 0.0
|
42
|
-
|
43
|
-
C = np.array([np.diag(a) for a in np.einsum('imx,ijxy,jmy->mi', V, 2*J0, V)])
|
44
|
-
|
45
|
-
return C
|
46
|
-
|
47
|
-
def get_J(H, kpoints, exchange):
|
48
|
-
|
49
|
-
n = int(H.shape[-1]/2)
|
50
|
-
upi = np.triu_indices(n)
|
51
|
-
dig = np.diag_indices(n)
|
52
|
-
i, j = upi
|
53
|
-
|
54
|
-
magmoms = exchange.magmoms()[np.unique(exchange.pairs)]
|
55
|
-
magmoms /= np.linalg.norm(magmoms, axis=-1).reshape(-1, 1)
|
56
|
-
u, V = get_coefficients(magmoms, indices=upi)
|
57
|
-
|
58
|
-
H0 = np.stack([1000*exchange._H_matrix(kpoints=np.zeros((1, 3)), with_DMI=True, with_Jani=True, u=u) for u in [ux, uy, uz]])[:, 0, :, :]
|
59
|
-
C = get_C(H0, u, V)
|
60
|
-
H[:, :, :n, :n] += C.reshape(3, 1, n, n)
|
61
|
-
H[:, :, n:, n:] += C.reshape(3, 1, n, n)
|
62
|
-
|
63
|
-
AB = H[:, :, [i, i, i+n], [j, j+n, j+n]]
|
64
|
-
AB[:, :, 2, :] = AB[:, ::-1, 2, :]
|
65
|
-
AB = np.moveaxis(AB, [2, 3], [1, 0]).reshape(len(i), 9, -1)
|
66
|
-
|
67
|
-
vectors = exchange.get_vectors()
|
68
|
-
exp_summand = np.exp( -2j*np.pi*vectors @ kpoints.T )
|
69
|
-
nAB = np.einsum('nik,ndk->nid', AB, exp_summand) / len(kpoints)
|
70
|
-
|
71
|
-
ii = np.where(i == j)
|
72
|
-
i0 = np.where(np.linalg.norm(vectors, axis=-1) == 0.0)
|
73
|
-
J = np.linalg.solve(u, nAB).swapaxes(1, 2)
|
74
|
-
J = J[:, :, [0, 6, 5, 3, 1, 7, 8, 4, 2]].reshape(len(i), -1, 3, 3)
|
75
|
-
J *= -1
|
76
|
-
J[ii] *= 2
|
77
|
-
J[i0] *= 0
|
78
|
-
|
79
|
-
return J
|