Ejemplo n.º 1
0
def test_store_and_load_potcar_data(interactive_potcar_file):
    from aiida.orm import load_node
    # generate arbitrary potential and process it using the potcar parser
    potential_contents = "\n".join([
        "functional Si 01Jan1000",
        "parameters from PSCTR are:",
        "VRHFIN =Si: s100p100d100",
        "TITEL  = functional Si 01Jan1000"
        "END of PSCTR-controll parameters",
    ])
    interactive_potcar_file.open("POTCAR")
    interactive_potcar_file.write(potential_contents)
    path_to_potcar = pathlib.Path(interactive_potcar_file.filepath)
    potcar_file_node = VaspPotcarFile.add_potential(path_to_potcar,
                                                    name='Si',
                                                    functional='pbe')
    potcar_file_node.store()
    # create VaspPotcarData instance associated with the stored potential
    potcar_data_set = VaspPotcarData(name='Si',
                                     version=10000101,
                                     functional='pbe')
    uuid = potcar_data_set.store().uuid

    # load the data node and compare stored contents
    potcar_data_get = load_node(uuid)
    assert potcar_data_get.name == potcar_file_node.name
    assert potcar_data_get.version == potcar_file_node.version
    assert potcar_data_get.functional == potcar_file_node.functional
    assert potcar_data_get.element == potcar_file_node.element
    assert potcar_data_get.hash == potcar_file_node.hash
    assert potcar_data_get.filenode_uuid == potcar_file_node.uuid
Ejemplo n.º 2
0
def test_potcar_from_linklist(with_pbe_potcars, multi_component_structure):
    from aiida_cusp.data.inputs.vasp_potcar import VaspPotcarFile
    from aiida_cusp.data.inputs.vasp_poscar import VaspPoscarData
    poscar = VaspPoscarData(structure=multi_component_structure)
    potmap = VaspPotcarData.from_structure(multi_component_structure, 'pbe')
    complete_potcar = VaspPotcarData.potcar_from_linklist(poscar, potmap)
    # build the expected potcar
    potcar_contents = []
    for symbol in poscar.get_poscar().site_symbols:
        potcar_file = VaspPotcarFile.from_tags(name=symbol)[0]
        potcar_contents.append(potcar_file.get_content())
    expected_potcar_contents = "\n".join(potcar_contents) + "\n"
    assert str(complete_potcar) == expected_potcar_contents
Ejemplo n.º 3
0
def test_potcar_from_linklist_raises_on_missing(symbol, with_pbe_potcars,
                                                multi_component_structure):
    from aiida_cusp.data.inputs.vasp_potcar import VaspPotcarData
    from aiida_cusp.utils.exceptions import VaspPotcarDataError
    poscar = VaspPoscarData(structure=multi_component_structure)
    potmap = VaspPotcarData.from_structure(multi_component_structure, 'pbe')
    # pop an arbitrary potential from the map and check that the call to
    # potcar_from_linklist() fails for the given structure
    potmap.pop(symbol)
    expected_error = ("Found no potential in passed potential-element map for "
                      "site symbol '{}'".format(symbol))
    with pytest.raises(VaspPotcarDataError) as exception:
        _ = VaspPotcarData.potcar_from_linklist(poscar, potmap)
    assert str(exception.value) == expected_error
Ejemplo n.º 4
0
def test_load_potential_file_node_properties_match(interactive_potcar_file,
                                                   change_prop):
    interactive_potcar_file.open("POTCAR")
    path = pathlib.Path(interactive_potcar_file.filepath).absolute()
    args = ['Si', 'Si', 10000101, 'pbe', 'hash']
    file_node = VaspPotcarFile(path, *args).store()
    # create VaspPotcarData instance associated with the stored potential and
    # change one of the properties
    potcar_data = VaspPotcarData(name='Si', version=10000101, functional='pbe')
    potcar_data.update_dict({change_prop: None})
    # try loading the potential file which should raise an attribute error
    # due to the mismatch in the stored potential properties
    with pytest.raises(AssertionError) as exception:
        potcar_file_get = potcar_data.load_potential_file_node()
Ejemplo n.º 5
0
def test_load_potential_file_node_from_uuid(interactive_potcar_file):
    # generate arbitrary potential and process it using the potcar parser
    interactive_potcar_file.open("POTCAR")
    path = pathlib.Path(interactive_potcar_file.filepath).absolute()
    args = ['Si', 'Si', 10000101, 'pbe', 'hash']
    potcar_file_set = VaspPotcarFile(path, *args).store()
    # create VaspPotcarData instance associated with the stored potential
    potcar_data = VaspPotcarData(name='Si', version=10000101, functional='pbe')
    # load node from potcar_data instance
    potcar_file_get = potcar_data.load_potential_file_node()
    assert potcar_file_get.uuid == potcar_file_set.uuid
    assert potcar_file_get.hash == potcar_file_set.hash
    assert potcar_file_get.element == potcar_file_set.element
    assert potcar_file_get.functional == potcar_file_set.functional
    assert potcar_file_get.name == potcar_file_set.name
Ejemplo n.º 6
0
def test_init_from_tags_raises_on_missing_node():
    # try to initialize from non-existent potential
    with pytest.raises(VaspPotcarDataError) as exception:
        potcar_data = VaspPotcarData(name='Si',
                                     version=10000101,
                                     functional='pbe')
    assert "Unable to initialize VaspPotcarData" in str(exception.value)
Ejemplo n.º 7
0
def test_init_from_tags_rases_on_missing_parameters(missing_prop):
    # complete parameter list
    kwargs = {'name': 'Si', 'version': 10000101, 'functional': 'pbe'}
    kwargs.update({missing_prop: None})
    expected_error = "Missing non-optional argument '{}'".format(missing_prop)
    with pytest.raises(VaspPotcarDataError) as exception:
        potcar_data = VaspPotcarData(**kwargs)
    assert str(exception.value) == expected_error
Ejemplo n.º 8
0
def test_load_potential_file_node_from_hash(interactive_potcar_file):
    # generate arbitrary potential and process it using the potcar parser
    interactive_potcar_file.open("POTCAR")
    path = pathlib.Path(interactive_potcar_file.filepath).absolute()
    args = ['Si', 'Si', 10000101, 'pbe', 'hash']
    potcar_file_set = VaspPotcarFile(path, *args).store()
    # create VaspPotcarData instance associated with the stored potential but
    # change the associated uuid
    potcar_data = VaspPotcarData(name='Si', version=10000101, functional='pbe')
    potcar_data.update_dict({'filenode_uuid': "changed_uuid"})
    assert potcar_data.filenode_uuid == "changed_uuid"
    # try loading the potential using the stored hash instead of the uuid
    potcar_file_get = potcar_data.load_potential_file_node()
    assert potcar_file_get.uuid == potcar_file_set.uuid
    assert potcar_file_get.hash == potcar_file_set.hash
    assert potcar_file_get.element == potcar_file_set.element
    assert potcar_file_get.functional == potcar_file_set.functional
    assert potcar_file_get.name == potcar_file_set.name
Ejemplo n.º 9
0
def test_from_structure_classmethod_single(name, interactive_potcar_file,
                                           version, functional, structure_type,
                                           minimal_pymatgen_structure):
    # create non-ordered structures of different types
    supercell = minimal_pymatgen_structure * (2, 2, 2)
    if structure_type == 'pymatgen':
        structure = supercell
    elif structure_type == 'aiida':
        structure = StructureData(pymatgen_structure=supercell)
    elif structure_type == 'poscar':
        structure = Poscar(supercell)
    elif structure_type == 'aiida_cusp_poscar':
        structure = VaspPoscarData(structure=supercell)
    # populate database with potentials
    potcar_args = [
        ['H', 'H', 10000101, 'pbe', 'hash1'],
        ['H', 'H', 10000102, 'pbe', 'hash2'],
        ['H_pv', 'H', 10000101, 'pbe', 'hash3'],
        ['H_pv', 'H', 10000102, 'pbe', 'hash4'],
        ['H', 'H', 10000101, 'pw91', 'hash5'],
        ['H', 'H', 10000102, 'pw91', 'hash6'],
        ['H_pv', 'H', 10000101, 'pw91', 'hash7'],
        ['H_pv', 'H', 10000102, 'pw91', 'hash8'],
    ]
    interactive_potcar_file.open("POTCAR")
    path = pathlib.Path(interactive_potcar_file.filepath).absolute()
    for args in potcar_args:
        VaspPotcarFile(path, *args).store()
    # setup alternative (non-default) potcar parameters
    potcar_params = {'H': {}}
    if name is not None:
        potcar_params['H'].update({'name': name})
    if version is not None:
        potcar_params['H'].update({'version': version})
    if not potcar_params['H']:
        potcar_params = {}
    # create the element-potential map
    potential_map = VaspPotcarData.from_structure(structure,
                                                  functional,
                                                  potcar_params=potcar_params)
    # check that the map contains only a single entry
    assert len(potential_map.keys()) == 1
    assert list(potential_map.keys()) == ['H']
    # assert potential properties match the wanted ones
    expected_name = name or 'H'
    expected_version = version or 10000102
    assert potential_map['H'].name == expected_name
    assert potential_map['H'].version == expected_version
    assert potential_map['H'].functional == functional.lower()
    # check that we indeed return a VaspPotcarData instance and nothing else
    assert isinstance(potential_map['H'], VaspPotcarData) is True
Ejemplo n.º 10
0
def test_load_potential_file_raises_on_undiscoverable(interactive_potcar_file):
    # generate arbitrary potential and process it using the potcar parser
    interactive_potcar_file.open("POTCAR")
    path = pathlib.Path(interactive_potcar_file.filepath).absolute()
    args = ['Si', 'Si', 10000101, 'pbe', 'hash']
    potcar_file_set = VaspPotcarFile(path, *args).store()
    # create VaspPotcarData instance associated with the stored potential but
    # change uuid and hash to make the potentials undiscoverable
    potcar_data = VaspPotcarData(name='Si', version=10000101, functional='pbe')
    potcar_data.update_dict({'filenode_uuid': "changed_uuid"})
    potcar_data.update_dict({'hash': "changed_hash"})
    # try loading the potential using the stored hash instead of the uuid
    with pytest.raises(VaspPotcarDataError) as exception:
        potcar_file_get = potcar_data.load_potential_file_node()
    assert "Unable to discover associated potential" in str(exception.value)
Ejemplo n.º 11
0
def test_from_structure_classmethod_multi(with_pbe_potcars, structure_type,
                                          multi_component_structure):
    from aiida_cusp.data.inputs.vasp_poscar import VaspPoscarData
    if structure_type == 'pymatgen':
        structure = multi_component_structure
    elif structure_type == 'aiida':
        structure = StructureData(pymatgen_structure=multi_component_structure)
    elif structure_type == 'poscar':
        structure = Poscar(multi_component_structure)
    elif structure_type == 'aiida_cusp_poscar':
        structure = VaspPoscarData(structure=multi_component_structure)
    # generate potental map using the default potential settings (i.e.
    # name == element, version == latest)
    potential_map = VaspPotcarData.from_structure(structure, 'pbe')
    all_elements = ['Li', 'S', 'P', 'Br']
    def_elements = potential_map.keys()
    assert set(def_elements) == set(all_elements)
    # check potential names and functionals match
    for element in all_elements:
        assert potential_map[element].name == element
        assert potential_map[element].functional == 'pbe'
Ejemplo n.º 12
0
def test_potcar_props_from_name_raises(inputlist, expected_error):
    from aiida_cusp.data import VaspPotcarData
    from aiida_cusp.utils.exceptions import VaspPotcarDataError
    with pytest.raises(VaspPotcarDataError) as exception:
        _ = VaspPotcarData.potcar_props_from_name_list(inputlist)
    assert expected_error in str(exception.value)
Ejemplo n.º 13
0
def test_potcar_props_from_name_list(element, potential_name):
    from aiida_cusp.data import VaspPotcarData
    potcar_name_list = [potential_name]
    potcar_props = VaspPotcarData.potcar_props_from_name_list(potcar_name_list)
    assert potcar_props[element]['name'] == potential_name