TB2J 0.9.12.9__py3-none-any.whl → 0.9.12.22__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 +8 -1
- TB2J/MAEGreen.py +78 -61
- TB2J/contour.py +3 -2
- TB2J/exchange.py +346 -51
- TB2J/exchangeCL2.py +285 -47
- TB2J/exchange_params.py +48 -0
- TB2J/green.py +73 -36
- TB2J/interfaces/abacus/gen_exchange_abacus.py +2 -1
- TB2J/interfaces/wannier90_interface.py +4 -4
- TB2J/io_exchange/__init__.py +19 -1
- TB2J/io_exchange/edit.py +594 -0
- TB2J/io_exchange/io_espins.py +276 -0
- TB2J/io_exchange/io_exchange.py +248 -76
- TB2J/io_exchange/io_tomsasd.py +4 -3
- TB2J/io_exchange/io_txt.py +72 -7
- TB2J/io_exchange/io_vampire.py +4 -2
- TB2J/io_merge.py +60 -40
- TB2J/magnon/magnon3.py +27 -2
- TB2J/mathutils/rotate_spin.py +7 -7
- TB2J/myTB.py +11 -11
- TB2J/mycfr.py +11 -11
- TB2J/pauli.py +32 -2
- TB2J/plot.py +26 -0
- TB2J/rotate_atoms.py +9 -6
- TB2J/scripts/TB2J_edit.py +403 -0
- TB2J/scripts/TB2J_plot_exchange.py +48 -0
- TB2J/spinham/hamiltonian.py +156 -13
- TB2J/spinham/hamiltonian_terms.py +40 -1
- TB2J/spinham/spin_xml.py +40 -8
- TB2J/symmetrize_J.py +140 -9
- TB2J/tests/test_cli_remove_sublattice.py +33 -0
- TB2J/tests/test_cli_toggle_exchange.py +50 -0
- {tb2j-0.9.12.9.dist-info → tb2j-0.9.12.22.dist-info}/METADATA +10 -7
- {tb2j-0.9.12.9.dist-info → tb2j-0.9.12.22.dist-info}/RECORD +38 -34
- {tb2j-0.9.12.9.dist-info → tb2j-0.9.12.22.dist-info}/WHEEL +1 -1
- {tb2j-0.9.12.9.dist-info → tb2j-0.9.12.22.dist-info}/entry_points.txt +2 -0
- TB2J/interfaces/abacus/test_read_HRSR.py +0 -43
- TB2J/interfaces/abacus/test_read_stru.py +0 -32
- {tb2j-0.9.12.9.dist-info → tb2j-0.9.12.22.dist-info}/licenses/LICENSE +0 -0
- {tb2j-0.9.12.9.dist-info → tb2j-0.9.12.22.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _get_shell_index(cls, key):
|
|
7
|
+
"""Determine shell index based on distance grouping.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
cls : SpinIO
|
|
12
|
+
SpinIO instance
|
|
13
|
+
key : tuple
|
|
14
|
+
(R, i, j) key for exchange parameter
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
int
|
|
19
|
+
Shell index (1 for nearest neighbors, 2 for next nearest, etc.)
|
|
20
|
+
"""
|
|
21
|
+
if not hasattr(cls, "_distance_shells"):
|
|
22
|
+
# Calculate all distances and group into shells
|
|
23
|
+
distances = []
|
|
24
|
+
for k in cls.exchange_Jdict:
|
|
25
|
+
if cls.distance_dict and k in cls.distance_dict:
|
|
26
|
+
distances.append(cls.distance_dict[k][1])
|
|
27
|
+
|
|
28
|
+
if distances:
|
|
29
|
+
# Sort distances and group by rounding to nearest 0.01 Å
|
|
30
|
+
sorted_distances = sorted(set(round(d * 100) for d in distances))
|
|
31
|
+
cls._distance_shells = {}
|
|
32
|
+
for shell_idx, dist_int in enumerate(sorted_distances, 1):
|
|
33
|
+
cls._distance_shells[dist_int / 100] = shell_idx
|
|
34
|
+
else:
|
|
35
|
+
cls._distance_shells = {}
|
|
36
|
+
|
|
37
|
+
if cls.distance_dict and key in cls.distance_dict:
|
|
38
|
+
distance = cls.distance_dict[key][1]
|
|
39
|
+
rounded_dist = round(distance * 100)
|
|
40
|
+
return cls._distance_shells.get(rounded_dist / 100, 1)
|
|
41
|
+
|
|
42
|
+
return 1
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def write_espins(cls, path="TB2J_results/ESPInS"):
|
|
46
|
+
"""Write ESPInS format input files.
|
|
47
|
+
|
|
48
|
+
Parameters
|
|
49
|
+
----------
|
|
50
|
+
cls : SpinIO
|
|
51
|
+
SpinIO instance containing exchange parameters
|
|
52
|
+
path : str
|
|
53
|
+
Output directory path
|
|
54
|
+
"""
|
|
55
|
+
if not os.path.exists(path):
|
|
56
|
+
os.makedirs(path)
|
|
57
|
+
|
|
58
|
+
write_espins_input(cls, os.path.join(path, "espins.in"))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def write_espins_input(cls, fname):
|
|
62
|
+
"""Write the main ESPInS input file.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
cls : SpinIO
|
|
67
|
+
SpinIO instance
|
|
68
|
+
fname : str
|
|
69
|
+
Output filename
|
|
70
|
+
"""
|
|
71
|
+
with open(fname, "w") as myfile:
|
|
72
|
+
# Write unit cell
|
|
73
|
+
myfile.write("! ESPInS input file generated by TB2J\n")
|
|
74
|
+
# myfile.write("! Compatible with ESPInS version > 1.0 \n")
|
|
75
|
+
myfile.write("! The unit cell in angstrom\n")
|
|
76
|
+
myfile.write("Begin Unit_Cell_Cart\n")
|
|
77
|
+
cell = cls.atoms.get_cell()
|
|
78
|
+
for i in range(3):
|
|
79
|
+
myfile.write(" " + " ".join(f"{x:12.8f}" for x in cell[i]) + "\n")
|
|
80
|
+
myfile.write("End Unit_Cell_Cart\n\n")
|
|
81
|
+
|
|
82
|
+
# Write atomic positions
|
|
83
|
+
myfile.write("! Atomic positions in reduced coordinates\n")
|
|
84
|
+
myfile.write("Begin Atoms_Frac\n")
|
|
85
|
+
scaled_positions = cls.atoms.get_scaled_positions()
|
|
86
|
+
symbols = cls.atoms.get_chemical_symbols()
|
|
87
|
+
|
|
88
|
+
for i, (symbol, pos) in enumerate(zip(symbols, scaled_positions)):
|
|
89
|
+
if cls.index_spin[i] >= 0: # Only magnetic atoms
|
|
90
|
+
myfile.write(
|
|
91
|
+
f" {symbol:<8} {pos[0]:10.7f} {pos[1]:10.7f} {pos[2]:10.7f} 1.00\n"
|
|
92
|
+
)
|
|
93
|
+
myfile.write("End Atoms_Frac\n\n\n")
|
|
94
|
+
|
|
95
|
+
# Write temperature settings (default values)
|
|
96
|
+
myfile.write("tem_start = 1\n")
|
|
97
|
+
myfile.write("tem_end = 30\n")
|
|
98
|
+
myfile.write("tems_num = 30\n")
|
|
99
|
+
# myfile.write("!! tems_mode = man\n")
|
|
100
|
+
# myfile.write("!! tems = 5.00 10.00 15.00 20.00\n\n")
|
|
101
|
+
|
|
102
|
+
# Write Monte Carlo parameters (default values)
|
|
103
|
+
myfile.write("! Pt = .True.\n")
|
|
104
|
+
myfile.write("! Pt_steps_swap = 40\n\n")
|
|
105
|
+
|
|
106
|
+
myfile.write("steps_warmup = 100000\n")
|
|
107
|
+
myfile.write("steps_mc = 100000\n")
|
|
108
|
+
myfile.write("steps_measure = 2\n\n")
|
|
109
|
+
|
|
110
|
+
myfile.write("initial_sconfig = ferro\n")
|
|
111
|
+
myfile.write("mcarlo_mode = random\n\n")
|
|
112
|
+
|
|
113
|
+
myfile.write("supercell_size = 10 10 1\n\n")
|
|
114
|
+
|
|
115
|
+
# Write Hamiltonian settings
|
|
116
|
+
myfile.write(" ## Hamiltonian\n")
|
|
117
|
+
myfile.write("Ham_bij = .False.\n")
|
|
118
|
+
myfile.write("Ham_jij_matrix = .True.\n")
|
|
119
|
+
myfile.write("! We don't have single ion anisotropy, put it to .False.\n")
|
|
120
|
+
myfile.write("Ham_singleion_matrix = .False.\n\n\n")
|
|
121
|
+
|
|
122
|
+
# Write single ion anisotropy matrix if available
|
|
123
|
+
# if cls.has_uniaxial_anistropy:
|
|
124
|
+
# myfile.write("! Don't put this block\n")
|
|
125
|
+
# myfile.write("!Begin SingleIon_Matrix\n")
|
|
126
|
+
# # Placeholder for single ion anisotropy
|
|
127
|
+
# myfile.write("@Axx=0.000 , Axy=-1.65e-07 , Axz=6e-08 , Ayx=-1.65e-07 , Ayy=7.73e-05 , Ayz=-1.5e-05 , Azx=6e-08 , Azz= 6.8e-05\n")
|
|
128
|
+
# myfile.write("!End SingleIon_Matrix\n\n")
|
|
129
|
+
|
|
130
|
+
# Write exchange parameters
|
|
131
|
+
myfile.write(
|
|
132
|
+
"""! f1 is the fractional coordinate of atom i, and f2 is of atom j (rj+Rj). Then jij in eV, sh is index of shell, t1 is index of i, t2 is index of j (counting from 1). \n
|
|
133
|
+
!The convention of the Hamiltonian is H = - sum_<ij> Jij Si Sj, and i, j are ordererd so that there is no double counting (ij and ji). To convert from TB2J exchange.out (which has both ij and ji), multiply Jij by 2. \n
|
|
134
|
+
\n"""
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
if cls.has_exchange:
|
|
138
|
+
myfile.write("Begin Jij_parameters\n")
|
|
139
|
+
|
|
140
|
+
# Create a list of unique exchange parameters sorted by distance
|
|
141
|
+
exchange_list = []
|
|
142
|
+
# written_keys = set()
|
|
143
|
+
|
|
144
|
+
for key, jval in cls.exchange_Jdict.items():
|
|
145
|
+
R, i, j = key
|
|
146
|
+
|
|
147
|
+
# Skip if this is the symmetric counterpart of an already written pair
|
|
148
|
+
# symmetric_key = (tuple(-np.array(R)), j, i)
|
|
149
|
+
# if symmetric_key in written_keys:
|
|
150
|
+
# continue
|
|
151
|
+
|
|
152
|
+
# Get distance for sorting
|
|
153
|
+
distance = (
|
|
154
|
+
cls.distance_dict[key][1]
|
|
155
|
+
if cls.distance_dict and key in cls.distance_dict
|
|
156
|
+
else 0.0
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
exchange_list.append((distance, key, jval))
|
|
160
|
+
# written_keys.add(key)
|
|
161
|
+
|
|
162
|
+
# Sort by distance
|
|
163
|
+
exchange_list.sort(key=lambda x: x[0])
|
|
164
|
+
|
|
165
|
+
for distance, key, jval in exchange_list:
|
|
166
|
+
R, i, j = key
|
|
167
|
+
iatom = cls.iatom(i)
|
|
168
|
+
jatom = cls.iatom(j)
|
|
169
|
+
|
|
170
|
+
# Get fractional coordinates
|
|
171
|
+
pos_i = cls.atoms.get_scaled_positions()[iatom]
|
|
172
|
+
pos_j = cls.atoms.get_scaled_positions()[jatom]
|
|
173
|
+
|
|
174
|
+
# Calculate fractional coordinates for j+R
|
|
175
|
+
pos_jR = pos_j + R
|
|
176
|
+
# Determine shell index based on distance
|
|
177
|
+
shell = _get_shell_index(cls, key)
|
|
178
|
+
|
|
179
|
+
myfile.write(
|
|
180
|
+
f" f1= {pos_i[0]:10.6f}, {pos_i[1]:10.6f}, {pos_i[2]:10.6f}:f2= {pos_jR[0]:10.6f}, {pos_jR[1]:10.6f}, {pos_jR[2]:10.6f}:jij= {jval*2:10.8f}!:sh= {shell}!:t1= {i+1}:t2= {j+1}\n"
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
myfile.write("End Jij_parameters\n\n")
|
|
184
|
+
|
|
185
|
+
# Write exchange matrix if available
|
|
186
|
+
if cls.has_exchange:
|
|
187
|
+
myfile.write(
|
|
188
|
+
"! Each matrix element is corresponding to the previous block. The J tensor include the isotropic, anisotropic exchange and DMI. \n"
|
|
189
|
+
)
|
|
190
|
+
myfile.write("Begin Jij_matrix\n")
|
|
191
|
+
|
|
192
|
+
# Create a list of unique exchange parameters sorted by distance
|
|
193
|
+
exchange_list = []
|
|
194
|
+
# written_keys = set()
|
|
195
|
+
|
|
196
|
+
for key in cls.exchange_Jdict:
|
|
197
|
+
R, i, j = key
|
|
198
|
+
|
|
199
|
+
# Skip if this is the symmetric counterpart of an already written pair
|
|
200
|
+
# symmetric_key = (tuple(-np.array(R)), j, i)
|
|
201
|
+
# if symmetric_key in written_keys:
|
|
202
|
+
# continue
|
|
203
|
+
|
|
204
|
+
# Get distance for sorting
|
|
205
|
+
distance = (
|
|
206
|
+
cls.distance_dict[key][1]
|
|
207
|
+
if cls.distance_dict and key in cls.distance_dict
|
|
208
|
+
else 0.0
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
exchange_list.append((distance, key))
|
|
212
|
+
# written_keys.add(key)
|
|
213
|
+
|
|
214
|
+
# Sort by distance
|
|
215
|
+
exchange_list.sort(key=lambda x: x[0])
|
|
216
|
+
|
|
217
|
+
for distance, key in exchange_list:
|
|
218
|
+
R, i, j = key
|
|
219
|
+
# Get full J tensor
|
|
220
|
+
J_tensor = cls.get_J_tensor(i, j, R, Jiso=True, Jani=True, DMI=True) * 2
|
|
221
|
+
|
|
222
|
+
# Format matrix elements exactly as in the example
|
|
223
|
+
myfile.write(
|
|
224
|
+
f"Jxx={J_tensor[0, 0]:.8f}, Jxy={J_tensor[0, 1]:.8f}, Jxz={J_tensor[0, 2]:.8f}, Jyx={J_tensor[1, 0]:.8f}, Jyy={J_tensor[1, 1]:.8f}, Jyz={J_tensor[1, 2]:.8f}, Jzx={J_tensor[2, 0]:.8f}, Jzy={J_tensor[2, 1]:.8f}, Jzz={J_tensor[2, 2]:.8f}\n"
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
myfile.write("End Jij_matrix\n\n")
|
|
228
|
+
|
|
229
|
+
# Write biquadratic exchange if available
|
|
230
|
+
# if cls.has_biquadratic and cls.biquadratic_Jdict:
|
|
231
|
+
if False:
|
|
232
|
+
myfile.write("! Biquadratic, don't put it. \n")
|
|
233
|
+
myfile.write("Begin Bij_parameters\n")
|
|
234
|
+
|
|
235
|
+
# Create a list of unique biquadratic parameters sorted by distance
|
|
236
|
+
biquadratic_list = []
|
|
237
|
+
written_keys = set()
|
|
238
|
+
|
|
239
|
+
for key, bval in cls.biquadratic_Jdict.items():
|
|
240
|
+
R, i, j = key
|
|
241
|
+
|
|
242
|
+
# Skip if this is the symmetric counterpart of an already written pair
|
|
243
|
+
symmetric_key = (tuple(-np.array(R)), j, i)
|
|
244
|
+
if symmetric_key in written_keys:
|
|
245
|
+
continue
|
|
246
|
+
|
|
247
|
+
# Get distance for sorting
|
|
248
|
+
distance = (
|
|
249
|
+
cls.distance_dict[key][1]
|
|
250
|
+
if cls.distance_dict and key in cls.distance_dict
|
|
251
|
+
else 0.0
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
biquadratic_list.append((distance, key, bval))
|
|
255
|
+
written_keys.add(key)
|
|
256
|
+
|
|
257
|
+
# Sort by distance
|
|
258
|
+
biquadratic_list.sort(key=lambda x: x[0])
|
|
259
|
+
|
|
260
|
+
for distance, key, bval in biquadratic_list:
|
|
261
|
+
R, i, j = key
|
|
262
|
+
iatom = cls.iatom(i)
|
|
263
|
+
jatom = cls.iatom(j)
|
|
264
|
+
|
|
265
|
+
# Get fractional coordinates
|
|
266
|
+
pos_i = cls.atoms.get_scaled_positions()[iatom]
|
|
267
|
+
pos_j = cls.atoms.get_scaled_positions()[jatom]
|
|
268
|
+
|
|
269
|
+
# Calculate fractional coordinates for j+R
|
|
270
|
+
pos_jR = pos_j + np.dot(R, np.linalg.inv(cls.atoms.get_cell()))
|
|
271
|
+
|
|
272
|
+
myfile.write(
|
|
273
|
+
f" f1= {pos_i[0]:10.6f}, {pos_i[1]:10.6f}, {pos_i[2]:10.6f}:f2= {pos_jR[0]:10.6f}, {pos_jR[1]:10.6f}, {pos_jR[2]:10.6f}:bij= {bval:10.6f} !t1= {i+1}:t2= {j+1}\n"
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
myfile.write("End Bij_parameters\n")
|