Beispiel #1
0
def test_coordination_shells():
    from random import random
    from numpy import array
    from numpy.random import randint, random
    from pylada.crystal 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-8)

    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)
Beispiel #2
0
def test_ewald():
    """ Ewald Rydberg test """
    from numpy import all, abs, sqrt
    from pylada.crystal import Structure
    from pylada.ewald import ewald
    from quantities import angstrom, a0, Ry

    structure = Structure([[1, 0, 0],
                           [0, 1, 0],
                           [0, 0, 1] ], scale=50 )             \
        .add_atom(0, 0, 0, 'A', charge=1e0)                     \
        .add_atom(float(a0.rescale(angstrom) / 50.0), 0, 0, 'A', charge=-1e0)

    result = ewald(structure, cutoff=80)
    assert abs(result.energy + 2e0 * Ry) < 1e-3
    assert all(abs(abs(result[0].force) - [2e0, 0, 0] * Ry / a0) < 1e-3)
    assert all(abs(abs(result[1].force) - [2e0, 0, 0] * Ry / a0) < 1e-3)

    a = float(a0.rescale(angstrom) / 50.0) / sqrt(2.)
    structure = Structure([[1, 0, 0],
                           [0, 1, 0],
                           [0, 0, 1] ], scale=50 )              \
        .add_atom(0, 0, 0, 'A', charge=1e0)                     \
        .add_atom(0, a, a, 'A', charge=-1e0)

    result = ewald(structure, cutoff=80)
    assert abs(result.energy + 2e0 * Ry) < 1e-3
    assert all(
        abs(abs(result[0].force) -
            [0, 2. / sqrt(2), 2. / sqrt(2)] * Ry / a0) < 1e-3)
    assert all(
        abs(abs(result[1].force) -
            [0, 2. / sqrt(2), 2. / sqrt(2)] * Ry / a0) < 1e-3)
Beispiel #3
0
def test_ediff():
    from pickle import loads, dumps
    from pylada.crystal 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
Beispiel #4
0
def test_encut(EncutClass):
    from pickle import loads, dumps
    from collections import namedtuple
    from pylada.crystal 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 = EncutClass.__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 EncutClass(None).incar_string(vasp=vasp, structure=structure) is None
    a = loads(dumps(EncutClass(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(EncutClass(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(EncutClass(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(EncutClass(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(EncutClass((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 EncutClass(-50).incar_string(vasp=vasp, structure=structure) is None
    assert EncutClass(-50 * eV).incar_string(vasp=vasp, structure=structure) is None
Beispiel #5
0
def test_primitive(cell):
    """ Tests whether primitivization works. """
    from numpy import abs, dot
    from numpy.linalg import inv
    from pylada.crystal import supercell, Structure, are_periodic_images as api, primitive, \
        is_primitive

    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)

    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)
        assert atom.type == lattice[atom.site].type
        assert getattr(lattice[atom.site], 'm',
                       False) == getattr(atom, 'm', False)
        assert (getattr(atom, 'm', False) or atom.site == 0)
Beispiel #6
0
def test(path):
  from shutil import rmtree
  from tempfile import mkdtemp
  from pylada.crystal import Structure
  from pylada.vasp import Vasp
  from epirelax import epitaxial
  from pylada import default_comm

  structure = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.55, name='has a name')\
                       .add_atom(0,0,0, "Si")\
                       .add_atom(0.25,0.25,0.25, "Si")

  vasp = Vasp()
  vasp.kpoints    = "Automatic generation\n0\nMonkhorst\n2 2 2\n0 0 0"
  vasp.prec       = "accurate"
  vasp.ediff      = 1e-5
  vasp.encut      = 1.4
  vasp.ismear     = "fermi"
  vasp.sigma      = 0.01
  vasp.relaxation = "volume"
  vasp.add_specie = "Si", "{0}/pseudos/Si".format(path)
  directory = mkdtemp()
  try: 
    result = epitaxial(vasp, structure, outdir=directory, epiconv=1e-4, comm=default_comm)
    assert result.success
  finally: 
    rmtree(directory)
    pass
def get_madelungenergy(latt_vec_array, charge, epsilon, cutoff):
    """ Function returns leading first order correction term, i.e.,
        screened Madelung-like lattice energy of point charge
    Reference: M. Leslie and M. J. Gillan, J. Phys. C: Solid State Phys. 18 (1985) 973

    Parameters
        defect = pylada.vasp.Extract object
        charge = charge of point defect. Default 1e0 elementary charge
        epsilon = dimensionless relative permittivity, SKW: isotropic average of dielectric constant
        cutoff = Ewald cutoff parameter

    Returns
        Madelung (electrostatic) energy in eV                                                                                                                

    Note:
        1. Units in this function are either handled by the module Quantities, or\
        defaults to Angstrom and elementary charges
        2. Function is adopted from Haowei Peng's version in pylada.defects modules
    """

    ewald_cutoff = cutoff * Ry

    cell_scale = 1.0  # SKW: In notebook workflow cell parameters are converted to Cartesians and units of Angstroms
    # SKW: Create point charge in pylada.crystal.structure class (used for charge model)
    # http://pylada.github.io/pylada/userguide/crystal.html
    struc = Structure()
    struc.cell = latt_vec_array
    struc.scale = cell_scale
    struc.add_atom(0., 0., 0., "P", charge=charge)

    #Anuj_05/22/18: added "cutoff" in ewald syntax
    result = ewald(struc, cutoff=ewald_cutoff).energy / epsilon
    return -1 * result.rescale(eV)
Beispiel #8
0
def s28():
    """ s28 lattice """
    from pylada.crystal import Structure
    return Structure( 7.342, -3.671, 0,\
                      0, 6.35836, 0,\
                      0, 0, 7.218,\
                      scale=1, name='s28' )\
             .add_atom(1.55419, 2.47041, 1.8045, 'A')\
             .add_atom(4.42546, 0.110763, 1.8045, 'A')\
             .add_atom(5.03334, 3.77718, 1.8045, 'A')\
             .add_atom(1.36234, 2.58118, 5.4135, 'A')\
             .add_atom(-2.11681, 3.88795, 5.4135, 'A')\
             .add_atom(0.754464, 6.2476, 5.4135, 'A')\
             .add_atom(-3.671e-08, 4.23891, 0.241153, 'B')\
             .add_atom(-3.671e-08, 4.23891, 3.36785, 'B')\
             .add_atom(3.671, 2.11945, 3.85015, 'B')\
             .add_atom(3.671, 2.11945, 6.97685, 'B')\
             .add_atom(0, 0, 1.8045, 'B')\
             .add_atom(0, 0, 5.4135, 'B')\
             .add_atom(2.67983, 4.6416, 0, 'X')\
             .add_atom(1.98234, 0, 0, 'X')\
             .add_atom(-0.99117, 1.71676, 0, 'X')\
             .add_atom(2.67983, 4.6416, 3.609, 'X')\
             .add_atom(1.98234, 0, 3.609, 'X')\
             .add_atom(-0.99117, 1.71676, 3.609, 'X')
Beispiel #9
0
    def __init__(self, vasp, dft, gw, outdir="nlep_fit", comm=None, units=None):
        from os import makedirs
        from os.path import exists
        from shutil import rmtree
        from boost.mpi import world
        from pylada.crystal import Structure

        self.gw = gw
        self.dft = dft
        self.gw.comm = comm
        self.dft.comm = comm
        # since comm has changed, makes sure there are no issues with caching
        self.gw.uncache()
        self.dft.uncache()

        self.vasp = vasp
        self.system = Structure(dft.structure)
        self._nbcalls = 0
        self.outdir = outdir
        self.comm = comm if comm != None else world
        self.units = units if units != None else 1e0

        self.use_syscall = True

        if self.comm.rank == 0 and exists(self.outdir):
            rmtree(self.outdir)
            makedirs(self.outdir)
        self.comm.barrier()
Beispiel #10
0
def s13():
    """ s13 lattice """
    from pylada.crystal import Structure
    return Structure( 14.462, 7.231, -2.12564,\
                      0, 2.785, 0,\
                      0, 0, 9.23657,\
                      scale=1.1, name='s13' )\
             .add_atom(12.2089, 1.30839, 5.17802, 'A')\
             .add_atom(13.5267, 1.30839, 8.67683, 'A')\
             .add_atom(7.35851, 1.47661, 4.05855, 'A')\
             .add_atom(6.04068, 1.47661, 0.559736, 'A')\
             .add_atom(9.78368, 1.3925, 4.61828, 'A')\
             .add_atom(3.6155, 1.3925, 0, 'A')\
             .add_atom(10.1658, 1.31619, 8.0469, 'B')\
             .add_atom(15.5698, 1.31619, 5.80795, 'B')\
             .add_atom(9.40159, 1.46881, 1.18967, 'B')\
             .add_atom(3.9976, 1.46881, 3.42861, 'B')\
             .add_atom(5.63677, 1.22429, 6.92742, 'B')\
             .add_atom(13.9306, 1.56071, 2.30914, 'B')\
             .add_atom(10.8767, 2.56777, 5.62507, 'X')\
             .add_atom(14.8588, 2.56777, 8.22978, 'X')\
             .add_atom(8.69066, 0.21723, 3.6115, 'X')\
             .add_atom(4.70852, 0.21723, 1.00679, 'X')\
             .add_atom(-1.06282, 0, 4.61828, 'X')\
             .add_atom(0, 0, 0, 'X')
Beispiel #11
0
def s41():
    """ s41 lattice """
    from pylada.crystal import Structure
    return Structure( 5.81, 0, 0,\
                      0, 5.96, 0,\
                      0, 0, 11.71,\
                      scale=1.2, name='s41' )\
             .add_atom(5.03146, 1.79992, 0.74944, 'A')\
             .add_atom(2.12646, 1.18008, 10.9606, 'A')\
             .add_atom(0.77854, 4.77992, 5.10556, 'A')\
             .add_atom(3.68354, 4.16008, 6.60444, 'A')\
             .add_atom(0.77854, 4.16008, 10.9606, 'A')\
             .add_atom(3.68354, 4.77992, 0.74944, 'A')\
             .add_atom(5.03146, 1.18008, 6.60444, 'A')\
             .add_atom(2.12646, 1.79992, 5.10556, 'A')\
             .add_atom(3.59058, 0.298, 3.7472, 'B')\
             .add_atom(0.68558, 2.682, 7.9628, 'B')\
             .add_atom(2.21942, 3.278, 2.1078, 'B')\
             .add_atom(5.12442, 5.662, 9.6022, 'B')\
             .add_atom(2.21942, 5.662, 7.9628, 'B')\
             .add_atom(5.12442, 3.278, 3.7472, 'B')\
             .add_atom(3.59058, 2.682, 9.6022, 'B')\
             .add_atom(0.68558, 0.298, 2.1078, 'B')\
             .add_atom(2.98634, 1.03108, 1.33494, 'X')\
             .add_atom(0.08134, 1.94892, 10.3751, 'X')\
             .add_atom(2.82366, 4.01108, 4.52006, 'X')\
             .add_atom(5.72866, 4.92892, 7.18994, 'X')\
             .add_atom(2.82366, 4.92892, 10.3751, 'X')\
             .add_atom(5.72866, 4.01108, 1.33494, 'X')\
             .add_atom(2.98634, 1.94892, 7.18994, 'X')\
             .add_atom(0.08134, 1.03108, 4.52006, 'X')
Beispiel #12
0
def test_b5(u):
    """ Test b5 space-group and equivalents """
    from numpy import dot
    from numpy.random import randint
    from pylada.crystal import Structure, which_site

    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")
    assert which_site(lattice[6].pos + [0.5, -0.5, 2], lattice) == 6
    for i, atom in enumerate(lattice):
        assert which_site(atom.pos, lattice) == i
        for j in xrange(10):
            newpos = dot(lattice.cell, randint(10, size=(3, )) - 5)
            assert which_site(atom.pos + newpos,
                              lattice) == i, (atom.pos, newpos, i)
Beispiel #13
0
def test(path):
    from os import makedirs
    from os.path import exists
    from shutil import rmtree
    from tempfile import mkdtemp
    from pylada.crystal import Structure
    from pylada.vasp import Vasp
    from pylada import default_comm

    structure = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.43, name='has a name')\
                         .add_atom(0,0,0, "Si")\
                         .add_atom(0.25,0.25,0.25, "Si")

    vasp = Vasp()
    vasp.kpoints = "Automatic generation\n0\nMonkhorst\n2 2 2\n0 0 0"
    vasp.prec = "accurate"
    vasp.ediff = 1e-5
    vasp.encut = 1
    vasp.ismear = "fermi"
    vasp.sigma = 0.01
    vasp.relaxation = "volume"
    vasp.add_specie = "Si", "{0}/pseudos/Si".format(path)
    directory = mkdtemp()
    if directory == '/tmp/test' or directory == '/tmp/test/':
        if exists(directory): rmtree(directory)
        makedirs(directory)
    try:
        result = vasp(structure, outdir=directory, comm=default_comm)
        assert result.success
    finally:
        if directory != '/tmp/test' and directory != '/tmp/test/':
            rmtree(directory)
Beispiel #14
0
def test(tmpdir, path):
    from numpy import abs
    from pylada.crystal import Structure
    from pylada.vasp import Vasp
    from pylada.vasp.relax import epitaxial
    from pylada import default_comm

    structure = Structure([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.55, name='has a name')\
        .add_atom(0, 0, 0, "Si")\
        .add_atom(0.25, 0.25, 0.25, "Si")

    vasp = Vasp()
    vasp.kpoints = "Automatic generation\n0\nMonkhorst\n2 2 2\n0 0 0"
    vasp.prec = "accurate"
    vasp.ediff = 1e-5
    vasp.encut = 1.4
    vasp.ismear = "fermi"
    vasp.sigma = 0.01
    vasp.relaxation = "volume"
    vasp.add_specie = "Si", "{0}/pseudos/Si".format(path)
    result = epitaxial(vasp,
                       structure,
                       outdir=str(tmpdir),
                       epiconv=1e-5,
                       comm=default_comm)
    assert result.success
    assert abs(result.stress[2, 2]) < 1.0
Beispiel #15
0
def test_system():
    from pylada.crystal 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'
Beispiel #16
0
def s26():
    """ s26 lattice """
    from pylada.crystal import Structure
    return Structure( 6.997, 0, 3.4985,\
                      0, 10.83, 5.415,\
                      0, 0, 3.1435,\
                      scale=1.1, name='s26' )\
             .add_atom(5.24775, 8.65967, 1.86347, 'A')\
             .add_atom(8.74625, 13.0003, 1.86347, 'A')\
             .add_atom(5.24775, 13.2202, 1.70189, 'A')\
             .add_atom(8.74625, 8.43982, 1.70189, 'A')\
             .add_atom(8.74625, 5.43774, 2.62671, 'A')\
             .add_atom(5.24775, 5.39226, 2.62671, 'A')\
             .add_atom(3.70491, 6.75359, 0.75444, 'B')\
             .add_atom(3.29209, 4.07641, 0.75444, 'B')\
             .add_atom(6.79059, 6.75359, 0.75444, 'B')\
             .add_atom(7.20341, 4.07641, 0.75444, 'B')\
             .add_atom(3.4985, 10.83, 1.57238, 'B')\
             .add_atom(6.997, 10.83, 1.57238, 'B')\
             .add_atom(7.03898, 14.431, 3.11395, 'X')\
             .add_atom(6.95502, 7.22903, 3.11395, 'X')\
             .add_atom(10.4535, 14.431, 3.11395, 'X')\
             .add_atom(3.54048, 7.22903, 3.11395, 'X')\
             .add_atom(1.74925, 5.689, 0.0345785, 'X')\
             .add_atom(5.24775, 5.141, 0.0345785, 'X')
Beispiel #17
0
def s18():
    """ s18 lattice """
    from pylada.crystal import Structure
    return Structure( 9.296, -4.648, 0,\
                      0, 8.05057, 0,\
                      0, 0, 7.346,\
                      scale=1.1, name='s18' )\
             .add_atom(4.648, 5.24897, 4.99528, 'A')\
             .add_atom(2.42626, 1.4008, 4.99528, 'A')\
             .add_atom(6.86974, 1.4008, 4.99528, 'A')\
             .add_atom(0, 2.8016, 1.32228, 'A')\
             .add_atom(2.22174, 6.64977, 1.32228, 'A')\
             .add_atom(-2.22174, 6.64977, 1.32228, 'A')\
             .add_atom(4.64846, 2.68326, 2.29195, 'A')\
             .add_atom(-0.0004648, 5.36732, 5.96495, 'A')\
             .add_atom(0, 7.76075, 3.673, 'B')\
             .add_atom(-2.07301, 4.1702, 3.673, 'B')\
             .add_atom(2.07301, 4.1702, 3.673, 'B')\
             .add_atom(4.648, 0.289821, 0, 'B')\
             .add_atom(6.72101, 3.88038, 0, 'B')\
             .add_atom(2.57499, 3.88038, 0, 'B')\
             .add_atom(0, 0, 3.673, 'B')\
             .add_atom(0, 0, 0, 'B')\
             .add_atom(4.648, 5.31338, 1.89527, 'X')\
             .add_atom(2.37048, 1.3686, 1.89527, 'X')\
             .add_atom(6.92552, 1.3686, 1.89527, 'X')\
             .add_atom(0, 2.73719, 5.56827, 'X')\
             .add_atom(2.27752, 6.68197, 5.56827, 'X')\
             .add_atom(-2.27752, 6.68197, 5.56827, 'X')\
             .add_atom(4.64846, 2.68326, 5.28177, 'X')\
             .add_atom(-0.0004648, 5.36732, 1.60877, 'X')
Beispiel #18
0
def s29():
    """ s29 lattice """
    from pylada.crystal import Structure
    return Structure( 4.308, 0, 0,\
                      0, 13.912, 0,\
                      0, 0, 7.431,\
                      scale=1.1, name='s29' )\
             .add_atom(3.231, 8.93276, 6.85658, 'A')\
             .add_atom(3.231, 11.9352, 6.85658, 'A')\
             .add_atom(1.077, 4.97924, 0.574416, 'A')\
             .add_atom(1.077, 1.97676, 0.574416, 'A')\
             .add_atom(3.231, 1.32039, 4.32023, 'A')\
             .add_atom(3.231, 5.63561, 4.32023, 'A')\
             .add_atom(1.077, 12.5916, 3.11077, 'A')\
             .add_atom(1.077, 8.27639, 3.11077, 'A')\
             .add_atom(3.231, 6.97603, 1.55828, 'B')\
             .add_atom(3.231, 13.892, 1.55828, 'B')\
             .add_atom(1.077, 6.93597, 5.87272, 'B')\
             .add_atom(1.077, 0.0200333, 5.87272, 'B')\
             .add_atom(3.231, 3.478, 2.16688, 'B')\
             .add_atom(1.077, 10.434, 5.26412, 'B')\
             .add_atom(3.231, 10.434, 2.22484, 'B')\
             .add_atom(1.077, 3.478, 5.20616, 'B')\
             .add_atom(3.231, 8.39728, 4.39321, 'X')\
             .add_atom(3.231, 12.4707, 4.39321, 'X')\
             .add_atom(1.077, 5.51472, 3.03779, 'X')\
             .add_atom(1.077, 1.44128, 3.03779, 'X')\
             .add_atom(3.231, 2.18001, 6.76072, 'X')\
             .add_atom(3.231, 4.77599, 6.76072, 'X')\
             .add_atom(1.077, 11.732, 0.670276, 'X')\
             .add_atom(1.077, 9.13601, 0.670276, 'X')
Beispiel #19
0
def from_spglib(strc):
    """
    converting the pylada structure object
    from the spglib format to pylada
    """

    import numpy as np
    from pylada import periodic_table
    from pylada.crystal import Structure

    out_s = Structure()
    out_s.scale = 1.

    cell      = strc[0]
    positions = strc[1]
    symbols   = strc[2]

    out_s.cell = np.transpose(cell)

    for ii in range(len(positions)):
        pp=np.dot(np.transpose(cell),positions[ii])
        ss=periodic_table.symbols[symbols[ii]-1]
        out_s.add_atom(pp[0],pp[1],pp[2],ss)

    return out_s
Beispiel #20
0
def icsd_cif_b(filename):
    from os.path import basename
    from numpy import dot, transpose
    from pylada.crystal import Structure, primitive
    from . import readCif

    rdr = readCif.CifReader(0, filename)    # buglevel = 0
    vaspMap = rdr.getVaspMap()
    cellBasis = vaspMap['cellBasis']

    structure = Structure(
        transpose(cellBasis),
        scale=1,
        name=basename(filename))

    usyms = vaspMap['uniqueSyms']
    posVecs = vaspMap['posVecs']

    # multiplicities = num atoms of each type.
    mults = [len(x) for x in posVecs]

    # For each unique type of atom ...
    for ii in range(len(usyms)):
        # For each atom of that type ...
        for jj in range(mults[ii]):
            atpos = dot(transpose(cellBasis), posVecs[ii][jj])
            structure.add_atom(atpos[0], atpos[1], atpos[2], usyms[ii])


    prim = primitive(structure)
    logger.info("  crystal/read: icsd_cif_b: structure: %s" % structure)

    return prim
Beispiel #21
0
def str_template(name, scale, cell):
  from pylada.crystal import Structure
  structure = Structure()
  structure.name   = name
  structure.scale  = scale
  structure.cell = cell
  return structure
def test_nelect():
    from os.path import dirname
    from pickle import loads, dumps
    from pylada.vasp import Vasp
    from pylada.crystal import Structure

    structure = Structure([[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]],
                          scale=5.43, name='has a name')\
        .add_atom(0, 0, 0, "Si")\
        .add_atom(0.25, 0.25, 0.25, "Si")
    a = Vasp()
    a.add_specie = "Si", "{0}/pseudos/Si".format(dirname(__file__))
    assert a.extraelectron is None
    assert a._input['extraelectron'].output_map() is None
    assert a._input['nelect'].output_map() is None
    a.extraelectron = 0
    assert a.extraelectron == 0
    assert a.nelect is None
    assert a._input['extraelectron'].output_map() is None
    assert a._input['nelect'].output_map() is None
    a.extraelectron = 1
    assert a.extraelectron == 1
    assert a.nelect is None
    assert 'nelect' in a._input['extraelectron'].output_map(
        vasp=a, structure=structure)
    assert abs(
        float(a._input['extraelectron'].output_map(vasp=a, structure=structure)
              ['nelect']) - 9.0) < 1e-8
    assert a._input['nelect'].output_map() is None
    a.nelect = 1
    a.extraelectron = -1
    assert a.extraelectron == -1
    assert a.nelect is None
    assert 'nelect' in a._input['extraelectron'].output_map(
        vasp=a, structure=structure)
    assert abs(
        float(a._input['extraelectron'].output_map(vasp=a, structure=structure)
              ['nelect']) - 7.0) < 1e-8
    assert a._input['nelect'].output_map() is None
    o = a._input['extraelectron']
    d = {'ExtraElectron': o.__class__}
    assert repr(eval(repr(o), d)) == repr(o)
    assert abs(
        float(
            eval(repr(o), d).output_map(vasp=a, structure=structure)['nelect'])
        - 7.0) < 1e-8
    assert repr(loads(dumps(o))) == repr(o)

    a.nelect = 8
    assert a.nelect == 8
    assert a.extraelectron is None
    assert 'nelect' in a._input['nelect'].output_map()
    assert abs(float(a._input['nelect'].output_map()['nelect']) - 8.0) < 1e-8
    assert a._input['extraelectron'].output_map() is None
    o = a._input['nelect']
    d = {'NElect': o.__class__}
    assert repr(eval(repr(o), d)) == repr(o)
    assert abs(float(eval(repr(o), d).output_map()['nelect']) - 8.0) < 1e-8
    assert repr(loads(dumps(o))) == repr(o)
Beispiel #23
0
def fcc():
  """ Creates an FCC lattice with a single site. """
  from pylada.crystal import Structure
  return Structure( 0, 0.5, 0.5,\
                    0.5, 0, 0.5,\
                    0.5, 0.5, 0,\
                    scale=1, name='fcc' )\
           .add_atom(0, 0, 0, 'A')
Beispiel #24
0
def bcc():
    """ Creates a BCC lattice with a single site. """
    from pylada.crystal import Structure
    return Structure(-0.5, 0.5, 0.5,
                     0.5, -0.5, 0.5,
                     0.5, 0.5, -0.5,
                     scale=1, name='bcc' )\
        .add_atom(0, 0, 0, 'A')
Beispiel #25
0
def test(path):
  from shutil import rmtree
  from tempfile import mkdtemp
  from os.path import join
  from quantities import eV
  from pylada.vasp import Vasp, read_incar
  from pylada.crystal import Structure
  structure = Structure([[0, 0.5, 0.5],[0.5, 0, 0.5], [0.5, 0.5, 0]], scale=5.43, name='has a name')\
                       .add_atom(0,0,0, "Si")\
                       .add_atom(0.25,0.25,0.25, "Si")

  vasp = Vasp()
  vasp.kpoints    = "Automatic generation\n0\nMonkhorst\n2 2 2\n0 0 0"
  vasp.precision  = "accurate"
  vasp.ediff      = 1e-5
  vasp.encut      = 1
  vasp.ismear     = "metal"
  vasp.sigma      = 0.06
  vasp.relaxation = "volume"
  vasp.add_specie = "Si", "{0}/pseudos/Si".format(path)

  directory = mkdtemp()
  try: 
    vasp.write_incar(path=join(directory, 'INCAR'), structure=structure)
    other = read_incar(join(directory, 'INCAR'))
    assert abs(other.ediff - 1e-5)  < 1e-8
    assert abs(other.encut - 245.345) < 1e-8
    assert abs(other.sigma - 0.06 * eV) < 1e-8
    assert other.ibrion     == 2
    assert other.icharg     == 'atomic'
    assert other.isif       == 7
    assert other.ismear     == 'metal'
    assert other.istart     == 'scratch'
    assert other.lcharg     == False
    assert other.nsw        == 50
    assert other.relaxation == 'volume'
    assert other.system     == 'has a name'
    with open(join(directory, 'INCAR'), 'a') as file:
      file.write('\nSOMETHing = 0.5\n')
    other = read_incar(join(directory, 'INCAR'))
    assert abs(other.ediff - 1e-5)  < 1e-8
    assert abs(other.encut - 245.345) < 1e-8
    assert abs(other.sigma - 0.06 * eV) < 1e-8
    assert other.ibrion     == 2
    assert other.icharg     == 'atomic'
    assert other.isif       == 7
    assert other.ismear     == 'metal'
    assert other.istart     == 'scratch'
    assert other.lcharg     == False
    assert other.nsw        == 50
    assert other.relaxation == 'volume'
    assert other.system     == 'has a name'
    assert 'something' in other._input
    assert isinstance(other.something, float)
    assert abs(other.something - 0.5) < 1e-8
  finally: 
    rmtree(directory)
    pass
Beispiel #26
0
def zinc_blende():
    """ zinc_blende lattice """
    from pylada.crystal import Structure
    return Structure(0, 0.5, 0.5,
                     0.5, 0, 0.5,
                     0.5, 0.5, 0,
                     scale=1, name='Zinc-Blende' )\
        .add_atom(0, 0, 0, 'A')\
        .add_atom(0.25, 0.25, 0.25, 'B')
Beispiel #27
0
def rock_salt():
    """ rock_salt lattice """
    from pylada.crystal import Structure
    return Structure(1, 0, 0,
                     0, 1, 0,
                     0, 0, 1,
                     scale=1, name='Rock-Salt' )\
        .add_atom(0, 0, 0, 'A')\
        .add_atom(0.5, 0.5, 0.5, 'B')
Beispiel #28
0
def test_lattice_is_primitive():
    from pylada.crystal import Structure, is_primitive

    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)
Beispiel #29
0
def s1():
    """ s1 lattice """
    from pylada.crystal import Structure
    return Structure( 0, 3.1, 3.1,\
                      3.1, 0, 3.1,\
                      3.1, 3.1, 0,\
                      scale=1, name='s1' )\
             .add_atom(3.1, 3.1, 3.1, 'A')\
             .add_atom(0, 0, 0, 'B')\
             .add_atom(1.55, 1.55, 1.55, 'X')
Beispiel #30
0
def s17():
    """ s17 lattice """
    from pylada.crystal import Structure
    return Structure( 4.244, -2.122, 0,\
                      0, 3.67541, 0,\
                      0, 0, 4.563,\
                      scale=1, name='s17' )\
             .add_atom(0, 0, 0, 'A')\
             .add_atom(2.122, 1.22514, 2.2815, 'B')\
             .add_atom(-2.122e-08, 2.45027, 2.2815, 'X')