Ejemplo n.º 1
0
def test_potcar_from_node(potcar_family):
    """Create a PotcarIo instance from a PotcarData node."""
    potcar_ga = get_data_class('vasp.potcar').find_one(element='Ga')
    from_ctor = PotcarIo(potcar_node=potcar_ga)
    verify_potcario(from_ctor)
    from_from = PotcarIo.from_(potcar_ga)
    assert from_ctor == from_from
Ejemplo n.º 2
0
def test_potcar_from_file_node(potcar_family):
    """Create a PotcarIo instance from a PotcarFileData node."""
    potcar_file_in = get_data_class('vasp.potcar_file').find_one(element='In')
    from_ctor = PotcarIo(potcar_file_node=potcar_file_in)
    verify_potcario(from_ctor)
    from_from = PotcarIo.from_(potcar_file_in)
    assert from_ctor == from_from
Ejemplo n.º 3
0
def test_potcar_from_path(fresh_aiida_env):
    """Create a PotcarIo instance from a file path."""
    potcar_path_as = data_path('potcar', 'As', 'POTCAR')
    from_ctor = PotcarIo(path=potcar_path_as)
    from_from = PotcarIo.from_(potcar_path_as)
    verify_potcario(from_from)
    assert from_ctor == from_from
Ejemplo n.º 4
0
def test_potcar_from_contents(potcar_family):
    """Create a PotcarIo from contents of a POTCAR file."""
    contents_as = read_file('potcar', 'As', 'POTCAR')
    from_ctor = PotcarIo(contents=contents_as.encode('utf-8'))
    verify_potcario(from_ctor)
    assert from_ctor.node.uuid == get_data_class('vasp.potcar').find_one(
        element='As').uuid
    from_from = PotcarIo.from_(contents_as)
    assert from_ctor == from_from
Ejemplo n.º 5
0
def mock_vasp():
    """Verify input files are parseable and copy in output files."""
    from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER  # pylint: disable=import-outside-toplevel
    pwd = Path().absolute()
    aiida_path = Path(AIIDA_CONFIG_FOLDER)
    aiida_cfg = aiida_path / 'config.json'
    click.echo('DEBUG: AIIDA_PATH = {}'.format(os.environ.get('AIIDA_PATH')))
    click.echo('DEBUG: AIIDA_CONFIG_FOLDER = {}'.format(str(aiida_path)))
    assert aiida_path.exists()
    assert aiida_cfg.is_file()
    click.echo(aiida_cfg.read_text())
    incar = pwd / 'INCAR'
    assert incar.is_file(), 'INCAR input file was not found.'

    potcar = pwd / 'POTCAR'
    assert potcar.is_file(), 'POTCAR input file not found.'

    poscar = pwd / 'POSCAR'
    assert poscar.is_file(), 'POSCAR input file not found.'

    kpoints = pwd / 'KPOINTS'
    assert kpoints.is_file(), 'KPOINTS input file not found.'
    incar_parser = IncarParser(file_path=str(incar))
    assert incar_parser, 'INCAR could not be parsed.'
    assert PotcarIo(path=str(potcar)), 'POTCAR could not be parsed.'
    assert PoscarParser(file_path=str(poscar)), 'POSCAR could not be parsed.'
    assert KpointsParser(
        file_path=str(kpoints)), 'KPOINTS could not be parsed.'

    system = incar_parser.incar.get('system', '')
    try:
        test_case = system.strip().split(':')[1].strip()
    except IndexError:
        test_case = ''
    if not test_case:
        shutil.copy(output_file('outcar', 'OUTCAR'), pwd / 'OUTCAR')
        shutil.copy(output_file('vasprun', 'vasprun.xml'), pwd / 'vasprun.xml')
        shutil.copy(output_file('chgcar', 'CHGCAR'), pwd / 'CHGCAR')
        shutil.copy(output_file('wavecar', 'WAVECAR'), pwd / 'WAVECAR')
        shutil.copy(output_file('eigenval', 'EIGENVAL'), pwd / 'EIGENVAL')
        shutil.copy(output_file('doscar', 'DOSCAR'), pwd / 'DOSCAR')
        shutil.copy(output_file('basic_run', 'vasp_output'),
                    pwd / 'vasp_output')
        shutil.copy(poscar, pwd / 'CONTCAR')
    else:
        test_data_path = data_path(test_case, 'out')
        for out_file in Path(test_data_path).iterdir():
            shutil.copy(out_file, pwd)
Ejemplo n.º 6
0
def mock_vasp():
    """Verify input files are parseable and copy in output files."""
    from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER  # pylint: disable=import-outside-toplevel
    pwd = py_path.local('.')
    aiida_path = py_path.local(AIIDA_CONFIG_FOLDER)
    aiida_cfg = aiida_path.join('config.json')
    click.echo('DEBUG: AIIDA_PATH = {}'.format(os.environ.get('AIIDA_PATH')))
    click.echo('DEBUG: AIIDA_CONFIG_FOLDER = {}'.format(aiida_path.strpath))
    assert aiida_path.isdir()
    assert aiida_cfg.isfile()
    click.echo(aiida_cfg.read())

    incar = pwd.join('INCAR')
    assert incar.isfile(), 'INCAR input file was not found.'

    potcar = pwd.join('POTCAR')
    assert potcar.isfile(), 'POTCAR input file not found.'

    poscar = pwd.join('POSCAR')
    assert poscar.isfile(), 'POSCAR input file not found.'

    kpoints = pwd.join('KPOINTS')
    assert kpoints.isfile(), 'KPOINTS input file not found.'

    incar_parser = IncarParser(file_path=incar.strpath)
    assert incar_parser, 'INCAR could not be parsed.'
    assert PotcarIo(path=potcar.strpath), 'POTCAR could not be parsed.'
    assert PoscarParser(file_path=poscar.strpath), 'POSCAR could not be parsed.'
    assert KpointsParser(file_path=kpoints.strpath), 'KPOINTS could not be parsed.'

    system = incar_parser.incar.get('system', '')
    try:
        test_case = system.strip().split(':')[1].strip()
    except IndexError:
        test_case = ''
    if not test_case:
        output_file('outcar', 'OUTCAR').copy(pwd.join('OUTCAR'))
        output_file('vasprun', 'vasprun.xml').copy(pwd.join('vasprun.xml'))
        output_file('chgcar', 'CHGCAR').copy(pwd.join('CHGCAR'))
        output_file('wavecar', 'WAVECAR').copy(pwd.join('WAVECAR'))
        output_file('eigenval', 'EIGENVAL').copy(pwd.join('EIGENVAL'))
        output_file('doscar', 'DOSCAR').copy(pwd.join('DOSCAR'))
        poscar.copy(pwd.join('CONTCAR'))
    else:
        test_data_path = data_path(test_case, 'out')
        for out_file in py_path.local(test_data_path).listdir():
            out_file.copy(pwd)
Ejemplo n.º 7
0
def test_file_contents_equivalence(fresh_aiida_env):
    potcar_path_as = ['potcar', 'As', 'POTCAR']
    from_file = PotcarIo(path=data_path(*potcar_path_as))
    from_contents = PotcarIo(contents=read_file(
        *potcar_path_as).encode('utf-8'))
    assert from_file.sha512 == from_contents.sha512