Exemplo n.º 1
0
def test_write_read_loop(tmpdir, pwscfin):
    from numpy import abs, allclose
    from f90nml import Namelist as F90Namelist
    from pylada.espresso.structure_handling import add_structure, read_structure
    from pylada.espresso.misc import write_pwscf_input
    structure = read_structure(str(pwscfin))

    namelist = F90Namelist()
    cards = []
    add_structure(structure, namelist, cards)
    write_pwscf_input(namelist, cards, str(tmpdir.join('other.in')))
    reread = read_structure(str(tmpdir.join('other.in')))

    assert allclose(reread.cell, structure.cell)
    assert abs(reread.scale - structure.scale) < 1e-12
    assert len(reread) == len(structure)
    for i in range(len(reread)):
        assert allclose(reread[i].pos, structure[i].pos)
        assert reread[i].type == structure[i].type
Exemplo n.º 2
0
def test_read_structure(pwscfin):
    from numpy import allclose, sqrt
    from quantities import bohr_radius
    from pylada.espresso.structure_handling import read_structure
    structure = read_structure(str(pwscfin))

    c = 0.5
    tx, ty, tz = sqrt((1. - c) / 2.), sqrt((1. - c) / 6.), sqrt(
        (1. + 2. * c) / 3.)
    assert allclose(structure.cell.transpose(),
                    [[tx, -ty, tz], [0, 2 * ty, tz], [-tx, -ty, tz]])
    assert abs(structure.scale - bohr_radius) < 1e-8
    assert len(structure) == 2
    assert structure[0].type == 'A'
    assert allclose(structure[0].pos, [0, 0, 0.])
    assert structure[1].type == 'B'
    assert allclose(structure[1].pos, [1, 2, 3.])
Exemplo n.º 3
0
def test_read_forces(tmpdir):
    from quantities import Ry, bohr_radius as a0
    from numpy import allclose
    from pylada.espresso.structure_handling import read_structure
    string = """
        &system
            ibrav=5,
            celldm = 1.0 0.0 0.0 0.5,
        /

    ATOMIC_POSITIONS alat
    A 0 0 0
    B 1 2 3
    ATOMIC_FORCES
    A 0 0 0
    B 1 2 3
    """
    tmpdir.join('pos.in').write(string)
    structure = read_structure(str(tmpdir.join('pos.in')))
    for atom in structure:
        assert hasattr(atom, 'force')
        assert atom.force.units == (Ry / a0)
    assert allclose(structure[0].force.magnitude, [0, 0, 0])
    assert allclose(structure[1].force.magnitude, [1, 2, 3])