Skip to content

Commit

Permalink
PwParser: add smearing_type and smearing from new XML output (#445
Browse files Browse the repository at this point in the history
)

These keys were not yet being parsed from the output file with the new
XML schema. In addition, if an exception is thrown by the raw XML or
stdout parser, it is now caught and added as a critical warning. Finally
the test input generator for `PwParser` is simplified and only a single
generator is used for both scf and relax tests.

Note that the units of the `degauss` depends on the version of the XML
output. It should always be in Hartree, but up until 6.5, it was
erroneously being written in Rydberg. This was corrected  in commit
`a9698a6971e4ad975ce89a15bc9b74294799ef3f`.
  • Loading branch information
sphuber authored Apr 1, 2020
1 parent 7c299a2 commit 1c8e240
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 141 deletions.
69 changes: 28 additions & 41 deletions aiida_quantumespresso/parsers/parse_xml/pw/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from __future__ import absolute_import
from __future__ import print_function

from distutils.version import StrictVersion
import numpy as np
from xmlschema import XMLSchema
from xmlschema.etree import ElementTree
from xmlschema.exceptions import URLError

from aiida_quantumespresso.utils.mapping import get_logging_container
from qe_tools.constants import hartree_to_ev, bohr_to_ang
from qe_tools.constants import hartree_to_ev, bohr_to_ang, ry_to_ev

from .exceptions import XMLParseError
from .legacy import parse_pw_xml_pre_6_2
Expand Down Expand Up @@ -50,17 +51,11 @@ def parse_xml(xml_file, dir_with_bands=None, include_deprecated_v2_keys=False):

xml_file_version = get_xml_file_version(xml_parsed)

try:
if xml_file_version == QeXmlVersion.POST_6_2:
parsed_data, logs = parse_pw_xml_post_6_2(xml_parsed, include_deprecated_v2_keys)
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)
except Exception:
import traceback
logs = get_logging_container()
logs.critical.append(traceback.format_exc())
parsed_data = {}
if xml_file_version == QeXmlVersion.POST_6_2:
parsed_data, logs = parse_pw_xml_post_6_2(xml_parsed, include_deprecated_v2_keys)
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)

return parsed_data, logs

Expand Down Expand Up @@ -107,6 +102,7 @@ def parse_pw_xml_post_6_2(xml, include_deprecated_v2_keys=False):
for err in errors:
logs.error.append(str(err))

xml_version = StrictVersion(xml_dictionary['general_info']['xml_format']['@VERSION'])
inputs = xml_dictionary['input']
outputs = xml_dictionary['output']

Expand Down Expand Up @@ -156,35 +152,6 @@ def parse_pw_xml_post_6_2(xml, include_deprecated_v2_keys=False):
# 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.)

# TODO/NOTE: Not including smearing type and width for now.
# In the old XML format they are under OCCUPATIONS as SMEARING_TYPE and SMEARING_PARAMETER,
# but watch out: the value in the old format is half of that in the new format
# (the code divides it by e2=2.0, see PW/src/pw_restart.f90:446)
'''
if 'smearing' in outputs['band_structure']:
smearing_xml = outputs['band_structure']['smearing']
elif 'smearing' in inputs:
smearing_xml = inputs['smearing']
try:
smearing_type = smearing_xml['$']
smearing_degauss = smearing_xml['@degauss']
except NameError:
pass
'''

# Here are some notes from the QE code for reference.
# SMEARING_METHOD = lgauss
# lgauss, &! if .TRUE.: use gaussian broadening
# ltetra, &! if .TRUE.: use tetrahedra
# SMEARING_TYPE = ngauss (see Modules/qexml.f90:1530)
# ngauss ! type of smearing technique
# From dos.x input description:
# Type of gaussian broadening:
# = 0 Simple Gaussian (default)
# = 1 Methfessel-Paxton of order 1
# = -1 Marzari-Vanderbilt "cold smearing"
# =-99 Fermi-Dirac function

starting_magnetization = []
magnetization_angle1 = []
magnetization_angle2 = []
Expand Down Expand Up @@ -340,6 +307,26 @@ def parse_pw_xml_post_6_2(xml, include_deprecated_v2_keys=False):
# Band structure
if 'band_structure' in outputs:
band_structure = outputs['band_structure']

smearing_xml = None

if 'smearing' in outputs['band_structure']:
smearing_xml = outputs['band_structure']['smearing']
elif 'smearing' in inputs:
smearing_xml = inputs['smearing']

if smearing_xml:
degauss = smearing_xml['@degauss']

# Versions below 19.03.04 (Quantum ESPRESSO<=6.4.1) incorrectly print degauss in Ry instead of Hartree
if xml_version < StrictVersion('19.03.04'):
degauss *= ry_to_ev
else:
degauss *= hartree_to_ev

xml_data['degauss'] = degauss
xml_data['smearing_type'] = smearing_xml['$']

num_k_points = band_structure['nks']
num_electrons = band_structure['nelec']
num_atomic_wfc = band_structure['num_of_atomic_wfc']
Expand Down
8 changes: 4 additions & 4 deletions aiida_quantumespresso/parsers/pw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""`Parser` implementation for the `PwCalculation` calculation job class."""
from __future__ import absolute_import

import traceback

import numpy

from aiida import orm
Expand Down Expand Up @@ -285,8 +287,7 @@ def parse_xml(self, dir_with_bands=None, parser_options=None):
except XMLUnsupportedFormatError:
self.exit_code_xml = self.exit_codes.ERROR_OUTPUT_XML_FORMAT
except Exception:
import traceback
traceback.print_exc()
logs.critical.append(traceback.format_exc())
self.exit_code_xml = self.exit_codes.ERROR_UNEXPECTED_PARSER_EXCEPTION

return parsed_data, logs
Expand Down Expand Up @@ -319,8 +320,7 @@ def parse_stdout(self, parameters, parser_options=None, parsed_xml=None):
try:
parsed_data, logs = parse_stdout(stdout, parameters, parser_options, parsed_xml)
except Exception:
import traceback
traceback.print_exc()
logs.critical.append(traceback.format_exc())
self.exit_code_stdout = self.exit_codes.ERROR_UNEXPECTED_PARSER_EXCEPTION

# If the stdout was incomplete, most likely the job was interrupted before it could cleanly finish, so the
Expand Down
6 changes: 6 additions & 0 deletions tests/parsers/test_neb/test_neb_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ parameters:
scf_error: 2.251833940343682e-10
creator_name: pwscf
creator_version: 6.4.1
degauss: 0.0408170751759
dft_exchange_correlation: PBE
do_magnetization: false
do_not_use_time_reversal: false
Expand Down Expand Up @@ -137,6 +138,7 @@ parameters:
q_real_space: false
rho_cutoff: 1360.56917253
rho_cutoff_units: eV
smearing_type: gaussian
smooth_fft_grid:
- 36
- 15
Expand Down Expand Up @@ -183,6 +185,7 @@ parameters:
scf_error: 2.987478357372217e-09
creator_name: pwscf
creator_version: 6.4.1
degauss: 0.0408170751759
dft_exchange_correlation: PBE
do_magnetization: false
do_not_use_time_reversal: false
Expand Down Expand Up @@ -234,6 +237,7 @@ parameters:
q_real_space: false
rho_cutoff: 1360.56917253
rho_cutoff_units: eV
smearing_type: gaussian
smooth_fft_grid:
- 36
- 15
Expand Down Expand Up @@ -296,6 +300,7 @@ parameters:
scf_error: 2.80245941733356e-10
creator_name: pwscf
creator_version: 6.4.1
degauss: 0.0408170751759
dft_exchange_correlation: PBE
do_magnetization: false
do_not_use_time_reversal: false
Expand Down Expand Up @@ -363,6 +368,7 @@ parameters:
q_real_space: false
rho_cutoff: 1360.56917253
rho_cutoff_units: eV
smearing_type: gaussian
smooth_fft_grid:
- 36
- 15
Expand Down
Loading

0 comments on commit 1c8e240

Please sign in to comment.