Example #1
0
def sssp(aiida_profile, generate_upf_data):
    """Create an SSSP pseudo potential family from scratch."""
    from aiida.common.constants import elements
    from aiida.plugins import GroupFactory

    aiida_profile.reset_db()

    SsspFamily = GroupFactory('pseudo.family.sssp')

    cutoffs = {}
    stringency = 'standard'

    with tempfile.TemporaryDirectory() as dirpath:
        for values in elements.values():

            element = values['symbol']
            upf = generate_upf_data(element)
            filename = os.path.join(dirpath, f'{element}.upf')

            with open(filename, 'w+b') as handle:
                with upf.open(mode='rb') as source:
                    handle.write(source.read())
                    handle.flush()

            cutoffs[element] = {
                'cutoff_wfc': 30.0,
                'cutoff_rho': 240.0,
            }

        label = 'SSSP/1.1/PBE/efficiency'
        family = SsspFamily.create_from_folder(dirpath, label)

    family.set_cutoffs(cutoffs, stringency, unit='Ry')

    return family
Example #2
0
def test_pseudopotential_group_get_structure():
    """Test get_pseudos from structure"""
    Pseudo = DataFactory("gaussian.pseudo")
    PseudopotentialGroup = GroupFactory("gaussian.pseudo")

    pseudogroup, created = PseudopotentialGroup.objects.get_or_create("test")
    assert created
    pseudogroup.store()

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    pseudogroup.add_nodes([pseudo.store() for pseudo in pseudos])

    StructureData = DataFactory("structure")
    structure = StructureData(cell=[[4.796302, 0, 0], [0, 4.796302, 0],
                                    [0, 0, 4.796302]],
                              pbc=True)
    structure.append_atom(position=(0.000, 0.000, 0.000), symbols="Li")
    structure.append_atom(position=(0.500, 0.500, 0.000), symbols="Li")
    structure.append_atom(position=(0.500, 0.000, 0.500), symbols="Li")
    structure.append_atom(position=(0.000, 0.500, 0.500), symbols="Li")
    structure.append_atom(position=(0.000, 0.500, 0.000), symbols="H")
    structure.append_atom(position=(0.000, 0.000, 0.500), symbols="H")
    structure.append_atom(position=(0.500, 0.000, 0.000), symbols="H")
    structure.append_atom(position=(0.500, 0.500, 0.500), symbols="H")

    retrieved_pseudos = pseudogroup.get_pseudos(structure=structure)

    assert retrieved_pseudos == {
        "Li": [p for p in pseudos if p.element == "Li"],
        "H": [p for p in pseudos if p.element == "H"],
    }
Example #3
0
    def convert(self, value, _, __):
        """Convert the entry point name to the corresponding class.

        :param value: entry point name that should correspond to subclass of `PseudoPotentialFamily` group plugin
        :return: the `PseudoPotentialFamily` subclass
        :raises: `click.BadParameter` if the entry point cannot be loaded or is not subclass of `PseudoPotentialFamily`
        """
        from aiida.common import exceptions
        from aiida.plugins import GroupFactory
        from aiida_pseudo.groups.family import PseudoPotentialFamily

        try:
            family_type = GroupFactory(value)
        except exceptions.EntryPointError as exception:
            raise click.BadParameter(
                f'`{value}` is not an existing group plugin.') from exception

        if not issubclass(family_type, PseudoPotentialFamily):
            raise click.BadParameter(
                f'`{value}` entry point is not a subclass of `PseudoPotentialFamily`.'
            )

        PseudoPotentialFamily.entry_point = value

        return family_type
Example #4
0
def sssp(generate_upf_data):
    """Create an SSSP pseudo potential family from scratch."""
    from aiida.plugins import GroupFactory

    SsspFamily = GroupFactory('pseudo.family.sssp')  # pylint: disable=invalid-name
    label = 'SSSP/1.1/PBE/efficiency'

    try:
        family = SsspFamily.objects.get(label=label)
    except exceptions.NotExistent:
        pass
    else:
        return family

    cutoffs_dict = {'normal': {}}

    with tempfile.TemporaryDirectory() as dirpath:
        for values in elements.values():

            element = values['symbol']
            upf = generate_upf_data(element)
            filename = os.path.join(dirpath, f'{element}.upf')

            with open(filename, 'w+b') as handle:
                with upf.open(mode='rb') as source:
                    handle.write(source.read())
                    handle.flush()

            cutoffs_dict['normal'][element] = {'cutoff_wfc': 30., 'cutoff_rho': 240.}

        family = SsspFamily.create_from_folder(dirpath, label)

    for stringency, cutoffs in cutoffs_dict.items():
        family.set_cutoffs(cutoffs, stringency, unit='Ry')

    return family
Example #5
0
def pseudo_dojo(aiida_profile, generate_psp8_data):
    """Create an PseudoDojo pseudo potential family from scratch."""
    from aiida.common.constants import elements
    from aiida.plugins import GroupFactory, DataFactory

    aiida_profile.reset_db()

    PseudoDojo = GroupFactory('pseudo.family.pseudo_dojo')  # pylint: disable=invalid-name
    Psp8Data = DataFactory('pseudo.psp8')

    cutoffs = {}
    stringency = 'standard'

    with tempfile.TemporaryDirectory() as dirpath:
        for values in elements.values():

            element = values['symbol']
            psp8 = generate_psp8_data(element)
            filename = os.path.join(dirpath, f'{element}.psp8')

            with open(filename, 'w+b') as handle:
                with psp8.open(mode='rb') as source:
                    handle.write(source.read())
                    handle.flush()

            cutoffs[element] = {
                'cutoff_wfc': 36.0,
                'cutoff_rho': 144.0,
            }

        label = 'PseudoDojo/0.4/PBE/SR/standard/psp8'
        family = PseudoDojo.create_from_folder(dirpath, label, pseudo_type=Psp8Data)

    family.set_cutoffs(cutoffs, stringency, unit='Ry')

    return family
Example #6
0
def group_path_ls(path, type_string, recursive, as_table, no_virtual,
                  with_description, no_warn):
    # pylint: disable=too-many-arguments,too-many-branches
    """Show a list of existing group paths."""
    from aiida.plugins import GroupFactory
    from aiida.tools.groups.paths import GroupPath, InvalidPath

    try:
        path = GroupPath(path or '',
                         cls=GroupFactory(type_string),
                         warn_invalid_child=not no_warn)
    except InvalidPath as err:
        echo.echo_critical(str(err))

    if recursive:
        children = path.walk()
    else:
        children = path.children

    if as_table or with_description:
        from tabulate import tabulate
        headers = ['Path', 'Sub-Groups']
        if with_description:
            headers.append('Description')
        rows = []
        for child in sorted(children):
            if no_virtual and child.is_virtual:
                continue
            row = [
                child.path if child.is_virtual else click.style(child.path,
                                                                bold=True),
                len([c for c in child.walk() if not c.is_virtual])
            ]
            if with_description:
                row.append(
                    '-' if child.is_virtual else child.get_group().description)
            rows.append(row)
        echo.echo(tabulate(rows, headers=headers))
    else:
        for child in sorted(children):
            if no_virtual and child.is_virtual:
                continue
            echo.echo(child.path, bold=not child.is_virtual)
Example #7
0
def test_pseudopotential_group_get():
    Pseudo = DataFactory("gaussian.pseudo")
    PseudopotentialGroup = GroupFactory("gaussian.pseudo")

    pseudogroup, created = PseudopotentialGroup.objects.get_or_create("test")
    assert created
    pseudogroup.store()

    with open(TEST_DIR.joinpath("GTH_POTENTIALS.LiH"), "r") as fhandle:
        pseudos = Pseudo.from_cp2k(fhandle)

    pseudogroup.add_nodes([pseudo.store() for pseudo in pseudos])

    retrieved_pseudos = pseudogroup.get_pseudos(elements=["Li", "H"])

    assert retrieved_pseudos == {
        "Li": [p for p in pseudos if p.element == "Li"],
        "H": [p for p in pseudos if p.element == "H"],
    }
Example #8
0
    def convert(self, value, _, __):
        """Convert the entry point name to the corresponding class.

        :param value: entry point name that should correspond to subclass of `BasisSet` group plugin
        :return: the `BasisSet` subclass
        :raises: `click.BadParameter` if the entry point cannot be loaded or is not subclass of `BasisSet`
        """
        from aiida.common import exceptions
        from aiida.plugins import GroupFactory
        from aiida_basis.groups.set import BasisSet

        try:
            basis_set_type = GroupFactory(value)
        except exceptions.EntryPointError as exception:
            raise click.BadParameter(f'`{value}` is not an existing group plugin.') from exception

        if not issubclass(basis_set_type, BasisSet):
            raise click.BadParameter(f'`{value}` entry point is not a subclass of `BasisSet`.')

        BasisSet.entry_point = value

        return basis_set_type
Example #9
0
# -*- coding: utf-8 -*-
"""Utilities to manipulate the workflow input protocols."""
import pathlib
from typing import Optional, Union
import yaml

from aiida.plugins import DataFactory, GroupFactory

StructureData = DataFactory('structure')
PseudoPotentialFamily = GroupFactory('pseudo.family')


class ProtocolMixin:
    """Utility class for processes to build input mappings for a given protocol based on a YAML configuration file."""
    @classmethod
    def get_protocol_filepath(cls) -> pathlib.Path:
        """Return the ``pathlib.Path`` to the ``.yaml`` file that defines the protocols."""
        raise NotImplementedError

    @classmethod
    def get_default_protocol(cls) -> str:
        """Return the default protocol for a given workflow class.

        :param cls: the workflow class.
        :return: the default protocol.
        """
        return cls._load_protocol_file()['default_protocol']

    @classmethod
    def get_available_protocols(cls) -> dict:
        """Return the available protocols for a given workflow class.
Example #10
0
from aiida.common.lang import type_check
from aiida.engine import ToContext, if_, while_, BaseRestartWorkChain, process_handler, ProcessHandlerReport, ExitCode
from aiida.plugins import CalculationFactory, GroupFactory

from aiida_quantumespresso.calculations.functions.create_kpoints_from_distance import create_kpoints_from_distance
from aiida_quantumespresso.common.types import ElectronicType, SpinType
from aiida_quantumespresso.utils.defaults.calculation import pw as qe_defaults
from aiida_quantumespresso.utils.mapping import update_mapping, prepare_process_inputs
from aiida_quantumespresso.utils.pseudopotential import validate_and_prepare_pseudos_inputs
from aiida_quantumespresso.utils.resources import get_default_options, get_pw_parallelization_parameters
from aiida_quantumespresso.utils.resources import cmdline_remove_npools, create_scheduler_resources

from ..protocols.utils import ProtocolMixin

PwCalculation = CalculationFactory('quantumespresso.pw')
SsspFamily = GroupFactory('pseudo.family.sssp')
PseudoDojoFamily = GroupFactory('pseudo.family.pseudo_dojo')
CutoffsPseudoPotentialFamily = GroupFactory('pseudo.family.cutoffs')


def validate_pseudo_family(value, _):
    """Validate the `pseudo_family` input."""
    if value:
        import warnings
        from aiida.common.warnings import AiidaDeprecationWarning
        warnings.warn(
            '`pseudo_family` is deprecated, use `pw.pseudos` instead.',
            AiidaDeprecationWarning)


class PwBaseWorkChain(ProtocolMixin, BaseRestartWorkChain):
Example #11
0
from aiida.common.lang import type_check
from aiida.engine import ToContext, if_, while_, BaseRestartWorkChain, process_handler, ProcessHandlerReport, ExitCode
from aiida.plugins import CalculationFactory, GroupFactory

from aiida_quantumespresso.calculations.functions.create_kpoints_from_distance import create_kpoints_from_distance
from aiida_quantumespresso.common.types import ElectronicType, SpinType
from aiida_quantumespresso.utils.defaults.calculation import pw as qe_defaults
from aiida_quantumespresso.utils.mapping import update_mapping, prepare_process_inputs
from aiida_quantumespresso.utils.pseudopotential import validate_and_prepare_pseudos_inputs
from aiida_quantumespresso.utils.resources import get_default_options, get_pw_parallelization_parameters
from aiida_quantumespresso.utils.resources import cmdline_remove_npools, create_scheduler_resources

from ..protocols.utils import ProtocolMixin

PwCalculation = CalculationFactory('quantumespresso.pw')
SsspFamily = GroupFactory('pseudo.family.sssp')
PseudoDojoFamily = GroupFactory('pseudo.family.pseudo_dojo')


def validate_pseudo_family(value, _):
    """Validate the `pseudo_family` input."""
    if value:
        import warnings
        from aiida.common.warnings import AiidaDeprecationWarning
        warnings.warn(
            '`pseudo_family` is deprecated, use `pw.pseudos` instead.',
            AiidaDeprecationWarning)


class PwBaseWorkChain(ProtocolMixin, BaseRestartWorkChain):
    """Workchain to run a Quantum ESPRESSO pw.x calculation with automated error handling and restarts."""
Example #12
0
def test_create_basisset_group():
    BasisSetGroup = GroupFactory("gaussian.basisset")

    basisgroup, created = BasisSetGroup.objects.get_or_create("test")
    assert created
    basisgroup.store()
Example #13
0
def test_create_pseudopotential_group():
    PseudopotentialGroup = GroupFactory("gaussian.pseudo")

    pseudogroup, created = PseudopotentialGroup.objects.get_or_create("test")
    assert created
    pseudogroup.store()