Ejemplo n.º 1
0
def test_multi_round_trip(potcar_family, tmpdir):
    """Write multiple POTCAR potentials to a file and recover the nodes stored in the db."""
    test_dir = tmpdir.mkdir('round_trip')
    potcar_cls = get_data_class('vasp.potcar')
    multi = MultiPotcarIo(
        potcar_cls.get_potcars_dict(elements=POTCAR_MAP.keys(),
                                    family_name=potcar_family,
                                    mapping=POTCAR_MAP).values())
    tempfile = test_dir.join('POTCAR')
    multi.write(tempfile)
    recovered = multi.read(tempfile)
    uuids_start = [potcar.node.uuid for potcar in multi.potcars]
    uuids_recov = [potcar.node.uuid for potcar in recovered.potcars]
    assert uuids_start == uuids_recov
Ejemplo n.º 2
0
def test_multi_from_structure(potcar_family, vasp_structure_poscar):
    potcar_cls = get_data_class('vasp.potcar')
    potcar_dict = potcar_cls.get_potcars_dict(elements=['As', 'In', 'In_d'],
                                              family_name=potcar_family,
                                              mapping=POTCAR_MAP)
    multi = MultiPotcarIo.from_structure(
        structure=vasp_structure_poscar.data_obj, potentials_dict=potcar_dict)
    assert [potcar.node.full_name
            for potcar in multi.potcars] == ['In_sv', 'As', 'In_d', 'As']
Ejemplo n.º 3
0
    def write_potcar(self, dst):
        """
        Concatenates multiple POTCAR files into one in the same order as the elements appear in POSCAR.

        :param dst: absolute path of the file to write to
        """
        structure = self._structure()
        multi_potcar = MultiPotcarIo.from_structure(structure,
                                                    self.inputs.potential)
        multi_potcar.write(dst)
Ejemplo n.º 4
0
def get_potcar_input(dir_path, structure=None, potential_family=None, potential_mapping=None):
    """Read potentials from a POTCAR file or set it up from a structure."""
    local_potcar = dir_path / 'POTCAR'
    structure = structure or get_poscar_input(dir_path)
    potentials = {}
    if local_potcar.exists():
        potentials = MultiPotcarIo.read(str(local_potcar)).get_potentials_dict(structure)
        potentials = {kind: potentials[kind] for kind in potentials}
    elif potential_family:
        potentials = PotcarData.get_potcars_from_structure(structure, potential_family, mapping=potential_mapping)
    else:
        raise InputValidationError('no POTCAR found in remote folder and potential_family was not passed')

    return potentials
Ejemplo n.º 5
0
def test_write_potcar(vasp_calc_and_ref):
    """Check that POTCAR is written correctly."""
    vasp_calc, _ = vasp_calc_and_ref

    with managed_temp_file() as temp_file:
        vasp_calc.write_potcar(temp_file)
        with open(temp_file, 'r') as potcar_fo:
            result_potcar = potcar_fo.read()
        assert 'In_sv' in result_potcar
        assert 'As' in result_potcar
        assert 'In_d' in result_potcar
        assert result_potcar.count('End of Dataset') == 2

        if isinstance(vasp_calc.inputs.structure, get_data_class('structure')):
            multipotcar = MultiPotcarIo.read(temp_file)
            potcar_order = [
                potcar.node.full_name for potcar in multipotcar.potcars
            ]
            assert potcar_order == ['In_sv', 'As', 'In_d', 'As']