Ejemplo n.º 1
0
def validate_inputs(value, _):
    """
    Validate the entire input namespace. It takes care to ckeck the consistency
    and compatibility of the inputed basis, pseudos, pseudofamilies and ions.
    Also calls the `bandskpoints_warnings` that issues warning about bandskpoints selection.
    It is similar to the `validate_inputs` of SiestaCalculation but with the additional complexity
    due to the presence of 'pseudo_family' input.
    """
    import warnings

    bandskpoints_warnings(value)

    if 'basis' in value:
        structure = internal_structure(value["structure"],
                                       value["basis"].get_dict())
        if structure is None:
            return "Not possibe to specify `floating_sites` (ghosts) with the same name of a structure kind."
    else:
        structure = value["structure"]

    #Check each kind in the structure (including freshly added ghosts) have a corresponding pseudo or ion
    kinds = [kind.name for kind in structure.kinds]
    if 'ions' in value:
        quantity = 'ions'
        if 'pseudos' in value or 'pseudo_family' in value:
            warnings.warn(
                "At least one ion file in input, all the pseudos or pseudo_family will be ignored"
            )
    else:
        quantity = 'pseudos'
        if 'pseudos' not in value and 'pseudo_family' not in value:
            return "No `pseudos`, nor `ions`, nor `pseudo_family` specified in input"
        if 'pseudos' in value and 'pseudo_family' in value:
            return "You cannot specify both `pseudos` and `pseudo_family`"

    if 'pseudo_family' in value:
        group = orm.Group.get(label=value['pseudo_family'].value)
        # To be removed in v2.0
        if "data" in group.type_string:
            from aiida_siesta.data.common import get_pseudos_from_structure
            try:
                get_pseudos_from_structure(structure,
                                           value['pseudo_family'].value)
            except NotExistent:
                return "The pseudo family does not incude all the required pseudos"
        else:
            try:
                group.get_pseudos(structure=structure)
            except ValueError:
                return "The pseudo family does not incude all the required pseudos"
    else:
        if set(kinds) != set(value[quantity].keys()):
            ps_io = ', '.join(list(value[quantity].keys()))
            kin = ', '.join(list(kinds))
            string_out = (
                'mismatch between defined pseudos/ions and the list of kinds of the structure\n'
                + f' pseudos/ions: {ps_io} \n kinds(including ghosts): {kin}')
            return string_out
    def prepare_pseudo_inputs(self,
                              structure,
                              pseudos=None,
                              pseudo_family=None):
        from aiida.orm import Str

        if pseudos and pseudo_family:
            raise ValueError(
                'you cannot specify both "pseudos" and "pseudo_family"')
        elif pseudos is None and pseudo_family is None:
            raise ValueError(
                'neither an explicit pseudos dictionary nor a pseudo_family was specified'
            )
        elif pseudo_family:
            # This will already raise some exceptions, potentially, like the ones below
            pseudos = get_pseudos_from_structure(structure,
                                                 pseudo_family.value)
        elif isinstance(pseudos, (six.string_types, Str)):
            raise TypeError(
                'you passed "pseudos" as a string - maybe you wanted to pass it as "pseudo_family" instead?'
            )

        for kind in structure.get_kind_names():
            if kind not in pseudos:
                raise ValueError(
                    'no pseudo available for element {}'.format(kind))

        return pseudos
Ejemplo n.º 3
0
    def _get_pseudos(self, key, structure):

        family = self._protocols[key]["pseudo_family"]
        group = Group.get(label=family)

        # To be removed in v2.0
        if "data" in group.type_string:
            from aiida_siesta.data.common import get_pseudos_from_structure
            pseudos = get_pseudos_from_structure(structure, family)
            return pseudos

        pseudos = group.get_pseudos(structure=structure)
        return pseudos
Ejemplo n.º 4
0
    def prepare_inputs(self):
        """
        Initialize context variables. Note that in context we must include
        exactly the same data nodes obtained in input (except the parameters
        where we add `max-walltime`)
        On the contrary, useless nodes would be created.
        """
        self.report("Preparing inputs of the SiestaBaseWorkChain")

        structure = self.inputs.structure

        self.ctx.inputs = {
            'code': self.inputs.code,
            'parameters': self.inputs.parameters,
            'structure': structure,
            'metadata': {
                'options': self.inputs.options.get_dict(),
            }
        }

        # Ions or pseudos
        if 'ions' in self.inputs:
            self.ctx.inputs['ions'] = self.inputs.ions
        else:
            if "pseudo_family" in self.inputs:
                fam_name = self.inputs.pseudo_family.value
                group = orm.Group.get(label=fam_name)
                if 'basis' in self.inputs:
                    temp_structure = internal_structure(
                        structure, self.inputs.basis.get_dict())
                    # To be removed in v2.0
                    if "data" in group.type_string:
                        from aiida_siesta.data.common import get_pseudos_from_structure
                        self.ctx.inputs[
                            'pseudos'] = get_pseudos_from_structure(
                                temp_structure, fam_name)
                    else:
                        self.ctx.inputs['pseudos'] = group.get_pseudos(
                            structure=temp_structure)
                else:
                    # To be removed in v2.0
                    if "data" in group.type_string:
                        from aiida_siesta.data.common import get_pseudos_from_structure
                        self.ctx.inputs[
                            'pseudos'] = get_pseudos_from_structure(
                                structure, fam_name)
                    else:
                        self.ctx.inputs['pseudos'] = group.get_pseudos(
                            structure=structure)
            else:
                self.ctx.inputs['pseudos'] = self.inputs.pseudos

        # Now the optional inputs
        if 'basis' in self.inputs:
            self.ctx.inputs['basis'] = self.inputs.basis
        if 'kpoints' in self.inputs:
            self.ctx.inputs['kpoints'] = self.inputs.kpoints
        if 'settings' in self.inputs:
            self.ctx.inputs['settings'] = self.inputs.settings
        if 'bandskpoints' in self.inputs:
            self.ctx.want_band_structure = True
            self.ctx.inputs['bandskpoints'] = self.inputs.bandskpoints
        if 'parent_calc_folder' in self.inputs:
            self.ctx.inputs[
                'parent_calc_folder'] = self.inputs.parent_calc_folder