Ejemplo n.º 1
0
def test_system():
  from pylada.crystal.cppwrappers import Structure
  from pylada.vasp import Vasp
  a = Vasp()
  b = Structure()

  assert a.system is None
  assert a._input['system'].keyword == 'system'
  assert a._input['system'].output_map(vasp=a, structure=b) is None

  a.system = 'system'
  assert a.system == 'system'
  assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
  assert a._input['system'].output_map(vasp=a, structure=b)['system'] == 'system'

  b.name = 'hello'
  assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
  assert a._input['system'].output_map(vasp=a, structure=b)['system'] == 'system: hello'

  a.system = None
  assert a.system is None
  assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
  assert a._input['system'].output_map(vasp=a, structure=b)['system'] == 'hello'

  a.system = None
  assert a.system is None
  assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
  assert a._input['system'].output_map(vasp=a, structure=b)['system'] == 'hello'
Ejemplo n.º 2
0
def test_system():
    from pylada.crystal.cppwrappers import Structure
    from pylada.vasp import Vasp
    a = Vasp()
    b = Structure()

    assert a.system is None
    assert a._input['system'].keyword == 'system'
    assert a._input['system'].output_map(vasp=a, structure=b) is None

    a.system = 'system'
    assert a.system == 'system'
    assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
    assert a._input['system'].output_map(vasp=a,
                                         structure=b)['system'] == 'system'

    b.name = 'hello'
    assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
    assert a._input['system'].output_map(
        vasp=a, structure=b)['system'] == 'system: hello'

    a.system = None
    assert a.system is None
    assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
    assert a._input['system'].output_map(vasp=a,
                                         structure=b)['system'] == 'hello'

    a.system = None
    assert a.system is None
    assert 'system' in a._input['system'].output_map(vasp=a, structure=b)
    assert a._input['system'].output_map(vasp=a,
                                         structure=b)['system'] == 'hello'
Ejemplo n.º 3
0
def test_magmom():
    from collections import namedtuple
    from pickle import loads, dumps
    from pylada.crystal.cppwrappers import Structure
    from pylada.vasp.incar._params import Magmom

    u = 0.25
    x, y = u, 0.25 - u
    structure = 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, "Mg") \
                         .add_atom(5.000000e-01, 2.500000e-01, 2.500000e-01, "Mg") \
                         .add_atom(2.500000e-01, 5.000000e-01, 2.500000e-01, "Mg") \
                         .add_atom(2.500000e-01, 2.500000e-01, 5.000000e-01, "Mg") \
                         .add_atom(8.750000e-01, 8.750000e-01, 8.750000e-01, "Al") \
                         .add_atom(1.250000e-01, 1.250000e-01, 1.250000e-01, "Al") \
                         .add_atom(     x,     x,     x, "O") \
                         .add_atom(     x,     y,     y, "O") \
                         .add_atom(     y,     x,     y, "O") \
                         .add_atom(     y,     y,     x, "O") \
                         .add_atom(    -x,    -x,    -x, "O") \
                         .add_atom(    -x,    -y,    -y, "O") \
                         .add_atom(    -y,    -x,    -y, "O") \
                         .add_atom(    -y,    -y,    -x, "O")

    for atom in structure:
        if atom.type == 'Mg': atom.magmom = -1e0

    Vasp = namedtuple('Vasp', ['ispin'])
    vasp = Vasp(1)

    # ispin == 1
    magmom = Magmom(True)
    assert magmom.incar_string(vasp=vasp, structure=structure) is None
    # ispins == 2, magmom == False
    magmom.value = False
    vasp = Vasp(2)
    assert magmom.incar_string(vasp=vasp, structure=structure) is None
    # now for real print
    magmom.value = True
    assert magmom.incar_string(
        vasp=vasp, structure=structure) == 'MAGMOM = 4*-1.00 2*0.00 8*0.00'
    # now print a string directly.
    magmom.value = 'hello'
    assert magmom.incar_string(vasp=vasp,
                               structure=structure) == 'MAGMOM = hello'

    # check repr
    assert repr(magmom) == "Magmom('hello')"
    # check pickling
    assert repr(loads(dumps(magmom))) == "Magmom('hello')"

    # more tests.
    magmom.value = True
    for atom, mag in zip(structure, [1, -1, 1, 1]):
        if atom.type == 'Mg': atom.magmom = mag
    for atom, mag in zip(structure, [0.5, 0.5]):
        if atom.type == 'Al': atom.magmom = mag

    assert magmom.incar_string(vasp=vasp, structure=structure) \
             == 'MAGMOM = 1.00 -1.00 2*1.00 2*0.00 8*0.00'
Ejemplo n.º 4
0
def test0():
    from pylada.crystal.cppwrappers import Structure

    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", "Ge")
    basis(zb, zb)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def b5(u=0.25):
    from pylada.crystal.cppwrappers import Structure
    x, y = u, 0.25 - u
    structure = 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")
    return structure
Ejemplo n.º 11
0
def test():
  from collections import namedtuple
  from pickle import loads, dumps
  from pylada.crystal.cppwrappers import Structure
  from pylada.vasp.incar._params import ExtraElectron

  u = 0.25
  x, y = u, 0.25-u
  structure = 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 atom in structure:
    if atom.type == 'Mg': atom.magmom = -1e0

  Vasp = namedtuple('Vasp', ['species'])
  Specie = namedtuple('Specie', ['valence'])
  vasp = Vasp({'A': Specie(5), 'B': Specie(10), 'X': Specie(2)})

  assert 4*5+2*10+2*8 == ExtraElectron(0).nelectrons(vasp, structure)
  assert ExtraElectron(0).incar_string(vasp=vasp, structure=structure)\
           == "# NELECT = 56.0 Charge neutral system"
  assert ExtraElectron(1).incar_string(vasp=vasp, structure=structure)\
           == "NELECT = 57.0  # negatively charged system (-1)"
  assert ExtraElectron(-1).incar_string(vasp=vasp, structure=structure)\
           == "NELECT = 55.0  # positively charged system (+1)"
  assert repr(ExtraElectron()) == 'ExtraElectron(0)'
  assert repr(loads(dumps(ExtraElectron()))) == 'ExtraElectron(0)'
  assert repr(ExtraElectron(-1)) == 'ExtraElectron(-1)'
  assert repr(loads(dumps(ExtraElectron(-1)))) == 'ExtraElectron(-1)'
Ejemplo n.º 12
0
def test_splitconfigs():
    """ regression test for splitconfigs """
    from numpy import abs
    from pylada.crystal.cppwrappers import Structure, splitconfigs, supercell
    structure = Structure([[-0.5, 0.5, 0.5], [0.5, -0.5, 0.5], [0.5, 0.5, -0.5]])\
        .add_atom(0, 0, 0, "Mo")
    configs = splitconfigs(structure, structure[0], 12)
    assert len(configs) == 1
    assert abs(configs[0][1] - 1e0) < 1e-8
    for u in configs[0][0]:
        assert u[0] is structure[0]
    assert all(abs(configs[0][0][0][1] - [0., 0., 0.]) < 1e-8)
    assert all(
        abs(configs[0][0][1][1] -
            [8.66025404e-01, -1.11022302e-16, 0.00000000e+00]) < 1e-8)
    assert all(abs(configs[0][0][2][1] - [0.28867513, 0.81649658, 0.]) < 1e-8)
    assert all(
        abs(configs[0][0][3][1] -
            [0.28867513, -0.40824829, 0.70710678]) < 1e-8)
    assert all(
        abs(configs[0][0][4][1] -
            [0.28867513, -0.40824829, -0.70710678]) < 1e-8)
    assert all(
        abs(configs[0][0][5][1] -
            [-0.28867513, 0.40824829, 0.70710678]) < 1e-8)
    assert all(
        abs(configs[0][0][6][1] -
            [-0.28867513, 0.40824829, -0.70710678]) < 1e-8)
    assert all(
        abs(configs[0][0][7][1] - [-0.28867513, -0.81649658, 0.]) < 1e-8)
    assert all(
        abs(configs[0][0][8][1] -
            [-8.66025404e-01, 1.11022302e-16, 0.00000000e+00]) < 1e-8)
    assert all(
        abs(configs[0][0][9][1] - [0.57735027, 0.40824829, 0.70710678]) < 1e-8)
    assert all(
        abs(configs[0][0][10][1] -
            [0.57735027, 0.40824829, -0.70710678]) < 1e-8)
    assert all(
        abs(configs[0][0][11][1] - [0.57735027, -0.81649658, 0.]) < 1e-8)
Ejemplo n.º 13
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
Ejemplo n.º 14
0
def test_encut(Encut):
    from pickle import loads, dumps
    from collections import namedtuple
    from pylada.crystal.cppwrappers import Structure, supercell
    from quantities import eV, hartree

    Vasp = namedtuple('Vasp', ['species'])
    Specie = namedtuple('Specie', ['enmax'])
    vasp = Vasp({
        'Si': Specie(1. * eV),
        'Ge': Specie(10.),
        'C': Specie(100. * eV)
    })
    name = Encut.__name__.upper()

    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, 'Ge')
    assert Encut(None).incar_string(vasp=vasp, structure=structure) is None
    a = loads(dumps(Encut(50))).incar_string(vasp=vasp,
                                             structure=structure).split()
    assert a[0] == name and a[1] == '=' and abs(float(a[2]) - 50) < 1e-8
    a = loads(dumps(Encut(1.0))).incar_string(vasp=vasp,
                                              structure=structure).split()
    assert a[0] == name and a[1] == '=' and abs(float(a[2]) - 10.) < 1e-8
    structure[0].type = 'C'
    a = loads(dumps(Encut(2.0))).incar_string(vasp=vasp,
                                              structure=structure).split()
    assert a[0] == name and a[1] == '=' and abs(float(a[2]) - 2. * 100.) < 1e-8
    a = loads(dumps(Encut(50. * eV))).incar_string(
        vasp=vasp, structure=structure).split()
    assert a[0] == name and a[1] == '=' and abs(float(a[2]) - 50.) < 1e-8
    a = loads(dumps(Encut((50. * eV).rescale(hartree)))).incar_string(
        vasp=vasp, structure=structure).split()
    assert a[0] == name and a[1] == '=' and abs(float(a[2]) - 50.) < 1e-8
    assert Encut(-50).incar_string(vasp=vasp, structure=structure) is None
    assert Encut(-50 * eV).incar_string(vasp=vasp, structure=structure) is None
Ejemplo n.º 15
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))
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
def test():
    from collections import namedtuple
    from pickle import loads, dumps
    from pylada.crystal.cppwrappers import Structure
    from pylada.vasp.incar._params import UParams
    from pylada.vasp.specie import U, nlep

    u = 0.25
    x, y = u, 0.25 - u
    structure = 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")
    Vasp = namedtuple('Vasp', ['species'])
    Specie = namedtuple('Specie', ['U'])
    vasp = Vasp({
        'A': Specie([U(2, 0, 0.5)]),
        'B': Specie([U(2, 0, -0.5), nlep(2, 1, -1.0)]),
        'X': Specie([])
    })
    a =\
  """\
LDAU = .TRUE.
LDAUPRINT = 0
LDAUTYPE = 2

LDUL1= 0 -1 0
LDUU1=   5.0000000000e-01   0.0000000000e+00  -5.0000000000e-01
LDUJ1=   0.0000000000e+00   0.0000000000e+00   0.0000000000e+00
LDUO1= 1 1 1

LDUL2= -1 -1 1
LDUU2=   0.0000000000e+00   0.0000000000e+00  -1.0000000000e+00
LDUJ2=   0.0000000000e+00   0.0000000000e+00   0.0000000000e+00
LDUO2= 1 1 2
"""
    assert a == UParams('off').incar_string(vasp=vasp, structure=structure)
    vasp = Vasp({
        'A': Specie([U(2, 0, 0.5)]),
        'B': Specie([U(2, 0, -0.5), nlep(2, 2, -1.0, -3.0)]),
        'X': Specie([])
    })
    a =\
  """\
LDAU = .TRUE.
LDAUPRINT = 1
LDAUTYPE = 2

LDUL1= 0 -1 0
LDUU1=   5.0000000000e-01   0.0000000000e+00  -5.0000000000e-01
LDUJ1=   0.0000000000e+00   0.0000000000e+00   0.0000000000e+00
LDUO1= 1 1 1

LDUL2= -1 -1 2
LDUU2=   0.0000000000e+00   0.0000000000e+00  -1.0000000000e+00
LDUJ2=   0.0000000000e+00   0.0000000000e+00  -3.0000000000e+00
LDUO2= 1 1 3
"""
    assert a == UParams('on').incar_string(vasp=vasp, structure=structure)
    vasp = Vasp({'A': Specie([]), 'B': Specie([]), 'X': Specie([])})
    assert '# no LDA+U/NLEP parameters' == UParams('all').incar_string(
        vasp=vasp, structure=structure)

    assert repr(UParams('off')) == "UParams('off')"
    assert repr(UParams('on')) == "UParams('on')"
    assert repr(UParams(None)) == "UParams('off')"
    assert repr(UParams('all')) == "UParams('all')"
    assert repr(loads(dumps(UParams('off')))) == "UParams('off')"
    assert repr(loads(dumps(UParams('on')))) == "UParams('on')"
    assert repr(loads(dumps(UParams(None)))) == "UParams('off')"
    assert repr(loads(dumps(UParams('all')))) == "UParams('all')"
Ejemplo n.º 18
0
 def test_(cell, numops):
     from pylada.crystal.cppwrappers import Structure
     from numpy import array
     test(array(cell), numops)
     # also good test to make sure that structure storage is correct.
     test(Structure(cell).add_atom(0, 0, 0, "Si"), numops)
Ejemplo n.º 19
0
def test_magmom():
    from pickle import loads, dumps
    from pylada.crystal.cppwrappers import Structure
    from pylada.vasp import Vasp

    u = 0.25
    x, y = u, 0.25 - u
    structure = 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, "Mg") \
                         .add_atom(5.000000e-01, 2.500000e-01, 2.500000e-01, "Mg") \
                         .add_atom(2.500000e-01, 5.000000e-01, 2.500000e-01, "Mg") \
                         .add_atom(2.500000e-01, 2.500000e-01, 5.000000e-01, "Mg") \
                         .add_atom(8.750000e-01, 8.750000e-01, 8.750000e-01, "Al") \
                         .add_atom(1.250000e-01, 1.250000e-01, 1.250000e-01, "Al") \
                         .add_atom(     x,     x,     x, "O") \
                         .add_atom(     x,     y,     y, "O") \
                         .add_atom(     y,     x,     y, "O") \
                         .add_atom(     y,     y,     x, "O") \
                         .add_atom(    -x,    -x,    -x, "O") \
                         .add_atom(    -x,    -y,    -y, "O") \
                         .add_atom(    -y,    -x,    -y, "O") \
                         .add_atom(    -y,    -y,    -x, "O")

    for atom in structure:
        if atom.type == 'Mg': atom.magmom = -1e0

    vasp = Vasp()
    vasp.magmom = None
    assert vasp.magmom is None
    assert vasp._input['magmom'].keyword == 'MAGMOM'
    assert vasp._input['magmom'].output_map(vasp=vasp,
                                            structure=structure) is None

    # ispin == 1
    vasp.magmom = True
    vasp.ispin = 1
    assert vasp._input['magmom'].output_map(vasp=vasp,
                                            structure=structure) is None
    # ispins == 2, magmom == False
    vasp.ispin = 2
    vasp.magmom = None
    assert vasp._input['magmom'].output_map(vasp=vasp,
                                            structure=structure) is None
    vasp.magmom = False
    assert vasp._input['magmom'].output_map(vasp=vasp,
                                            structure=structure) is None
    # now for real print
    vasp.magmom = True
    assert 'MAGMOM' in vasp._input['magmom'].output_map(vasp=vasp,
                                                        structure=structure)
    print vasp._input['magmom'].output_map(vasp=vasp,
                                           structure=structure)['MAGMOM']
    assert vasp._input['magmom'].output_map(
        vasp=vasp, structure=structure)['MAGMOM'] == '4*-1.0 2*0.0 8*0.0'
    # now print a string directly.
    vasp.magmom = 'hello'
    assert vasp.magmom == 'hello'
    assert 'MAGMOM' in vasp._input['magmom'].output_map(vasp=vasp,
                                                        structure=structure)
    assert vasp._input['magmom'].output_map(
        vasp=vasp, structure=structure)['MAGMOM'] == 'hello'

    # check repr
    assert repr(vasp._input['magmom']) == "Magmom(value='hello')"
    # check pickling
    assert repr(loads(dumps(vasp._input['magmom']))) == "Magmom(value='hello')"

    # more tests.
    for atom, mag in zip(structure, [1, -1, 1, 1]):
        if atom.type == 'Mg': atom.magmom = mag
    for atom, mag in zip(structure, [0.5, 0.5]):
        if atom.type == 'Al': atom.magmom = mag

    vasp.magmom = True
    assert 'MAGMOM' in vasp._input['magmom'].output_map(vasp=vasp,
                                                        structure=structure)
    assert vasp._input['magmom'].output_map(
        vasp=vasp,
        structure=structure)['MAGMOM'] == '1.0 -1.0 2*1.0 2*0.0 8*0.0'
Ejemplo n.º 20
0
def check_bcc():
  """ Check on BCC structure. """
  from pylada.crystal.cppwrappers import Structure, neighbors
  structure = Structure([[-0.5,0.5,0.5],[0.5,-0.5,0.5],[0.5,0.5,-0.5]])\
                       .add_atom(0,0,0,"Mo")
  print neighbors(structure, 12, [0,0,0])