Skip to content

Commit

Permalink
Dependencies: update to aiida-pseudo==0.4.0
Browse files Browse the repository at this point in the history
This new minor version comes with some significant changes:

 * All format specific pseudopotential family subclasses have been
   removed, for example, `UpfFamily` no longer exists. The format of
   the pseudos in a family are now stored as an extra and can be
   retrieved through the `pseudo_type` property. The command line
   option param type `PseudoFamilyType` was updated to reflect these
   changes.

 * The recommended cutoffs for families are now always stored in
   electronvolt. They therefore have to be converted explicitly to
   Rydberg before they are passed to the calculations.
  • Loading branch information
sphuber committed Dec 10, 2020
1 parent f076bfa commit 7d17de5
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 51 deletions.
6 changes: 4 additions & 2 deletions aiida_quantumespresso/cli/calculations/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def launch_calculation(code, structure, pseudo_family, max_num_machines, max_wal
"""Run a CpCalculation."""
from aiida.orm import Dict
from aiida.plugins import CalculationFactory
from qe_tools import CONSTANTS

from aiida_quantumespresso.utils.resources import get_default_options

cutoff_wfc, cutoff_rho = pseudo_family.get_recommended_cutoffs(structure=structure)
Expand All @@ -38,8 +40,8 @@ def launch_calculation(code, structure, pseudo_family, max_num_machines, max_wal
'nstep': 10,
},
'SYSTEM': {
'ecutwfc': cutoff_wfc,
'ecutrho': cutoff_rho,
'ecutwfc': cutoff_wfc / CONSTANTS.ry_to_ev,
'ecutrho': cutoff_rho / CONSTANTS.ry_to_ev,
'nr1b': 24,
'nr2b': 24,
'nr3b': 24,
Expand Down
6 changes: 4 additions & 2 deletions aiida_quantumespresso/cli/calculations/neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def launch_calculation(
"""
from aiida.orm import Dict
from aiida.plugins import CalculationFactory
from qe_tools import CONSTANTS

from aiida_quantumespresso.utils.resources import get_default_options

cutoff_wfc, cutoff_rho = pseudo_family.get_recommended_cutoffs(structure=structures[0])
Expand All @@ -68,8 +70,8 @@ def launch_calculation(
'calculation': 'relax',
},
'SYSTEM': {
'ecutwfc': ecutwfc or cutoff_wfc,
'ecutrho': ecutrho or cutoff_rho,
'ecutwfc': ecutwfc or cutoff_wfc / CONSTANTS.ry_to_ev,
'ecutrho': ecutrho or cutoff_rho / CONSTANTS.ry_to_ev,
}
}

Expand Down
6 changes: 4 additions & 2 deletions aiida_quantumespresso/cli/calculations/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def launch_calculation(
"""Run a PwCalculation."""
from aiida.orm import Dict, KpointsData
from aiida.plugins import CalculationFactory
from qe_tools import CONSTANTS

from aiida_quantumespresso.utils.resources import get_default_options

cutoff_wfc, cutoff_rho = pseudo_family.get_recommended_cutoffs(structure=structure)
Expand All @@ -67,8 +69,8 @@ def launch_calculation(
'calculation': mode,
},
'SYSTEM': {
'ecutwfc': ecutwfc or cutoff_wfc,
'ecutrho': ecutrho or cutoff_rho,
'ecutwfc': ecutwfc or cutoff_wfc / CONSTANTS.ry_to_ev,
'ecutrho': ecutrho or cutoff_rho / CONSTANTS.ry_to_ev,
}
}

Expand Down
16 changes: 14 additions & 2 deletions aiida_quantumespresso/cli/utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
class PseudoFamilyType(types.GroupParamType):
"""Subclass of `GroupParamType` in order to be able to print warning with instructions."""

def __init__(self, pseudo_types=None, **kwargs):
"""Construct a new instance."""
super().__init__(**kwargs)
self._pseudo_types = pseudo_types

@decorators.with_dbenv()
def convert(self, value, param, ctx):
"""Convert the value to actual pseudo family instance."""
Expand All @@ -28,16 +33,23 @@ def convert(self, value, param, ctx):
raise click.BadParameter( # pylint: disable=raise-missing-from
f'`{value}` is not of a supported pseudopotential family type.\nTo install a supported '
'pseudofamily, use the `aiida-pseudo` plugin. See the following link for detailed instructions:\n\n'
' https://github.com/aiidateam/aiida-quantumespresso#pseudo-potentials'
' https://github.com/aiidateam/aiida-quantumespresso#pseudopotentials'
)

if self._pseudo_types is not None and group.pseudo_type not in self._pseudo_types:
pseudo_types = ', '.join(self._pseudo_types)
raise click.BadParameter(
f'family `{group.label}` contains pseudopotentials of the wrong type `{group.pseudo_type}`.\nOnly the '
f'following types are supported: {pseudo_types}'
)

return group


PSEUDO_FAMILY = OverridableOption(
'-F',
'--pseudo-family',
type=PseudoFamilyType(sub_classes=('aiida.groups:pseudo.family.upf', 'aiida.groups:pseudo.family.sssp')),
type=PseudoFamilyType(sub_classes=('aiida.groups:pseudo.family',), pseudo_types=('pseudo.upf',)),
required=True,
help='Select a pseudopotential family.'
)
Expand Down
6 changes: 4 additions & 2 deletions aiida_quantumespresso/cli/workflows/pw/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def launch_workflow(
# pylint: disable=too-many-statements
from aiida.orm import Bool, Float, Dict
from aiida.plugins import WorkflowFactory
from qe_tools import CONSTANTS

from aiida_quantumespresso.utils.resources import get_default_options, get_automatic_parallelization_options

builder = WorkflowFactory('quantumespresso.pw.bands').get_builder()
Expand All @@ -48,8 +50,8 @@ def launch_workflow(

parameters = {
'SYSTEM': {
'ecutwfc': ecutwfc or cutoff_wfc,
'ecutrho': ecutrho or cutoff_rho,
'ecutwfc': ecutwfc or cutoff_wfc / CONSTANTS.ry_to_ev,
'ecutrho': ecutrho or cutoff_rho / CONSTANTS.ry_to_ev,
},
}

Expand Down
6 changes: 4 additions & 2 deletions aiida_quantumespresso/cli/workflows/pw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def launch_workflow(
"""Run a `PwBaseWorkChain`."""
from aiida.orm import Bool, Float, Dict
from aiida.plugins import WorkflowFactory
from qe_tools import CONSTANTS

from aiida_quantumespresso.utils.resources import get_default_options, get_automatic_parallelization_options

builder = WorkflowFactory('quantumespresso.pw.base').get_builder()
Expand All @@ -48,8 +50,8 @@ def launch_workflow(

parameters = {
'SYSTEM': {
'ecutwfc': ecutwfc or cutoff_wfc,
'ecutrho': ecutrho or cutoff_rho,
'ecutwfc': ecutwfc or cutoff_wfc / CONSTANTS.ry_to_ev,
'ecutrho': ecutrho or cutoff_rho / CONSTANTS.ry_to_ev,
},
}

Expand Down
5 changes: 3 additions & 2 deletions aiida_quantumespresso/cli/workflows/pw/relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def launch_workflow(
"""Run a `PwRelaxWorkChain`."""
from aiida.orm import Bool, Float, Dict, Str
from aiida.plugins import WorkflowFactory
from qe_tools import CONSTANTS

from aiida_quantumespresso.common.types import RelaxType
from aiida_quantumespresso.utils.resources import get_default_options, get_automatic_parallelization_options
Expand All @@ -57,8 +58,8 @@ def launch_workflow(

parameters = {
'SYSTEM': {
'ecutwfc': ecutwfc or cutoff_wfc,
'ecutrho': ecutrho or cutoff_rho,
'ecutwfc': ecutwfc or cutoff_wfc / CONSTANTS.ry_to_ev,
'ecutrho': ecutrho or cutoff_rho / CONSTANTS.ry_to_ev,
},
}

Expand Down
11 changes: 5 additions & 6 deletions aiida_quantumespresso/workflows/pw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ..protocols.utils import ProtocolMixin

PwCalculation = CalculationFactory('quantumespresso.pw')
UpfFamily = GroupFactory('pseudo.family.upf')
SsspFamily = GroupFactory('pseudo.family.sssp')


Expand Down Expand Up @@ -140,6 +139,7 @@ def get_builder_from_protocol(
guess for the magnetization is automatically set in case this argument is not provided.
:return: a process builder instance with all inputs defined ready for launch.
"""
from qe_tools import CONSTANTS
from aiida_quantumespresso.workflows.protocols.utils import get_starting_magnetization

if isinstance(code, str):
Expand Down Expand Up @@ -168,18 +168,17 @@ def get_builder_from_protocol(
nkinds = len(structure.kinds)

try:
types = (UpfFamily, SsspFamily)
pseudo_family = orm.QueryBuilder().append(types, filters={'label': pseudo_family}).one()[0]
pseudo_family = orm.QueryBuilder().append(SsspFamily, filters={'label': pseudo_family}).one()[0]
except exceptions.NotExistent as exception:
raise ValueError(f'required pseudo family `{pseudo_family}` is not installed') from exception

cutoffs = pseudo_family.get_recommended_cutoffs(structure=structure)
cutoff_wfc, cutoff_rho = pseudo_family.get_recommended_cutoffs(structure=structure)

parameters = inputs['pw']['parameters']
parameters['CONTROL']['etot_conv_thr'] = natoms * meta_parameters['etot_conv_thr_per_atom']
parameters['ELECTRONS']['conv_thr'] = natoms * meta_parameters['conv_thr_per_atom']
parameters['SYSTEM']['ecutwfc'] = cutoffs[0]
parameters['SYSTEM']['ecutrho'] = cutoffs[1]
parameters['SYSTEM']['ecutwfc'] = cutoff_wfc / CONSTANTS.ry_to_ev
parameters['SYSTEM']['ecutrho'] = cutoff_rho / CONSTANTS.ry_to_ev

if electronic_type is ElectronicType.INSULATOR:
parameters['SYSTEM']['occupations'] = 'fixed'
Expand Down
4 changes: 2 additions & 2 deletions setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
]
},
"install_requires": [
"aiida_core[atomic_tools]~=1.4,>=1.4.2",
"aiida-pseudo~=0.3.0",
"aiida_core[atomic_tools]~=1.4,>=1.4.4",
"aiida-pseudo~=0.4.0",
"packaging",
"qe-tools~=2.0rc1",
"xmlschema~=1.2,>=1.2.5",
Expand Down
29 changes: 0 additions & 29 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,35 +293,6 @@ def _generate_upf_data(element):
return _generate_upf_data


@pytest.fixture
def generate_upf_family(tmp_path, generate_upf_data):
"""Return a factory for a `UpfFamily` instance."""

def _generate_upf_family(label='family', elements=('Si',)):
"""Return an instance of `UpfFamily` or subclass containing the given elements.
:param elements: optional list of elements to include instead of all the available ones
:return: the pseudo family
"""
from aiida_pseudo.groups.family import UpfFamily

cutoffs = {}

for element in elements:
upf = generate_upf_data(element)
with open(os.path.join(tmp_path, f'{element}.upf'), 'wb') as handle:
with upf.open(mode='rb') as source:
handle.write(source.read())
cutoffs[element] = {'cutoff_wfc': 1.0, 'cutoff_rho': 2.0}

family = UpfFamily.create_from_folder(str(tmp_path), label)
family.set_cutoffs({'standard': cutoffs})

return family

return _generate_upf_family


@pytest.fixture
def generate_structure():
"""Return a `StructureData` representing bulk silicon."""
Expand Down

0 comments on commit 7d17de5

Please sign in to comment.