예제 #1
0
def test_parse_poscar_write(fresh_aiida_env, vasp_structure, tmpdir):
    """
    Parse (write) a reference POSCAR file.

    Using the PoscarParser, parse (read), and compare to reference
    structure.

    """

    structure = vasp_structure
    parser = PoscarParser(data=structure)
    result = parser.get_quantity('poscar-structure', {})
    assert result['poscar-structure'].cell == structure.cell
    assert result['poscar-structure'].get_site_kindnames(
    ) == structure.get_site_kindnames()
    assert result['poscar-structure'].sites[2].position == structure.sites[
        2].position
    temp_file = str(tmpdir.join('POSCAR'))
    parser.write(temp_file)
    parser = PoscarParser(file_path=temp_file)
    result_reparse = parser.get_quantity('poscar-structure', {})
    assert result_reparse['poscar-structure'].cell == structure.cell
    assert result_reparse['poscar-structure'].get_site_kindnames() == \
        structure.get_site_kindnames()
    assert result_reparse['poscar-structure'].sites[2].position == \
        structure.sites[2].position
예제 #2
0
def test_parse_poscar_silly_read(fresh_aiida_env):
    """
    Parse (read) a reference POSCAR with silly elemental names.

    Using the PoscarParser and compare the result to a reference
    structure.

    """

    path = data_path('poscar', 'POSCARSILLY')
    parser = PoscarParser(file_path=path)
    result = parser.get_quantity('poscar-structure', {})
    names = result['poscar-structure'].get_site_kindnames()
    assert names == ['Hamburger', 'Pizza']
    symbols = result['poscar-structure'].get_symbols_set()
    assert symbols == set(['X', 'X'])
예제 #3
0
def test_write_poscar(fresh_aiida_env, vasp2w90_calc_and_ref, vasp_structure_poscar):
    """Write POSCAR input file and compare to reference."""
    from aiida_vasp.io.poscar import PoscarParser
    vasp_calc, _ = vasp2w90_calc_and_ref
    inp = vasp_calc.get_inputs_dict()
    with tempfile.NamedTemporaryFile() as temp_file:
        vasp_calc.write_poscar(inp, temp_file.name)
        result_structure = PoscarParser(file_path=temp_file.name).get_quantity('poscar-structure', {})['poscar-structure']
        ref_structure = vasp_structure_poscar.get_quantity('poscar-structure', {})['poscar-structure']
        assert result_structure.cell, ref_structure.cell
        assert result_structure.get_formula() == ref_structure.get_formula()

        vasp_structure_poscar._parsed_data.update(vasp_structure_poscar.get_quantity('poscar-structure', {}))  # pylint: disable=protected-access
        ref_string = vasp_structure_poscar._parsed_object.get_string()  # pylint: disable=protected-access
        with open(temp_file.name, 'r') as poscar:
            assert_contents_equivalent(poscar.read(), ref_string)
예제 #4
0
파일: data.py 프로젝트: wes-amat/aiida-vasp
def vasp_structure_poscar(vasp_structure):
    """Fixture: Well formed POSCAR contents"""
    aiida_structure = vasp_structure
    if isinstance(vasp_structure, get_data_class('cif')):
        ase_structure = vasp_structure.get_ase()
        aiida_structure = get_data_node('structure', ase=ase_structure)
    writer = PoscarParser(data=aiida_structure)
    return writer
예제 #5
0
def test_parse_poscar(fresh_aiida_env, vasp_structure):
    """
    Parse a reference POSCAR file.

    Using the PoscarParser and compare the result to a reference
    structure.

    """

    path = data_path('poscar', 'POSCAR')
    parser = PoscarParser(file_path=path)
    result = parser.get_quantity('poscar-structure', {})
    structure = vasp_structure
    assert result['poscar-structure'].cell == structure.cell
    assert result['poscar-structure'].get_site_kindnames(
    ) == structure.get_site_kindnames()
    assert result['poscar-structure'].sites[2].position == structure.sites[
        2].position
예제 #6
0
def mock_vasp():
    """Verify input files are parseable and copy in output files."""
    from aiida.common.setup import AIIDA_CONFIG_FOLDER
    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 KpParser(file_path=kpoints.strpath), 'KPOINTS could not be parsed.'

    system = incar_parser.get_quantity('incar', {})['incar'].get_dict().get(
        'system', '')
    test_case = re.findall(r'test-case:(.*)$', system)

    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_case = test_case[0]
        test_data_path = py_path.local(data_path(test_case)).join('out')
        for out_file in test_data_path.listdir():
            out_file.copy(pwd)
예제 #7
0
파일: vasp.py 프로젝트: wes-amat/aiida-vasp
    def write_poscar(self, inputdict, dst):  # pylint: disable=unused-argument
        """
        Converts from structures node (StructureData) to POSCAR format and writes to dst.

        :param inputdict: required by baseclass
        :param dst: absolute path of the file to write to
        """
        settings = inputdict.get('settings')
        settings = settings.get_dict() if settings else {}
        poscar_precision = settings.get('poscar_precision', 10)
        writer = PoscarParser(data=self._structure(),
                              precision=poscar_precision)
        writer.get_quantity('poscar-structure', {})
        writer.write(dst)
예제 #8
0
def test_parse_poscar_silly_write(fresh_aiida_env, vasp_structure, tmpdir):
    """
    Parse (read, write) a reference POSCAR with silly elemental names.

    Using the PoscarParser and compare the result to a reference structure.

    """

    parser = PoscarParser(data=vasp_structure)
    result = parser.get_quantity('poscar-structure', {})
    names = result['poscar-structure'].get_site_kindnames()
    assert names == ['Hamburger', 'Pizza']
    symbols = result['poscar-structure'].get_symbols_set()
    assert symbols == set(['As', 'In'])
    temp_file = str(tmpdir.join('POSCAR'))
    parser.write(temp_file)
    parser = PoscarParser(file_path=temp_file)
    result_reparse = parser.get_quantity('poscar-structure', {})
    names = result_reparse['poscar-structure'].get_site_kindnames()
    assert names == ['Hamburger', 'Pizza']
    symbols = result_reparse['poscar-structure'].get_symbols_set()
    assert symbols == set(['X', 'X'])
예제 #9
0
def test_parse_poscar_undercase(fresh_aiida_env, vasp_structure, tmpdir):
    """
    Parse a reference POSCAR.

    With potential elemental names using the PoscarParser and compare
    the result to a reference structure.

    """

    parser = PoscarParser(data=vasp_structure)
    result = parser.get_quantity('poscar-structure', {})
    names = result['poscar-structure'].get_site_kindnames()
    assert names == ['In', 'As', 'As', 'In_d', 'In_d', 'As']
    symbols = result['poscar-structure'].get_symbols_set()
    assert symbols == set(['As', 'In'])
    temp_file = str(tmpdir.join('POSCAR'))
    parser.write(temp_file)
    parser = PoscarParser(file_path=temp_file)
    result_reparse = parser.get_quantity('poscar-structure', {})
    names = result_reparse['poscar-structure'].get_site_kindnames()
    assert names == ['In', 'As', 'As', 'In_d', 'In_d', 'As']
    symbols = result_reparse['poscar-structure'].get_symbols_set()
    assert symbols == set(['As', 'In'])
예제 #10
0
def test_relax_wf(fresh_aiida_env, vasp_params, potentials, mock_vasp):
    """Test submitting only, not correctness, with mocked vasp code."""
    from aiida.orm import WorkflowFactory, Code
    from aiida import work

    rmq_config = None
    runner = work.Runner(poll_interval=0.,
                         rmq_config=rmq_config,
                         enable_persistence=True)
    work.set_runner(runner)

    base_wf_proc = WorkflowFactory('vasp.relax')

    mock_vasp.store()
    print(mock_vasp.get_remote_exec_path())
    comp = mock_vasp.get_computer()
    create_authinfo(computer=comp).store()

    structure = PoscarParser(
        file_path=data_path('test_relax_wf', 'inp', 'POSCAR')).get_quantity(
            'poscar-structure', {})['poscar-structure']
    kpoints = KpParser(
        file_path=data_path('test_relax_wf', 'inp', 'KPOINTS')).get_quantity(
            'kpoints-kpoints', {})['kpoints-kpoints']
    incar_add = IncarParser(
        file_path=data_path('test_relax_wf', 'inp', 'INCAR')).get_quantity(
            'incar', {})['incar'].get_dict()
    incar_add = {
        k: v
        for k, v in incar_add.items() if k not in ['isif', 'ibrion']
    }
    incar_add['system'] = 'test-case:test_relax_wf'

    restart_clean_workdir = get_data_node('bool', False)
    restart_clean_workdir.store()

    inputs = AttributeDict()
    inputs.code = Code.get_from_string('mock-vasp@localhost')
    inputs.structure = structure
    inputs.incar_add = get_data_node('parameter', dict=incar_add)
    inputs.kpoints = AttributeDict()
    inputs.kpoints.mesh = kpoints
    inputs.potcar_family = get_data_node('str', POTCAR_FAMILY_NAME)
    inputs.potcar_mapping = get_data_node('parameter', dict=POTCAR_MAP)
    inputs.options = get_data_node('parameter',
                                   dict={
                                       'queue_name': 'None',
                                       'resources': {
                                           'num_machines': 1,
                                           'num_mpiprocs_per_machine': 1
                                       }
                                   })
    inputs.max_iterations = get_data_node('int', 1)
    inputs.convergence = AttributeDict()
    inputs.convergence.shape = AttributeDict()
    inputs.convergence.on = get_data_node('bool', True)
    inputs.convergence.positions = get_data_node('float', 0.1)
    inputs.restart = AttributeDict()
    inputs.restart.clean_workdir = restart_clean_workdir
    inputs.relax = AttributeDict()

    results = work.run(base_wf_proc, **inputs)
    assert 'relaxed_structure' in results
예제 #11
0
def get_poscar_input(dir_path):
    return get_quantity_node(PoscarParser(file_path=dir_path.join('POSCAR').strpath), 'poscar-structure')