Example #1
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)
Example #2
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)
Example #3
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)
Example #4
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)
Example #5
0
def test_noop_if_primitive():
    from numpy import allclose
    from pylada.crystal import Structure, primitive, is_primitive
    original = Structure(4.18742, 2.09371, 2.09376,
                         -1.36476e-06, -3.62642, -1.20883,
                         -1.58443e-05, -1.77396e-05, -10.0923,
                         scale=1, name="icsd_042545.cif")\
        .add_atom(4.18743, -2.41762, -1.94751, "Bi")\
        .add_atom(4.18746, -2.41763, -8.1448, "Bi")\
        .add_atom(2.09376, -1.20883, -10.0923, "Se")\
        .add_atom(6.28117, -3.62644, -6.57868, "Se")\
        .add_atom(2.09372, -1.20882, -3.51363, "Se")
    assert is_primitive(original)
    p = primitive(original)

    assert allclose(p.cell, original.cell)
    for a, b in zip(p, original):
        assert allclose(a.pos, b.pos)
        assert a.type == b.type
Example #6
0
def test_noop_if_primitive():
    from numpy import allclose
    from pylada.crystal import Structure, primitive, is_primitive
    original = Structure(4.18742, 2.09371, 2.09376,
                         -1.36476e-06, -3.62642, -1.20883,
                         -1.58443e-05, -1.77396e-05, -10.0923,
                         scale=1, name="icsd_042545.cif")\
        .add_atom(4.18743, -2.41762, -1.94751, "Bi")\
        .add_atom(4.18746, -2.41763, -8.1448, "Bi")\
        .add_atom(2.09376, -1.20883, -10.0923, "Se")\
        .add_atom(6.28117, -3.62644, -6.57868, "Se")\
        .add_atom(2.09372, -1.20882, -3.51363, "Se")
    assert is_primitive(original)
    p = primitive(original)

    assert allclose(p.cell, original.cell)
    for a, b in zip(p, original):
        assert allclose(a.pos, b.pos)
        assert a.type == b.type