37namespace pseudopotential {
42 struct element_values {
49 typedef std::map<std::string, element_values> element_map;
58 load_element_map(dirname);
60 for (
auto& [key, elem] : map_) {
61 elem.file_dir_ = dirname;
66 bool has(
const element &el)
const {
67 return map_.find(el.symbol()) != map_.end();
71 return map_.at(el.symbol()).file_dir_ +
"/" + map_.at(el.symbol()).file_rel_path_;
74 int lmax(
const element &el)
const {
return map_.at(el.symbol()).lmax_; }
76 int llocal(
const element &el)
const {
return map_.at(el.symbol()).llocal_; }
79 void generate_element_map(
const std::string &dirname) {
84 while ((ent =
readdir(dir)) != NULL) {
86 const std::string fullname = dirname +
"/" + filename;
88 if (filename ==
"." || filename ==
"..")
91 pseudopotential::format format = detect_format(fullname);
93 if (format == pseudopotential::format::FILE_NOT_FOUND ||
94 format == pseudopotential::format::UNKNOWN)
99 pseudopotential::base *pseudo = NULL;
104 case pseudopotential::format::QSO:
105 pseudo =
new pseudopotential::qso(fullname);
107 case pseudopotential::format::UPF1:
108 pseudo =
new pseudopotential::upf1(fullname,
true);
110 case pseudopotential::format::UPF2:
111 pseudo =
new pseudopotential::upf2(fullname,
true);
113 case pseudopotential::format::PSML:
114 pseudo =
new pseudopotential::psml(fullname,
true);
116 case pseudopotential::format::PSP8:
117 pseudo =
new pseudopotential::psp8(fullname);
121 for (
int ii = 0; ii < 3; ii++) {
122 char cc = filename[ii];
123 bool is_letter = (cc >=
'a' && cc <=
'z') || (cc >=
'A' && cc <=
'Z');
126 symbol.push_back(cc);
131 symbol = pseudo->symbol();
137 vals.file_rel_path_ = filename;
138 vals.lmax_ = INVALID_L;
139 vals.llocal_ = INVALID_L;
144 std::ifstream defaults_file((dirname +
"/set_defaults").c_str());
150 getline(defaults_file, line);
154 defaults_file >> symbol;
155 if (defaults_file.eof())
162 defaults_file >> fname;
164 defaults_file >> map_[symbol].lmax_;
165 defaults_file >> map_[symbol].llocal_;
168 getline(defaults_file, line);
171 defaults_file.close();
176 const std::string file_name = dirname +
"/elements_map.dat";
177 std::ofstream map_file(file_name);
179 if (!map_file.is_open()) {
180 throw std::ios_base::failure(
"Failed to open file for writing: " + file_name);
183 for (
const auto& [symbol, elem] : map_) {
184 map_file << trim(symbol) <<
" "
185 << trim(elem.file_rel_path_) <<
" "
187 << elem.llocal_ <<
"\n";
195 void load_element_map(
const std::string &dirname) {
201 std::ifstream map_file((dirname +
"/elements_map.dat").c_str());
203 std::cerr <<
"Internal warning: cannot open file element_map.dat for the pseudopotential set."
205 std::cerr <<
"This will be regenerated in the installation folder."
207 generate_element_map(dirname);
212 while (map_file >> symbol) {
215 if (!(map_file >> vals.file_rel_path_ >> vals.lmax_ >> vals.llocal_)) {
216 std::cerr <<
"Error parsing the file: " << vals.file_rel_path_ << std::endl;
226 str.erase(0, str.find_first_not_of(chars));
232 str.erase(str.find_last_not_of(chars) + 1);
238 return ltrim(rtrim(str, chars), chars);
258 return a.map_it_ != b.map_it_;
261 element operator*() {
return element(map_it_->first); }
if write to the Free Software Franklin Fifth USA !If the compiler accepts long Fortran it is better to use that and build all the preprocessor definitions in one line In !this the debuggers will provide the right line numbers !If the compiler accepts line number then CARDINAL and ACARDINAL !will put them just a new line or a ampersand plus a new line !These macros should be used in macros that span several lines They should by !put immedialty before a line where a compilation error might occur and at the !end of the macro !Note that the cardinal and newline words are substituted by the program !preprocess pl by the ampersand and by a real new line just before compilation !The assertions are ignored if the code is compiled in not debug when !prints out the assertion string
type(oct_iterator_t), save iterator
DIR DIR struct dirent * readdir(DIR *__dirp) __attribute__((__nonnull__(1)))
DIR * opendir(const char *__name) __attribute__((__nonnull__(1))) __attribute__((__malloc__)) __attribute__((__malloc__(closedir
int closedir(DIR *__dirp) __attribute__((__nonnull__(1)))