Beispiel #1
0
    def get_entry_point_from_string(self, entry_point_string):
        """
        Validate a given entry point string, which means that it should have a valid entry point string format
        and that the entry point unambiguously corresponds to an entry point in the groups configured for this
        instance of PluginParameterType.

        :returns: the entry point if valid
        :raises: ValueError if the entry point string is invalid
        """
        group = None
        name = None

        entry_point_format = get_entry_point_string_format(entry_point_string)

        if entry_point_format in (EntryPointFormat.FULL,
                                  EntryPointFormat.PARTIAL):

            group, name = entry_point_string.split(
                ENTRY_POINT_STRING_SEPARATOR)

            if entry_point_format == EntryPointFormat.PARTIAL:
                group = ENTRY_POINT_GROUP_PREFIX + group

            if group not in self.groups:
                raise ValueError(
                    'entry point group {} is not supported by this parameter')

        elif entry_point_format == EntryPointFormat.MINIMAL:

            name = entry_point_string
            matching_groups = [
                group for group, entry_point in self._entry_points
                if entry_point.name == name
            ]

            if len(matching_groups) > 1:
                raise ValueError(
                    "entry point '{}' matches more than one valid entry point group [{}], "
                    "please specify an explicit group prefix".format(
                        name, ' '.join(matching_groups)))
            elif not matching_groups:
                raise ValueError(
                    "entry point '{}' is not valid for any of the allowed "
                    "entry point groups: {}".format(name,
                                                    ' '.join(self.groups)))
            else:
                group = matching_groups[0]

        else:
            ValueError('invalid entry point string format: {}'.format(
                entry_point_string))

        try:
            entry_point = get_entry_point(group, name)
        except (MissingEntryPointError, MultipleEntryPointError) as exception:
            raise ValueError(exception)

        return entry_point
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