def test_sparse_orbital_transform_nonortho_so(): M = SparseOrbitalBZSpin(geom.graphene(), spin='so', orthogonal=False) a = np.arange(M.spin.size + 1) + 0.3 M.construct(([0.1, 1.44], [a, a + 0.1])) M.finalize() Mcsr = [M.tocsr(i) for i in range(M.shape[2])] Mt = M.transform(spin='unpolarized') assert np.abs(0.5 * Mcsr[0] + 0.5 * Mcsr[1] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0 Mt = M.transform(spin='polarized') assert np.abs(Mcsr[0] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[1] - Mt.tocsr(1)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0 Mt = M.transform(spin='non-colinear') assert np.abs(Mcsr[0] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[1] - Mt.tocsr(1)).sum() == 0 assert np.abs(Mcsr[2] - Mt.tocsr(2)).sum() == 0 assert np.abs(Mcsr[3] - Mt.tocsr(3)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0 Mt = M.transform(spin='so') assert np.abs(Mcsr[0] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[1] - Mt.tocsr(1)).sum() == 0 assert np.abs(Mcsr[2] - Mt.tocsr(2)).sum() == 0 assert np.abs(Mcsr[3] - Mt.tocsr(3)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0
def test_sparse_orbital_bz_spin_orbit(): M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('SO')) M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]])) new = (M + M.transpose(True)) / 2 assert np.abs((M - new)._csr._D).sum() == 0
def test_sparse_orbital_bz_spin_orbit_warns_hermitian(): M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('SO')) with pytest.warns(SislWarning, match='Hermitian'): M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]]))
def test_sparse_orbital_transform_fail(): M = SparseOrbitalBZSpin(geom.graphene(), spin='polarized', orthogonal=False, dtype=np.int32) M.construct(([0.1, 1.44], [(1, 2, 3), (4, 5, 6)])) M.finalize() with pytest.raises(ValueError): M.transform(np.zeros([2, 2]), spin='unpolarized')
def test_sparse_orbital_bz_non_colinear(): M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC')) M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]])) MT = M.transpose() MH = M.transpose(True) assert np.abs((M - MT)._csr._D).sum() != 0 assert np.abs((M - MH)._csr._D).sum() != 0 assert np.abs((MT - MH)._csr._D).sum() != 0
def test_sparse_orbital_bz_spin_orbit(): M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('SO')) M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]])) MT = M.transpose() MH = M.transpose(True) assert np.abs((M - MT)._csr._D).sum() != 0 assert np.abs((M - MH)._csr._D).sum() != 0 assert np.abs((MT - MH)._csr._D).sum() != 0
def test_sparse_orbital_transform_basis(): M = SparseOrbitalBZSpin(geom.graphene(), spin='polarized', orthogonal=False) M.construct(([0.1, 1.44], [(3., 2., 1.), (0.3, 0.2, 0.)])) M.finalize() Mcsr = [M.tocsr(i) for i in range(M.shape[2])] Mt = M.transform(orthogonal=True).transform(orthogonal=False) assert M.dim == Mt.dim assert np.abs(Mcsr[0] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[1] - Mt.tocsr(1)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0
def test_sparse_orbital_bz_non_colinear(): M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC')) M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]])) MT = M.transpose() MH = M.transpose(True) assert np.abs((M - MT)._csr._D).sum() != 0 # For a non-collinear with construct we don't take # into account the imaginary parts... :( # This should be fixed assert np.abs((M - MH)._csr._D).sum() == 0 assert np.abs((MT - MH)._csr._D).sum() != 0
def test_sparse_orbital_bz_non_colinear_trs_kramers_theorem(): M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC')) M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]])) M = (M + M.transpose(True)) * 0.5 MTRS = (M + M.trs()) * 0.5 # This will in principle also work for M since the above parameters preserve # TRS k = np.array([0.1, 0.1, 0]) eig1 = MTRS.eigh(k=k) eig2 = MTRS.eigh(k=-k) assert np.allclose(eig1, eig2)
def test_sparse_orbital_bz_non_colinear(): M = SparseOrbitalBZSpin(geom.graphene(), spin=Spin('NC')) M.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]])) M.finalize() MT = M.transpose() MH = M.transpose(True) assert np.abs((M - MT)._csr._D).sum() != 0 # For a non-collinear with construct we don't take # into account the imaginary parts... :( # Transposing and Hermitian transpose are the same for NC # There are only 1 imaginary part which will change sign regardless assert np.abs((MT - MH)._csr._D).sum() != 0 assert np.abs((M - MH)._csr._D).sum() == 0
def test_sparse_orbital_transform_matrix(): M = SparseOrbitalBZSpin(geom.graphene(), spin='polarized', orthogonal=False, dtype=np.int32) M.construct(([0.1, 1.44], [(1, 2, 3), (4, 5, 6)])) M.finalize() Mcsr = [M.tocsr(i) for i in range(M.shape[2])] Mt = M.transform(spin='unpolarized', matrix=np.ones((1, 3)), orthogonal=True) assert Mt.dim == 1 assert np.abs(Mcsr[0] + Mcsr[1] + Mcsr[2] - Mt.tocsr(0)).sum() == 0 Mt = M.transform(spin='polarized', matrix=np.ones((2, 3)), orthogonal=True) assert Mt.dim == 2 assert np.abs(Mcsr[0] + Mcsr[1] + Mcsr[2] - Mt.tocsr(1)).sum() == 0 Mt = M.transform(matrix=np.ones((3, 3)), dtype=np.float64) assert Mt.dim == 3 assert np.abs(Mcsr[0] + Mcsr[1] + Mcsr[2] - Mt.tocsr(2)).sum() == 0 Mt = M.transform(spin='non-colinear', matrix=np.ones((4, 3)), orthogonal=True, dtype=np.float64) assert Mt.dim == 4 assert np.abs(Mcsr[0] + Mcsr[1] + Mcsr[2] - Mt.tocsr(3)).sum() == 0 Mt = M.transform(spin='non-colinear', matrix=np.ones((5, 3)), dtype=np.float64) assert Mt.dim == 5 assert np.abs(Mcsr[0] + Mcsr[1] + Mcsr[2] - Mt.tocsr(4)).sum() == 0 Mt = M.transform(spin='so', matrix=np.ones((8, 3)), orthogonal=True, dtype=np.float64) assert Mt.dim == 8 assert np.abs(Mcsr[0] + Mcsr[1] + Mcsr[2] - Mt.tocsr(7)).sum() == 0 Mt = M.transform(spin='so', matrix=np.ones((9, 3)), dtype=np.float64) assert Mt.dim == 9 assert np.abs(Mcsr[0] + Mcsr[1] + Mcsr[2] - Mt.tocsr(8)).sum() == 0
def test_sparse_orbital_transform_combinations(): M = SparseOrbitalBZSpin(geom.graphene(), spin='polarized', orthogonal=False, dtype=np.int32) M.construct(([0.1, 1.44], [(3, 2, 1), (2, 1, 0)])) M.finalize() Mcsr = [M.tocsr(i) for i in range(M.shape[2])] Mt = M.transform(spin='non-colinear', dtype=np.float64, orthogonal=True).transform(spin='polarized', orthogonal=False) assert M.dim == Mt.dim assert np.abs(Mcsr[0] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[1] - Mt.tocsr(1)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0 Mt = M.transform(dtype=np.float128, orthogonal=True).transform(spin='so', dtype=np.float64, orthogonal=False) assert np.abs(Mcsr[0] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[1] - Mt.tocsr(1)).sum() == 0 assert np.abs(Mt.tocsr(2)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0 Mt = M.transform(spin='polarized', orthogonal=True).transform(spin='so', dtype=np.float64, orthogonal=False) assert np.abs(Mcsr[0] - Mt.tocsr(0)).sum() == 0 assert np.abs(Mcsr[1] - Mt.tocsr(1)).sum() == 0 assert np.abs(Mt.tocsr(2)).sum() == 0 assert np.abs(Mcsr[-1] - Mt.tocsr(-1)).sum() == 0 Mt = M.transform(spin='unpolarized', dtype=np.float32, orthogonal=True).transform(dtype=np.complex128, orthogonal=False) assert np.abs(0.5 * Mcsr[0] + 0.5 * Mcsr[1] - Mt.tocsr(0)).sum() == 0