Skip to content
Draft
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
15 changes: 9 additions & 6 deletions aiida_quantumespresso/calculations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from functools import partial
from types import MappingProxyType

from qe_tools.converters import get_parameters_from_cell
from aiida import orm
from aiida.common import datastructures, exceptions
from aiida.common.lang import classproperty
from aiida.common.warnings import AiidaDeprecationWarning
from aiida.plugins import DataFactory
from qe_tools.converters import get_parameters_from_cell

from aiida_quantumespresso.utils.convert import convert_input_to_namelist_entry
from .base import CalcJob
Expand Down Expand Up @@ -115,7 +115,8 @@ def define(cls, spec):
spec.input('structure', valid_type=orm.StructureData,
help='The input structure.')
spec.input('parameters', valid_type=orm.Dict,
help='The input parameters that are to be used to construct the input file.')
help='The input parameters that are to be used to construct the input file.',
validator=cls.validate_parameters)
spec.input('settings', valid_type=orm.Dict, required=False,
help='Optional parameters to affect the way the calculation job and the parsing are performed.')
spec.input('parent_folder', valid_type=orm.RemoteData, required=False,
Expand Down Expand Up @@ -152,6 +153,11 @@ def _validate_parallelization(cls, value, port_namespace): # pylint: disable=un
if invalid_values:
return f'Parallelization values must be integers; got invalid values {invalid_values}.'

@staticmethod
def validate_parameters(value, _):
"""Validate the input parameters of the pw.x calculation."""
raise NotImplementedError

def prepare_for_submission(self, folder):
"""Create the input files from the input nodes passed to this instance of the `CalcJob`.

Expand Down Expand Up @@ -442,11 +448,8 @@ def _generate_PWCPinputdata(cls, parameters, settings, pseudos, structure, kpoin
pseudo = pseudos[kind.name]
if kind.is_alloy or kind.has_vacancies:
raise exceptions.InputValidationError(
"Kind '{}' is an alloy or has "
'vacancies. This is not allowed for pw.x input structures.'
''.format(kind.name)
f'Kind `{kind.name}` is an alloy or has vacancies. This is not allowed for `pw.x` input structures.'
)

try:
# If it is the same pseudopotential file, use the same filename
filename = pseudo_filenames[pseudo.pk]
Expand Down
12 changes: 12 additions & 0 deletions aiida_quantumespresso/calculations/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
TODO: all a lot of logger.debug stuff
"""
import os
import pathlib
import yaml
import jsonschema

from aiida import orm
from aiida.common.lang import classproperty
Expand Down Expand Up @@ -159,6 +162,15 @@ def define(cls, spec):
message='The required trajectory data could not be read.')
# yapf: enable

@staticmethod
def validate_parameters(value, _):
"""Validate the input parameters of the pw.x calculation."""

with (pathlib.Path(__file__).resolve().parent / 'schemas' / 'cp' / 'parameters.yaml').open() as handle:
parameters_schema = yaml.safe_load(handle)

jsonschema.validate(value.get_dict(), parameters_schema)

@staticmethod
def _generate_PWCP_input_tail(*args, **kwargs):
"""Parse CP specific input parameters."""
Expand Down
Loading