Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
hf.h
Go to the documentation of this file.
1 #ifndef HF_H
2 #define HF_H
3 
4 #include <map>
5 #include <unordered_map>
6 #include <string>
7 #include <boost/functional/hash.hpp>
8 #include <boost/algorithm/string.hpp>
9 #include <boost/regex.hpp>
10 
11 struct iequal_to
12  : std::binary_function<std::string, std::string, bool>
13 {
14  bool operator()(std::string const& x,
15  std::string const& y) const
16  {
17  return boost::algorithm::iequals(x, y, std::locale());
18  }
19 };
20 
21 struct ihash
22  : std::unary_function<std::string, std::size_t>
23 {
24  std::size_t operator()(std::string const& x) const
25  {
26  std::size_t seed = 0;
27  std::locale locale;
28 
29  for(std::string::const_iterator it = x.begin();
30  it != x.end(); ++it)
31  {
32  boost::hash_combine(seed, std::toupper(*it, locale));
33  }
34 
35  return seed;
36  }
37 };
38 
39 class HF
40 {
41 public:
47  };
48 
49  enum AtomType {
169  };
170 
171  static std::string escapeBasis(std::string basisName) {
172  std::string basisNameEscaped = boost::regex_replace(basisName, boost::regex("\\*"), "ds");
173  basisNameEscaped = boost::regex_replace(basisNameEscaped, boost::regex(" "), "_");
174  return basisNameEscaped;
175  }
176 
177  static std::string filenameFromAtomAndBasis(AtomType type, std::string basisName) {
178  std::stringstream fileNameBuilder;
179  std::stringstream atomTypeBuilder;
180  atomTypeBuilder << type;
181 
182  std::string basisNameEscaped = escapeBasis(basisName);
183 
184  std::string atomTypeString = atomTypeBuilder.str();
185  fileNameBuilder << "atom_" << atomTypeString << "_basis_" << basisNameEscaped << ".tm";
186 
187  std::string filename = fileNameBuilder.str();
188  return filename;
189  }
190 
191  static std::string filenameFromAtomAndBasis(std::string abbreviation, std::string basisName) {
192  HF::AtomType type = HF::abbreviationToAtomType(abbreviation);
193  if(type == HF::Unknown) {
194  std::cerr << "Unknown atom abbreviation " << abbreviation << std::endl;
195  return "";
196  }
197  return filenameFromAtomAndBasis(type, basisName);
198  }
199 
200  static AtomType abbreviationToAtomType(std::string abbreviation) {
201  std::unordered_map<std::string, AtomType, ihash, iequal_to> abbreviationMap {
202  {"H",Hydrogen},
203  {"He",Helium},
204  {"Li",Lithium},
205  {"Be",Beryllium},
206  {"B",Boron},
207  {"C",Carbon},
208  {"N",Nitrogen},
209  {"O",Oxygen},
210  {"F",Fluorine},
211  {"Ne",Neon},
212  {"Na",Sodium},
213  {"Mg",Magnesium},
214  {"Al",Aluminum},
215  {"Si",Silicon},
216  {"P",Phosphorus},
217  {"S",Sulfur},
218  {"Cl",Chlorine},
219  {"Ar",Argon},
220  {"K",Potassium},
221  {"Ca",Calcium},
222  {"Sc",Scandium},
223  {"Ti",Titanium},
224  {"V",Vanadium},
225  {"Cr",Chromium},
226  {"Mn",Manganese},
227  {"Fe",Iron},
228  {"Co",Cobalt},
229  {"Ni",Nickel},
230  {"Cu",Copper},
231  {"Zn",Zinc},
232  {"Ga",Gallium},
233  {"Ge",Germanium},
234  {"As",Arsenic},
235  {"Se",Selenium},
236  {"Br",Bromine},
237  {"Kr",Krypton},
238  {"Rb",Rubidium},
239  {"Sr",Strontium},
240  {"Y",Yttrium},
241  {"Zr",Zirconium},
242  {"Nb",Niobium},
243  {"Mo",Molybdenum},
244  {"Tc",Technetium},
245  {"Ru",Ruthenium},
246  {"Rh",Rhodium},
247  {"Pd",Palladium},
248  {"Ag",Silver},
249  {"Cd",Cadmium},
250  {"In",Indium},
251  {"Sn",Tin},
252  {"Sb",Antimony},
253  {"Te",Tellurium},
254  {"I",Iodine},
255  {"Xe",Xenon},
256  {"Cs",Cesium},
257  {"Ba",Barium},
258  {"La",Lanthanum},
259  {"Ce",Cerium},
260  {"Pr",Praseodymium},
261  {"Nd",Neodymium},
262  {"Pm",Promethium},
263  {"Sm",Samarium},
264  {"Eu",Europium},
265  {"Gd",Gadolinium},
266  {"Tb",Terbium},
267  {"Dy",Dysprosium},
268  {"Ho",Holmium},
269  {"Er",Erbium},
270  {"Tm",Thulium},
271  {"Yb",Ytterbium},
272  {"Lu",Lutetium},
273  {"Hf",Hafnium},
274  {"Ta",Tantalum},
275  {"W",Tungsten},
276  {"Re",Rhenium},
277  {"Os",Osmium},
278  {"Ir",Iridium},
279  {"Pt",Platinum},
280  {"Au",Gold},
281  {"Hg",Mercury},
282  {"Tl",Thallium},
283  {"Pb",Lead},
284  {"Bi",Bismuth},
285  {"Po",Polonium},
286  {"At",Astatine},
287  {"Rn",Radon},
288  {"Fr",Francium},
289  {"Ra",Radium},
290  {"Ac",Actinium},
291  {"Th",Thorium},
292  {"Pa",Protactinium},
293  {"U",Uranium},
294  {"Np",Neptunium},
295  {"Pu",Plutonium},
296  {"Am",Americium},
297  {"Cm",Curium},
298  {"Bk",Berkelium},
299  {"Cf",Californium},
300  {"Es",Einsteinium},
301  {"Fm",Fermium},
302  {"Md",Mendelevium},
303  {"No",Nobelium},
304  {"Lr",Lawrencium},
305  {"Rf",Rutherfordium},
306  {"Db",Dubnium},
307  {"Sg",Seaborgium},
308  {"Bh",Bohrium},
309  {"Hs",Hassium},
310  {"Mt",Meitnerium},
311  {"Ds",Darmstadtium},
312  {"Rg",Roentgenium},
313  {"Cn",Copernicium},
314  {"Uut",Ununtrium},
315  {"Fl",Flerovium},
316  {"Uup",Ununpentium},
317  {"Lv",Livermorium},
318  {"Uus",Ununseptium},
319  {"Uuo",Ununoctium}
320  };
321  if(abbreviationMap.find(abbreviation) != abbreviationMap.end()) {
322  return abbreviationMap.find(abbreviation)->second;
323  } else {
324  return Unknown;
325  }
326  }
327 };
328 
329 #endif // HF_H