Esempio n. 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
Esempio n. 2
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)