Usage

The UPFDict class is the heart of upf-tools. It is an ordered dictionary with a few extra functionalities.

class UPFDict(version, filename=None, *args, **kwargs)

Class that contains all of the information of a UPF pseudopotential file.

Note that it will usually be more convenient to create a UPFDict object using the class method UPFDict.from_upf(...) i.e.

from upf_tools import UPFDict
psp = UPFDict.from_upf("/path/to/file.upf")

instead of direct instantiation.

Parameters:
  • version (str, Version) – the UPF version number

  • filename (Union[str, Path, None]) – the name of the UPF file

  • args – arguments used to construct the dictionary of UPF entries (header, mesh, local, …)

  • kwargs – keyword arguments used to construct the dictionary of UPF entries

property filename: Path

The filename of the pseudopotential (including the path), protected to always be a Path.

classmethod from_str(string)

Create a UPFDict object from a string (typically the contents of a .upf file).

Return type:

UPFDict

classmethod from_upf(filename)

Create a UPFDict object from a .upf file.

Return type:

UPFDict

to_dat()

Generate a .dat file from a UPFDict object.

These files contain projectors that wannier90.x can read.

Raises:

ValueError – The pseudopotential does not contain the pseudo-wavefunctions necessary to generate a .dat file

Return type:

str

Returns:

the contents of a .dat file

to_input()

Extract the contents of the input file block.

Return type:

str

to_ld1_input()

Extract the ld1.x input file used to generate the pseudopotential.

Return type:

str

to_oncvpsp_input()

Extract the oncvpsp.x input file used to generate the pseudopotential.

Return type:

ONCVPSPInput

to_str()

Serialise this UPFDict back to UPF text.

Currently only UPF v2 (the modern XML format) is supported on write. Reading is unaffected; v1 files can still be loaded but not written back out.

Raises:

NotImplementedError – if version is below 2.0.

Return type:

str

Returns:

the UPF file contents as a string

to_upf(filename)

Write this UPFDict to filename in UPF v2 format.

Parameters:

filename (Union[Path, str]) – destination path

Return type:

Path

Returns:

the Path written to

property version: Version

The UPF version of the pseudopotential file, protected to always be a Version.