aiida_quantumespresso.utils.convert#

Utilties to convert between python and fortran data types and formats.

Module Contents#

Functions#

conv_to_fortran(val[, quote_strings])

Convert a python value to a format suited for fortran input.

conv_to_fortran_withlists(val[, quote_strings])

Convert a python value to a format suited for fortran input, recursively for lists.

convert_input_to_namelist_entry(key, val[, mapping])

Convert a key and a value, from an input parameters dictionary for a namelist calculation.

aiida_quantumespresso.utils.convert.conv_to_fortran(val, quote_strings=True)[source]#

Convert a python value to a format suited for fortran input.

Parameters:

val – the value to be read and converted to a Fortran-friendly string.

aiida_quantumespresso.utils.convert.conv_to_fortran_withlists(val, quote_strings=True)[source]#

Convert a python value to a format suited for fortran input, recursively for lists.

Parameters:

val – the value to be read and converted to a Fortran-friendly string.

aiida_quantumespresso.utils.convert.convert_input_to_namelist_entry(key, val, mapping=None)[source]#

Convert a key and a value, from an input parameters dictionary for a namelist calculation.

Map it to the appropriate string format for the namelist input file. For single values it will return a single string, but for values that are a dictionary, list or tuple, the returned string may be multiline.

Parameters:
  • key – the namelist keyword name

  • val

    the namelist keyword value The value can be either a single value, list/tuple, a double nested list or a dictionary. Depending on the type of the value the resulting string differs vastly

    • single list:

      A list of keywords will be generated, where the index of the value in the list will be used as the index in the keyword and the value itself will be converted using conv_to_fortran. For example:

      'efield': [4, 5, 6]
      

      will result in:

      efield(1) = 4
      efield(1) = 5
      efield(1) = 6
      
    • double nested list:

      This format can be used for keywords that require one or more indices that do not necessarily follow a sequential number, but take specific values that need to be defined by the user. For example:

      'starting_ns_eigenvalue': [
          [1, 1, 3, 3.5],
          [2, 1, 1, 2.8]
      ]
      

      will be formatted as:

      starting_ns_eigenvalue(1,1,3) = 3.5
      starting_ns_eigenvalue(2,1,1) = 2.8
      

      Note that if the mapping argument is provided in the input, any value in sub lists that matches a key in the mapping dictionary (that is to say it is a string that matches one of the kinds), it will be replaced with the index of the corresponding atomic species. For example:

      hubbard_j: [
          [2, 'Ni', 3.5],
          [2, 'Fe', 7.4],
      ]
      

      would be formatted as:

      hubbard_j(2, 1) = 3.5
      hubbard_j(2, 3) = 7.4
      

      Assuming the mapping dictionary contained the kinds ‘Ni’ and ‘Fe’, with the indices 1 and 3, respectively

    • dictionary:

      The keys of this dictionary should correspond to keys in the mapping input argument and will be replaced with the corresponding value. This can be used for keywords that take a single index that needs to conform to the index of the atomic species to which the keyword value should apply. For example:

      hubbard_u: {
          'Co': 3.5,
          'O': 7.4,
      }
      

      will be formatted as:

      hubbard_u(1) = 3.5
      hubbard_u(3) = 7.4
      

      assuming that the kinds ‘Co’ and ‘O’ would have atomic species indices 1 and 3, respectively. This mapping from kind name to atomic species index should be defined by the mapping argument.

  • mapping

    optional parameter, that must be provided if val is a dictionary or a double nested list where the sub lists contain string values. The keys of the mapping dictionary should be the atomic species names that will be encountered in the value, and the corresponding value should be the index of that atomic species. Example:

    mapping = {
        'Fe': 1,
        'O': 2,
    }
    

    This will map every occurrence of ‘Fe’ and ‘O’ in the values to the corresponding integer.