Exemplo n.º 1
0
def test(cell, numops):
    """ Test structure initialization. """
    from numpy import all, abs, dot, array
    from numpy.linalg import inv, det
    from pylada.crystal.cppwrappers import cell_invariants, Structure
    from pylada.math import is_integer

    ops = cell_invariants(cell)
    if isinstance(cell, Structure): cell = cell.cell.copy()
    assert len(ops) == numops
    for op in ops:
        assert op.shape == (4, 3)
        assert all(abs(op[3, :]) < 1e-8)
        transformation = dot(dot(inv(cell), op[:3]), cell)
        assert is_integer(transformation)
        assert abs(abs(det(transformation)) - 1e0) < 1e-8
    if numops != 48:
        allops = cell_invariants(
            array([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]))
        failed = 0
        for op in allops:
            transformation = dot(dot(inv(cell), op[:3]), cell)
            if not (is_integer(transformation)
                    and abs(abs(det(transformation)) - 1e0) < 1e-8):
                failed += 1
        assert failed == 48 - numops
Exemplo n.º 2
0
def test_gruber():
  from numpy import dot
  from numpy.linalg import inv
  from pylada.math import gruber, is_integer
  from pylada.error import internal, input
  
  cell = [[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]
  lim = 5
   
  for a00 in [-1, 1]: 
    for a10 in xrange(-lim, lim+1): 
      for a11 in [-1, 1]:
        for a20 in xrange(-lim, lim+1): 
          for a21 in xrange(-lim, lim+1): 
            for a22 in [-1, 1]:
              a = [[a00, 0, 0], [a10, a11, 0], [a20, a21, a22]]
              g = gruber(dot(cell, a))
              assert is_integer(dot(inv(cell), g))
              assert is_integer(dot(inv(g), cell))

  try: gruber([[0, 0, 0], [1, 2, 0], [4, 5, 6]])
  except input: pass
  else: raise Exception()

  try: gruber([[1, 0, 0], [1, 1, 0], [4, 5, 1]], itermax=2)
  except internal: pass
  else: raise Exception()
def test_gruber():
  from numpy import dot
  from numpy.linalg import inv
  from pylada.math import gruber, is_integer
  from pylada.error import internal, input

  cell = [[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]
  lim = 5

  for a00 in [-1, 1]:
    for a10 in xrange(-lim, lim+1):
      for a11 in [-1, 1]:
        for a20 in xrange(-lim, lim+1):
          for a21 in xrange(-lim, lim+1):
            for a22 in [-1, 1]:
              a = [[a00, 0, 0], [a10, a11, 0], [a20, a21, a22]]
              testcell = dot(cell, a)
              g = gruber(testcell)
              print testcell
              print g
              assert is_integer(dot(inv(cell), g))
              assert is_integer(dot(inv(g), cell))

  try: gruber([[0, 0, 0], [1, 2, 0], [4, 5, 6]])
  except input: pass
  else: raise Exception()

  try: gruber([[1, 0, 0], [1, 1, 0], [4, 5, 1]], itermax=2)
  except internal: pass
  else: raise Exception()
Exemplo n.º 4
0
def test_primitive():
  """ Tests whether primitivization works. """
  from numpy import abs, dot
  from numpy.linalg import inv
  from pylada.crystal.cppwrappers import supercell, Structure, are_periodic_images as api, \
                                       primitive, is_primitive
  from pylada.math import is_integer

  lattice = Structure( 0.0, 0.5, 0.5,
                       0.5, 0.0, 0.5,
                       0.5, 0.5, 0.0, scale=2.0, m=True ) \
                     .add_atom(0, 0, 0, "As")           \
                     .add_atom(0.25, 0.25, 0.25, ['In', 'Ga'], m = True)
  assert is_primitive(lattice)
  for cell in itercells(10): 
    structure = supercell(lattice, dot(lattice.cell, cell))
    assert not is_primitive(structure)
    structure = primitive(structure, 1e-8)
    assert is_primitive(structure)
    assert abs(structure.volume - lattice.volume) < 1e-8
    assert len(structure) == len(lattice)
    assert is_integer(dot(structure.cell, inv(lattice.cell)))
    assert is_integer(dot(lattice.cell, inv(structure.cell)))
    invcell = inv(lattice.cell)
    for atom in structure:
      assert api(lattice[atom.site].pos, atom.pos, invcell) and \
             atom.type == lattice[atom.site].type and \
             getattr(lattice[atom.site], 'm', False) == getattr(atom, 'm', False) and \
             (getattr(atom, 'm', False) or atom.site == 0)
Exemplo n.º 5
0
def test_isinteger():
    from numpy import array
    from pylada.math import is_integer
    from pylada.error import TypeError

    assert is_integer(array([0, 1, 0, 2]))
    assert is_integer(array([0L, 1, 0, 2]))
    assert is_integer(array([0, 1.0, 0.0, 2.0]))
    assert not is_integer(array([0, 1.1, 0.0, 2.0]))
    try:
        is_integer([5, 6, 7])
    except TypeError:
        pass
    else:
        raise Exception()
Exemplo n.º 6
0
def decoration(A, B, lattice):
    """ Adds changes to the motif. """
    from numpy import dot
    from numpy.linalg import inv
    from pylada.crystal.cppwrappers import SmithTransform
    from pylada.math import is_integer
    basis(A, B)
    return

    smith = SmithTransform(lattice, A)

    # create map of atoms.
    indices = [-1] * len(A)
    for i, atom in enumerate(A):
        u = smith.index(atom.pos - lattice[atom.site].pos, atom.site)
        indices[u] = i

    # transform A according to all possible atom-atom translations.
    for atom in A:
        if atom.site != A[0].site: continue  # only primitive translations.
        trans = atom.pos - A[0].pos
        B = A.copy()
        for index in indices:
            vec = A[index].pos + trans - lattice[A[index].site].pos
            assert is_integer(dot(inv(lattice.cell),
                                  vec))  # vector should be on lattice
            B[indices[smith.index(vec, A[index].site)]] = A[index]
        basis(A, B)
Exemplo n.º 7
0
def decoration(A, B, lattice):
  """ Adds changes to the motif. """
  from numpy import dot
  from numpy.linalg import inv
  from pylada.crystal.cppwrappers import SmithTransform
  from pylada.math import is_integer
  basis(A, B)
  return

  smith = SmithTransform(lattice, A)

  # create map of atoms.
  indices = [-1] * len(A)
  for i, atom in enumerate(A):
    u = smith.index(atom.pos-lattice[atom.site].pos, atom.site)
    indices[u] = i

  # transform A according to all possible atom-atom translations.
  for atom in A:
    if atom.site != A[0].site: continue # only primitive translations.
    trans = atom.pos - A[0].pos
    B = A.copy()
    for index in indices:
      vec = A[index].pos + trans - lattice[A[index].site].pos
      assert is_integer(dot(inv(lattice.cell), vec)) # vector should be on lattice
      B[ indices[smith.index(vec, A[index].site)] ] = A[index]
    basis(A, B)
Exemplo n.º 8
0
def test(cell, numops):
  """ Test structure initialization. """
  from numpy import all, abs, dot, array
  from numpy.linalg import inv, det
  from pylada.crystal.cppwrappers import cell_invariants, Structure
  from pylada.math import is_integer

  ops = cell_invariants(cell) 
  if isinstance(cell, Structure): cell = cell.cell.copy()
  assert len(ops) == numops
  for op in ops:
    assert op.shape == (4, 3)
    assert all(abs(op[3, :]) < 1e-8) 
    transformation = dot(dot(inv(cell), op[:3]), cell)
    assert is_integer(transformation)
    assert abs(abs(det(transformation))-1e0) < 1e-8
  if numops != 48:
    allops = cell_invariants(array([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]]))
    failed = 0
    for op in allops: 
      transformation = dot(dot(inv(cell), op[:3]), cell)
      if not (is_integer(transformation) and abs(abs(det(transformation))-1e0) < 1e-8):
        failed += 1
    assert failed == 48 - numops
Exemplo n.º 9
0
def test_isinteger():
  from numpy import array
  from pylada.math import is_integer
  from pylada.error import TypeError

  assert is_integer(array([0, 1, 0, 2]))
  assert is_integer(array([0L, 1, 0, 2]))
  assert is_integer(array([0, 1.0, 0.0, 2.0]))
  assert not is_integer(array([0, 1.1, 0.0, 2.0]))
  try: is_integer([5, 6, 7])
  except TypeError: pass
  else: raise Exception()