Exemplo n.º 1
0
def test_parser_nodes(request, calc_with_retrieved):
    """Test a few basic node items of the parser."""
    from aiida.plugins import ParserFactory

    settings_dict = {
        'parser_settings': {
            'add_bands': True,
            'add_kpoints': True,
            'add_misc': ['fermi_level']
        }
    }

    file_path = str(request.fspath.join('..') + '../../../test_data/basic')

    node = calc_with_retrieved(file_path, settings_dict)

    parser_cls = ParserFactory('vasp.vasp')
    result, _ = parser_cls.parse_from_node(
        node, store_provenance=False, retrieved_temporary_folder=file_path)

    misc = result['misc']
    bands = result['bands']
    kpoints = result['kpoints']

    assert isinstance(misc, get_data_class('dict'))
    assert isinstance(bands, get_data_class('array.bands'))
    assert isinstance(kpoints, get_data_class('array.kpoints'))
    assert misc.get_dict()['fermi_level'] == 5.96764939
Exemplo n.º 2
0
def test_stream_history(request, calc_with_retrieved):
    """Test that the stream parser keeps history."""
    file_path = str(
        request.fspath.join('..') + '../../../test_data/stdout/out')

    # turn of everything, except misc
    settings_dict = {
        'parser_settings': {
            'add_trajectory': False,
            'add_bands': False,
            'add_chgcar': False,
            'add_dos': False,
            'add_kpoints': False,
            'add_energies': False,
            'add_misc': ['notifications'],
            'add_structure': False,
            'add_projectors': False,
            'add_born_charges': False,
            'add_dielectrics': False,
            'add_hessian': False,
            'add_dynmat': False,
            'add_wavecar': False,
            'add_site_magnetization': False,
            'stream_config': {
                'random_error': {
                    'kind': 'ERROR',
                    'regex': 'I AM A WELL DEFINED ERROR',
                    'message': 'Okey, this error you do not want.',
                    'suggestion': '',
                    'location': 'STDOUT',
                    'recover': False
                }
            },
            'stream_history': True
        }
    }

    node = calc_with_retrieved(file_path, settings_dict)

    parser_cls = ParserFactory('vasp.vasp')
    result, _ = parser_cls.parse_from_node(
        node, store_provenance=False, retrieved_temporary_folder=file_path)

    misc = result['misc']
    misc_dict = misc.get_dict()
    assert len(misc_dict['notifications']) == 3
    assert misc_dict['notifications'][0]['name'] == 'ibzkpt'
    assert misc_dict['notifications'][0]['kind'] == 'ERROR'
    assert misc_dict['notifications'][0][
        'regex'] == 'internal error in subroutine IBZKPT'
    assert misc_dict['notifications'][1]['name'] == 'random_error'
    assert misc_dict['notifications'][1]['kind'] == 'ERROR'
    assert misc_dict['notifications'][1][
        'regex'] == 'I AM A WELL DEFINED ERROR'
    assert misc_dict['notifications'][2]['name'] == 'random_error'
    assert misc_dict['notifications'][2]['kind'] == 'ERROR'
    assert misc_dict['notifications'][2][
        'regex'] == 'I AM A WELL DEFINED ERROR'
    for item in misc_dict['notifications']:
        assert item['kind'] != 'WARNING'
Exemplo n.º 3
0
def test_misc(request, calc_with_retrieved):
    """Test that it is possible to extract misc from both vasprun and OUTCAR."""
    # turn of everything, except misc
    settings_dict = {
        'parser_settings': {
            'add_trajectory':
            False,
            'add_bands':
            False,
            'add_chgcar':
            False,
            'add_dos':
            False,
            'add_kpoints':
            False,
            'add_energies':
            False,
            'add_misc': [
                'fermi_level', 'maximum_stress', 'maximum_force',
                'total_energies', 'symmetries'
            ],
            'add_structure':
            False,
            'add_projectors':
            False,
            'add_born_charges':
            False,
            'add_dielectrics':
            False,
            'add_hessian':
            False,
            'add_dynmat':
            False,
            'add_wavecar':
            False,
            'add_site_magnetization':
            False,
        }
    }

    file_path = str(
        request.fspath.join('..') + '../../../test_data/disp_details')

    node = calc_with_retrieved(file_path, settings_dict)

    parser_cls = ParserFactory('vasp.vasp')
    result, _ = parser_cls.parse_from_node(
        node, store_provenance=False, retrieved_temporary_folder=file_path)

    misc = result['misc']
    assert isinstance(misc, get_data_class('dict'))
    data = misc.get_dict()
    # We already have a test to check if the quantities from the OUTCAR is correct, so
    # only perform rudimentary checks, and the content comming from the xml file.
    assert data['fermi_level'] == 6.17267267
    assert data['maximum_stress'] == 42.96872956444064
    assert data['maximum_force'] == 0.21326679
    assert data['total_energies']['energy_extrapolated'] == -10.823296
Exemplo n.º 4
0
def _get_vasp_parser(calc_with_retrieved):
    """Return vasp parser before parsing"""
    settings_dict = {
        # 'ADDITIONAL_RETRIEVE_LIST': CalculationFactory('vasp.vasp')._ALWAYS_RETRIEVE_LIST,
        'parser_settings': {
            'add_custom': {
                'link_name': 'custom_node',
                'type': 'dict',
                'quantities': ['quantity2', 'quantity_with_alternatives']
            }
        }
    }
    file_path = str(
        os.path.abspath(os.path.dirname(__file__)) +
        '/../../test_data/basic_run')
    node = calc_with_retrieved(file_path, settings_dict)
    parser = ParserFactory('vasp.vasp')(node)
    return parser, file_path, node
Exemplo n.º 5
0
def vasp_parser_with_test(calc_with_retrieved):
    """Fixture providing a VaspParser instance coupled to a VaspCalculation."""
    from aiida.plugins import ParserFactory
    from aiida.plugins import CalculationFactory

    settings_dict = {
        # 'ADDITIONAL_RETRIEVE_LIST': CalculationFactory('vasp.vasp')._ALWAYS_RETRIEVE_LIST,
        'parser_settings': {
            'add_custom': {
                'link_name': 'custom_node',
                'type': 'dict',
                'quantities': ['quantity2', 'quantity_with_alternatives']
            }
        }
    }

    file_path = str(
        os.path.abspath(os.path.dirname(__file__)) +
        '/../../test_data/test_relax_wc/out')

    node = calc_with_retrieved(file_path, settings_dict)

    parser = ParserFactory('vasp.vasp')(node)
    parser.add_file_parser('_scheduler-stderr.txt', {
        'parser_class': ExampleFileParser,
        'is_critical': False
    })
    parser.add_parsable_quantity(
        'quantity_with_alternatives',
        {
            'inputs': [],
            'prerequisites': [],
        },
    )
    success = parser.parse(retrieved_temporary_folder=file_path)
    try:
        yield parser
    finally:
        parser = ParserFactory('vasp.vasp')(node)
Exemplo n.º 6
0
def base_parser(calc_with_retrieved):
    file_path = str(
        os.path.abspath(os.path.dirname(__file__)) +
        '/../../test_data/basic_run/')
    node = calc_with_retrieved(file_path)
    return BaseParser(node)
Exemplo n.º 7
0
def test_structure(request, calc_with_retrieved):
    """Test that the structure from vasprun and POSCAR is the same."""
    from aiida.plugins import ParserFactory

    # turn of everything, except structure
    settings_dict = {
        'parser_settings': {
            'add_trajectory': False,
            'add_bands': False,
            'add_chgcar': False,
            'add_dos': False,
            'add_kpoints': False,
            'add_energies': False,
            'add_misc': False,
            'add_structure': True,
            'add_projectors': False,
            'add_born_charges': False,
            'add_dielectrics': False,
            'add_hessian': False,
            'add_dynmat': False,
            'add_wavecar': False,
            'add_site_magnetization': False,
            'file_parser_set': 'default'
        }
    }

    file_path = str(request.fspath.join('..') + '../../../test_data/basic')

    node = calc_with_retrieved(file_path, settings_dict)

    parser_cls = ParserFactory('vasp.vasp')
    result, _ = parser_cls.parse_from_node(
        node, store_provenance=False, retrieved_temporary_folder=file_path)

    # First fetch structure from vasprun

    structure_vasprun = result['structure']
    assert isinstance(structure_vasprun, get_data_class('structure'))

    # Then from POSCAR/CONTCAR
    file_path = str(
        request.fspath.join('..') + '../../../test_data/basic_poscar')

    node = calc_with_retrieved(file_path, settings_dict)

    parser_cls = ParserFactory('vasp.vasp')
    result, _ = parser_cls.parse_from_node(
        node, store_provenance=False, retrieved_temporary_folder=file_path)

    structure_poscar = result['structure']

    assert isinstance(structure_poscar, get_data_class('structure'))
    assert np.array_equal(np.round(structure_vasprun.cell, 7),
                          np.round(structure_poscar.cell, 7))
    positions_vasprun = []
    positions_poscar = []
    for site in structure_vasprun.sites:
        pos = np.round(np.asarray(site.position), 7)
        positions_vasprun.append(pos)
    for site in structure_poscar.sites:
        pos = np.round(np.asarray(site.position), 7)
        positions_poscar.append(pos)
    positions_vasprun = np.asarray(positions_vasprun)
    positions_poscar = np.asarray(positions_poscar)
    assert np.array_equal(positions_vasprun, positions_poscar)
Exemplo n.º 8
0
def test_stream(misc_input, config, request, calc_with_retrieved):
    """Test that the stream parser works and gets stored on a node."""
    file_path = str(
        request.fspath.join('..') + '../../../test_data/stdout/out')

    # turn of everything, except misc
    settings_dict = {
        'parser_settings': {
            'add_trajectory': False,
            'add_bands': False,
            'add_chgcar': False,
            'add_dos': False,
            'add_kpoints': False,
            'add_energies': False,
            'add_misc': misc_input,
            'add_structure': False,
            'add_projectors': False,
            'add_born_charges': False,
            'add_dielectrics': False,
            'add_hessian': False,
            'add_dynmat': False,
            'add_wavecar': False,
            'add_site_magnetization': False,
            'stream_config': config
        }
    }

    node = calc_with_retrieved(file_path, settings_dict)

    parser_cls = ParserFactory('vasp.vasp')
    result, _ = parser_cls.parse_from_node(
        node, store_provenance=False, retrieved_temporary_folder=file_path)

    if misc_input == []:
        # Test empty misc specification, yields no misc output node
        with pytest.raises(KeyError) as error:
            misc = result['misc']
    else:
        misc = result['misc']
        misc_dict = misc.get_dict()
        if config is not None:
            if 'random_error' in config:
                assert len(misc_dict['notifications']) == 2
                assert misc_dict['notifications'][0]['name'] == 'ibzkpt'
                assert misc_dict['notifications'][0]['kind'] == 'ERROR'
                assert misc_dict['notifications'][0][
                    'regex'] == 'internal error in subroutine IBZKPT'
                assert misc_dict['notifications'][1]['name'] == 'random_error'
                assert misc_dict['notifications'][1]['kind'] == 'ERROR'
                assert misc_dict['notifications'][1][
                    'regex'] == 'I AM A WELL DEFINED ERROR'
            if 'random_warning' in config:
                assert len(misc_dict['notifications']) == 2
                assert misc_dict['notifications'][0]['name'] == 'ibzkpt'
                assert misc_dict['notifications'][0]['kind'] == 'ERROR'
                assert misc_dict['notifications'][0][
                    'regex'] == 'internal error in subroutine IBZKPT'
                assert misc_dict['notifications'][1][
                    'name'] == 'random_warning'
                assert misc_dict['notifications'][1]['kind'] == 'WARNING'
                assert misc_dict['notifications'][1][
                    'regex'] == 'I AM A WELL DEFINED WARNING'
        else:
            assert len(misc_dict['notifications']) == 1
            assert misc_dict['notifications'][0]['name'] == 'ibzkpt'
            assert misc_dict['notifications'][0]['kind'] == 'ERROR'
            assert misc_dict['notifications'][0][
                'regex'] == 'internal error in subroutine IBZKPT'