Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use typing.NamedTuple for pseudo family configurations #111

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions aiida_pseudo/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def cmd_install_sssp(version, functional, protocol, download_only, traceback):
label = SsspFamily.format_configuration_label(configuration)

if configuration not in SsspFamily.valid_configurations:
echo.echo_critical(f'{version} {functional} {protocol} is not a valid SSSP configuration')
echo.echo_critical(f'{configuration} is not a valid configuration.')

if not download_only and QueryBuilder().append(SsspFamily, filters={'label': label}).first():
echo.echo_critical(f'{SsspFamily.__name__}<{label}> is already installed')
Expand Down Expand Up @@ -250,7 +250,7 @@ def cmd_install_sssp(version, functional, protocol, download_only, traceback):
family.description = description
family.set_cutoffs(cutoffs, 'normal', unit='Ry')

echo.echo_success(f'installed `{label}` containing {family.count()} pseudopotentials')
echo.echo_success(f'installed `{label}` containing {family.count()} pseudopotentials.')


@cmd_install.command('pseudo-dojo')
Expand Down Expand Up @@ -299,17 +299,17 @@ def cmd_install_pseudo_dojo(
try:
pseudo_type = pseudo_type_mapping[pseudo_format]
except KeyError:
echo.echo_critical(f'{pseudo_format} is not a valid PseudoDojo pseudopotential format')
echo.echo_critical(f'{pseudo_format} is not a valid PseudoDojo pseudopotential format.')

configuration = PseudoDojoConfiguration(version, functional, relativistic, protocol, pseudo_format)
label = PseudoDojoFamily.format_configuration_label(configuration)
description = 'PseudoDojo v{} {} {} {} {} installed with aiida-pseudo v{}'.format(*configuration, __version__)
description = f'{configuration} installed with aiida-pseudo v{__version__}'

if configuration not in PseudoDojoFamily.valid_configurations:
echo.echo_critical('{} {} {} {} {} is not a valid PseudoDojo configuration'.format(*configuration))
echo.echo_critical(f'{configuration} is not a valid configuration')

if not download_only and QueryBuilder().append(PseudoDojoFamily, filters={'label': label}).first():
echo.echo_critical(f'{PseudoDojoFamily.__name__}<{label}> is already installed')
echo.echo_critical(f'{PseudoDojoFamily.__name__}<{label}> is already installed.')

with tempfile.TemporaryDirectory() as dirpath:

Expand Down Expand Up @@ -373,4 +373,4 @@ def cmd_install_pseudo_dojo(
family.set_cutoffs(cutoff_values, stringency, unit='Eh')
family.set_default_stringency(default_stringency)

echo.echo_success(f'installed `{label}` containing {family.count()} pseudopotentials')
echo.echo_success(f'installed `{label}` containing {family.count()} pseudopotentials.')
19 changes: 14 additions & 5 deletions aiida_pseudo/groups/family/pseudo_dojo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
"""Subclass of `PseudoPotentialFamily` designed to represent a PseudoDojo configuration."""
import collections
import json
import os
import re
from typing import NamedTuple, Sequence
import warnings

from pathlib import Path
from typing import Sequence

from aiida.common.exceptions import ParsingError

Expand All @@ -17,9 +16,19 @@

__all__ = ('PseudoDojoConfiguration', 'PseudoDojoFamily')

PseudoDojoConfiguration = collections.namedtuple(
'PseudoDojoConfiguration', ['version', 'functional', 'relativistic', 'protocol', 'pseudo_format']
)

class PseudoDojoConfiguration(NamedTuple):
"""Named tuple that represents a PseudoDojo configuration."""

version: str
functional: str
relativistic: str
protocol: str
pseudo_format: str

def __str__(self):
"""Represent the configuration as a string."""
return f'PseudoDojo v{self.version} {self.functional} {self.relativistic} {self.protocol} {self.pseudo_format}'


class PseudoDojoFamily(RecommendedCutoffMixin, PseudoPotentialFamily):
Expand Down
15 changes: 12 additions & 3 deletions aiida_pseudo/groups/family/sssp.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# -*- coding: utf-8 -*-
"""Subclass of ``PseudoPotentialFamily`` designed to represent an SSSP configuration."""
from collections import namedtuple
from typing import Sequence, Optional
from typing import NamedTuple, Optional, Sequence

from aiida_pseudo.data.pseudo import UpfData
from ..mixins import RecommendedCutoffMixin
from .pseudo import PseudoPotentialFamily

__all__ = ('SsspConfiguration', 'SsspFamily')

SsspConfiguration = namedtuple('SsspConfiguration', ['version', 'functional', 'protocol'])

class SsspConfiguration(NamedTuple):
"""Named tuple that represents an SSSP configuration."""

version: str
functional: str
protocol: str

def __str__(self):
"""Represent the configuration as a string."""
return f'SSSP v{self.version} {self.functional} {self.protocol}'


class SsspFamily(RecommendedCutoffMixin, PseudoPotentialFamily):
Expand Down