TB2J 0.9.9rc14__py3-none-any.whl → 0.9.9rc17__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/exchange.py +83 -65
- TB2J/exchange_params.py +24 -0
- TB2J/io_exchange/__init__.py +2 -0
- TB2J/magnon/__init__.py +3 -0
- TB2J/magnon/io_exchange2.py +688 -0
- TB2J/magnon/plot.py +58 -0
- TB2J/magnon/structure.py +348 -0
- TB2J/mathutils/__init__.py +1 -0
- TB2J/mathutils/magnons.py +45 -0
- TB2J/rotate_siestaDM.py +11 -9
- tb2j-0.9.9rc17.data/scripts/TB2J_magnon2.py +77 -0
- tb2j-0.9.9rc17.data/scripts/abacus2J.py +62 -0
- tb2j-0.9.9rc17.data/scripts/siesta2J.py +78 -0
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/wann2J.py +6 -1
- {tb2j-0.9.9rc14.dist-info → tb2j-0.9.9rc17.dist-info}/METADATA +2 -1
- {tb2j-0.9.9rc14.dist-info → tb2j-0.9.9rc17.dist-info}/RECORD +27 -21
- {tb2j-0.9.9rc14.dist-info → tb2j-0.9.9rc17.dist-info}/WHEEL +1 -1
- tb2j-0.9.9rc14.data/scripts/abacus2J.py +0 -146
- tb2j-0.9.9rc14.data/scripts/siesta2J.py +0 -163
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/TB2J_downfold.py +0 -0
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/TB2J_eigen.py +0 -0
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/TB2J_magnon.py +0 -0
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/TB2J_magnon_dos.py +0 -0
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/TB2J_merge.py +0 -0
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/TB2J_rotate.py +0 -0
- {tb2j-0.9.9rc14.data → tb2j-0.9.9rc17.data}/scripts/TB2J_rotateDM.py +0 -0
- {tb2j-0.9.9rc14.dist-info → tb2j-0.9.9rc17.dist-info}/entry_points.txt +0 -0
- {tb2j-0.9.9rc14.dist-info → tb2j-0.9.9rc17.dist-info}/licenses/LICENSE +0 -0
- {tb2j-0.9.9rc14.dist-info → tb2j-0.9.9rc17.dist-info}/top_level.txt +0 -0
TB2J/exchange.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
import pickle
|
3
|
-
from collections import
|
3
|
+
from collections import defaultdict
|
4
4
|
|
5
5
|
import numpy as np
|
6
6
|
from tqdm import tqdm
|
@@ -96,78 +96,96 @@ class Exchange(ExchangeParams):
|
|
96
96
|
|
97
97
|
def _prepare_orb_dict(self):
|
98
98
|
"""
|
99
|
-
|
100
|
-
"""
|
101
|
-
# adict: dictionary of {'Fe': ['dxy', 'dyz', ...], ...}
|
102
|
-
adict = OrderedDict()
|
103
|
-
# orb_dict: {ind_atom:[ind_orb,1,2], ...}
|
104
|
-
self.orb_dict = {}
|
105
|
-
# labels: {0:{dxy, ...}}
|
106
|
-
self.labels = {}
|
107
|
-
# magnetic atoms index
|
108
|
-
self.ind_mag_atoms = []
|
109
|
-
|
110
|
-
sdict = symbol_number(self.atoms)
|
111
|
-
|
112
|
-
for i, base in enumerate(self.basis):
|
113
|
-
if i not in self.exclude_orbs:
|
114
|
-
# e.g. Fe2, dxy, _, _
|
115
|
-
if isinstance(base, str):
|
116
|
-
atom_sym, orb_sym = base.split("|")[:2]
|
117
|
-
iatom = sdict[atom_sym]
|
118
|
-
else:
|
119
|
-
try:
|
120
|
-
atom_sym, orb_sym = base[:2]
|
121
|
-
iatom = sdict[atom_sym]
|
122
|
-
except Exception:
|
123
|
-
iatom = base.iatom
|
124
|
-
atom_sym = base.iatom
|
125
|
-
orb_sym = base.sym
|
126
|
-
|
127
|
-
if atom_sym in adict:
|
128
|
-
adict[atom_sym].append(orb_sym)
|
129
|
-
else:
|
130
|
-
adict[atom_sym] = [orb_sym]
|
131
|
-
if iatom not in self.orb_dict:
|
132
|
-
self.orb_dict[iatom] = [i]
|
133
|
-
self.labels[iatom] = [orb_sym]
|
134
|
-
else:
|
135
|
-
self.orb_dict[iatom] += [i]
|
136
|
-
self.labels[iatom] += [orb_sym]
|
99
|
+
Generate orbital and magnetic atom mappings needed for exchange calculations.
|
137
100
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
101
|
+
Creates:
|
102
|
+
- self.orb_dict: Maps atom indices to their orbital indices
|
103
|
+
- self.labels: Maps atom indices to their orbital labels
|
104
|
+
- self.ind_mag_atoms: List of indices of magnetic atoms
|
105
|
+
- self._spin_dict: Maps atom indices to spin indices
|
106
|
+
- self._atom_dict: Maps spin indices back to atom indices
|
107
|
+
"""
|
108
|
+
self._create_orbital_mappings()
|
109
|
+
self._identify_magnetic_atoms()
|
110
|
+
self._validate_orbital_assignments()
|
111
|
+
self._create_spin_mappings()
|
112
|
+
self._prepare_orb_mmat()
|
144
113
|
|
145
|
-
|
146
|
-
|
147
|
-
|
114
|
+
def _create_orbital_mappings(self):
|
115
|
+
"""Create mappings between atoms and their orbitals."""
|
116
|
+
self.orb_dict = {} # {atom_index: [orbital_indices]}
|
117
|
+
self.labels = {} # {atom_index: [orbital_labels]}
|
118
|
+
atom_symbols = symbol_number(self.atoms)
|
119
|
+
|
120
|
+
for orb_idx, base in enumerate(self.basis):
|
121
|
+
if orb_idx in self.exclude_orbs:
|
122
|
+
continue
|
123
|
+
|
124
|
+
# Extract atom and orbital info
|
125
|
+
if isinstance(base, str):
|
126
|
+
atom_sym, orb_sym = base.split("|")[:2]
|
127
|
+
atom_idx = atom_symbols[atom_sym]
|
128
|
+
else:
|
129
|
+
try:
|
130
|
+
atom_sym, orb_sym = base[:2]
|
131
|
+
atom_idx = atom_symbols[atom_sym]
|
132
|
+
except Exception:
|
133
|
+
atom_idx = base.iatom
|
134
|
+
atom_sym = base.iatom
|
135
|
+
orb_sym = base.sym
|
136
|
+
|
137
|
+
# Update orbital mappings
|
138
|
+
if atom_idx not in self.orb_dict:
|
139
|
+
self.orb_dict[atom_idx] = [orb_idx]
|
140
|
+
self.labels[atom_idx] = [orb_sym]
|
141
|
+
else:
|
142
|
+
self.orb_dict[atom_idx].append(orb_idx)
|
143
|
+
self.labels[atom_idx].append(orb_sym)
|
144
|
+
|
145
|
+
def _identify_magnetic_atoms(self):
|
146
|
+
"""Identify which atoms are magnetic based on elements/tags."""
|
147
|
+
if self.index_magnetic_atoms is not None:
|
148
|
+
self.ind_mag_atoms = self.index_magnetic_atoms
|
149
|
+
else:
|
150
|
+
self.ind_mag_atoms = []
|
151
|
+
symbols = self.atoms.get_chemical_symbols()
|
152
|
+
tags = self.atoms.get_tags()
|
153
|
+
|
154
|
+
for atom_idx, (sym, tag) in enumerate(zip(symbols, tags)):
|
155
|
+
if (
|
156
|
+
sym in self.magnetic_elements
|
157
|
+
or f"{sym}{tag}" in self.magnetic_elements
|
158
|
+
):
|
159
|
+
self.ind_mag_atoms.append(atom_idx)
|
160
|
+
print(f"Magnetic atoms: {self.ind_mag_atoms}")
|
161
|
+
|
162
|
+
def _validate_orbital_assignments(self):
|
163
|
+
"""Validate that magnetic atoms have proper orbital assignments."""
|
164
|
+
# Check all magnetic atoms have orbitals
|
165
|
+
for atom_idx in self.ind_mag_atoms:
|
166
|
+
if atom_idx not in self.orb_dict:
|
148
167
|
raise ValueError(
|
149
|
-
f"
|
168
|
+
f"Atom {atom_idx} is magnetic but has no orbitals assigned. "
|
169
|
+
"Check Wannier function definitions."
|
150
170
|
)
|
171
|
+
|
172
|
+
# For non-collinear case, check spin-orbital pairing
|
151
173
|
if not self._is_collinear:
|
152
|
-
for
|
153
|
-
|
154
|
-
nsorb = len(self.orb_dict[iatom])
|
155
|
-
if nsorb % 2 != 0 and False:
|
174
|
+
for atom_idx, orbitals in self.orb_dict.items():
|
175
|
+
if len(orbitals) % 2 != 0:
|
156
176
|
raise ValueError(
|
157
|
-
f"
|
158
|
-
|
159
|
-
which means the spin up/down does not have same number of orbitals.
|
160
|
-
This is often because the Wannier functions are wrongly defined,
|
161
|
-
or badly localized. Please check the Wannier centers in the Wannier90 output file.
|
162
|
-
"""
|
177
|
+
f"Atom {atom_idx} has {len(orbitals)} spin-orbitals "
|
178
|
+
"(should be even). Check Wannier function localization."
|
163
179
|
)
|
164
|
-
self._spin_dict = {}
|
165
|
-
self._atom_dict = {}
|
166
|
-
for ispin, iatom in enumerate(self.ind_mag_atoms):
|
167
|
-
self._spin_dict[iatom] = ispin
|
168
|
-
self._atom_dict[ispin] = iatom
|
169
180
|
|
170
|
-
|
181
|
+
def _create_spin_mappings(self):
|
182
|
+
"""Create mappings between atom indices and spin indices."""
|
183
|
+
self._spin_dict = {} # {atom_index: spin_index}
|
184
|
+
self._atom_dict = {} # {spin_index: atom_index}
|
185
|
+
|
186
|
+
for spin_idx, atom_idx in enumerate(self.ind_mag_atoms):
|
187
|
+
self._spin_dict[atom_idx] = spin_idx
|
188
|
+
self._atom_dict[spin_idx] = atom_idx
|
171
189
|
|
172
190
|
def _prepare_orb_mmat(self):
|
173
191
|
self.mmats = {}
|
TB2J/exchange_params.py
CHANGED
@@ -15,6 +15,7 @@ class ExchangeParams:
|
|
15
15
|
efermi: float
|
16
16
|
basis = []
|
17
17
|
magnetic_elements = []
|
18
|
+
index_magnetic_atoms = None
|
18
19
|
include_orbs = {}
|
19
20
|
_kmesh = [4, 4, 4]
|
20
21
|
emin: float = -15
|
@@ -55,6 +56,7 @@ class ExchangeParams:
|
|
55
56
|
mae_angles=None,
|
56
57
|
orth=False,
|
57
58
|
ibz=False,
|
59
|
+
index_magnetic_atoms=None,
|
58
60
|
):
|
59
61
|
self.efermi = efermi
|
60
62
|
self.basis = basis
|
@@ -79,6 +81,7 @@ class ExchangeParams:
|
|
79
81
|
self.mae_angles = mae_angles
|
80
82
|
self.orth = orth
|
81
83
|
self.ibz = ibz
|
84
|
+
self.index_magnetic_atoms = index_magnetic_atoms
|
82
85
|
|
83
86
|
def set_params(self, **kwargs):
|
84
87
|
for key, val in kwargs.items():
|
@@ -229,10 +232,30 @@ def add_exchange_args_to_parser(parser: argparse.ArgumentParser):
|
|
229
232
|
default=False,
|
230
233
|
)
|
231
234
|
|
235
|
+
parser.add_argument(
|
236
|
+
"--mae_angles",
|
237
|
+
help="angles for computing MAE, default is 0 0 0",
|
238
|
+
type=float,
|
239
|
+
nargs="*",
|
240
|
+
default=[0.0, 0.0, 0.0],
|
241
|
+
)
|
242
|
+
parser.add_argument(
|
243
|
+
"--index_magnetic_atoms",
|
244
|
+
help="index of magnetic atoms in the unit cell, default is None. If specified, this will be used to determine the atoms to be considered as magnetic atoms, instead of determined from magnetic elements. Note that the index starts from 1 ",
|
245
|
+
type=int,
|
246
|
+
nargs="*",
|
247
|
+
default=None,
|
248
|
+
)
|
249
|
+
|
232
250
|
return parser
|
233
251
|
|
234
252
|
|
235
253
|
def parser_argument_to_dict(args) -> dict:
|
254
|
+
ind_mag_atoms = args.index_magnetic_atoms
|
255
|
+
if ind_mag_atoms is not None:
|
256
|
+
ind_mag_atoms = [int(i) - 1 for i in ind_mag_atoms]
|
257
|
+
else:
|
258
|
+
ind_mag_atoms = None
|
236
259
|
return {
|
237
260
|
"efermi": args.efermi,
|
238
261
|
"magnetic_elements": args.elements,
|
@@ -250,4 +273,5 @@ def parser_argument_to_dict(args) -> dict:
|
|
250
273
|
"orb_decomposition": args.orb_decomposition,
|
251
274
|
"output_path": args.output_path,
|
252
275
|
"orth": args.orth,
|
276
|
+
"index_magnetic_atoms": ind_mag_atoms,
|
253
277
|
}
|
TB2J/io_exchange/__init__.py
CHANGED
TB2J/magnon/__init__.py
ADDED