43 static std::unique_ptr<Pseudopotential>
read(
const std::string& filename) {
44 std::ifstream file_stream(filename);
45 if (!file_stream.is_open())
46 throw std::runtime_error(
"Cannot open PP file: " + filename);
48 std::string first_line;
49 std::getline(file_stream, first_line);
55 bool is_ultrasoft_type =
false;
56 bool is_paw_type =
false;
57 std::string pseudopotential_type_string;
59 if (first_line.find(
"version=\"2") != std::string::npos) {
62 std::string content((std::istreambuf_iterator<char>(file_stream)),
63 std::istreambuf_iterator<char>());
66 auto header_position = content.find(
"<PP_HEADER");
67 if (header_position != std::string::npos) {
68 auto end_position = content.find(
"/>", header_position);
69 if (end_position == std::string::npos)
70 end_position = content.find(
">", header_position);
71 std::string header_tag =
72 content.substr(header_position, end_position - header_position + 2);
77 is_paw_type = (pseudopotential_type_string ==
"PAW");
78 is_ultrasoft_type = (pseudopotential_type_string ==
"US");
81 std::unique_ptr<Pseudopotential> pseudopotential;
83 pseudopotential = std::make_unique<PawPseudopotential>();
84 }
else if (is_ultrasoft_type) {
85 pseudopotential = std::make_unique<UltrasoftPseudopotential>();
87 pseudopotential = std::make_unique<Pseudopotential>();
91 if (is_ultrasoft_type || is_paw_type) {
103 return pseudopotential;
107 std::ifstream v1_stream(filename);
114 auto temporary_pseudopotential = std::make_unique<Pseudopotential>();
117 is_ultrasoft_type = (temporary_pseudopotential->pseudopotential_type ==
"US");
119 std::unique_ptr<Pseudopotential> pseudopotential;
120 if (is_ultrasoft_type) {
122 auto ultrasoft_pseudopotential = std::make_unique<UltrasoftPseudopotential>();
125 std::move(*temporary_pseudopotential);
126 pseudopotential = std::move(ultrasoft_pseudopotential);
128 pseudopotential = std::move(temporary_pseudopotential);
131 if (is_ultrasoft_type) {
132 std::ifstream us_stream(filename);
141 return pseudopotential;