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
UPFDictobject using the class methodUPFDict.from_upf(...)i.e.from upf_tools import UPFDict psp = UPFDict.from_upf("/path/to/file.upf")
instead of direct instantiation.
- Parameters:
- property filename: Path
The filename of the pseudopotential (including the path), protected to always be a
Path.
- classmethod from_str(string)
Create a
UPFDictobject from a string (typically the contents of a.upffile).- Return type:
- to_dat()
Generate a
.datfile from aUPFDictobject.These files contain projectors that
wannier90.xcan read.- Raises:
ValueError – The pseudopotential does not contain the pseudo-wavefunctions necessary to generate a
.datfile- Return type:
- Returns:
the contents of a
.datfile
- to_oncvpsp_input()
Extract the oncvpsp.x input file used to generate the pseudopotential.
- Return type:
ONCVPSPInput
- to_str()
Serialise this
UPFDictback 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.
The result is not byte-for-byte the file that was read. Two differences affect
PP_INFOin particular:a block that contains a
PP_INPUTFILEkeeps only that input file, the human-readable summary alongside it having been discarded on read;ampersands are written escaped, so the namelist that
ld1.xquotes verbatim comes back as&input.
- Raises:
NotImplementedError – if
versionis below 2.0.- Return type:
- Returns:
the UPF file contents as a string
- property version: Version
The UPF version of the pseudopotential file, protected to always be a
Version.
When only the header of a pseudopotential is wanted, read_header fetches it without
reading the body.
- read_header(source)
Read the header of a UPF file without reading or parsing its body.
The file is read only as far as the end of its header, so a body that
upf_tools.UPFDict.from_upf()chokes on still yields a header:from upf_tools import read_header read_header("Si.upf")["pseudo_type"] # 'NC', 'US', 'USPP', 'PAW', ...
The entries are those the full parser puts under
psp["header"]. UPF v1 headers carry nopseudo_type; there theUS/NC/PAWfield is reported as the booleanis_ultrasoft, again matching the full parser.A header that is absent or malformed raises
ValueError.
- header_from_str(contents)
Extract the header from the contents of a UPF file.
contents need only reach the end of the header; what follows is ignored, whether or not
upf_tools.UPFDict.from_str()could parse it. A header that is absent or malformed raisesValueError.