Example #1
0
def init():
    p = [None, np.asarray([0., 0., 1.])]
    S = 1. / np.sqrt(2.)
    U1 = np.identity(3)
    U2 = np.asarray([[S, 0, S], [0, 1, 0], [S, 0, -S]])
    for _p in p:
        p2 = 0 if _p is None else np.dot(_p, _p)
        try:
            _g = gc.TOh.read(p2=p2)
            if np.allclose(_g.U3, U1):
                g.append(_g)
                gt.append(gc.TOh(pref=_p, irreps=True, U3=U2))
            elif np.allclose(_g.U3, U2):
                gt.append(_g)
                a = gc.TOh(pref=_p, irreps=True, U3=U1)
                a.save()
                g.append(a)
            else:
                raise IOError
        except IOError:
            a = gc.TOh(pref=_p, irreps=True, U3=U1)
            a.save()
            g.append(a)
            gt.append(gc.TOh(pref=_p, irreps=True, U3=U2))
    if not g or not gt:
        print("at least one list is empty")
Example #2
0
def init_groups(p2max=4,
                prefs=None,
                U2=None,
                U3=None,
                U4=None,
                path=None,
                fname=None):
    groups = []

    # check reference vectors
    if prefs is None:
        _prefs = [[0., 0., 0.], [0., 0., 1.], [1., 1., 0.], [1., 1., 1.],
                  [0., 0., 2.], [0., 1., 2.], [1., 1., 2.]]
        if p2max > 6:
            _p2max = 6
        else:
            _p2max = p2max
    else:
        _prefs = prefs
        if p2max > len(_prefs):
            _p2max = len(_prefs)
        else:
            _p2max = p2max

    # check basis change matrices
    if U2 is None:
        _U2 = np.identity(2)
    else:
        _U2 = U2
    if U3 is None:
        _U3 = np.identity(3)
    else:
        _U3 = U3
    if U4 is None:
        _U4 = np.identity(4)
    else:
        _U4 = U4

    for p2 in range(p2max):
        try:
            _g = gc.TOh.read(p2=p2, path=path)
            if (not np.allclose(_g.U4, _U4) or not np.allclose(_g.U3, _U3)
                    or not np.allclose(_g.U2, _U2)):
                raise IOError("redo computation")
        except IOError:
            _g = gc.TOh(pref=prefs[p2], irreps=True, U4=_U4, U3=_U3, U2=_U2)
            _g.save(path=path, fname=fname)
        groups.append(_g)
    return groups
 def test_wrong_init(self):
     self.assertRaises(RuntimeError, gb.TOhBasis, gc.TOh())
"""Unit test for the group class
"""

import unittest
import numpy as np

import utils
import group_class_quat as gc
import group_basis_quat as gb

try:
    g0 = gc.TOh.read(p2=0)
except IOError:
    g0 = gc.TOh(irreps=True)
    g0.save()
try:
    g1 = gc.TOh.read(p2=1)
except IOError:
    g1 = gc.TOh(irreps=True)
    g1.save()


#@unittest.skip("skip base tests")
class TestBasis(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.basis = gb.TOhBasis(g0)

    def setUp(self):
        self.addTypeEqualityFunc(np.ndarray, utils.check_array)
 def setUpClass(self):
     tmp = np.asarray([1., 1., 0.])
     self.group = gc.TOh(pref=tmp)
 def setUpClass(self):
     tmp = np.asarray([0., 0., 1.])
     self.group = gc.TOh(pref=tmp, debug=0)
 def setUpClass(self):
     self.pref = np.asarray([1., 1., 1.])
     self.group = gc.TOh(self.pref, withinversion=True, irreps=True, debug=0)
 def setUpClass(self):
     self.pref = np.asarray([0., 0., 1.])
     S = 1./np.sqrt(2.)
     self.U = np.asarray([[S,0,S],[0,1,0],[S,0,-S]])
     self.group = gc.TOh(self.pref, withinversion=True, irreps=True, U3=self.U)
     self.g1 = gc.TOh(self.pref, withinversion=True, irreps=True)
 def setUpClass(self):
     self.group = gc.TOh(withinversion=True, irreps=True)
 def setUpClass(self):
     self.group = gc.TOh()