Ejemplo n.º 1
0
def psml_family(generate_psml_data):
    """Create a pseudopotential family with PsmlData potentials from scratch."""
    from aiida import plugins

    PsmlData = plugins.DataFactory('pseudo.psml')  # pylint: disable=invalid-name
    PseudoPotentialFamily = plugins.GroupFactory('pseudo.family')  # pylint: disable=invalid-name
    label = 'nc-sr-04_pbe_standard_psml'

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

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

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

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

        family = PseudoPotentialFamily.create_from_folder(dirpath, label, pseudo_type=PsmlData)

    return family
Ejemplo n.º 2
0
    def has_unknown_species(self):
        """
        Returns whether the cif contains atomic species that are not recognized by AiiDA.

        The known species are taken from the elements dictionary in `aiida.common.constants`, with the exception of
        the "unknown" placeholder element with symbol 'X', as this could not be used to construct a real structure.
        If any of the formula of the cif data contain species that are not in that elements dictionary, the function
        will return True and False in all other cases. If there is no formulae to be found, it will return None

        :returns: True when there are unknown species in any of the formulae, False if not, None if no formula found
        """
        from aiida.common.constants import elements

        # Get all the elements known by AiiDA, excluding the "unknown" element with symbol 'X'
        known_species = [element['symbol'] for element in elements.values() if element['symbol'] != 'X']

        for formula in self.get_formulae():

            if formula is None:
                return None

            species = parse_formula(formula).keys()
            if any([specie not in known_species for specie in species]):
                return True

        return False
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def validate_element(cls, element: str):
     """Validate the given element symbol.
     :param element: the symbol of the element following the IUPAC naming standard.
     :raises ValueError: if the element symbol is invalid.
     """
     if element not in [values['symbol'] for values in elements.values()]:
         raise ValueError(f'`{element}` is not a valid element.')
Ejemplo n.º 5
0
    def _generate_structure(symbols=None):
        from aiida.plugins import DataFactory

        structure = DataFactory('structure')()

        valid_symbols = [value['symbol'] for value in elements.values()]

        if symbols is not None:
            for index, symbol in enumerate(symbols):
                if symbol not in valid_symbols:
                    raise ValueError(f'symbol `{symbol}` is not a valid element.')

                structure.append_atom(position=(0. + index * 1, 0. + index * 1, 0. + index * 1), symbols=[symbol])

        return structure
Ejemplo n.º 6
0
def pseudo_dojo(generate_jthxml_data):
    """Create a PseudoDojo pseudo potential family from scratch."""
    from aiida import plugins

    PseudoDojoFamily = plugins.GroupFactory('pseudo.family.pseudo_dojo')  # pylint: disable=invalid-name
    label = 'PseudoDojo/1.0/PBE/SR/standard/jthxml'

    try:
        family = PseudoDojoFamily.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_jthxml_data(element)
            filename = os.path.join(dirpath, f'{element}.jthxml')

            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 = PseudoDojoFamily.create_from_folder(dirpath, label, pseudo_type=plugins.DataFactory('pseudo.jthxml'))

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

    return family
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
0
    def has_unknown_species(self):
        """
        Returns whether the cif contains atomic species that are not recognized by AiiDA.
        The known species are taken from the elements dictionary in aiida.common.constants.
        If any of the formula of the cif data contain species that are not in that elements
        dictionary, the function will return True and False in all other cases. If there is
        no formulae to be found, it will return None

        :returns: True when there are unknown species in any of the formulae, False if not, None if no formula found
        """
        from aiida.common.constants import elements

        known_species = [element['symbol'] for element in elements.values()]

        for formula in self.get_formulae():

            if formula is None:
                return None

            species = parse_formula(formula).keys()
            if any([specie not in known_species for specie in species]):
                return True

        return False