Exemplo n.º 1
0
def setup_code(non_interactive, **kwargs):
    """Setup a new code."""
    from aiida.common.exceptions import ValidationError
    from aiida.orm.utils.builders.code import CodeBuilder

    if not non_interactive:
        try:
            pre, post = ensure_scripts(kwargs.pop('prepend_text', ''),
                                       kwargs.pop('append_text', ''), kwargs)
        except InputValidationError as exception:
            raise click.BadParameter(
                'invalid prepend and or append text: {}'.format(exception))

        kwargs['prepend_text'] = pre
        kwargs['append_text'] = post

    if kwargs.pop('on_computer'):
        kwargs['code_type'] = CodeBuilder.CodeType.ON_COMPUTER
    else:
        kwargs['code_type'] = CodeBuilder.CodeType.STORE_AND_UPLOAD

    code_builder = CodeBuilder(**kwargs)
    code = code_builder.new()

    try:
        code.store()
        code.reveal()
    except ValidationError as exception:
        echo.echo_critical('Unable to store the Code: {}'.format(exception))

    echo.echo_success('Code<{}> {} created'.format(code.pk, code.full_label))
def get_crystal_props_code(computer,
                           exec_path=DEFAULT_PPROPERTIES_PATH,
                           modules=('intel-suite/2016.3', 'mpi/intel-5.1')):
    """create a Code node for the CRYSTAL17 Properties code

    Parameters
    ----------
    computer : aiida.orm.Computer
    exec_path : str
        absolute path on the computer, to the properties executable
    modules : list[str]
        modules to load before execution

    Returns
    -------
    aiida.orm.Code

    """
    try:
        code_props17 = Code.objects.get(label=_PROPS_CODE_LABEL)
    except NotExistent:
        code_builder = CodeBuilder(
            **{
                'label':
                _PROPS_CODE_LABEL,
                'description':
                'The CRYSTAL17 PProperties code on CX1',
                'code_type':
                CodeBuilder.CodeType.ON_COMPUTER,
                'computer':
                computer,
                'prepend_text':
                'module load ' + ' '.join(modules),
                'append_text':
                '',
                'input_plugin':
                get_entry_point('aiida.calculations', 'crystal17.doss'),
                'remote_abs_path':
                exec_path
            })
        code_props17 = code_builder.new()
        code_props17.store()
    return code_props17
Exemplo n.º 3
0
    def on_setup_code(self, _=None, on_success=None):
        """Setup an AiiDA code."""
        with self.setup_code_out:
            clear_output()

            if not self.computer.value:
                print("Please select an existing computer.")
                return

            items_to_configure = [
                "label",
                "computer",
                "description",
                "input_plugin",
                "remote_abs_path",
                "prepend_text",
                "append_text",
            ]

            kwargs = {
                key: getattr(self, key).value
                for key in items_to_configure
            }
            kwargs["code_type"] = CodeBuilder.CodeType.ON_COMPUTER

            # Checking if the code with this name already exists
            qb = orm.QueryBuilder()
            qb.append(orm.Computer,
                      filters={"uuid": kwargs["computer"].uuid},
                      tag="computer")
            qb.append(orm.Code,
                      with_computer="computer",
                      filters={"label": kwargs["label"]})
            if qb.count() > 0:
                print(
                    f"Code {kwargs['label']}@{kwargs['computer'].label} already exists."
                )
                return

            try:
                code = CodeBuilder(**kwargs).new()
            except (common.exceptions.InputValidationError,
                    KeyError) as exception:
                print(f"Invalid inputs: {exception}")
                return

            try:
                code.store()
                code.reveal()
            except common.exceptions.ValidationError as exception:
                print(f"Unable to store the Code: {exception}")
                return

            if on_success:
                on_success()

            print(f"Code<{code.pk}> {code.full_label} created")
Exemplo n.º 4
0
def setup_code(non_interactive, **kwargs):
    """Setup a new code."""
    from aiida.common.exceptions import ValidationError
    from aiida.orm.utils.builders.code import CodeBuilder

    if kwargs.pop('on_computer'):
        kwargs['code_type'] = CodeBuilder.CodeType.ON_COMPUTER
    else:
        kwargs['code_type'] = CodeBuilder.CodeType.STORE_AND_UPLOAD

    code_builder = CodeBuilder(**kwargs)

    try:
        code = code_builder.new()
    except InputValidationError as exception:
        echo.echo_critical('invalid inputs: {}'.format(exception))

    try:
        code.store()
        code.reveal()
    except ValidationError as exception:
        echo.echo_critical('Unable to store the Code: {}'.format(exception))

    echo.echo_success('Code<{}> {} created'.format(code.pk, code.full_label))
Exemplo n.º 5
0
def set_code_builder(ctx, param, value):
    """Set the code spec for defaults of following options."""
    from aiida.orm.utils.builders.code import CodeBuilder
    ctx.code_builder = CodeBuilder.from_code(value)
    return value