Esempio n. 1
0
def generate_inputs(process_class: engine.Process,
                    protocol: Dict,
                    code: orm.Code,
                    structure: StructureData,
                    override: Dict[str, Any] = None) -> Dict[str, Any]:
    """Generate the input parameters for the given workchain type for a given code and structure.

    The override argument can be used to pass a dictionary with values for specific inputs that should override the
    defaults. This dictionary should have the same nested structure as the final input dictionary would have for the
    workchain submission.

    :param process_class: process class, either calculation or workchain,
        i.e. ``AbinitCalculation`` or ``AbinitBaseWorkChain``
    :param protocol: the protocol based on which to choose input parameters
    :param code: the code or code name to use
    :param magnetism: the type of magnetisation to be used
    :param initial_mag: value for the initial magnetisation along the z axis.
    :param soc: whether or not to use spin-orbit coupling
    :param structure: the structure
    :param override: a dictionary to override specific inputs
    :return: input dictionary
    """
    # pylint: disable=too-many-arguments,unused-argument
    from aiida.common.lang import type_check

    AbinitCalculation = plugins.CalculationFactory('abinit')  # pylint: disable=invalid-name
    AbinitBaseWorkChain = plugins.WorkflowFactory('abinit.base')  # pylint: disable=invalid-name

    type_check(structure, orm.StructureData)

    if not isinstance(code, orm.Code):
        try:
            code = orm.load_code(code)
        except (exceptions.MultipleObjectsError,
                exceptions.NotExistent) as exception:
            raise ValueError('could not load the code {}: {}'.format(
                code, exception))

    if process_class == AbinitCalculation:
        protocol = protocol['abinit']
        dictionary = generate_inputs_calculation(protocol, code, structure,
                                                 override)
    elif process_class == AbinitBaseWorkChain:
        protocol = protocol['base']
        dictionary = generate_inputs_base(protocol, code, structure, override)
    else:
        raise NotImplementedError(
            'process class {} is not supported'.format(process_class))

    return dictionary
def generate_inputs(process_class: engine.Process,
                    protocol: Dict,
                    code: orm.Code,
                    structure: orm.StructureData,
                    override: Dict[str, Any] = None) -> Dict[str, Any]:
    """Generate the input parameters for the given workchain type for a given code, structure and pseudo family.

    The override argument can be used to pass a dictionary with values for specific inputs that should override the
    defaults. This dictionary should have the same nested structure as the final input dictionary would have for the
    workchain submission. For example if one wanted to generate the inputs for a PwBandsWorkChain and override the
    ecutwfc parameter for the PwBaseWorkChain of the PwRelaxWorkChains, one would have to pass:

        override = {'relax': {'base': {'ecutwfc': 400}}}

    :param process_class: process class, either calculation or workchain, i.e. ``PwCalculation`` or ``PwBaseWorkChain``
    :param protocol: the protocol based on which to choose input parameters
    :param code: the code or code name to use
    :param structure: the structure
    :param override: a dictionary to override specific inputs
    :return: input dictionary
    """
    # pylint: disable=too-many-arguments,unused-argument
    from aiida.common.lang import type_check

    family_name = protocol['relax']['base']['pseudos_family']
    if isinstance(family_name, orm.Str):
        family_name = family_name.value
    try:
        otfg_family = OTFGGroup.objects.get(label=family_name)
    except exceptions.NotExistent:
        raise ValueError(
            'protocol `{}` requires the `{}` `pseudos family` but could not be found.'
            .format(protocol['name'],
                    protocol['relax']['base']['pseudos_family']))

    CastepCalculation = plugins.CalculationFactory('castep.castep')  # pylint: disable=invalid-name
    CastepBaseWorkChain = plugins.WorkflowFactory('castep.base')  # pylint: disable=invalid-name
    CastepRelaxWorkChain = plugins.WorkflowFactory('castep.relax')  # pylint: disable=invalid-name

    type_check(structure, orm.StructureData)

    if not isinstance(code, orm.Code):
        try:
            code = orm.load_code(code)
        except (exceptions.MultipleObjectsError,
                exceptions.NotExistent) as exception:
            raise ValueError('could not load the code {}: {}'.format(
                code, exception))

    if process_class == CastepCalculation:
        protocol = protocol['relax']['base']['calc']
        dictionary = generate_inputs_calculation(protocol, code, structure,
                                                 otfg_family, override)
    elif process_class == CastepBaseWorkChain:
        protocol = protocol['relax']['base']
        dictionary = generate_inputs_base(protocol, code, structure,
                                          otfg_family, override)
    elif process_class == CastepRelaxWorkChain:
        protocol = protocol['relax']
        dictionary = generate_inputs_relax(protocol, code, structure,
                                           otfg_family, override)
    else:
        raise NotImplementedError(
            'process class {} is not supported'.format(process_class))

    return dictionary
Esempio n. 3
0
 def __init__(self, code_name, *args, **kwargs):
     """Pass also a code name, that should be a code associated to an `arithmetic.add` plugin."""
     super().__init__(*args, **kwargs)
     self._code = orm.load_code(code_name)
     self._process_class = plugins.CalculationFactory('arithmetic.add')
Esempio n. 4
0

def clean_workchain_calcs(workchain):
    """Clean all remote directories of a workchain's descendant calculations."""
    cleaned_calcs = []

    for called_descendant in workchain.called_descendants:
        if isinstance(called_descendant, orm.CalcJobNode):
            if clean_calcjob_remote(called_descendant):
                cleaned_calcs.append(called_descendant.pk)

    return cleaned_calcs


PwBaseWorkChain = plugins.WorkflowFactory('quantumespresso.pw.base')
DosCalculation = plugins.CalculationFactory('quantumespresso.dos')
ProjwfcCalculation = plugins.CalculationFactory('quantumespresso.projwfc')


class PdosWorkChain(ProtocolMixin, WorkChain):
    """A WorkChain to compute Total & Partial Density of States of a structure, using Quantum Espresso."""
    @classmethod
    def define(cls, spec):
        # yapf: disable
        """Define the process specification."""
        super().define(spec)
        spec.input('structure', valid_type=orm.StructureData, help='The input structure.')
        spec.input(
            'serial_clean',
            valid_type=orm.Bool,
            serializer=to_aiida_type,
Esempio n. 5
0
from aiida import orm, plugins, engine

builder = plugins.CalculationFactory("quantumespresso.pw").get_builder()

builder.code = orm.Code.get(label="qe-direct")
builder.structure = orm.load_node("5eb94d2d-2f58-4769-9f74-80c223791077")
builder.kpoints = orm.load_node("a63f51e4-4a86-4271-bb30-ad69c1e1a7e2")
builder.parameters = orm.load_node("ea01fb5e-9098-481c-b46e-57cfa60a77cc")
upf_family = orm.Group.get(label="SSSP/1.1/PBE/efficiency",
                           type_string="sssp.family")
builder.pseudos = upf_family.get_pseudos(builder.structure)
builder.metadata.options.withmpi = True
builder.metadata.options.resources = {"num_machines": 1, "tot_num_mpiprocs": 2}
builder.metadata.options.max_wallclock_seconds = 1800

calc = engine.submit(builder)
print("pk=", calc.pk)