aiida.tools documentation

Tools

qe input parser

Tools for parsing QE PW input files and creating AiiDa Node objects based on them.

TODO: Parse CONSTRAINTS, OCCUPATIONS, ATOMIC_FORCES once they are implemented
in AiiDA
class aiida_quantumespresso.tools.qeinputparser.QeInputFile(pwinput)[source]

Class used for parsing Quantum Espresso pw.x input files and using the info.

Members:

  • namelists:

    A nested dictionary of the namelists and their key-value pairs. The namelists will always be upper-case keys, while the parameter keys will always be lower-case.

    For example:

    {"CONTROL": {"calculation": "bands",
                 "prefix": "al",
                 "pseudo_dir": "./pseudo",
                 "outdir": "./out"},
     "ELECTRONS": {"diagonalization": "cg"},
     "SYSTEM": {"nbnd": 8,
                "ecutwfc": 15.0,
                "celldm(1)": 7.5,
                "ibrav": 2,
                "nat": 1,
                "ntyp": 1}
    }
    
  • atomic_positions:

    A dictionary with

    • units: the units of the positions (always lower-case) or None
    • names: list of the atom names (e.g. 'Si', 'Si0', 'Si_0')
    • positions: list of the [x, y, z] positions
    • fixed_coords: list of [x, y, z] (bools) of the force modifications (Note: True <–> Fixed, as defined in the BasePwCpInputGenerator._if_pos method)

    For example:

    {'units': 'bohr',
     'names': ['C', 'O'],
     'positions': [[0.0, 0.0, 0.0],
                   [0.0, 0.0, 2.5]]
     'fixed_coords': [[False, False, False],
                      [True, True, True]]}
    
  • cell_parameters:

    A dictionary (if CELL_PARAMETERS is present; else: None) with

    • units: the units of the lattice vectors (always lower-case) or None
    • cell: 3x3 list with lattice vectors as rows

    For example:

    {'units': 'angstrom',
     'cell': [[16.9, 0.0, 0.0],
              [-2.6, 8.0, 0.0],
              [-2.6, -3.5, 7.2]]}
    
  • k_points:

    A dictionary containing

    • type: the type of kpoints (always lower-case)
    • points: an Nx3 list of the kpoints (will not be present if type = ‘gamma’ or type = ‘automatic’)
    • weights: a 1xN list of the kpoint weights (will not be present if type = ‘gamma’ or type = ‘automatic’)
    • mesh: a 1x3 list of the number of equally-spaced points in each direction of the Brillouin zone, as in Monkhorst-Pack grids (only present if type = ‘automatic’)
    • offset: a 1x3 list of the grid offsets in each direction of the Brillouin zone (only present if type = ‘automatic’) (Note: The offset value for each direction will be one of 0.0 [no offset] or 0.5 [offset by half a grid step]. This differs from the Quantum Espresso convention, where an offset value of 1 corresponds to a half-grid-step offset, but adheres to the current AiiDa convention.

    Examples:

    {'type': 'crystal',
     'points': [[0.125,  0.125,  0.0],
                [0.125,  0.375,  0.0],
                [0.375,  0.375,  0.0]],
     'weights': [1.0, 2.0, 1.0]}
    
    {'type': 'automatic',
     'points': [8, 8, 8],
     'offset': [0.0, 0.5, 0.0]}
    
    {'type': 'gamma'}
    
  • atomic_species:

    A dictionary with

    • names: list of the atom names (e.g. ‘Si’, ‘Si0’, ‘Si_0’) (case as-is)
    • masses: list of the masses of the atoms in ‘names’
    • pseudo_file_names: list of the pseudopotential file names for the atoms in ‘names’ (case as-is)

    Example:

    {'names': ['Li', 'O', 'Al', 'Si'],
     'masses': [6.941,  15.9994, 26.98154, 28.0855],
     'pseudo_file_names': ['Li.pbe-sl-rrkjus_psl.1.0.0.UPF',
                           'O.pbe-nl-rrkjus_psl.1.0.0.UPF',
                           'Al.pbe-nl-rrkjus_psl.1.0.0.UPF',
                           'Si3 28.0855 Si.pbe-nl-rrkjus_psl.1.0.0.UPF']
    
__init__(pwinput)[source]

Parse inputs’s namelist and cards to create attributes of the info.

Parameters:

pwinput

Any one of the following

  • A string of the (existing) absolute path to the pwinput file.
  • A single string containing the pwinput file’s text.
  • A list of strings, with the lines of the file as the elements.
  • A file object. (It will be opened, if it isn’t already.)

Raises:
  • IOError – if pwinput is a file and there is a problem reading the file.
  • TypeError – if pwinput is a list containing any non-string element(s).
  • aiida.common.exceptions.ParsingError – if there are issues parsing the pwinput.
get_structuredata()[source]

Return a StructureData object based on the data in the input file.

This uses all of the data in the input file to do the necessary unit conversion, ect. and then creates an AiiDA StructureData object.

All of the names corresponding of the Kind objects composing the StructureData object will match those found in the ATOMIC_SPECIES block, so the pseudopotentials can be linked to the calculation using the kind.name for each specific type of atom (in the event that you wish to use different pseudo’s for two or more of the same atom).

Returns:StructureData object of the structure in the input file
Return type:aiida.orm.nodes.data.structure.StructureData
Raises:aiida.common.exceptions.ParsingError – if there are issues parsing the input.
aiida_quantumespresso.tools.qeinputparser.get_cell_from_parameters(cell_parameters, system_dict, alat, using_celldm)[source]

A function to get the cell from cell parameters and SYSTEM card dictionary as read by parse_namelists. :param cell_parameters: The parameters as returned by parse_cell_parameters :param system_dict: the dictionary for card SYSTEM :param alat: The value for alat :returns: The cell as a numpy array

aiida_quantumespresso.tools.qeinputparser.get_structuredata_from_qeinput(filepath=None, text=None, namelists=None, atomic_species=None, atomic_positions=None, cell_parameters=None)[source]

Function that receives either :param filepath: the filepath storing or :param text: the string of a standard QE-input file. An instance of StructureData is initialized with kinds, positions and cell as defined in the input file. This function can deal with ibrav being set different from 0 and the cell being defined with celldm(n) or A,B,C, cosAB etc.

aiida_quantumespresso.tools.qeinputparser.parse_atomic_positions(txt)[source]

Return a dictionary containing info from the ATOMIC_POSITIONS card block in txt.

Note

If the units are unspecified, they will be returned as None.

Parameters:txt (str) – A single string containing the QE input text to be parsed.
Returns:A dictionary with
  • units: the units of the positions (always lower-case) or None
  • names: list of the atom names (e.g. 'Si', 'Si0', 'Si_0')
  • positions: list of the [x, y, z] positions
  • fixed_coords: list of [x, y, z] (bools) of the force modifications (Note: True <–> Fixed, as defined in the BasePwCpInputGenerator._if_pos method)

For example:

{'units': 'bohr',
 'names': ['C', 'O'],
 'positions': [[0.0, 0.0, 0.0],
               [0.0, 0.0, 2.5]]
 'fixed_coords': [[False, False, False],
                  [True, True, True]]}
Raises:aiida.common.exceptions.ParsingError – if there are issues parsing the input.
aiida_quantumespresso.tools.qeinputparser.parse_atomic_species(txt)[source]

Return a dictionary containing info from the ATOMIC_SPECIES card block in txt.

Parameters:txt (str) – A single string containing the QE input text to be parsed.
Returns:A dictionary with
  • names: list of the atom names (e.g. ‘Si’, ‘Si0’, ‘Si_0’) (case as-is)
  • masses: list of the masses of the atoms in ‘names’
  • pseudo_file_names: list of the pseudopotential file names for the atoms in ‘names’ (case as-is)

Example:

{'names': ['Li', 'O', 'Al', 'Si'],
 'masses': [6.941,  15.9994, 26.98154, 28.0855],
 'pseudo_file_names': ['Li.pbe-sl-rrkjus_psl.1.0.0.UPF',
                       'O.pbe-nl-rrkjus_psl.1.0.0.UPF',
                       'Al.pbe-nl-rrkjus_psl.1.0.0.UPF',
                       'Si3 28.0855 Si.pbe-nl-rrkjus_psl.1.0.0.UPF']
Raises:aiida.common.exceptions.ParsingError – if there are issues parsing the input.
aiida_quantumespresso.tools.qeinputparser.parse_cell_parameters(txt)[source]

Return dict containing info from the CELL_PARAMETERS card block in txt.

Note

This card is only needed if ibrav = 0. Therefore, if the card is not present, the function will return None and not raise an error.

Note

If the units are unspecified, they will be returned as None. The units interpreted by QE depend on whether or not one of ‘celldm(1)’ or ‘a’ is set in &SYSTEM.

Parameters:txt – A single string containing the QE input text to be parsed.
Returns:A dictionary (if CELL_PARAMETERS is present; else: None) with
  • units: the units of the lattice vectors (always lower-case) or None
  • cell: 3x3 list with lattice vectors as rows

For example:

{'units': 'angstrom',
 'cell': [[16.9, 0.0, 0.0],
          [-2.6, 8.0, 0.0],
          [-2.6, -3.5, 7.2]]}
Raises:aiida.common.exceptions.ParsingError – if there are issues parsing the input.
aiida_quantumespresso.tools.qeinputparser.parse_namelists(txt)[source]

Parse txt to extract a dictionary of the namelist info.

Parameters:txt (str) – A single string containing the QE input text to be parsed.
Returns:A nested dictionary of the namelists and their key-value pairs. The namelists will always be upper-case keys, while the parameter keys will always be lower-case.

For example:

{"CONTROL": {"calculation": "bands",
             "prefix": "al",
             "pseudo_dir": "./pseudo",
             "outdir": "./out"},
 "ELECTRONS": {"diagonalization": "cg"},
 "SYSTEM": {"nbnd": 8,
            "ecutwfc": 15.0,
            "celldm(1)": 7.5,
            "ibrav": 2,
            "nat": 1,
            "ntyp": 1}
}
Raises:aiida.common.exceptions.ParsingError – if there are issues parsing the input.
aiida_quantumespresso.tools.qeinputparser.str2val(valstr)[source]

Return a python value by converting valstr according to f90 syntax.

Parameters:valstr (str) – String representation of the variable to be converted. (e.g. ‘.true.’)
Returns:A python variable corresponding to valstr.
Return type:bool or float or int or str
Raises:ValueError: if a suitable conversion of valstr cannot be found.

pw input parser

Tools for parsing QE PW input files and creating AiiDa Node objects based on them.

TODO: Parse CONSTRAINTS, OCCUPATIONS, ATOMIC_FORCES once they are implemented
in AiiDA
class aiida_quantumespresso.tools.pwinputparser.PwInputFile(pwinput)[source]

Class used for parsing Quantum Espresso pw.x input files and using the info.

Members:

  • namelists:

    A nested dictionary of the namelists and their key-value pairs. The namelists will always be upper-case keys, while the parameter keys will always be lower-case.

    For example:

    {"CONTROL": {"calculation": "bands",
                 "prefix": "al",
                 "pseudo_dir": "./pseudo",
                 "outdir": "./out"},
     "ELECTRONS": {"diagonalization": "cg"},
     "SYSTEM": {"nbnd": 8,
                "ecutwfc": 15.0,
                "celldm(1)": 7.5,
                "ibrav": 2,
                "nat": 1,
                "ntyp": 1}
    }
    
  • atomic_positions:

    A dictionary with

    • units: the units of the positions (always lower-case) or None
    • names: list of the atom names (e.g. 'Si', 'Si0', 'Si_0')
    • positions: list of the [x, y, z] positions
    • fixed_coords: list of [x, y, z] (bools) of the force modifications (Note: True <–> Fixed, as defined in the BasePwCpInputGenerator._if_pos method)

    For example:

    {'units': 'bohr',
     'names': ['C', 'O'],
     'positions': [[0.0, 0.0, 0.0],
                   [0.0, 0.0, 2.5]]
     'fixed_coords': [[False, False, False],
                      [True, True, True]]}
    
  • cell_parameters:

    A dictionary (if CELL_PARAMETERS is present; else: None) with

    • units: the units of the lattice vectors (always lower-case) or None
    • cell: 3x3 list with lattice vectors as rows

    For example:

    {'units': 'angstrom',
     'cell': [[16.9, 0.0, 0.0],
              [-2.6, 8.0, 0.0],
              [-2.6, -3.5, 7.2]]}
    
  • k_points:

    A dictionary containing

    • type: the type of kpoints (always lower-case)
    • points: an Nx3 list of the kpoints (will not be present if type = ‘gamma’ or type = ‘automatic’)
    • weights: a 1xN list of the kpoint weights (will not be present if type = ‘gamma’ or type = ‘automatic’)
    • mesh: a 1x3 list of the number of equally-spaced points in each direction of the Brillouin zone, as in Monkhorst-Pack grids (only present if type = ‘automatic’)
    • offset: a 1x3 list of the grid offsets in each direction of the Brillouin zone (only present if type = ‘automatic’) (Note: The offset value for each direction will be one of 0.0 [no offset] or 0.5 [offset by half a grid step]. This differs from the Quantum Espresso convention, where an offset value of 1 corresponds to a half-grid-step offset, but adheres to the current AiiDa convention.

    Examples:

    {'type': 'crystal',
     'points': [[0.125,  0.125,  0.0],
                [0.125,  0.375,  0.0],
                [0.375,  0.375,  0.0]],
     'weights': [1.0, 2.0, 1.0]}
    
    {'type': 'automatic',
     'points': [8, 8, 8],
     'offset': [0.0, 0.5, 0.0]}
    
    {'type': 'gamma'}
    
  • atomic_species:

    A dictionary with

    • names: list of the atom names (e.g. ‘Si’, ‘Si0’, ‘Si_0’) (case as-is)
    • masses: list of the masses of the atoms in ‘names’
    • pseudo_file_names: list of the pseudopotential file names for the atoms in ‘names’ (case as-is)

    Example:

    {'names': ['Li', 'O', 'Al', 'Si'],
     'masses': [6.941,  15.9994, 26.98154, 28.0855],
     'pseudo_file_names': ['Li.pbe-sl-rrkjus_psl.1.0.0.UPF',
                           'O.pbe-nl-rrkjus_psl.1.0.0.UPF',
                           'Al.pbe-nl-rrkjus_psl.1.0.0.UPF',
                           'Si3 28.0855 Si.pbe-nl-rrkjus_psl.1.0.0.UPF']
    
__init__(pwinput)[source]

Parse inputs’s namelist and cards to create attributes of the info.

Parameters:

pwinput

Any one of the following

  • A string of the (existing) absolute path to the pwinput file.
  • A single string containing the pwinput file’s text.
  • A list of strings, with the lines of the file as the elements.
  • A file object. (It will be opened, if it isn’t already.)

Raises:
  • IOError – if pwinput is a file and there is a problem reading the file.
  • TypeError – if pwinput is a list containing any non-string element(s).
  • aiida.common.exceptions.ParsingError – if there are issues parsing the pwinput.
get_kpointsdata()[source]

Return a KpointsData object based on the data in the input file.

This uses all of the data in the input file to do the necessary unit conversion, ect. and then creates an AiiDa KpointsData object.

Note: If the calculation uses only the gamma k-point (if self.k_points[‘type’] == ‘gamma’), it is necessary to also attach a settings node to the calculation with gamma_only = True.

Returns:KpointsData object of the kpoints in the input file
Return type:aiida.orm.nodes.data.array.kpoints.KpointsData
Raises:NotImplementedError – if the kpoints are in a format not yet supported.
aiida_quantumespresso.tools.pwinputparser.create_builder_from_file(input_folder, input_file_name, code, metadata, pseudo_folder_path=None, use_first=False)[source]

Create a populated process builder for a Pw calculation, from a standard QE input file and pseudo (upf) files

Parameters:
  • input_folder (aiida.common.folders.Folder or str) – the folder containing the input file
  • input_file_name (str) – the name of the input file
  • code (aiida.orm.Code or str) – the code associated with the calculation
  • metadata (dict) – metadata values for the calculation (e.g. resources)
  • pseudo_folder_path (aiida.common.folders.Folder or str or None) – the folder containing the upf files (if None, then input_folder is used)
  • use_first (bool) – parsed to UpfData.get_or_create
Raises:

NotImplementedError – if the structure is not ibrav=0

Returns:

a builder instance for PwCalculation

aiida_quantumespresso.tools.pwinputparser.parse_k_points(txt)[source]

Return a dictionary containing info from the K_POINTS card block in txt.

Note

If the type of kpoints (where type = x in the card header, “K_POINTS x”) is not present, type will be returned as ‘tpiba’, the QE default.

Parameters:txt – A single string containing the QE input text to be parsed.
Returns:A dictionary containing
  • type: the type of kpoints (always lower-case)
  • points: an Nx3 list of the kpoints (will not be present if type = ‘gamma’ or type = ‘automatic’)
  • weights: a 1xN list of the kpoint weights (will not be present if type = ‘gamma’ or type = ‘automatic’)
  • mesh: a 1x3 list of the number of equally-spaced points in each direction of the Brillouin zone, as in Monkhorst-Pack grids (only present if type = ‘automatic’)
  • offset: a 1x3 list of the grid offsets in each direction of the Brillouin zone (only present if type = ‘automatic’) (Note: The offset value for each direction will be one of 0.0 [no offset] or 0.5 [offset by half a grid step]. This differs from the Quantum Espresso convention, where an offset value of 1 corresponds to a half-grid-step offset, but adheres to the current AiiDa convention.

Examples:

{'type': 'crystal',
 'points': [[0.125,  0.125,  0.0],
            [0.125,  0.375,  0.0],
            [0.375,  0.375,  0.0]],
 'weights': [1.0, 2.0, 1.0]}

{'type': 'automatic',
 'points': [8, 8, 8],
 'offset': [0.0, 0.5, 0.0]}

{'type': 'gamma'}
Raises:aiida.common.exceptions.ParsingError – if there are issues parsing the input.

cp input parser

class aiida_quantumespresso.tools.cpinputparser.CpInputFile(pwinput)[source]
__init__(pwinput)[source]

Parse inputs’s namelist and cards to create attributes of the info.

Parameters:

pwinput

Any one of the following

  • A string of the (existing) absolute path to the pwinput file.
  • A single string containing the pwinput file’s text.
  • A list of strings, with the lines of the file as the elements.
  • A file object. (It will be opened, if it isn’t already.)

Raises:
  • IOError – if pwinput is a file and there is a problem reading the file.
  • TypeError – if pwinput is a list containing any non-string element(s).
  • aiida.common.exceptions.ParsingError – if there are issues parsing the pwinput.