Exemplo n.º 1
0
def test2():
  from random import randint
  from numpy import all, abs, dot, array
  from pylada.crystal.cppwrappers import HFTransform, Structure, supercell
  
  unitcell = array([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]])
  lattice = Structure(unitcell).add_atom(0,0,0, "Si")
  supercell = supercell(lattice, dot(lattice.cell, [[3,0,5],[0,0,-1],[-2,1,2]]))

  a = HFTransform(unitcell, supercell)

  assert all(abs(a.transform-[[0, 2, 0],[1, 5, -1],[-2, -4, 0]]) < 1e-8)
  assert all(abs(a.quotient-[1,1,3]) < 1e-8)
  all_indices = set()
  for atom in supercell:
    indices = a.indices(atom.pos)
    index = a.index(atom.pos)
    assert index not in all_indices, (index, all_indices )
    assert all(indices >= 0)
    assert all(indices <= a.quotient )
    assert index == a.flatten_indices(*indices)
    all_indices.add(index)
    for i in xrange(20):
      vec = dot(supercell.cell, array([randint(-20, 20), randint(-20, 20), randint(-20, 20)], dtype="float64"))
      vec += atom.pos
      assert all(abs(a.indices(vec)-indices) < 1e-8)
      try: a.indices(vec + [0.1, 0.1, 0])
      except ValueError: pass
      else: raise RuntimeError("Should have failed.")
      assert index == a.index(vec)
      try: a.index(vec + [0.1, 0.1, 0])
      except ValueError: pass
      else: raise RuntimeError("Should have failed.")
  assert len(all_indices) == len(supercell)
def test_coordination_shells():
  from random import random
  from numpy import array
  from numpy.random import randint, random
  from pylada.crystal.cppwrappers import supercell, Structure

  lattice = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]]) \
                     .add_atom(0, 0, 0, "Si")                       \
                     .add_atom(0.25, 0.25, 0.25, "Ge")
  for atom in lattice: check(lattice, atom)

  structure = supercell(lattice, [1, 1, 0, -5, 2, 0, 0, 0, 1])
  for index in randint(len(structure), size=4):
      check(structure, structure[index])

  for atom in lattice: atom.pos += random(3) * 1e-4 - 5e-5 
  for atom in lattice:
      check(lattice, atom, 1e-2)

  for atom in structure: atom.pos += random(3) * 1e-4 - 5e-5 
  for index in randint(len(structure), size=4):
      check(structure, structure[index], 1e-2)

  check_against_neighbors(structure, 1e-2)

  lattice = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]]) \
                     .add_atom(0, 0, 0, "Si")
  check_against_neighbors(structure, 1e-8)
  lattice = Structure([[-0.5, 0.5, 0.5],[0.5, -0.5, 0.5], [0.5, 0.5, -0.5]]) \
                     .add_atom(0, 0, 0, "Si")
  check_against_neighbors(structure, 1e-8)
Exemplo n.º 3
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.º 4
0
def test_ediff():
    from pickle import loads, dumps
    from pylada.crystal.cppwrappers import Structure, supercell
    from pylada.vasp.incar._params import Ediff, Ediffg

    structure = (
        Structure([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]])
        .add_atom(0, 0, 0, "Si")
        .add_atom(0.25, 0.25, 0.25, "Si")
    )
    assert Ediff(None).incar_string(structure=structure) is None
    a = loads(dumps(Ediff(1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFF" and a[1] == "=" and abs(float(a[2]) - 1e-4 * 2.0) < 1e-8
    a = loads(dumps(Ediff(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFF" and a[1] == "=" and abs(float(a[2]) - 1e-4) < 1e-8 and float(a[2]) > 0e0

    assert Ediffg(None).incar_string(structure=structure) is None
    a = loads(dumps(Ediffg(1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFFG" and a[1] == "=" and abs(float(a[2]) - 1e-4 * 2.0) < 1e-8
    a = loads(dumps(Ediffg(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFFG" and a[1] == "=" and abs(float(a[2]) + 1e-4) < 1e-8

    structure = supercell(structure, [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    a = loads(dumps(Ediff(1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFF" and a[1] == "=" and abs(float(a[2]) - 1e-4 * 8.0) < 1e-8
    a = loads(dumps(Ediff(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFF" and a[1] == "=" and abs(float(a[2]) - 1e-4) < 1e-8 and float(a[2]) > 0e0

    a = loads(dumps(Ediffg(1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFFG" and a[1] == "=" and abs(float(a[2]) - 1e-4 * 8.0) < 1e-8
    a = loads(dumps(Ediffg(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == "EDIFFG" and a[1] == "=" and abs(float(a[2]) + 1e-4) < 1e-8
Exemplo n.º 5
0
def test3(u):
  from random import randint
  from numpy import all, abs, dot, array, concatenate
  from pylada.crystal.cppwrappers import HFTransform, supercell
  
  lattice = b5(u)
  supercell = supercell(lattice, dot(lattice.cell, [[2,2,0],[0,2,2],[4,0,4]]))

  a = HFTransform(lattice.cell, supercell)

  assert all(abs(a.transform-[[-1, 1, 1],[1, -1, 1],[5, -3, -1]]) < 1e-8)
  assert all(abs(a.quotient-[2,2,8]) < 1e-8)
  all_indices = set()
  others = set()
  for atom in supercell:
    indices = a.indices(atom.pos - lattice[atom.site].pos)
    index = a.index(atom.pos - lattice[atom.site].pos, atom.site)
    assert index not in all_indices, (index, all_indices )
    assert all(indices >= 0)
    assert all(indices <= a.quotient )
    all_indices.add(index)
    assert str(concatenate((indices, [atom.site]))) not in others
    others.add(str(concatenate((indices, [atom.site]))))
    for i in xrange(20):
      vec = dot(supercell.cell, array([randint(-20, 20), randint(-20, 20), randint(-20, 20)], dtype="float64"))
      vec += atom.pos - lattice[atom.site].pos
      assert all(abs(a.indices(vec)-indices) < 1e-8)
      try: a.indices(vec + [0.1, 0.1, 0])
      except ValueError: pass
      else: raise RuntimeError("Should have failed.")
      assert index == a.index(vec, atom.site)
      try: a.index(vec + [0.1, 0.1, 0])
      except ValueError: pass
      else: raise RuntimeError("Should have failed.")
  assert len(all_indices) == len(supercell)
Exemplo n.º 6
0
def newstructure(i=10):
  from numpy import zeros
  from numpy.linalg import det
  from random import randint
  from pylada.crystal.cppwrappers import supercell
  
  lattice = b5()
  cell = zeros((3,3))
  while det(cell) == 0:
    cell[:] = [[randint(-i, i+1) for j in xrange(3)] for k in xrange(3)]
  if det(cell) < 0: cell[:, 0], cell[:, 1] = cell[:, 1].copy(), cell[:, 0].copy()
  return supercell(lattice, cell)
Exemplo n.º 7
0
def test1():
  from pylada.crystal.cppwrappers import Structure, supercell

  zb = Structure( 0,0.5,0.5,
                  0.5,0,0.5,
                  0.5,0.5,0 )\
                .add_atom(0,0,0, "Si")\
                .add_atom(0.25,0.25,0.25, "Si")
  sc = supercell(zb, [[3, 0, 0], [0, 0.5,-0.5], [0, 0.5, 0.5]])
  sc[0].type = "Ge"
  sc[1].type = "Ge"
  sc[3].type = "Ge"
  decoration(sc, sc, zb)
Exemplo n.º 8
0
def get_a_supercell(u):
    from random import randint
    from numpy import array
    from numpy.linalg import det
    from pylada.crystal.cppwrappers import supercell
    lattice = get_some_lattice(u)
    while True:
      cell = [ [randint(-2, 3) for j in xrange(3)] for k in xrange(3)]
      if det(cell) != 0: break
    structure = supercell(lattice, cell)
    copy = structure.copy()
    for atom in copy: del atom.site
    return structure, copy, lattice
Exemplo n.º 9
0
def test1():
    from pylada.crystal.cppwrappers import Structure, supercell

    zb = Structure( 0,0.5,0.5,
                    0.5,0,0.5,
                    0.5,0.5,0 )\
                  .add_atom(0,0,0, "Si")\
                  .add_atom(0.25,0.25,0.25, "Si")
    sc = supercell(zb, [[3, 0, 0], [0, 0.5, -0.5], [0, 0.5, 0.5]])
    sc[0].type = "Ge"
    sc[1].type = "Ge"
    sc[3].type = "Ge"
    decoration(sc, sc, zb)
Exemplo n.º 10
0
def test2():
  from random import random
  from pylada.crystal.cppwrappers import Structure, supercell

  zb = Structure( 0,0.5,0.5,
                  0.5,0,0.5,
                  0.5,0.5,0 )\
                .add_atom(0,0,0, "Si")\
                .add_atom(0.25,0.25,0.25, "Si")
  sc = supercell(zb, [[2, 0, 0], [0, 2,0], [0, 0, 2]])
  del sc.lattice
  for i in xrange(1):
    x = random() * 0.5
    for atom in sc:
      atom.type = "Si" if x > random() else "Ge"
    decoration(sc, sc, zb)
Exemplo n.º 11
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)
Exemplo n.º 12
0
def test2():
    from random import random
    from pylada.crystal.cppwrappers import Structure, supercell

    zb = Structure( 0,0.5,0.5,
                    0.5,0,0.5,
                    0.5,0.5,0 )\
                  .add_atom(0,0,0, "Si")\
                  .add_atom(0.25,0.25,0.25, "Si")
    sc = supercell(zb, [[2, 0, 0], [0, 2, 0], [0, 0, 2]])
    del sc.lattice
    for i in xrange(1):
        x = random() * 0.5
        for atom in sc:
            atom.type = "Si" if x > random() else "Ge"
        decoration(sc, sc, zb)
Exemplo n.º 13
0
def test3(u):
    from random import randint
    from numpy import all, abs, dot, array, concatenate
    from pylada.crystal.cppwrappers import HFTransform, supercell

    lattice = b5(u)
    supercell = supercell(lattice,
                          dot(lattice.cell, [[2, 2, 0], [0, 2, 2], [4, 0, 4]]))

    a = HFTransform(lattice.cell, supercell)

    assert all(abs(a.transform - [[-1, 1, 1], [1, -1, 1], [5, -3, -1]]) < 1e-8)
    assert all(abs(a.quotient - [2, 2, 8]) < 1e-8)
    all_indices = set()
    others = set()
    for atom in supercell:
        indices = a.indices(atom.pos - lattice[atom.site].pos)
        index = a.index(atom.pos - lattice[atom.site].pos, atom.site)
        assert index not in all_indices, (index, all_indices)
        assert all(indices >= 0)
        assert all(indices <= a.quotient)
        all_indices.add(index)
        assert str(concatenate((indices, [atom.site]))) not in others
        others.add(str(concatenate((indices, [atom.site]))))
        for i in xrange(20):
            vec = dot(
                supercell.cell,
                array([randint(-20, 20),
                       randint(-20, 20),
                       randint(-20, 20)],
                      dtype="float64"))
            vec += atom.pos - lattice[atom.site].pos
            assert all(abs(a.indices(vec) - indices) < 1e-8)
            try:
                a.indices(vec + [0.1, 0.1, 0])
            except ValueError:
                pass
            else:
                raise RuntimeError("Should have failed.")
            assert index == a.index(vec, atom.site)
            try:
                a.index(vec + [0.1, 0.1, 0])
            except ValueError:
                pass
            else:
                raise RuntimeError("Should have failed.")
    assert len(all_indices) == len(supercell)
Exemplo n.º 14
0
def test2():
    from random import randint
    from numpy import all, abs, dot, array
    from pylada.crystal.cppwrappers import HFTransform, Structure, supercell

    unitcell = array([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]])
    lattice = Structure(unitcell).add_atom(0, 0, 0, "Si")
    supercell = supercell(
        lattice, dot(lattice.cell, [[3, 0, 5], [0, 0, -1], [-2, 1, 2]]))

    a = HFTransform(unitcell, supercell)

    assert all(abs(a.transform - [[0, 2, 0], [1, 5, -1], [-2, -4, 0]]) < 1e-8)
    assert all(abs(a.quotient - [1, 1, 3]) < 1e-8)
    all_indices = set()
    for atom in supercell:
        indices = a.indices(atom.pos)
        index = a.index(atom.pos)
        assert index not in all_indices, (index, all_indices)
        assert all(indices >= 0)
        assert all(indices <= a.quotient)
        assert index == a.flatten_indices(*indices)
        all_indices.add(index)
        for i in xrange(20):
            vec = dot(
                supercell.cell,
                array([randint(-20, 20),
                       randint(-20, 20),
                       randint(-20, 20)],
                      dtype="float64"))
            vec += atom.pos
            assert all(abs(a.indices(vec) - indices) < 1e-8)
            try:
                a.indices(vec + [0.1, 0.1, 0])
            except ValueError:
                pass
            else:
                raise RuntimeError("Should have failed.")
            assert index == a.index(vec)
            try:
                a.index(vec + [0.1, 0.1, 0])
            except ValueError:
                pass
            else:
                raise RuntimeError("Should have failed.")
    assert len(all_indices) == len(supercell)
Exemplo n.º 15
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)
Exemplo n.º 16
0
def test_b5(u):
    """ Test b5 space-group and equivalents """
    from random import randint, random
    from numpy import array
    from numpy.linalg import det
    from pylada.crystal.cppwrappers import Structure, map_sites, supercell

    x, y = u, 0.25 - u
    lattice = Structure([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]]) \
                       .add_atom(5.000000e-01, 5.000000e-01, 5.000000e-01, "A") \
                       .add_atom(5.000000e-01, 2.500000e-01, 2.500000e-01, "A") \
                       .add_atom(2.500000e-01, 5.000000e-01, 2.500000e-01, "A") \
                       .add_atom(2.500000e-01, 2.500000e-01, 5.000000e-01, "A") \
                       .add_atom(8.750000e-01, 8.750000e-01, 8.750000e-01, "B") \
                       .add_atom(1.250000e-01, 1.250000e-01, 1.250000e-01, "B") \
                       .add_atom(     x,     x,     x, "X") \
                       .add_atom(     x,     y,     y, "X") \
                       .add_atom(     y,     x,     y, "X") \
                       .add_atom(     y,     y,     x, "X") \
                       .add_atom(    -x,    -x,    -x, "X") \
                       .add_atom(    -x,    -y,    -y, "X") \
                       .add_atom(    -y,    -x,    -y, "X") \
                       .add_atom(    -y,    -y,    -x, "X")
    for i in xrange(5):
        while True:
            cell = [[randint(-2, 3) for j in xrange(3)] for k in xrange(3)]
            if det(cell) != 0: break
        structure0 = supercell(lattice, cell)
        structure1 = structure0.copy()

        for atom in structure1:
            del atom.site
        assert map_sites(lattice, structure1)
        for a, b in zip(structure0, structure1):
            assert a.site == b.site

        for atom in structure1:
            del atom.site
            atom.pos += array(
                [random() * 1e-3,
                 random() * 1e-3,
                 random() * 1e-3])
        assert map_sites(lattice, structure1, tolerance=1e-2)
        for a, b in zip(structure0, structure1):
            assert a.site == b.site
Exemplo n.º 17
0
def test_b5(u):
  """ Test b5 space-group and equivalents """
  from random import randint, random
  from numpy import array
  from numpy.linalg import det
  from pylada.crystal.cppwrappers import Structure, map_sites, supercell

  x, y = u, 0.25-u
  lattice = Structure([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]]) \
                     .add_atom(5.000000e-01, 5.000000e-01, 5.000000e-01, "A") \
                     .add_atom(5.000000e-01, 2.500000e-01, 2.500000e-01, "A") \
                     .add_atom(2.500000e-01, 5.000000e-01, 2.500000e-01, "A") \
                     .add_atom(2.500000e-01, 2.500000e-01, 5.000000e-01, "A") \
                     .add_atom(8.750000e-01, 8.750000e-01, 8.750000e-01, "B") \
                     .add_atom(1.250000e-01, 1.250000e-01, 1.250000e-01, "B") \
                     .add_atom(     x,     x,     x, "X") \
                     .add_atom(     x,     y,     y, "X") \
                     .add_atom(     y,     x,     y, "X") \
                     .add_atom(     y,     y,     x, "X") \
                     .add_atom(    -x,    -x,    -x, "X") \
                     .add_atom(    -x,    -y,    -y, "X") \
                     .add_atom(    -y,    -x,    -y, "X") \
                     .add_atom(    -y,    -y,    -x, "X") 
  for i in xrange(5):
    while True:
      cell = [ [randint(-2, 3) for j in xrange(3)] for k in xrange(3)]
      if det(cell) != 0: break
    structure0 = supercell(lattice, cell)
    structure1 = structure0.copy()

    for atom in structure1: del atom.site
    assert map_sites(lattice, structure1)
    for a, b in zip(structure0, structure1): 
      assert a.site == b.site

    for atom in structure1:
      del atom.site
      atom.pos += array([random() * 1e-3, random() * 1e-3, random() * 1e-3])
    assert map_sites(lattice, structure1, tolerance=1e-2)
    for a, b in zip(structure0, structure1): 
      assert a.site == b.site
Exemplo n.º 18
0
def test_manysupercell():
  from numpy import dot
  from numpy.linalg import inv, det
  from pylada.crystal import supercell, binary
  from pylada.crystal.cppwrappers import are_periodic_images as api
  lattice = binary.zinc_blende()
  invlat = inv(lattice.cell)
  for i in xrange(100):
    cell = get_cell()
    struc = supercell(lattice, dot(lattice.cell, cell))
    assert len(struc) == len(lattice) * int(abs(det(cell))+0.01)
    invcell = inv(struc.cell)
    for i, atom in enumerate(struc):
      # compare to lattice
      tolat = [api(atom.pos, site.pos, invlat) for site in lattice]
      assert tolat.count(True) == 1
      assert tolat.index(True) == atom.site
      assert lattice[tolat.index(True)].type == atom.type
      # compare to self
      tolat = [api(atom.pos, site.pos, invcell) for site in struc]
      assert tolat.count(True) == 1
      assert i == tolat.index(True)
Exemplo n.º 19
0
def test_manysupercell():
    from numpy import dot
    from numpy.linalg import inv, det
    from pylada.crystal import supercell, binary
    from pylada.crystal.cppwrappers import are_periodic_images as api
    lattice = binary.zinc_blende()
    invlat = inv(lattice.cell)
    for i in xrange(100):
        cell = get_cell()
        struc = supercell(lattice, dot(lattice.cell, cell))
        assert len(struc) == len(lattice) * int(abs(det(cell)) + 0.01)
        invcell = inv(struc.cell)
        for i, atom in enumerate(struc):
            # compare to lattice
            tolat = [api(atom.pos, site.pos, invlat) for site in lattice]
            assert tolat.count(True) == 1
            assert tolat.index(True) == atom.site
            assert lattice[tolat.index(True)].type == atom.type
            # compare to self
            tolat = [api(atom.pos, site.pos, invcell) for site in struc]
            assert tolat.count(True) == 1
            assert i == tolat.index(True)
Exemplo n.º 20
0
def test_ediff():
    from pickle import loads, dumps
    from pylada.crystal.cppwrappers import Structure, supercell
    from pylada.vasp.incar._params import Ediff, Ediffg

    structure = Structure([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]])\
                         .add_atom(0, 0, 0, 'Si')\
                         .add_atom(0.25, 0.25, 0.25, 'Si')
    assert Ediff(None).incar_string(structure=structure) is None
    a = loads(dumps(Ediff(1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFF' and a[1] == '=' and abs(float(a[2]) -
                                                   1e-4 * 2.) < 1e-8
    a = loads(dumps(Ediff(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFF' and a[1] == '=' and abs(float(a[2]) -
                                                   1e-4) < 1e-8 and float(
                                                       a[2]) > 0e0

    assert Ediffg(None).incar_string(structure=structure) is None
    a = loads(dumps(Ediffg(1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFFG' and a[1] == '=' and abs(float(a[2]) -
                                                    1e-4 * 2.) < 1e-8
    a = loads(dumps(Ediffg(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFFG' and a[1] == '=' and abs(float(a[2]) + 1e-4) < 1e-8

    structure = supercell(structure, [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    a = loads(dumps(Ediff(1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFF' and a[1] == '=' and abs(float(a[2]) -
                                                   1e-4 * 8.) < 1e-8
    a = loads(dumps(Ediff(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFF' and a[1] == '=' and abs(float(a[2]) -
                                                   1e-4) < 1e-8 and float(
                                                       a[2]) > 0e0

    a = loads(dumps(Ediffg(1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFFG' and a[1] == '=' and abs(float(a[2]) -
                                                    1e-4 * 8.) < 1e-8
    a = loads(dumps(Ediffg(-1e-4))).incar_string(structure=structure).split()
    assert a[0] == 'EDIFFG' and a[1] == '=' and abs(float(a[2]) + 1e-4) < 1e-8
Exemplo n.º 21
0
def test_supercell():
  """ Simple supercell test. """
  from numpy import identity, abs, all, dot
  from numpy.linalg import inv
  from pylada.crystal.cppwrappers import supercell, Structure, are_periodic_images as api
  from quantities import angstrom
  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)
  result = supercell(lattice, dot(lattice.cell, [ [-1, 1, 1],
                                [1, -1, 1], 
                                [1, 1, -1] ] ) )
  assert all(abs(result.cell - identity(3)) < 1e-8)
  assert abs(result.scale - 2 * angstrom) < 1e-8
  assert getattr(result, 'm', False) 
  assert all(abs(result[0].pos - [0.00, 0.00, 0.00]) < 1e-8) and result[0].type == "As" \
         and getattr(result[0], 'site', -1) == 0 and api(result[0].pos, lattice[0].pos, inv(lattice.cell))
  assert all(abs(result[1].pos - [0.25, 0.25, 0.25]) < 1e-8) and result[1].type == ["In", "Ga"] \
         and getattr(result[1], 'm', False) and getattr(result[1], 'site', -1) == 1 \
         and api(result[1].pos, lattice[1].pos, inv(lattice.cell))
  assert all(abs(result[2].pos - [0.50, 0.00, 0.50]) < 1e-8) and result[2].type == "As" \
         and getattr(result[2], 'site', -1) == 0 and api(result[2].pos, lattice[0].pos, inv(lattice.cell))
  assert all(abs(result[3].pos - [0.75, 0.25, 0.75]) < 1e-8) and result[3].type == ["In", "Ga"] \
         and getattr(result[3], 'm', False) and getattr(result[3], 'site', -1) == 1 \
         and api(result[3].pos, lattice[1].pos, inv(lattice.cell))
  assert all(abs(result[4].pos - [0.50, 0.50, 0.00]) < 1e-8) and result[4].type == "As" \
         and getattr(result[4], 'site', -1) == 0 and api(result[4].pos, lattice[0].pos, inv(lattice.cell))
  assert all(abs(result[5].pos - [0.75, 0.75, 0.25]) < 1e-8) and result[5].type == ["In", "Ga"] \
         and getattr(result[5], 'm', False) and getattr(result[5], 'site', -1) == 1 \
         and api(result[5].pos, lattice[1].pos, inv(lattice.cell))
  assert all(abs(result[6].pos - [0.00, 0.50, 0.50]) < 1e-8) and result[6].type == "As" \
         and getattr(result[6], 'site', -1) == 0 and api(result[6].pos, lattice[0].pos, inv(lattice.cell))
  assert all(abs(result[7].pos - [0.25, 0.75, 0.75]) < 1e-8) and result[7].type == ["In", "Ga"] \
         and getattr(result[7], 'm', False) and getattr(result[7], 'site', -1) == 1 \
         and api(result[7].pos, lattice[1].pos, inv(lattice.cell))
Exemplo n.º 22
0
def test_supercell():
    """ Simple supercell test. """
    from numpy import identity, abs, all, dot
    from numpy.linalg import inv
    from pylada.crystal.cppwrappers import supercell, Structure, are_periodic_images as api
    from quantities import angstrom
    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)
    result = supercell(lattice,
                       dot(lattice.cell, [[-1, 1, 1], [1, -1, 1], [1, 1, -1]]))
    assert all(abs(result.cell - identity(3)) < 1e-8)
    assert abs(result.scale - 2 * angstrom) < 1e-8
    assert getattr(result, 'm', False)
    assert all(abs(result[0].pos - [0.00, 0.00, 0.00]) < 1e-8) and result[0].type == "As" \
           and getattr(result[0], 'site', -1) == 0 and api(result[0].pos, lattice[0].pos, inv(lattice.cell))
    assert all(abs(result[1].pos - [0.25, 0.25, 0.25]) < 1e-8) and result[1].type == ["In", "Ga"] \
           and getattr(result[1], 'm', False) and getattr(result[1], 'site', -1) == 1 \
           and api(result[1].pos, lattice[1].pos, inv(lattice.cell))
    assert all(abs(result[2].pos - [0.50, 0.00, 0.50]) < 1e-8) and result[2].type == "As" \
           and getattr(result[2], 'site', -1) == 0 and api(result[2].pos, lattice[0].pos, inv(lattice.cell))
    assert all(abs(result[3].pos - [0.75, 0.25, 0.75]) < 1e-8) and result[3].type == ["In", "Ga"] \
           and getattr(result[3], 'm', False) and getattr(result[3], 'site', -1) == 1 \
           and api(result[3].pos, lattice[1].pos, inv(lattice.cell))
    assert all(abs(result[4].pos - [0.50, 0.50, 0.00]) < 1e-8) and result[4].type == "As" \
           and getattr(result[4], 'site', -1) == 0 and api(result[4].pos, lattice[0].pos, inv(lattice.cell))
    assert all(abs(result[5].pos - [0.75, 0.75, 0.25]) < 1e-8) and result[5].type == ["In", "Ga"] \
           and getattr(result[5], 'm', False) and getattr(result[5], 'site', -1) == 1 \
           and api(result[5].pos, lattice[1].pos, inv(lattice.cell))
    assert all(abs(result[6].pos - [0.00, 0.50, 0.50]) < 1e-8) and result[6].type == "As" \
           and getattr(result[6], 'site', -1) == 0 and api(result[6].pos, lattice[0].pos, inv(lattice.cell))
    assert all(abs(result[7].pos - [0.25, 0.75, 0.75]) < 1e-8) and result[7].type == ["In", "Ga"] \
           and getattr(result[7], 'm', False) and getattr(result[7], 'site', -1) == 1 \
           and api(result[7].pos, lattice[1].pos, inv(lattice.cell))
Exemplo n.º 23
0
    if i < N: continue
    x.extend([(atom.pos[0] + trans[0]) for atom, trans, inbox in box if not inbox])
    y.extend([(atom.pos[1] + trans[1]) for atom, trans, inbox in box if not inbox])
    z.extend([(atom.pos[2] + trans[2]) for atom, trans, inbox in box if not inbox])
    s.extend([float(i+2) + (0. if inbox else 0.4) for atom, trans, inbox in box if not inbox])
    break
  points3d(x,y,z,s, scale_factor=0.01, opacity=0.3)


if __name__ == "__main__":
  from sys import argv, path 
  if len(argv) > 0: path.extend(argv[1:])

  from random import randint
  from numpy import zeros
  from numpy.linalg import det
  from pylada.crystal.cppwrappers import supercell
  
  lattice = b5()
  check(lattice)

  for i in xrange(10): 
    cell = zeros((3,3))
    while det(cell) == 0:
      cell[:] = [[randint(-10, 11) for j in xrange(3)] for k in xrange(3)]
    if det(cell) < 0: cell[:, 0], cell[:, 1] = cell[:, 1].copy(), cell[:, 0].copy()
    structure = supercell(lattice, cell)
    check(structure)


Exemplo n.º 24
0
    assert a is d
    assert all(abs(b-e)) < tolerance
    assert abs(c-f) < tolerance

  # check neighbor completeness.
  assert len(neighbors(structure, 2, center,tolerance)) == 4
  assert len(neighbors(structure, 4, center,tolerance)) == 4
  assert len(neighbors(structure, 6, center,tolerance)) == 16

if __name__ == "__main__":
  from sys import argv, path 
  if len(argv) > 0: path.extend(argv[1:])

  from random import random
  from numpy import array
  from pylada.crystal.cppwrappers import supercell, Structure

  lattice = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]]) \
                     .add_atom(0, 0, 0, "Si")                       \
                     .add_atom(0.25, 0.25, 0.25, "Ge")
  for atom in lattice: check(lattice, atom)

  structure = supercell(lattice, [1, 1, 0, -5, 2, 0, 0, 0, 1])
  for atom in structure: check(structure, atom)

  for atom in lattice: atom.pos += array([random(), random(), random()])*1e-4-5e-5 
  for atom in lattice: check(lattice, atom, 1e-2)

  for atom in structure: atom.pos += array([random(), random(), random()])*1e-4-5e-5 
  for atom in structure: check(structure, atom, 1e-2)