コード例 #1
0
ファイル: hart-forcade.py プロジェクト: mdavezac/LaDa
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)
コード例 #2
0
def test1():
    from random import randint
    from numpy import all, abs, dot, array
    from pylada.crystal.cppwrappers import HFTransform

    unitcell = array([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]])
    supercell = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    a = HFTransform(unitcell, supercell)
    assert all(abs(a.transform - [[1, 1, -1], [0, 2, 0], [0, 0, 2]]) < 1e-8)
    assert all(abs(a.quotient - [1, 2, 2]) < 1e-8)
    for i in xrange(20):
        vec = dot(
            supercell,
            array([randint(-20, 20),
                   randint(-20, 20),
                   randint(-20, 20)],
                  dtype="float64"))
        vec += [0, -0.5, 0.5]
        assert all(abs(a.indices(vec) - [0, 1, 1]) < 1e-8)
        try:
            a.indices(vec + [0.1, 0.1, 0])
        except ValueError:
            pass
        else:
            raise RuntimeError("Should have failed.")
コード例 #3
0
ファイル: hart-forcade.py プロジェクト: mdavezac/LaDa
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)
コード例 #4
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)
コード例 #5
0
ファイル: hart-forcade.py プロジェクト: mdavezac/LaDa
def test1():
  from random import randint
  from numpy import all, abs, dot, array
  from pylada.crystal.cppwrappers import HFTransform
  
  unitcell = array([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]])
  supercell = array([[1,0,0],[0,1,0],[0,0,1]])
  a = HFTransform(unitcell, supercell)
  assert all(abs(a.transform-[[1, 1, -1],[0, 2, 0],[0, 0, 2]]) < 1e-8)
  assert all(abs(a.quotient-[1,2,2]) < 1e-8)
  for i in xrange(20):
    vec = dot(supercell, array([randint(-20, 20), randint(-20, 20), randint(-20, 20)], dtype="float64"))
    vec += [0, -0.5, 0.5]
    assert all(abs(a.indices(vec)-[0, 1, 1]) < 1e-8)
    try: a.indices(vec + [0.1, 0.1, 0])
    except ValueError: pass
    else: raise RuntimeError("Should have failed.")
コード例 #6
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)