Loading...
Searching...
No Matches
q3::upf_utilities Namespace Reference

Functions

std::string canonical_pseudopotential_type (const std::string &raw_type)
 
void check_atomic_wavefunction_norm (Pseudopotential &pseudopotential)
 Validate atomic wavefunction norms and mark zero-norm wavefunctions.
 
bool find_tag (std::ifstream &file_stream, const std::string &tag)
 Advance the stream until a line containing the given tag is found.
 
std::runtime_error malformed_attribute_error (const std::string &attribute_name, const std::string &source_description, const std::string &expected_kind, const std::string &found_value)
 
std::vector< Real > read_reals (std::ifstream &file_stream, int count)
 Read a specified number of real values from a stream.
 
int required_integer_attribute (const std::string &text, const std::string &attribute_name, const std::string &source_description)
 
Real required_real_attribute (const std::string &text, const std::string &attribute_name, const std::string &source_description)
 Read a required real-valued attribute from a UPF header tag.
 
std::string trim (const std::string &input)
 Remove leading and trailing whitespace from a string.
 
std::string xml_attribute (const std::string &text, const std::string &attribute_name)
 Extract an XML attribute value from a block of text (e.g. attr="value" or attr='value').
 
std::vector< Real > xml_data (const std::string &section)
 Extract numeric data from an XML section body, skipping lines that contain XML tags.
 

Function Documentation

◆ canonical_pseudopotential_type()

std::string q3::upf_utilities::canonical_pseudopotential_type ( const std::string &  raw_type)
inline

Canonical kind name for a UPF pseudo_type header value.

Pseudopotential::pseudopotential_type is documented to hold "NC", "US" or "PAW", and the rest of the tree relies on that: the reader factory picks the subclass to construct by comparing against those spellings, and pseudopotential_kind_name renders them into the provenance record. The v2 reader, though, stored the header attribute verbatim, so whether a dataset got its augmentation apparatus depended on how its generator happened to spell the field.

The spellings are not uniform in practice. The UPF header documents "NC", "SL", "US" and "PAW", but generators also emit "USPP" for an ultrasoft dataset — a UPF v2 carbon USPP written by the atomic code reports pseudo_type="USPP", and against the exact-match test that read as "not ultrasoft". The file was then built as a plain norm-conserving Pseudopotential, silently dropping every Q_ij it carried, and the first code to ask for its augmentation data aborted on the as_ultrasoft cast. Matching on a canonical form rather than one blessed spelling is what keeps that from being a per-generator lottery.

An unrecognized value is returned trimmed but otherwise untouched, so it still lands on the norm-conserving construction path exactly as before and the original label survives for diagnostics.

Definition at line 60 of file utilities.hpp.

References trim().

Referenced by q3::UPFReader::read().

◆ check_atomic_wavefunction_norm()

void q3::upf_utilities::check_atomic_wavefunction_norm ( Pseudopotential &  pseudopotential)
inline

Validate atomic wavefunction norms and mark zero-norm wavefunctions.

Definition at line 210 of file utilities.hpp.

References q3::Pseudopotential::element, q3::Pseudopotential::mesh_size, q3::Pseudopotential::radial_grid_derivative, q3::simpson_rule(), q3::log::warn(), and q3::Pseudopotential::wavefunctions_atomic.

Referenced by q3::UPFReader::read().

◆ find_tag()

bool q3::upf_utilities::find_tag ( std::ifstream &  file_stream,
const std::string &  tag 
)
inline

Advance the stream until a line containing the given tag is found.

Definition at line 89 of file utilities.hpp.

◆ malformed_attribute_error()

std::runtime_error q3::upf_utilities::malformed_attribute_error ( const std::string &  attribute_name,
const std::string &  source_description,
const std::string &  expected_kind,
const std::string &  found_value 
)
inline

Build the error a malformed required attribute produces.

Named separately so the "missing" and "unparseable" paths report the same way: both are the same problem from a user's point of view — this file cannot be read, and here is the field to look at.

Definition at line 122 of file utilities.hpp.

Referenced by required_integer_attribute(), and required_real_attribute().

◆ read_reals()

std::vector< Real > q3::upf_utilities::read_reals ( std::ifstream &  file_stream,
int  count 
)
inline

Read a specified number of real values from a stream.

Definition at line 77 of file utilities.hpp.

◆ required_integer_attribute()

int q3::upf_utilities::required_integer_attribute ( const std::string &  text,
const std::string &  attribute_name,
const std::string &  source_description 
)
inline

Read a required numeric attribute from a UPF header tag.

xml_attribute() returns an empty string for an attribute that is not present, and handing that to the standard conversions yields "stoi: no conversion" — an error naming neither the file nor the field, which is no help to someone holding a pseudopotential that will not load. These two helpers name both.

Trailing characters are rejected rather than ignored: std::stoi("20x0") happily returns 20, and a mesh size silently truncated from a corrupt attribute is worse than a refusal.

Use only for attributes a file genuinely cannot omit. Optional attributes (number_of_wfc, core_correction) stay tolerant of absence at their call sites.

Definition at line 153 of file utilities.hpp.

References malformed_attribute_error(), trim(), and xml_attribute().

◆ required_real_attribute()

Real q3::upf_utilities::required_real_attribute ( const std::string &  text,
const std::string &  attribute_name,
const std::string &  source_description 
)
inline

Read a required real-valued attribute from a UPF header tag.

Definition at line 173 of file utilities.hpp.

References malformed_attribute_error(), trim(), and xml_attribute().

◆ trim()

std::string q3::upf_utilities::trim ( const std::string &  input)
inline

Remove leading and trailing whitespace from a string.

Definition at line 27 of file utilities.hpp.

Referenced by canonical_pseudopotential_type(), required_integer_attribute(), and required_real_attribute().

◆ xml_attribute()

std::string q3::upf_utilities::xml_attribute ( const std::string &  text,
const std::string &  attribute_name 
)
inline

Extract an XML attribute value from a block of text (e.g. attr="value" or attr='value').

Definition at line 99 of file utilities.hpp.

Referenced by q3::UPFReader::read(), required_integer_attribute(), and required_real_attribute().

◆ xml_data()

std::vector< Real > q3::upf_utilities::xml_data ( const std::string &  section)
inline

Extract numeric data from an XML section body, skipping lines that contain XML tags.

Definition at line 193 of file utilities.hpp.