def symmetryfromstr(string): words = string.split(',') assert len(words) == 3, \ "The following string looks like a Symmetry, but it has not "\ "three comma-separated terms: %s" % (string) liste = [] for word in words: row = nb.Row(str2linearterm(word, ['x', 'y', 'z'])) liste.append(row) liste.append( nb.Row([fromstr("0"), fromstr("0"), fromstr("0"), fromstr("1")])) return geo.Symmetry(nb.Matrix(liste))
def to_Metric(self): a = self.a b = self.b c = self.c alpha = self.alpha beta = self.beta gamma = self.gamma aa = a * a bb = b * b cc = c * c ab = a * b * nb.cos(nb.deg2rad(gamma)) ac = a * c * nb.cos(nb.deg2rad(beta)) bc = b * c * nb.cos(nb.deg2rad(alpha)) return Metric( nb.Matrix([ nb.Row([aa, ab, ac, 0]), nb.Row([ab, bb, bc, 0]), nb.Row([ac, bc, cc, 0]), nb.Row([0, 0, 0, 1]) ]))
def __init__(self, value): assert isinstance(value, nb.Matrix), \ "Must be created by an object of type Matrix." assert value.shape() == (4, 4), \ "Must be created by a 4x4-Matrix." assert value.liste[3] == nb.Row([0, 0, 0, 1]), \ "Must be created by a 4x4-Matrix of this shape: \n"\ " * * * * \n"\ " * * * * \n"\ " * * * * \n"\ " 0 0 0 1 \n" self.value = value
def __str__(self): result = 'Transformation ' m = self.value.inv() Ox = m.liste[0].liste[3] Oy = m.liste[1].liste[3] Oz = m.liste[2].liste[3] matrix = nb.Matrix([[1, 0, 0, Ox], [0, 1, 0, Oy], [0, 0, 1, Oz], [0, 0, 0, 1]]) result = "Transformation O -> (%s, %s, %s)\n" \ " then\n" % \ (Ox.__str__(), Oy.__str__(), Oz.__str__()) matrix = nb.Matrix([ nb.Row([ m.liste[0].liste[0], m.liste[1].liste[0], m.liste[2].liste[0], 0 ]), nb.Row([ m.liste[0].liste[1], m.liste[1].liste[1], m.liste[2].liste[1], 0 ]), nb.Row([ m.liste[0].liste[2], m.liste[1].liste[2], m.liste[2].liste[2], 0 ]), nb.Row([ m.liste[3].liste[0], m.liste[3].liste[1], m.liste[3].liste[2], 1 ]) ]) terms = [] for i in range(3): print(matrix.liste[i].liste[0], matrix.liste[i].liste[1], matrix.liste[i].liste[2], matrix.liste[i].liste[3]) terms.append( linearterm2str(matrix.liste[i].liste, ["a", "b", "c", ''])) return result + " a' = " + terms[0] + "\n" \ + " b' = " + terms[1] + "\n" \ + " c' = " + terms[2]
def __init__(self, b1, b2, b3): assert isinstance(b1, Dif) \ and isinstance(b2, Dif) \ and isinstance(b3, Dif), \ "Arguments must be of type Dif." self.liste = [b1, b2, b3] m00 = b1.value.liste[0].liste[0] m01 = b2.value.liste[0].liste[0] m02 = b3.value.liste[0].liste[0] m10 = b1.value.liste[1].liste[0] m11 = b2.value.liste[1].liste[0] m12 = b3.value.liste[1].liste[0] m20 = b1.value.liste[2].liste[0] m21 = b2.value.liste[2].liste[0] m22 = b3.value.liste[2].liste[0] self.transformation = Transformation( nb.Matrix([ nb.Row([m00, m01, m02, 0]), nb.Row([m10, m11, m12, 0]), nb.Row([m20, m21, m22, 0]), nb.Row([0, 0, 0, 1]) ])) self.transformationinv = self.transformation.inv()
def __init__(self, value): assert isinstance(value, nb.Matrix), \ "Must be created by an object of type Matrix." assert value.shape() == (4, 4), \ "Must be created by a 4x4-Matrix." assert (value.liste[3] == nb.Row([0, 0, 0, 1])) \ and (value.liste[0].liste[3] == 0) \ and (value.liste[1].liste[3] == 0) \ and (value.liste[2].liste[3] == 0), \ "Argument must be a Matrix of this shape:\n" \ " * * * 0\n" \ " * * * 0\n" \ " * * * 0\n" \ " 0 0 0 1" self.value = value self.valueinv = value.inv() self.schmidttransformation = self.calculate_schmidttransformation()
def matrixfromstr(string): string = string.replace('|', '\\') string = re.sub('\/ | \/|[<>]', ' ', string) # string = string.replace('/ ', ' ') # string = string.replace('<', ' ') # string = string.replace('>', ' ') # string = string.replace(' /', ' ') string = string.replace('\n', '\\') # string = re.sub('\\\\ +\\\\', '\\', string) for i in range(4): string = string.replace('\\ \\', '\\') string = string.replace('\\ \\', '\\') string = string.replace('\\ \\', '\\') rowwords = string.split('\\') rowliste = [] for rowword in rowwords: words = rowword.split() liste = [] for word in words: liste.append(mixedfromstr(word)) rowliste.append(nb.Row(liste)) return nb.Matrix(rowliste)
def transformationfromstr(string): if len(string.split("then")) > 1: # The string respresents not an elementar transformation, # i.e. the string represents a transformation which is # a composition of elementar transformations. result = geo.Transformation(nb.Matrix.onematrix(4)) for word in string.split("\nthen\n"): result = transformationfromstr(word) * result return result else: # The string represents an elementar transformation, # i.e. either a pure translation of the origin or a # pure change of the axes. if ('O' in string) or ("->" in string): # The string represents a pure translation of the origin. words = string.split("->") word = words[1] word = word.replace('\n', ' ') word = word.replace('(', ' ').replace(')', ' ').replace(',', ' ') threenumbers = fromstr(word) matrix = nb.Matrix([[1, 0, 0, -threenumbers.liste[0].liste[0]], [0, 1, 0, -threenumbers.liste[0].liste[1]], [0, 0, 1, -threenumbers.liste[0].liste[2]], [0, 0, 0, 1]]) return geo.Transformation(matrix) elif ('a' in string) or ('b' in string) or ('c' in string): # The string represents a pure change of the axes lines = string.split('\n') assert len(lines) == 3, \ "The following string looks like a Transformation, " \ "but it has not exactly three lines: %s" % (string) liste = [] i = 0 for line in lines: if len(line.split(' ')) > 0: i += 1 words = line.split(' ') assert ( ((i == 1) and (words[0] == "a'")) or ((i == 2) and (words[0] == "b'")) or ((i == 3) and (words[0] == "c'")) )\ and (words[1] == '='), \ "The Transformation must have the following form: \n" \ "a' = ... \n" \ "b' = ... \n" \ "c' = ... \n" \ "in this Order!" words = line.split('=') row = nb.Row(str2linearterm(words[1], ['a', 'b', 'c'])) liste.append(row) liste.append( nb.Row( [fromstr("0"), fromstr("0"), fromstr("0"), fromstr("1")])) m = nb.Matrix(liste) matrix = nb.Matrix([ nb.Row([ m.liste[0].liste[0], m.liste[1].liste[0], m.liste[2].liste[0], 0 ]), nb.Row([ m.liste[0].liste[1], m.liste[1].liste[1], m.liste[2].liste[1], 0 ]), nb.Row([ m.liste[0].liste[2], m.liste[1].liste[2], m.liste[2].liste[2], 0 ]), nb.Row([0, 0, 0, 1]) ]) return geo.Transformation(matrix.inv())
def test_Row(): # Create e = uc.ufloat(1.2, 0.1) R = nb.Row([nb.Mixed(fr.Fraction(1, 2)), nb.Mixed(e), nb.Mixed(1), nb.Mixed(0.5)]) assert isinstance(R.liste, list) assert isinstance(R.liste[0], nb.Mixed) assert isinstance(R.liste[0].value, fr.Fraction) assert R.liste[0] == nb.Mixed(fr.Fraction(1, 2)) assert isinstance(R.liste[1], nb.Mixed) assert isinstance(R.liste[1].value, uc.UFloat) assert R.liste[1] == nb.Mixed(e) assert isinstance(R.liste[2], nb.Mixed) assert isinstance(R.liste[2].value, int) assert R.liste[2] == nb.Mixed(1) assert isinstance(R.liste[3], nb.Mixed) assert isinstance(R.liste[3].value, float) assert approx(R.liste[3].value, 0.5) R = nb.Row([fr.Fraction(1, 2), e, 1, 0.5]) assert isinstance(R.liste, list) assert isinstance(R.liste[0], nb.Mixed) assert isinstance(R.liste[0].value, fr.Fraction) assert R.liste[0] == nb.Mixed(fr.Fraction(1, 2)) assert isinstance(R.liste[1], nb.Mixed) assert isinstance(R.liste[1].value, uc.UFloat) assert R.liste[1] == nb.Mixed(e) assert isinstance(R.liste[2], nb.Mixed) assert isinstance(R.liste[2].value, int) assert R.liste[2] == nb.Mixed(1) assert isinstance(R.liste[3], nb.Mixed) assert isinstance(R.liste[3].value, float) assert approx(R.liste[3].value, 0.5) # len R = nb.Row([fr.Fraction(1, 2), uc.ufloat(1.2, 0.1), 1, 0.5]) assert len(R) == 4 assert R.__str__() == "( 1/2 1.20(10) 1 0.5 )" # Equal e = uc.ufloat(1.2, 0.1) R1 = nb.Row([fr.Fraction(1, 2), e, 1, 0.5]) R2 = nb.Row([fr.Fraction(1, 2), e, 1, 0.5]) R2wrong = nb.Row([fr.Fraction(1, 2), uc.ufloat(1.2, 0.1), 1, 0.5]) R3 = nb.Row([fr.Fraction(1, 2), e, 1, fr.Fraction(1, 2)]) R4 = nb.Row([fr.Fraction(1, 2), e, 1]) assert R1 == R2 assert (R1 == R2wrong) == False assert (R1 == R3) == False assert (R1 == R4) == False assert (R1 == 5) == False # Hash R1 = nb.Row([0, 0, 1.00000000]) R2 = nb.Row([0, 0, 0.99999999]) assert hash(R1) == hash(R2) e1 = uc.ufloat(1.2, 0.1) R1 = nb.Row([0, 0, e1]) R2 = nb.Row([0, 0, e1]) R3 = nb.Row([0, 0, uc.ufloat(1.2, 0.1)]) assert hash(R1) == hash(R2) assert (hash(R1) == hash(R3)) == False # canonical assert nb.Row.canonical(5, 3) == nb.Row([0, 0, 0, 1, 0]) # block R = nb.Row([1, 2, 3, 4]) assert R.block(1, 3) == nb.Row([2, 3]) # Addition R1 = nb.Row([1, 2, fr.Fraction(1, 2)]) R2 = nb.Row([2, 3, 4]) assert R1 + R2 == nb.Row([3, 5, fr.Fraction(9, 2)]) # Subtraction R1 = nb.Row([1, 2, fr.Fraction(1, 2)]) R2 = nb.Row([2, 3, 4]) assert R1 - R2 == nb.Row([-1, -1, fr.Fraction(-7, 2)]) # Multiplication R1 = nb.Row([1, 2, fr.Fraction(1, 2)]) assert R1 * nb.Mixed(2) == nb.Row([2, 4, 1]) assert nb.Mixed(2) * R1 == nb.Row([2, 4, 1]) assert R1 * 2 == nb.Row([2, 4, 1]) assert 2 * R1 == nb.Row([2, 4, 1]) # neg R1 = nb.Row([1, 2, 3]) assert -R1 == nb.Row([-1, -2, -3])
def test_Matrix(): # create and shape M1 = nb.Matrix([nb.Row([1, 2, 3]), nb.Row([4, 5, 6])]) M2 = nb.Matrix([[1, 2, 3], [4, 5, 6]]) assert M1.shape() == (2, 3) assert M2.shape() == (2, 3) # Equal M1 = nb.Matrix([nb.Row([1, 2, 3]), nb.Row([4, 5, 6])]) M2 = nb.Matrix([[1, 2, 3], [4, 5, 6]]) M3 = nb.Matrix([[1, 2, 3], [4, 5.1, 6]]) M4 = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) M5 = nb.Matrix([[1, 2], [4, 5]]) M6 = nb.Matrix([[1, 2, 3], [4, 5.0, 6]]) M7 = nb.Matrix([[1, 2, 3], [4, fr.Fraction(5, 1), 6]]) assert M1 == M2 assert (M1 == M3) == False assert (M1 == M4) == False assert (M1 == M5) == False assert (M1 == M6) == False assert M1 == M7 M1 = nb.Matrix([nb.Row([1, 2, 3.0]), nb.Row([4, 5, 6])]) M2 = nb.Matrix([nb.Row([1, 2, 2.999999999999]), nb.Row([4, 5, 6])]) print(hash(M1)) print(hash(M2)) assert hash(M1) == hash(M2) e = uc.ufloat(1.2, 0.1) M1 = nb.Matrix([nb.Row([1, 2, e]), nb.Row([4, 5, 6])]) M2 = nb.Matrix([nb.Row([1, 2, e]), nb.Row([4, 5, 6])]) M3 = nb.Matrix([nb.Row([1, 2, uc.ufloat(1.2, 0.1)]), nb.Row([4, 5, 6])]) assert M1 == M2 assert (M1 == M3) == False assert hash(M1) == hash(M2) assert (hash(M1) == hash(M3)) == False # print assert nb.Matrix([[1, 2]]).__str__() == " < 1 2 > " assert nb.Matrix([[1, 2], [3, 4]]).__str__() == " / 1 2 \ \n" \ " \ 3 4 / " assert nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 800, 9]]).__str__() == \ " / 1 2 3 \ \n" \ "| 4 5 6 |\n" \ " \ 7 800 9 / " # Addition assert nb.Matrix([[1, 2], [3, 4]]) + nb.Matrix([[5, 6], [7, 8]]) == \ nb.Matrix([[6, 8], [10, 12]]) assert nb.Matrix([[1, 2], [3, 4], [5, 6]]) + \ nb.Matrix([[1, 1], [1, 1], [1, 1]]) == \ nb.Matrix([[2, 3], [4, 5], [6, 7]]) # Subtraction assert nb.Matrix([[1, 2], [3, 4]]) - nb.Matrix([[5, 6], [7, 8]]) == \ nb.Matrix([[-4, -4], [-4, -4]]) assert nb.Matrix([[1, 2], [3, 4], [5, 6]]) - \ nb.Matrix([[1, 1], [1, 1], [1, 1]]) == \ nb.Matrix([[0, 1], [2, 3], [4, 5]]) # neg M1 = nb.Matrix([[1, 2, 3], [4, 5, 6]]) assert -M1 == nb.Matrix([[-1, -2, -3], [-4, -5, -6]]) # Multiplication "Matrix * Matrix" M1 = nb.Matrix([[1, 2], [3, 4]]) M2 = nb.Matrix([[5, 6], [7, 8]]) assert isinstance(M1 * M2, nb.Matrix) assert M1 * M2 == nb.Matrix([[19, 22], [43, 50]]) M1 = nb.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) M2 = nb.Matrix([[uc.ufloat(1.2, 0.1)], [1], [2]]) print(M2) print(M1*M2) assert (M1 * M2).liste[1].liste[0] == M2.liste[1].liste[0] assert M1 * M2 == M2 # Multiplication "Scalar * Matrix" M1 = nb.Matrix([[1, 2], [3, 4]]) assert M1 * nb.Mixed(fr.Fraction(1, 2)) == \ nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]]) assert M1 * fr.Fraction(1, 2) == \ nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]]) assert nb.Mixed(fr.Fraction(1, 2)) * M1 == \ nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]]) assert fr.Fraction(1, 2) * M1 == \ nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]]) M = M1 * nb.Mixed(uc.ufloat(1.2, 0.1)) assert approx(M.liste[0].liste[0].value.n, 1.2) assert approx(M.liste[0].liste[0].value.s, 0.1) assert approx(M.liste[0].liste[1].value.n, 2.4) assert approx(M.liste[0].liste[1].value.s, 0.2) assert approx(M.liste[1].liste[0].value.n, 3.6) assert approx(M.liste[1].liste[0].value.s, 0.3) assert approx(M.liste[1].liste[1].value.n, 4.8) assert approx(M.liste[1].liste[1].value.s, 0.4) M = M1 * uc.ufloat(1.2, 0.1) assert approx(M.liste[0].liste[0].value.n, 1.2) assert approx(M.liste[0].liste[0].value.s, 0.1) assert approx(M.liste[0].liste[1].value.n, 2.4) assert approx(M.liste[0].liste[1].value.s, 0.2) assert approx(M.liste[1].liste[0].value.n, 3.6) assert approx(M.liste[1].liste[0].value.s, 0.3) assert approx(M.liste[1].liste[1].value.n, 4.8) assert approx(M.liste[1].liste[1].value.s, 0.4) M = nb.Mixed(uc.ufloat(1.2, 0.1)) * M1 assert approx(M.liste[0].liste[0].value.n, 1.2) assert approx(M.liste[0].liste[0].value.s, 0.1) assert approx(M.liste[0].liste[1].value.n, 2.4) assert approx(M.liste[0].liste[1].value.s, 0.2) assert approx(M.liste[1].liste[0].value.n, 3.6) assert approx(M.liste[1].liste[0].value.s, 0.3) assert approx(M.liste[1].liste[1].value.n, 4.8) assert approx(M.liste[1].liste[1].value.s, 0.4) M = uc.ufloat(1.2, 0.1) * M1 assert approx(M.liste[0].liste[0].value.n, 1.2) assert approx(M.liste[0].liste[0].value.s, 0.1) assert approx(M.liste[0].liste[1].value.n, 2.4) assert approx(M.liste[0].liste[1].value.s, 0.2) assert approx(M.liste[1].liste[0].value.n, 3.6) assert approx(M.liste[1].liste[0].value.s, 0.3) assert approx(M.liste[1].liste[1].value.n, 4.8) assert approx(M.liste[1].liste[1].value.s, 0.4) assert M1 * nb.Mixed(2) == nb.Matrix([[2, 4], [6, 8]]) assert M1 * 2 == nb.Matrix([[2, 4], [6, 8]]) assert nb.Mixed(2) * M1 == nb.Matrix([[2, 4], [6, 8]]) assert 2 * M1 == nb.Matrix([[2, 4], [6, 8]]) M = M1 * nb.Mixed(2.5) assert approx(M.liste[0].liste[0].value, 2.5) assert approx(M.liste[0].liste[1].value, 5.0) assert approx(M.liste[1].liste[0].value, 7.5) assert approx(M.liste[1].liste[1].value, 10.0) M = M1 * 2.5 assert approx(M.liste[0].liste[0].value, 2.5) assert approx(M.liste[0].liste[1].value, 5.0) assert approx(M.liste[1].liste[0].value, 7.5) assert approx(M.liste[1].liste[1].value, 10.0) M = nb.Mixed(2.5) * M1 assert approx(M.liste[0].liste[0].value, 2.5) assert approx(M.liste[0].liste[1].value, 5.0) assert approx(M.liste[1].liste[0].value, 7.5) assert approx(M.liste[1].liste[1].value, 10.0) M = 2.5 * M1 assert approx(M.liste[0].liste[0].value, 2.5) assert approx(M.liste[0].liste[1].value, 5.0) assert approx(M.liste[1].liste[0].value, 7.5) assert approx(M.liste[1].liste[1].value, 10.0) # onematrix assert nb.Matrix.onematrix(2) == nb.Matrix([[1, 0], [0, 1]]) assert nb.Matrix.onematrix(3) == nb.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # block M = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) assert M.block(0, 2, 0, 2) == nb.Matrix([[1, 2], [4, 5]]) assert M.block(1, 2, 0, 3) == nb.Matrix([[4, 5, 6]]) M = nb.Matrix([[1, 2, 3, 4]]) assert M.block(0, 1, 0, 3) == nb.Matrix([[1, 2, 3]]) # swap_rows M = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) assert M.swap_rows(0, 1) == nb.Matrix([[4, 5, 6], [1, 2, 3], [7, 8, 9]]) # vglue M1 = nb.Matrix([[1, 2, 3]]) M2 = nb.Matrix([[4, 5, 6]]) assert nb.Matrix.vglue(M1, M2) == nb.Matrix([[1, 2, 3], [4, 5, 6]]) # subtract_x_times_rowj_from_rowi M = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) assert M.subtract_x_times_rowj_from_rowi(2, 2, 0) == \ nb.Matrix([[1, 2, 3], [4, 5, 6], [5, 4, 3]]) # inv assert nb.Matrix([[2, 3], [4, 5]]).inv() == \ nb.Matrix([[-fr.Fraction(5, 2), fr.Fraction(3, 2)], [2, -1]]) assert nb.Matrix([[0, 1, 1], [1, 0, 0], [0, 0, -1]]).inv() == \ nb.Matrix([[0, 1, 0], [1, 0, 1], [0, 0, -1]]) assert nb.Matrix([[0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1]]).inv() == \ nb.Matrix([[0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0], [0, 0, 0, 1]]) # transpose assert nb.Matrix([[1, 2, 3], [4, 5, 6]]).transpose() == \ nb.Matrix([[1, 4], [2, 5], [3, 6]]) # delete_ith_row_and_first_column M = nb.Matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) assert M.delete_ith_row_and_first_column(1) == nb.Matrix([[2, 3, 4], [10, 11, 12]]) # det M = nb.Matrix([[3]]) assert M.det() == 3 M = nb.Matrix([[1, 2], [3, 4]]) assert M.det() == -2 M = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) assert M.det() == 0 M = nb.Matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 8, 11, 12], [13, 14, 15, 17]]) assert M.det() == -16 # delete_translation M = nb.Matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [0, 0, 0, 1]]) assert M.delete_translation() == nb.Matrix([[1, 2, 3, 0], [5, 6, 7, 0], [9, 10, 11, 0], [0, 0, 0, 1]])
def test_fromstr(): string = "1/2" assert isinstance(fs(string), nb.Mixed) assert fs(string) == nb.Mixed(fr.Fraction(1, 2)) string = "1.2+/-0.1" assert fs(string).value.n == nb.Mixed(uc.ufloat(1.2, 0.1)).value.n assert fs(string).value.s == nb.Mixed(uc.ufloat(1.2, 0.1)).value.s string = "1.2(1)" assert fs(string).value.n == nb.Mixed(uc.ufloat(1.2, 0.1)).value.n assert fs(string).value.s == nb.Mixed(uc.ufloat(1.2, 0.1)).value.s string = "4" assert fs(string) == nb.Mixed(fr.Fraction(4, 1)) string = "4.5" assert fs(string) == nb.Mixed(4.5) string = "1 2 3" assert fromstr.typefromstr(string) == nb.Matrix assert fs(string) == nb.Matrix([[1, 2, 3]]) string = "/ 1 2 \ \n \ 3 4 /" assert fs(string) == \ nb.Matrix([nb.Row([nb.Mixed(1), nb.Mixed(2)]), nb.Row([nb.Mixed(3), nb.Mixed(4)])]) string = "1 2 \n 3 4" assert fs(string) == \ nb.Matrix([nb.Row([nb.Mixed(1), nb.Mixed(2)]), nb.Row([nb.Mixed(3), nb.Mixed(4)])]) string = "x+y,y - x +1/3,2z" g = fs(string) assert g == geo.Symmetry( fs("/ 1 1 0 0 \n" " -1 1 0 1/3 \n" " 0 0 2 0 \n" " 0 0 0 1")) string = "O->(0,0,0)\n" \ "then\n" \ "a' = a-b \n" \ "b' = b+a \n" \ "c' = 2c" g = fs(string) assert g == geo.Transformation( fs(" 1 1 0 0 \n" "-1 1 0 0 \n" " 0 0 2 0 \n" " 0 0 0 1").inv()) string = "O->(0,0,0) \n" \ "then\n" \ "a' = c \n" \ "b' = a \n" \ "c' = b" g = fs(string) assert g == geo.Transformation( fs("0 1 0 0 \n" "0 0 1 0 \n" "1 0 0 0 \n" "0 0 0 1").inv()) string = "O -> (1/2, 0, 0) \n" \ "then\n" \ "a' = a \n" \ "b' = b \n" \ "c' = c" g = fs(string) assert g == geo.Transformation( fs("1 0 0 -1/2 \n" "0 1 0 0 \n" "0 0 1 0 \n" "0 0 0 1")) string1 = "O -> (1/2, 0, 0) \n" \ "then\n" \ "a' = a \n" \ "b' = b \n" \ "c' = c" string2 = "O -> (0,0,0) \n" \ "then\n" \ "a' = b\n" \ "b' = a\n" \ "c' = c" string = "O -> (1/2, 0, 0) \n" \ "then\n"\ "a' = b\n"\ "b' = a\n"\ "c' = c" g1 = fs(string1) g2 = fs(string2) g = fs(string) assert g == g2 * g1 string = "O -> (1/2, 0, 0) \n" \ "then\n" \ "a' = a + b\n" \ "b' = b\n" \ "c' = c" print("--------") g = fs(string) print(g.value) assert g**fs("p 1/2 0 0") == fs("p 0 0 0") assert g**fs("p 1/2 1/3 0") == fs("p 0 1/3 0") assert g**fs("p 0 0 0") == fs("p -1/2 1/2 0") assert g * g.inv() == geo.Transformation(nb.Matrix.onematrix(4)) string = "p0 0 0" p = fs(string) assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1")) string = "P0 0 0" p = fs(string) assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1")) string = "r0 0 0" p = fs(string) assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1")) string = "R0 0 0" p = fs(string) assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1")) string = p.__str__() assert string == "Pos / 0 \ \n" \ " | 0 |\n" \ " \ 0 / " p1 = fs(string) assert p == p1 string = "R1/2 1/2 1/2" p = fs(string) assert p == geo.Pos(fs("1/2 \n 1/2 \n 1/2 \n 1")) q = fs("k1 2 3") assert q == geo.Rec(fs("1 2 3 0")) q = fs("K 1 2 3") assert q == geo.Rec(fs("1 2 3 0")) q = fs("q 1/2 1/2 0") assert q == geo.Rec(fs("1/2 1/2 0 0")) q = fs("Q0 0 0") assert q == geo.Rec(fs("0 0 0 0")) q = fs("Rec < 1 2 3 > ") assert q == geo.Rec(fs("1 2 3 0"))
return Dif( nb.Matrix([[right * self.x()], [right * self.y()], [right * self.z()], [0]])) else: return NotImplemented def to_Symmetry(self): # Returns the symmetry operation that is a translation with # the Dif-Vector. return Symmetry( nb.Matrix([[1, 0, 0, self.x()], [0, 1, 0, self.y()], [0, 0, 1, self.z()], [0, 0, 0, 1]])) canonical_e0 = Dif( nb.Matrix([nb.Row([1]), nb.Row([0]), nb.Row([0]), nb.Row([0])])) canonical_e1 = Dif( nb.Matrix([nb.Row([0]), nb.Row([1]), nb.Row([0]), nb.Row([0])])) canonical_e2 = Dif( nb.Matrix([nb.Row([0]), nb.Row([0]), nb.Row([1]), nb.Row([0])])) # **** class Rec **** # An object of this class represents a vector in 3D reciprocal space. # It is constructed via a 1x4-numbers.Matrix, wherein the last # entry must be a 0.