Exemple #1
0
def test_labelexchange():
  """ Tests label exchange """
  from pylada.crystal import binary, supercell, HFTransform
  from pylada.enum import Transforms

  lattice = binary.zinc_blende()
  lattice[0].type = ['Si', 'Ge']
  lattice[1].type = ['Si', 'Ge', 'C']
  transforms = Transforms(lattice)
  lattice = transforms.lattice

  structure = supercell(lattice, [[8, 0, 0], [0, 0.5, 0.5], [0, -0.5, 0.5]])
  species = [ 'Ge', 'C', 'Si', 'C', 'Si', 'C', 'Si', 'Si', 'Ge', 'Si', 'Ge',
              'Si', 'Ge', 'Si', 'Ge', 'Ge', 'Ge', 'C', 'Ge', 'Si', 'Si', 'Si',
              'Si', 'Ge', 'Si', 'Ge', 'Si', 'Si', 'Si', 'C', 'Ge', 'Si']
  for atom, s in zip(structure, species): atom.type = s
  hft = HFTransform(lattice, structure) 
  x = transforms.toarray(hft, structure)
  results = [ 21112222221111123331111231122131L, # <- this is x
              21112222221111122221111321133121L,
              21112222221111123332222132211232L,
              21112222221111121112222312233212L,
              21112222221111122223333123311323L,
              21112222221111121113333213322313L,
              12221111112222213331111231122131L,
              12221111112222212221111321133121L,
              12221111112222213332222132211232L,
              12221111112222211112222312233212L,
              12221111112222212223333123311323L,
              12221111112222211113333213322313L ]
  permutations = transforms.label_exchange(hft)
  for a, b in zip(permutations(x), results[1:]): 
    assert int(str(a)[1:-1].replace(' ', '')) == b
Exemple #2
0
def test_rotations():
  from numpy import all, dot, zeros
  from numpy.linalg import inv
  from pylada.crystal import binary, supercell, HFTransform, space_group,        \
                           which_site
  from pylada.enum import Transforms

  lattice = binary.zinc_blende()
  lattice[0].type = ['Si', 'Ge']
  lattice[1].type = ['Si', 'Ge', 'C']
  sg = space_group(lattice)
  invcell = inv(lattice.cell)

  def get_cells(n):
    for i in xrange(1, n):
      yield [[i, 0, 0], [0, 0.5, 0.5], [0, -0.5, 0.5]]
    for i in xrange(1, n):
      yield [[i, 0, 0], [0, i, 0], [0, 0, 1]]
    for i in xrange(1, n):
      yield [[i, 0, 0], [0, i, 0], [0, 0, i]]
    yield dot(lattice.cell, [[1, 0, 0], [0, 1, 0], [0, 0, 2]])
  for cell in get_cells(8):
    # create random structure
    structure = supercell(lattice, cell)
    hft = HFTransform(lattice, structure)
 
    # these are all the translations
    transforms = Transforms(lattice)
    permutations = transforms.transformations(hft)
    assert permutations.shape == (len(sg) - 1, len(structure))
    operations = transforms.invariant_ops(structure)
    assert any(operations) 

    # compute each translation and gets decorations
    for index, (op, isgood) in enumerate(zip(sg[1:], operations)):
      if not isgood: continue
      # Create rotation and figure out its index
      permutation = zeros(len(structure), dtype='int') - 1
      for atom in structure:
        pos = dot(op[:3], atom.pos) + op[3]
        newsite = which_site(pos, lattice, invcell)
        i = hft.index(atom.pos - lattice[atom.site].pos, atom.site)
        j = hft.index(pos - lattice[newsite].pos, newsite)
        permutation[i] = j
      assert all(permutation == permutations[index])
Exemple #3
0
def test_toarray():
  """ Tests label exchange """
  from random import choice
  from numpy import all, zeros
  from pylada.crystal import binary, supercell, HFTransform
  from pylada.enum import Transforms

  lattice = binary.zinc_blende()
  lattice[0].type = ['Si', 'Ge']
  lattice[1].type = ['Si', 'Ge', 'C']
  transforms = Transforms(lattice)
  lattice = transforms.lattice

  for u in xrange(11):
    structure = supercell(lattice, get_cell())
    for atom in structure: atom.type = choice(atom.type)
    hft = HFTransform(lattice, structure) 
    a = transforms.toarray(hft, structure)
    b = zeros(len(structure), dtype='int')
    for atom in structure:
      site = lattice[atom.site]
      b[hft.index(atom.pos-site.pos, atom.site)]                               \
        = site.type.index(atom.type) + 1
    assert all(a == b)