# Calculation parsers¶

This section describes the different parsers classes for calculations.

## Quantum ESPRESSO parsers¶

exception aiida_quantumespresso.parsers.QEOutputParsingError[source]

Exception raised when there is a parsing error in the QE parser

aiida_quantumespresso.parsers.convert_qe2aiida_structure(output_dict, input_structure=None)[source]

Receives the dictionary cell parsed from quantum espresso Convert it into an AiiDA structure object

aiida_quantumespresso.parsers.convert_qe_time_to_sec(timestr)[source]

Given the walltime string of Quantum Espresso, converts it in a number of seconds (float).

aiida_quantumespresso.parsers.get_parser_info(parser_info_template=None)[source]

Return a template dictionary with details about the parser such as the version

Parameters: parser_info_template – template string with single placeholder to be replaced by current version number dictionary with parser name, version and empty list for warnings
aiida_quantumespresso.parsers.ldlparse_QE_errors(lines, count, warnings)[source]

Parse QE errors messages (those appearing between some lines with %%%%%%%%)

Parameters: Return messages: lines – list of strings, the output text file as read by readlines() or as obtained by data.split('\\n') when data is the text file read by read() count – the line at which we identified some %%%%%%%% warnings – the warnings already parsed in the file a list of QE error messages
aiida_quantumespresso.parsers.parse_QE_errors(lines, count, warnings)[source]

Parse QE errors messages (those appearing between some lines with %%%%%%%%)

Parameters: Return messages: lines – list of strings, the output text file as read by readlines() or as obtained by data.split('\\n') when data is the text file read by read() count – the line at which we identified some %%%%%%%% warnings – the warnings already parsed in the file a list of QE error messages
aiida_quantumespresso.parsers.parse_raw_out_basic(out_file, calc_name)[source]

A very simple parser for the standard out, usually aiida.outputs. Currently only parses basic warnings and the walltime. :param out_file: the standard out to be parsed :param calc_name: the name of the calculation, e.g. PROJWFC :return: parsed_data

### Pw Parser¶

class aiida_quantumespresso.parsers.pw.PwParser(node)[source]

Parser implementation for the PwCalculation calculation job class.

build_output_bands(parsed_bands, parsed_kpoints=None)[source]

Build the output bands from the raw parsed bands data.

Parameters: parsed_bands – the raw parsed bands data parsed_kpoints – the KpointsData to use for the bands a BandsData or None
build_output_kpoints(parsed_parameters, structure)[source]

Build the output kpoints from the raw parsed data.

Parameters: parsed_parameters – the raw parsed data a KpointsData or None
build_output_parameters(parsed_stdout, parsed_xml)[source]

Build the dictionary of output parameters from the raw parsed data.

The output parameters are based on the union of raw parsed data from the XML and stdout output files. Currently, if both raw parsed data dictionaries contain the same key, the stdout version takes precedence, but this should not occur as the parse_stdout method should already have solved these conflicts.

Parameters: parsed_stdout – the raw parsed data dictionary from the stdout output file parsed_xml – the raw parsed data dictionary from the XML output file the union of the two parsed raw and information about the parser
build_output_structure(parsed_structure)[source]

Build the output structure from the raw parsed data.

Parameters: parsed_structure – the dictionary with raw parsed structure data a new StructureData created from the parsed data iff the calculation type produces a new structure and the parsed data contained a cell definition. In all other cases, the input structure will be returned.
build_output_trajectory(parsed_trajectory, structure)[source]

Build the output trajectory from the raw parsed trajectory data.

Parameters: parsed_trajectory – the raw parsed trajectory data a TrajectoryData or None
emit_logs(*args)[source]

Emit the messages in one or multiple “log dictionaries” through the logger of the parser.

A log dictionary is expected to have the following structure: each key must correspond to a log level of the python logging module, e.g. error or warning and its values must be a list of string messages. The method will loop over all log dictionaries and emit the messages it contains with the log level indicated by the key.

Example log dictionary structure:

logs = {
'warning': ['Could not parse the etot_threshold variable from the stdout.'],
'error': ['Self-consistency was not achieved']
}

Parameters: args – log dictionaries
exit(exit_code)[source]

Log the exit message of the give exit code with level ERROR and return the exit code.

This is a utility function if one wants to return from the parse method and automically add the exit message associated to the exit code as a log message to the node: e.g. return self.exit(self.exit_codes.LABEL))

Parameters: exit_code – an ExitCode the exit code
final_trajectory_frame_to_parameters(parameters, parsed_trajectory)[source]

Copy the last frame of certain properties from the TrajectoryData to the outputs parameters.

This makes these properties queryable.

get_calculation_type()[source]

Return the type of the calculation.

get_extended_symmetries()[source]

Return the extended dictionary of symmetries based on reduced symmetries stored in output parameters.

get_parser_settings_key()[source]

Return the key that contains the optional parser options in the settings input node.

parse(**kwargs)[source]

Parse the retrieved files of a completed PwCalculation into output nodes.

Two nodes that are expected are the default ‘retrieved’ FolderData node which will store the retrieved files permanently in the repository. The second required node is a filepath under the key retrieved_temporary_files which should contain the temporary retrieved files.

parse_stdout(parameters, parser_options=None, parsed_xml=None)[source]

Parse the stdout output file.

Parameters: parameters – the input parameters dictionary parser_options – optional dictionary with parser options parsed_xml – the raw parsed data from the XML output tuple of two dictionaries, first with raw parsed data and second with log messages
parse_xml(dir_with_bands=None)[source]

Parse the XML output file.

Parameters: dir_with_bands – absolute path to directory containing individual k-point XML files for old XML format. tuple of two dictionaries, first with raw parsed data and second with log messages
reduce_symmetries(parsed_parameters, parsed_structure, parser_options=None)[source]

Reduce the symmetry information parsed from the output to save space.

In the standard output, each symmetry operation print two rotation matrices:

• S_cryst^T: matrix in crystal coordinates, transposed
• S_cart: matrix in cartesian coordinates,

The XML files only print one matrix:

• S_cryst: matrix in crystal coordinates

The raw parsed symmetry information from the XML is large and will load the database heavily if stored as is for each calculation. Instead, we will map these dictionaries onto a static dictionary of rotation matrices generated by the _get_qe_symmetry_list static method. This dictionary will return the rotation matrices in cartesian coordinates, i.e. S_cart. In order to compare the raw matrices from the XML to these static matrices we have to convert S_cryst into S_cart. We derive here how that is done:

S_cryst * v_cryst = v_cryst’

where v_cryst’ is the rotated vector v_cryst under S_cryst We define cell where cell vectors are rows. Converting a vector from crystal to cartesian coordinates is defined as:

cell^T * v_cryst = v_cart

The inverse of this operation is defined as

v_cryst = cell^Tinv * v_cart

Replacing the last equation into the first we find:

S_cryst * cell^Tinv * v_cart = cell^Tinv * v_cart’

Multiply on the left with cell^T gives:

cell^T * S_cryst * cell^Tinv * v_cart = v_cart’

which can be rewritten as:

S_cart * v_cart = v_cart’

where:

S_cart = cell^T * S_cryst * cell^Tinv

We compute here the transpose and its inverse of the structure cell basis, which is needed to transform the parsed rotation matrices, which are in crystal coordinates, to cartesian coordinates, which are the matrices that are returned by the _get_qe_symmetry_list staticmethod

validate_dynamics(trajectory, parameters, logs)[source]

Analyze problems that are specific to dynamics type calculations: i.e. md and vc-md.

validate_electronic(trajectory, parameters, logs)[source]

Analyze problems that are specific to electronic type calculations: i.e. scf, nscf and bands.

validate_ionic(trajectory, parameters, logs)[source]

Analyze problems that are specific to ionic type calculations: i.e. relax and vc-relax.

validate_premature_exit(logs)[source]

Analyze problems that will cause a pre-mature termination of the calculation, controlled or not.

### Raw Pw Parser¶

A collection of function that are used to parse the output of Quantum Espresso PW. The function that needs to be called from outside is parse_raw_output(). The functions mostly work without aiida specific functionalities. The parsing will try to convert whatever it can in some dictionary, which by operative decision doesn’t have much structure encoded, [the values are simple ]

aiida_quantumespresso.parsers.parse_raw.pw.convert_qe_time_to_sec(timestr)[source]

Given the walltime string of Quantum Espresso, converts it in a number of seconds (float).

aiida_quantumespresso.parsers.parse_raw.pw.parse_QE_errors(lines, line_number_start, warnings)[source]

Parse QE errors messages (those appearing between some lines with %%%%%%%%)

Parameters: Return messages: lines – list of strings, the output text file as read by readlines() or as obtained by data.split('\\n') when data is the text file read by read() line_number_start – the line at which we identified some %%%%%%%% warnings – dictionary where keys are error markers and the value the corresponding warning messages that should be returned. a list of QE error messages
aiida_quantumespresso.parsers.parse_raw.pw.parse_stdout(stdout, input_parameters, parser_options=None, parsed_xml=None)[source]

Parses the stdout content of a Quantum ESPRESSO pw.x calculation.

Parameters: stdout – the stdout content as a string input_parameters – dictionary with the input parameters parser_options – the parser options from the settings input parameter node parsed_xml – dictionary with data parsed from the XML output file tuple of two dictionaries, with the parsed data and log messages, respectively

### Cp Parser¶

class aiida_quantumespresso.parsers.cp.CpParser(node)[source]

This class is the implementation of the Parser class for Cp.

get_linkname_trajectory()[source]

Returns the name of the link to the output_structure (None if not present)

parse(**kwargs)[source]

Receives in input a dictionary of retrieved nodes. Does all the logic here.

### Raw Cp Parser¶

aiida_quantumespresso.parsers.parse_raw.cp.parse_cp_text_output(data, xml_data)[source]

data must be a list of strings, one for each lines, as returned by readlines(). On output, a dictionary with parsed values

aiida_quantumespresso.parsers.parse_raw.cp.parse_cp_traj_stanzas(num_elements, splitlines, prepend_name, rescale=1.0)[source]

num_elements: Number of lines (with three elements) between lines with two only elements (containing step number and time in ps). num_elements is 3 for cell, and the number of atoms for coordinates and positions.

splitlines: a list of lines of the file, already split in pieces using string.split

prepend_name: a string to be prepended to the name of keys returned in the return dictionary.

rescale: the values in each stanza are multiplied by this factor, for units conversion

aiida_quantumespresso.parsers.parse_raw.cp.parse_cp_xml_counter_output(data)[source]

Parse xml file print_counter.xml data must be a single string, as returned by file.read() (notice the difference with parse_text_output!) On output, a dictionary with parsed values.

aiida_quantumespresso.parsers.parse_raw.cp.parse_cp_xml_output(data)[source]

Parse xml data data must be a single string, as returned by file.read() (notice the difference with parse_text_output!) On output, a dictionary with parsed values. Democratically, we have decided to use picoseconds as units of time, eV for energies, Angstrom for lengths.

### Constants¶

Physical or mathematical constants. Since every code has its own conversion units, this module defines what QE understands as for an eV or other quantities. Whenever possible, we try to use the constants defined in :py:mod:aiida.common.constants:, but if some constants are slightly different among different codes (e.g., different standard definition), we define the constants in this file.

### Dos Parser¶

class aiida_quantumespresso.parsers.dos.DosParser(node)[source]

This class is the implementation of the Parser class for Dos.

parse(**kwargs)[source]

Parses the datafolder, stores results. Retrieves dos output, and some basic information from the out_file, such as warnings and wall_time

aiida_quantumespresso.parsers.dos.parse_raw_dos(dos_file, array_names, array_units)[source]

This function takes as input the dos_file as a list of filelines along with information on how to give labels and units to the parsed data

Parameters: Return array_data: dos_file (list) – dos file lines in the form of a list array_names (list) – list of all array names, note that array_names[0] is for the case with non spin-polarized calculations and array_names[1] is for the case with spin-polarized calculation array_units (list) – list of all array units, note that array_units[0] is for the case with non spin-polarized calculations and array_units[1] is for the case with spin-polarized calculation narray, a dictionary for ArrayData type, which contains all parsed dos output along with labels and units boolean, indicates whether the parsed results are spin polarized

### Projwfc Parser¶

class aiida_quantumespresso.parsers.projwfc.ProjwfcParser(node)[source]

This class is the implementation of the Parser class for projwfc.x in Quantum Espresso. Parses projection arrays that map the projection onto each point in the bands structure, as well as pdos arrays, which map the projected density of states onto an energy axis.

parse(**kwargs)[source]

Parses the datafolder, stores results. Retrieves projwfc output, and some basic information from the out_file, such as warnings and wall_time

aiida_quantumespresso.parsers.projwfc.find_orbitals_from_statelines(out_info_dict)[source]

This function reads in all the state_lines, that is, the lines describing which atomic states, taken from the pseudopotential, are used for the projection. Then it converts these state_lines into a set of orbitals.

Parameters: out_info_dict – contains various technical internals useful in parsing orbitals, a list of orbitals suitable for setting ProjectionData
aiida_quantumespresso.parsers.projwfc.natural_sort_key(sort_key, _nsre=re.compile('([0-9]+)'))[source]

Pass to key for str.sort to achieve natural sorting. For example, ["2", "11", "1"] will be sorted to ["1", "2", "11"] instead of ["1", "11", "2"] :param sort_key: Original key to be processed :return: A list of string and integers.

aiida_quantumespresso.parsers.projwfc.spin_dependent_pdos_subparser(out_info_dict)[source]

Finds and labels the pdos arrays associated with the out_info_dict

Parameters: out_info_dict – contains various technical internals useful in parsing (pdos_name, pdos_array) tuples for all the specific pdos
aiida_quantumespresso.parsers.projwfc.spin_dependent_subparser(out_info_dict)[source]

This find the projection and bands arrays from the out_file and out_info_dict. Used to handle the different possible spin-cases in a convenient manner.

Parameters: out_info_dict – contains various technical internals useful in parsing ProjectionData, BandsData parsed from out_file