Octopus 16.0
real-space, real-time, TDDFT code
element.hpp
Go to the documentation of this file.
1#ifndef PSEUDO_ELEMENT_HPP
2#define PSEUDO_ELEMENT_HPP
3
4/*
5 Copyright (C) 2018 Xavier Andrade
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#include <cassert>
23#include <cctype>
24#include <cstdlib>
25#include <fstream>
26#include <iostream>
27#include <map>
28#include <string>
29
30#include "share_directory.hpp"
31
32namespace pseudopotential {
33
34class element {
35
36private:
37 struct properties;
38 typedef std::map<std::string, properties> map_type;
39
40public:
42 symbol_[0] = std::toupper(symbol_[0]);
43 for (unsigned ii = 1; ii < symbol_.size(); ii++)
44 symbol_[ii] = std::tolower(symbol_[ii]);
45
46 map(); // make sure the map is initialized
47 }
48
50
51 // special case: avoid ambiguity between isotopes
52 if (atomic_number == 1) {
53 symbol_ = 'H';
54 return;
55 }
56
57 for (map_type::iterator it = map().begin(); it != map().end(); ++it) {
58 if (it->second.z_ == atomic_number) {
59 symbol_ = trim(it->first);
60 break;
61 }
62 }
63 }
64
65 bool valid() const { return map().find(symbol_) != map().end(); }
66
67 double charge() const { return -1.0 * atomic_number(); }
68
69 const std::string &symbol() const { return symbol_; }
70
71 int atomic_number() const { return map().at(symbol_).z_; }
72
73 double mass() const { return map().at(symbol_).mass_; }
74
75 double vdw_radius() const { return map().at(symbol_).vdw_radius_; }
76
77private:
78 struct properties {
79 int z_;
80 double mass_;
82 };
83
84 static map_type &map() {
85
86 static map_type map;
87 if (map.empty()) {
88
90 "/pseudopotentials/elements.dat";
91
92 std::ifstream file(filename.c_str());
93
94 if (!file) {
95 std::cerr << "Internal error: cannot open file '" << filename << "'."
96 << std::endl;
97 exit(EXIT_FAILURE);
98 }
99
100 while (true) {
102
103 file >> symbol;
104
105 if (file.eof())
106 break;
107
108 if (symbol[0] == '#') {
109 getline(file, symbol);
110 continue;
111 }
112
113 properties prop;
114
115 file >> prop.z_ >> prop.mass_ >> prop.vdw_radius_;
116
117 if (file.eof())
118 break;
119
120 map[symbol] = prop;
121 }
122 }
123
124 return map;
125 }
126
128 const std::string &chars = "\t\n\v\f\r ") {
129 str.erase(0, str.find_first_not_of(chars));
130 return str;
131 }
132
134 const std::string &chars = "\t\n\v\f\r ") {
135 str.erase(str.find_last_not_of(chars) + 1);
136 return str;
137 }
138
139public:
141 const std::string &chars = "\t\n\v\f\r ") {
142 return ltrim(rtrim(str, chars), chars);
143 }
144
145private:
147};
148
149} // namespace pseudopotential
150
151#endif
152
153// Local Variables:
154// mode: c++
155// coding: utf-8
156// End:
Definition: element.hpp:34
element(int atomic_number)
Definition: element.hpp:49
double mass() const
Definition: element.hpp:73
static std::string & ltrim(std::string &str, const std::string &chars="\t\n\v\f\r ")
Definition: element.hpp:127
int atomic_number() const
Definition: element.hpp:71
static std::string & rtrim(std::string &str, const std::string &chars="\t\n\v\f\r ")
Definition: element.hpp:133
std::string symbol_
Definition: element.hpp:146
const std::string & symbol() const
Definition: element.hpp:69
static std::string trim(std::string str, const std::string &chars="\t\n\v\f\r ")
Definition: element.hpp:140
double vdw_radius() const
Definition: element.hpp:75
element(const std::string &symbol="none")
Definition: element.hpp:41
std::map< std::string, properties > map_type
Definition: element.hpp:38
bool valid() const
Definition: element.hpp:65
double charge() const
Definition: element.hpp:67
static map_type & map()
Definition: element.hpp:84
static std::string get()
Definition: share_directory.hpp:32
!The assertions are ignored if the code is compiled in not debug when !prints out the assertion the file
Definition: global.h:58
!The assertions are ignored if the code is compiled in not debug when !prints out the assertion string
Definition: global.h:58
Definition: anygrid.hpp:27
Definition: element.hpp:78
double mass_
Definition: element.hpp:80
double vdw_radius_
Definition: element.hpp:81
int z_
Definition: element.hpp:79