Skip to content

Commit

Permalink
PwCalculation: remove deprecated key functionality (#495)
Browse files Browse the repository at this point in the history
The added maintenance cost of this functionality is not worth the added
benefit. The keys made little sense anyway and besides these are not the
only backward incompatible changes between v2 and v3 of the plugin.
  • Loading branch information
sphuber committed May 7, 2020
1 parent 80f4957 commit 5b1cb5b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 145 deletions.
49 changes: 0 additions & 49 deletions CHANGELOG_v3_parser_keys.txt

This file was deleted.

7 changes: 1 addition & 6 deletions aiida_quantumespresso/parsers/neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ def parse(self, **kwargs):
settings = {}
parser_options = {}

try:
include_deprecated_v2_keys = parser_options['include_deprecated_v2_keys']
except (TypeError, KeyError):
include_deprecated_v2_keys = False

# load the pw input parameters dictionary
pw_input_dict = self.node.inputs.pw__parameters.get_dict()

Expand Down Expand Up @@ -111,7 +106,7 @@ def parse(self, **kwargs):
xml_file_path = os.path.join(relative_output_folder, xml_filename)
try:
with out_folder.open(xml_file_path) as xml_file:
parsed_data_xml, logs_xml = parse_pw_xml(xml_file, None, include_deprecated_v2_keys)
parsed_data_xml, logs_xml = parse_pw_xml(xml_file, None)
except IOError:
return self.exit(self.exit_codes.ERROR_OUTPUT_XML_READ)
except XMLParseError:
Expand Down
10 changes: 5 additions & 5 deletions aiida_quantumespresso/parsers/parse_xml/pw/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
default_length_units = 'Angstrom'


def parse_pw_xml_pre_6_2(xml_file, dir_with_bands, include_deprecated_keys=False):
def parse_pw_xml_pre_6_2(xml_file, dir_with_bands):
"""Parse the content of XML output file written by `pw.x` with the old schema-less XML format.
:param xml_file: filelike object to the XML output file
:param dir_with_bands: absolute filepath to directory containing k-point XML files
:param include_deprecated_v2_keys: boolean, if True, includes deprecated keys from old parser v2
:returns: tuple of two dictionaries, with the parsed data and log messages, respectively
"""
import copy
Expand Down Expand Up @@ -260,9 +259,10 @@ def parse_pw_xml_pre_6_2(xml_file, dir_with_bands, include_deprecated_keys=False
parsed_data['occupations'] = 'tetrahedra' # TODO: might also be tetrahedra_lin or tetrahedra_opt: check input?
elif parsed_data['fixed_occupations']:
parsed_data['occupations'] = 'fixed'
if not include_deprecated_keys:
for tagname in ['SMEARING_METHOD','TETRAHEDRON_METHOD','FIXED_OCCUPATIONS']:
parsed_data.pop(tagname.lower())

# Remove the following deprecated keys
for tagname in ['SMEARING_METHOD','TETRAHEDRON_METHOD','FIXED_OCCUPATIONS']:
parsed_data.pop(tagname.lower())

#CARD CHARGE-DENSITY
cardname='CHARGE-DENSITY'
Expand Down
43 changes: 4 additions & 39 deletions aiida_quantumespresso/parsers/parse_xml/pw/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def cell_volume(a1, a2, a3):
return abs(float(a1[0] * a_mid_0 + a1[1] * a_mid_1 + a1[2] * a_mid_2))


def parse_xml(xml_file, dir_with_bands=None, include_deprecated_v2_keys=False):
def parse_xml(xml_file, dir_with_bands=None):
try:
xml_parsed = ElementTree.parse(xml_file)
except ElementTree.ParseError:
Expand All @@ -52,19 +52,18 @@ def parse_xml(xml_file, dir_with_bands=None, include_deprecated_v2_keys=False):
xml_file_version = get_xml_file_version(xml_parsed)

if xml_file_version == QeXmlVersion.POST_6_2:
parsed_data, logs = parse_pw_xml_post_6_2(xml_parsed, include_deprecated_v2_keys)
parsed_data, logs = parse_pw_xml_post_6_2(xml_parsed)
elif xml_file_version == QeXmlVersion.PRE_6_2:
xml_file.seek(0)
parsed_data, logs = parse_pw_xml_pre_6_2(xml_file, dir_with_bands, include_deprecated_v2_keys)
parsed_data, logs = parse_pw_xml_pre_6_2(xml_file, dir_with_bands)

return parsed_data, logs


def parse_pw_xml_post_6_2(xml, include_deprecated_v2_keys=False):
def parse_pw_xml_post_6_2(xml):
"""Parse the content of XML output file written by `pw.x` with the new schema-based XML format.
:param xml: parsed XML
:param include_deprecated_v2_keys: boolean, if True, includes deprecated keys from old parser v2
:returns: tuple of two dictionaries, with the parsed data and log messages, respectively
"""
e_bohr2_to_coulomb_m2 = 57.214766 # e/a0^2 to C/m^2 (electric polarization) from Wolfram Alpha
Expand Down Expand Up @@ -123,35 +122,6 @@ def parse_pw_xml_post_6_2(xml, include_deprecated_v2_keys=False):
else:
occupations = None

if include_deprecated_v2_keys:

# NOTE: these flags are not super clear
# TODO: remove them and just use 'occupations' as a string, with possible values "smearing","tetrahedra", ...

if occupations == 'from_input': # False for 'fixed' # TODO: does this make sense?
fixed_occupations = True
else:
fixed_occupations = False

if occupations and 'tetrahedra' in occupations:
tetrahedron_method = True
else:
tetrahedron_method = False

if occupations == 'from_input':
smearing_method = False
else:
smearing_method = True

if smearing_method:
if 'smearing' not in (list(outputs['band_structure'].keys()) + list(inputs.keys())):
logs.error.append("occupations is '{}' but key 'smearing' is not present under input/bands "
'nor under output/band_structure'.format(occupations))
# TODO: this error is triggered if no smearing is specified in input. But this is a valid input, so we should't throw an error.
# Should we ask QE to print something nonetheless?
# Also happens if occupations='fixed'.
# (Example: occupations is 'fixed' but key 'smearing' is not present under input/bands nor output/band_structure. See calculation 4940, versus 4981.)

starting_magnetization = []
magnetization_angle1 = []
magnetization_angle2 = []
Expand Down Expand Up @@ -468,11 +438,6 @@ def parse_pw_xml_post_6_2(xml, include_deprecated_v2_keys=False):
# 3 = ionic convergence failed
# These might be changed in the future. Also see PW/src/run_pwscf.f90

if include_deprecated_v2_keys:
xml_data['fixed_occupations'] = fixed_occupations
xml_data['tetrahedron_method'] = tetrahedron_method
xml_data['smearing_method'] = smearing_method

try:
berry_phase = outputs['electric_field']['BerryPhase']
except KeyError:
Expand Down
7 changes: 1 addition & 6 deletions aiida_quantumespresso/parsers/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,9 @@ def parse_xml(self, dir_with_bands=None, parser_options=None):
self.exit_code_xml = self.exit_codes.ERROR_OUTPUT_XML_MULTIPLE
return parsed_data, logs

try:
include_deprecated_keys = parser_options['include_deprecated_v2_keys']
except (TypeError, KeyError):
include_deprecated_keys = False

try:
with self.retrieved.open(xml_files[0]) as xml_file:
parsed_data, logs = parse_xml(xml_file, dir_with_bands, include_deprecated_keys)
parsed_data, logs = parse_xml(xml_file, dir_with_bands)
except IOError:
self.exit_code_xml = self.exit_codes.ERROR_OUTPUT_XML_READ
except XMLParseError:
Expand Down
14 changes: 0 additions & 14 deletions docs/source/user_guide/calculation_plugins/pw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,3 @@ occupations::

Note that for ``pw.x`` to print the required information, the flag ``lda_plus_u`` has to be
set to ``True`` in the ``SYSTEM`` card of the input ``parameters`` node.

Include deprecated output keys
..........................
In version 3 of the plugin, some keys have been deprecated and removed by default
from the ``output_parameters`` node, often replaced by more appropriate keys.
To also include the deprecated keys, add ``include_deprecated_v2_keys: True``
to the ``parser_options`` element of the settings dictionary.
The default value of this options is ``False``. Example::

settings_dict = {
'parser_options': {
'include_deprecated_v2_keys': True,
}
}
26 changes: 0 additions & 26 deletions tests/parsers/test_neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,3 @@ def test_neb_all_iterations(

data = build_num_regression_dictionary([results['iteration_array']], [results['iteration_array'].get_arraynames()])
num_regression.check(data, default_tolerance=dict(atol=0, rtol=1e-18))


def test_neb_deprecated_keys(aiida_profile, fixture_localhost, generate_calc_job_node, generate_parser):
"""Test a NEB calculation with the parser option `include_deprecated_v2_keys=True`."""
name = 'default'
entry_point_calc_job = 'quantumespresso.neb'
entry_point_parser = 'quantumespresso.neb'

inputs = generate_inputs(parser_options={'include_deprecated_v2_keys': True})
node = generate_calc_job_node(entry_point_calc_job, fixture_localhost, name, inputs)
parser = generate_parser(entry_point_parser)
results, calcfunction = parser.parse_from_node(node, store_provenance=False)

assert calcfunction.is_finished, calcfunction.exception
assert calcfunction.is_finished_ok, calcfunction.exit_message
assert not orm.Log.objects.get_logs_for(node)
assert 'output_parameters' in results
assert 'output_mep' in results
assert 'output_trajectory' in results
assert 'iteration_array' not in results

for key, dictionary in results['output_parameters'].get_dict().items():
if key.startswith('pw_output_image'):
assert dictionary['fixed_occupations'] is False
assert dictionary['smearing_method'] is True
assert dictionary['tetrahedron_method'] is False

0 comments on commit 5b1cb5b

Please sign in to comment.