Skip to content

Commit

Permalink
Warning message for underdetermined equations
Browse files Browse the repository at this point in the history
  • Loading branch information
antelmor committed Apr 10, 2024
1 parent 7594cec commit 2ee9760
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion TB2J/io_merge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import copy
import warnings
import numpy as np
from itertools import combinations_with_replacement, product
from TB2J.io_exchange import SpinIO
Expand Down Expand Up @@ -106,6 +107,14 @@ def _set_projv(self):
coeff_matrix[key] = np.vstack(coefficients)
proju[key] = np.stack(u)
projv[key] = np.stack(v)
if np.linalg.matrix_rank(coeff_matrix[key], tol=1e-2) < 6:
warnings.warn('''
WARNING: The matrix of equations to reconstruct the exchange tensors is
close to being singular. This happens when the magnetic moments between
different configurations are cloes to being parallel. You need to consider
more rotated spin configurations, otherwise the results might have a large
error.'''
)

self.proju = proju
self.projv = projv
Expand All @@ -126,7 +135,7 @@ def merge_Jani(self):
raise KeyError(
"Can not find key: %s, Please make sure the three calculations use the same k-mesh and same Rcut."
% err)
newJani = np.linalg.lstsq(coeff_matrix[i, j], projections, rcond=4e-1)[0]
newJani = np.linalg.lstsq(coeff_matrix[i, j], projections, rcond=1e-2)[0]
Jani_dict[key] = np.array([
[newJani[0], newJani[3], newJani[5]],
[newJani[3], newJani[1], newJani[4]],
Expand Down

0 comments on commit 2ee9760

Please sign in to comment.