From 5b1cb5bf161c69ca180f0b4f97e1f599b311965d Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Wed, 6 May 2020 14:56:37 +0200 Subject: [PATCH] `PwCalculation`: remove deprecated key functionality (#495) 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. --- CHANGELOG_v3_parser_keys.txt | 49 ------------------- aiida_quantumespresso/parsers/neb.py | 7 +-- .../parsers/parse_xml/pw/legacy.py | 10 ++-- .../parsers/parse_xml/pw/parse.py | 43 ++-------------- aiida_quantumespresso/parsers/pw.py | 7 +-- .../user_guide/calculation_plugins/pw.rst | 14 ------ tests/parsers/test_neb.py | 26 ---------- 7 files changed, 11 insertions(+), 145 deletions(-) delete mode 100644 CHANGELOG_v3_parser_keys.txt diff --git a/CHANGELOG_v3_parser_keys.txt b/CHANGELOG_v3_parser_keys.txt deleted file mode 100644 index e81934336..000000000 --- a/CHANGELOG_v3_parser_keys.txt +++ /dev/null @@ -1,49 +0,0 @@ -## v3.0.0: - -### !!! WIP !!! - -~~ aiida-quantumespresso develop vs v3 ~~ -(tested on QE 6.2.1 (old XML) and QE 6.3-backports (old XML)) - -Output parameters: -* removed: u'k_points_units': u'2 pi / Angstrom', -* removed: u'fixed_occupations': False, -* removed: u'smearing_method': True, -* removed: u'tetrahedron_method': False, -* added: u'occupations': u'smearing', ( or 'tetrahedra' or 'fixed') - -~~ "include_deprecated_v2_keys"=False vs =True ~~ -(tested with aiida-quantumespresso v3, on QE 6.2.1 (old XML), QE 6.3-backports (old XML), QE 6.3-backports (new XML)) - -Re-added output parameters: -* u'fixed_occupations': False, -* u'smearing_method': True, -* u'tetrahedron_method': False, - -~~ QE 6.2.1 vs QE 6.3-backports (both old XML) ~~ -(tested with aiida-quantumespresso v3 and aiida-quantumespresso develop) - -No difference (except for u'creator_version': u'6.2' / u'6.3') - -~~ QE 6.3-backports (old XML) vs (new XML), aiida-quantumespresso v3 ~~ - -Output parameters: -* now optional: u'beta_real_space': False, # changed name to "real_space_beta", but only found in 6.4+ -* added: u'convergence_info': {u'opt_conv': {u'grad_norm': 2.81412559154777e-26, - u'n_opt_steps': 0}, - u'scf_conv': {u'n_scf_steps': 32729, - u'scf_error': 2.36844843377886e-10}}, -* changed value: 'dft_exchange_correlation': - old: u' SLA PW PBX PBC', new: u'PBE', -* added: u'do_magnetization': False, -* added: u'exit_status': 0, -* changed value: u'format_name': - old: u'qexml', new: u'QEXSD', -* changed value: u'format_version': - old: u'1.4.0', new: u'0.1.0', -* added (possibly empty): u'lattice_symmetries': [], -* changed value: u'lkpoint_dir': False # now hardcoded -* removed: u'pp_check_flag': True, - -### NB: more changes since v2.1.0 - diff --git a/aiida_quantumespresso/parsers/neb.py b/aiida_quantumespresso/parsers/neb.py index f74c343fc..85993cc77 100644 --- a/aiida_quantumespresso/parsers/neb.py +++ b/aiida_quantumespresso/parsers/neb.py @@ -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() @@ -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: diff --git a/aiida_quantumespresso/parsers/parse_xml/pw/legacy.py b/aiida_quantumespresso/parsers/parse_xml/pw/legacy.py index b8be8ae01..f9f698cb0 100644 --- a/aiida_quantumespresso/parsers/parse_xml/pw/legacy.py +++ b/aiida_quantumespresso/parsers/parse_xml/pw/legacy.py @@ -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 @@ -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' diff --git a/aiida_quantumespresso/parsers/parse_xml/pw/parse.py b/aiida_quantumespresso/parsers/parse_xml/pw/parse.py index d409b52a0..499b76f02 100644 --- a/aiida_quantumespresso/parsers/parse_xml/pw/parse.py +++ b/aiida_quantumespresso/parsers/parse_xml/pw/parse.py @@ -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: @@ -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 @@ -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 = [] @@ -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: diff --git a/aiida_quantumespresso/parsers/pw.py b/aiida_quantumespresso/parsers/pw.py index fd05fbe48..627bcb097 100644 --- a/aiida_quantumespresso/parsers/pw.py +++ b/aiida_quantumespresso/parsers/pw.py @@ -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: diff --git a/docs/source/user_guide/calculation_plugins/pw.rst b/docs/source/user_guide/calculation_plugins/pw.rst index ba38ee931..7e2ce8d6a 100644 --- a/docs/source/user_guide/calculation_plugins/pw.rst +++ b/docs/source/user_guide/calculation_plugins/pw.rst @@ -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, - } - } diff --git a/tests/parsers/test_neb.py b/tests/parsers/test_neb.py index a50f1591f..5cd67de27 100644 --- a/tests/parsers/test_neb.py +++ b/tests/parsers/test_neb.py @@ -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