示例#1
0
def test_get_order(rotation_matrix, translation_vector, repr_matrix,
                   repr_has_cc, result, numeric):
    """
    Check that the ``get_order`` method matches the expected result.
    """
    sym_op = sr.SymmetryOperation(rotation_matrix=rotation_matrix,
                                  translation_vector=translation_vector,
                                  repr_matrix=repr_matrix,
                                  repr_has_cc=repr_has_cc,
                                  numeric=numeric)
    assert sym_op.get_order() == result
示例#2
0
def test_get_order_invalid(numeric):
    """
    Check that the ``get_order`` method raises an error when the symmetry
    operations are invalid (have no power that is the identity).
    """
    sym_op = sr.SymmetryOperation(rotation_matrix=[[1, 1], [0, 1]],
                                  translation_vector=None,
                                  repr_matrix=sp.eye(2, 2),
                                  repr_has_cc=True,
                                  numeric=numeric)
    with pytest.raises(ValueError):
        sym_op.get_order()
示例#3
0
from sympy.physics.quantum import TensorProduct
import symmetry_representation as sr

import kdotp_symmetry as kp

kx, ky, kz = sp.symbols('kx, ky, kz')
PAULI_VEC = [sp.eye(2), *(sm.msigma(i) for i in range(1, 4))]


@pytest.mark.parametrize(
    'symmetry_operations,expr_basis,repr_basis,result', [
        (
            [
                sr.SymmetryOperation(
                    rotation_matrix=[[0, 1, 0], [1, 0, 0], [0, 0, 1]],
                    repr_matrix=[[0, 1], [1, 0]],
                    repr_has_cc=False,
                    numeric=False
                )
            ], kp.monomial_basis(0), 'auto',
            [Matrix([[1, 0], [0, 1]]),
             Matrix([[0, 1], [1, 0]])]
        ), (
            [
                sr.SymmetryOperation(
                    rotation_matrix=[[0, 1, 0], [1, 0, 0], [0, 0, 1]],
                    repr_matrix=[[0, 1], [1, 0]],
                    repr_has_cc=False,
                    numeric=False
                )
            ], kp.monomial_basis(1), 'auto', [
                Matrix([[kx, 0], [0, ky]]),
示例#4
0
                    15,
                )
        else:  # case of inversion (does not do anything to spin)
            spin = D12(0, 0, 0, 0)
    return np.array(spin)


if __name__ == "__main__":
    # For this example we already changed the order of the orbitals (unlike the
    # other symmetrization example).
    model_nosym = tb.Model.from_hdf5_file("data/model_nosym.hdf5")

    # set up symmetry operations
    time_reversal = sr.SymmetryOperation(
        rotation_matrix=np.eye(3),
        repr_matrix=np.kron([[0, -1j], [1j, 0]], np.eye(7)),
        repr_has_cc=True,
    )

    structure = mg.Structure(
        lattice=model_nosym.uc,
        species=["In", "As"],
        coords=np.array([[0, 0, 0], [0.25, 0.25, 0.25]]),
    )

    # get real-space representations
    analyzer = mg.symmetry.analyzer.SpacegroupAnalyzer(structure)
    symops = analyzer.get_symmetry_operations(cartesian=False)
    symops_cart = analyzer.get_symmetry_operations(cartesian=True)
    rots = [x.rotation_matrix for x in symops]
    taus = [x.translation_vector for x in symops]
示例#5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tempfile

import pytest
import numpy as np

import symmetry_representation as sr

SYM_OP = sr.SymmetryOperation(rotation_matrix=np.array([[1, 2, 3], [4, 5j,
                                                                    9]]),
                              repr_matrix=np.array([[0, 1], [3, 5]]),
                              repr_has_cc=True)
REPR_MATRIX = sr.Representation(matrix=np.array([[1j, 0], [-2j, 3j]]))
SYM_GROUP = sr.SymmetryGroup(symmetries=[SYM_OP, SYM_OP], full_group=True)


@pytest.mark.parametrize('data', [
    SYM_OP, [SYM_OP], REPR_MATRIX, [REPR_MATRIX],
    [SYM_OP, [SYM_OP], REPR_MATRIX], SYM_GROUP,
    [SYM_GROUP, SYM_OP, REPR_MATRIX]
])
def test_save_load(data):
    with tempfile.NamedTemporaryFile() as f:
        print(data)
        sr.io.save(data, f.name)
        result = sr.io.load(f.name)
        np.testing.assert_equal(result, data)

# (c) 2017-2018, ETH Zurich, Institut fuer Theoretische Physik
# Author: Dominik Gresch <*****@*****.**>
"""
Tests for saving and loading ``symmetry-representation`` objects.
"""

import tempfile

import pytest
import numpy as np
import sympy as sp

import symmetry_representation as sr

SYM_OP = sr.SymmetryOperation(rotation_matrix=np.array([[1, 2, 3], [4, 5, 9],
                                                        [10, 11, 12]]),
                              repr_matrix=np.array([[0, 1], [1, 0]]),
                              repr_has_cc=True)
SYM_OP_ANALYTIC = sr.SymmetryOperation(rotation_matrix=np.array([[1, 2, 3],
                                                                 [4, 5, 9],
                                                                 [10, 11,
                                                                  12]]),
                                       repr_matrix=sp.Matrix([[0, sp.I],
                                                              [-sp.I, 0]]),
                                       repr_has_cc=True)
REPR_MATRIX = sr.Representation(matrix=np.array([[1j, 0], [0, -1j]]))
REPR_MATRIX_ANALYTIC = sr.Representation(
    matrix=sp.Matrix([[sp.I, 0], [0, sp.I]]))
SYM_GROUP = sr.SymmetryGroup(symmetries=[SYM_OP, SYM_OP], full_group=True)


@pytest.mark.parametrize('data', [
示例#7
0
# Author: Dominik Gresch <*****@*****.**>
"""
Tests for the SymmetryOperation class.
"""

import pytest

import numpy as np
import sympy as sp

import symmetry_representation as sr


@pytest.mark.parametrize(['left', 'right', 'result'], [
    (sr.SymmetryOperation(rotation_matrix=np.eye(3),
                          repr_matrix=[[0, 1], [1, 0]],
                          repr_has_cc=True),
     sr.SymmetryOperation(rotation_matrix=np.eye(3),
                          repr_matrix=[[0, 1], [1, 0]],
                          repr_has_cc=True),
     sr.SymmetryOperation(
         rotation_matrix=np.eye(3), repr_matrix=np.eye(2), repr_has_cc=False)),
    (sr.SymmetryOperation(rotation_matrix=sp.eye(3, 3),
                          repr_matrix=[[0, 1], [1, 0]],
                          repr_has_cc=True,
                          numeric=False),
     sr.SymmetryOperation(rotation_matrix=sp.eye(3, 3),
                          repr_matrix=[[0, 1], [1, 0]],
                          repr_has_cc=True,
                          numeric=False),
     sr.SymmetryOperation(rotation_matrix=np.eye(3),
示例#8
0
import sympy as sp
from sympy.core.numbers import I
import sympy.physics.matrices as sm
from sympy.physics.quantum import TensorProduct
import symmetry_representation as sr

import kdotp_symmetry as kp

# In this project we used the basis of tensor products of Pauli matrices
pauli_vec = [sp.eye(2), *(sm.msigma(i) for i in range(1, 4))]
basis = [TensorProduct(p1, p2) for p1 in pauli_vec for p2 in pauli_vec]

# creating the symmetry operations
c2y = sr.SymmetryOperation(
    rotation_matrix=[[0, 1, 0], [1, 0, 0], [0, 0, -1]],
    repr_matrix=sp.diag(I, -I, I, -I),
    repr_has_cc=False
)

parity = sr.SymmetryOperation(
    rotation_matrix=-sp.eye(3),
    repr_matrix=sp.diag(1, 1, -1, -1),
    repr_has_cc=False
)

time_reversal = sr.SymmetryOperation(
    rotation_matrix=sp.eye(3),
    repr_matrix=TensorProduct(sp.eye(2), sp.Matrix([[0, -1], [1, 0]])),
    repr_has_cc=True
)