Expand description
Rust types and helpers for the Unified Pseudopotential Format (UPF).
This crate models UPF 2.0.1 documents as typed Rust data structures built
around the top-level UpfData type. Parsing and serialization are backed
by quick-xml, while a small validation layer enforces invariants that are
required by the UPF structure used in this repository:
PP_HEADER/@mesh_sizemust match the lengths ofPP_R,PP_RAB,PP_LOCAL, andPP_RHOATOMPP_HEADER/@is_paw="T"requires aPP_PAWsectionPP_HEADER/@has_gipaw="T"requires aPP_GIPAWsection
The public API intentionally stays small:
from_str,from_reader, andfrom_filedeserialize UPF textto_string,to_writer, andto_fileserialize validated modelsmodelexposes Rust representations of UPF sections
§Example
use upf::from_str;
let xml = r#"
<UPF version="2.0.1">
<PP_HEADER generated="unit" author="tester" date="2026-04-03" comment="demo"
element="He" pseudo_type="NC" relativistic="scalar"
is_ultrasoft="F" is_paw="F" is_coulomb="F"
has_so="F" has_wfc="F" has_gipaw="F" core_correction="F"
z_valence="2.0" total_psenergy="-1.25"
wfc_cutoff="20.0" rho_cutoff="80.0"
l_max="0" l_max_rho="0" l_local="0"
mesh_size="3" number_of_wfc="0" number_of_proj="0" />
<PP_MESH dx="0.1" mesh="3" xmin="0.0" rmax="0.2" zmesh="1.0">
<PP_R>0.0 0.1 0.2</PP_R>
<PP_RAB>0.1 0.1 0.1</PP_RAB>
</PP_MESH>
<PP_LOCAL>1.0 2.0 3.0</PP_LOCAL>
<PP_NONLOCAL />
<PP_RHOATOM>0.2 0.3 0.4</PP_RHOATOM>
</UPF>
"#;
let upf_data = from_str(xml).unwrap();
assert_eq!(upf_data.header.element, "He");
assert_eq!(upf_data.mesh.r.values.len(), upf_data.header.mesh_size);Re-exports§
pub use model::UpfData;
Modules§
- model
- Rust representations of UPF sections and sub-sections. Typed Rust models for UPF sections.
Enums§
- UpfError
- Errors produced while parsing, validating, or serializing UPF documents.
Functions§
- format_
bool_ flag - Format a Rust boolean as the compact UPF flag used in this crate,
TorF. - format_
f64_ slice - Format numeric values the same compact way used by this crate’s serializer.
- from_
file - Parse a UPF document from a filesystem path.
- from_
reader - Parse a full UPF document from any buffered reader.
- from_
str - Parse a full UPF document from a string slice.
- parse_
bool_ flag - Parse a UPF logical flag such as
T,.T.,FALSE, or.FALSE.. - parse_
f64_ vec - Parse a whitespace-delimited UPF numeric field into
f64values. - to_file
- Serialize a validated UPF document to a filesystem path.
- to_
string - Serialize a validated UPF document into an XML string.
- to_
writer - Serialize a validated UPF document into an arbitrary writer.