RDKit
Open-source cheminformatics and machine learning.
PeriodicTable.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2011 Rational Discovery LLC
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10#include <RDGeneral/export.h>
11#ifndef _RD_PERIODIC_TABLE_H
12#define _RD_PERIODIC_TABLE_H
13
14#include <map>
15#include <vector>
16#include <RDGeneral/types.h>
17#include "atomic_data.h"
18
19namespace RDKit {
20
21//! singleton class for retrieving information about atoms
22/*!
23 Use the singleton like this:
24
25 \verbatim
26 const PeriodicTable *tbl = PeriodicTable::getTable();
27 tbl->getAtomicWeight(6); // get atomic weight for Carbon
28 tbl->getAtomicWeight("C"); // get atomic weight for Carbon
29 \endverbatim
30
31*/
33 public:
34 //! returns a pointer to the singleton PeriodicTable
35 /*
36 \return a pointer to the singleton ParamCollection
37
38 <b>Notes:</b>
39 - do <b>not</b> delete the pointer returned here
40 - if the singleton PeriodicTable has already been instantiated and
41 the singleton will be returned, otherwise the singleton will
42 be constructed.
43
44 */
46
48 byanum.clear();
49 byname.clear();
50 }
51
52 //! returns the atomic weight
53 double getAtomicWeight(UINT atomicNumber) const {
54 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
55 double mass = byanum[atomicNumber].Mass();
56 return mass;
57 }
58 //! \overload
59 double getAtomicWeight(const std::string &elementSymbol) const {
60 PRECONDITION(byname.count(elementSymbol), "Element not found");
61 int anum = byname.find(elementSymbol)->second;
62 double mass = byanum[anum].Mass();
63 return mass;
64 }
65 //! \overload
66 double getAtomicWeight(const char *elementSymbol) const {
67 return getAtomicWeight(std::string(elementSymbol));
68 }
69
70 //! returns the atomic number
71 int getAtomicNumber(const char *elementSymbol) const {
72 std::string symb(elementSymbol);
73
74 return getAtomicNumber(symb);
75 }
76 //! overload
77 int getAtomicNumber(const std::string &elementSymbol) const {
78 // this little optimization actually makes a measurable difference
79 // in molecule-construction time
80 int anum = -1;
81 if (elementSymbol == "C") {
82 anum = 6;
83 } else if (elementSymbol == "N") {
84 anum = 7;
85 } else if (elementSymbol == "O") {
86 anum = 8;
87 } else {
88 STR_UINT_MAP::const_iterator iter = byname.find(elementSymbol);
89 if (iter != byname.end()) {
90 anum = iter->second;
91 }
92 }
93 POSTCONDITION(anum > -1, "Element '" + elementSymbol + "' not found");
94 return anum;
95 }
96
97 //! returns the atomic symbol
98 std::string getElementSymbol(UINT atomicNumber) const {
99 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
100 return byanum[atomicNumber].Symbol();
101 }
102
103 //! returns the atom's van der Waals radius
104 double getRvdw(UINT atomicNumber) const {
105 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
106 return byanum[atomicNumber].Rvdw();
107 }
108 //! \overload
109 double getRvdw(const std::string &elementSymbol) const {
110 PRECONDITION(byname.count(elementSymbol),
111 "Element '" + elementSymbol + "' not found");
112 return getRvdw(byname.find(elementSymbol)->second);
113 }
114 //! \overload
115 double getRvdw(const char *elementSymbol) const {
116 return getRvdw(std::string(elementSymbol));
117 }
118
119 //! returns the atom's covalent radius
120 double getRcovalent(UINT atomicNumber) const {
121 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
122 return byanum[atomicNumber].Rcov();
123 }
124 //! \overload
125 double getRcovalent(const std::string &elementSymbol) const {
126 PRECONDITION(byname.count(elementSymbol),
127 "Element '" + elementSymbol + "' not found");
128 return getRcovalent(byname.find(elementSymbol)->second);
129 }
130 //! \overload
131 double getRcovalent(const char *elementSymbol) const {
132 return getRcovalent(std::string(elementSymbol));
133 }
134
135 //! returns the atom's bond radius
136 double getRb0(UINT atomicNumber) const {
137 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
138 return byanum[atomicNumber].Rb0();
139 }
140 //! \overload
141 double getRb0(const std::string &elementSymbol) const {
142 PRECONDITION(byname.count(elementSymbol),
143 "Element '" + elementSymbol + "' not found");
144 return getRb0(byname.find(elementSymbol)->second);
145 }
146 //! \overload
147 double getRb0(const char *elementSymbol) const {
148 return getRb0(std::string(elementSymbol));
149 }
150
151 //! returns the atom's default valence
152 int getDefaultValence(UINT atomicNumber) const {
153 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
154 return byanum[atomicNumber].DefaultValence();
155 }
156 //! \overload
157 int getDefaultValence(const std::string &elementSymbol) const {
158 PRECONDITION(byname.count(elementSymbol),
159 "Element '" + elementSymbol + "' not found");
160 return getDefaultValence(byname.find(elementSymbol)->second);
161 }
162 //! \overload
163 int getDefaultValence(const char *elementSymbol) const {
164 return getDefaultValence(std::string(elementSymbol));
165 }
166
167 //! returns a vector of all stable valences. For atoms where
168 //! we really don't have any idea what a reasonable maximum
169 //! valence is (like transition metals), the vector ends with -1
170 const INT_VECT &getValenceList(UINT atomicNumber) const {
171 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
172 return byanum[atomicNumber].ValenceList();
173 }
174 //! \overload
175 const INT_VECT &getValenceList(const std::string &elementSymbol) const {
176 PRECONDITION(byname.count(elementSymbol),
177 "Element '" + elementSymbol + "' not found");
178 return getValenceList(byname.find(elementSymbol)->second);
179 }
180 //! \overload
181 const INT_VECT &getValenceList(const char *elementSymbol) const {
182 return getValenceList(std::string(elementSymbol));
183 }
184
185 //! returns the number of outer shell electrons
186 int getNouterElecs(UINT atomicNumber) const {
187 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
188 return byanum[atomicNumber].NumOuterShellElec();
189 }
190 //! \overload
191 int getNouterElecs(const std::string &elementSymbol) const {
192 PRECONDITION(byname.count(elementSymbol),
193 "Element '" + elementSymbol + "' not found");
194 return getNouterElecs(byname.find(elementSymbol)->second);
195 }
196 //! \overload
197 int getNouterElecs(const char *elementSymbol) const {
198 return getNouterElecs(std::string(elementSymbol));
199 }
200
201 //! returns the number of the most common isotope
202 int getMostCommonIsotope(UINT atomicNumber) const {
203 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
204 return byanum[atomicNumber].MostCommonIsotope();
205 }
206 //! \overload
207 int getMostCommonIsotope(const std::string &elementSymbol) const {
208 PRECONDITION(byname.count(elementSymbol),
209 "Element '" + elementSymbol + "' not found");
210 return getMostCommonIsotope(byname.find(elementSymbol)->second);
211 }
212 //! \overload
213 int getMostCommonIsotope(const char *elementSymbol) const {
214 return getMostCommonIsotope(std::string(elementSymbol));
215 }
216
217 //! returns the mass of the most common isotope
218 double getMostCommonIsotopeMass(UINT atomicNumber) const {
219 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
220 return byanum[atomicNumber].MostCommonIsotopeMass();
221 }
222 //! \overload
223 double getMostCommonIsotopeMass(const std::string &elementSymbol) const {
224 PRECONDITION(byname.count(elementSymbol),
225 "Element '" + elementSymbol + "' not found");
226 return getMostCommonIsotopeMass(byname.find(elementSymbol)->second);
227 }
228 //! \overload
229 double getMostCommonIsotopeMass(const char *elementSymbol) const {
230 return getMostCommonIsotopeMass(std::string(elementSymbol));
231 }
232
233 //! returns the mass of a particular isotope; zero if that
234 //! isotope is unknown.
235 double getMassForIsotope(UINT atomicNumber, UINT isotope) const {
236 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
237 const std::map<unsigned int, std::pair<double, double>> &m =
238 byanum[atomicNumber].d_isotopeInfoMap;
239 std::map<unsigned int, std::pair<double, double>>::const_iterator item =
240 m.find(isotope);
241 if (item == m.end()) {
242 return 0.0;
243 } else {
244 return item->second.first;
245 }
246 }
247 //! \overload
248 double getMassForIsotope(const std::string &elementSymbol,
249 UINT isotope) const {
250 PRECONDITION(byname.count(elementSymbol),
251 "Element '" + elementSymbol + "' not found");
252 return getMassForIsotope(byname.find(elementSymbol)->second, isotope);
253 }
254 //! \overload
255 double getMassForIsotope(const char *elementSymbol, UINT isotope) const {
256 return getMassForIsotope(std::string(elementSymbol), isotope);
257 }
258 //! returns the abundance of a particular isotope; zero if that
259 //! isotope is unknown.
260 double getAbundanceForIsotope(UINT atomicNumber, UINT isotope) const {
261 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
262 const std::map<unsigned int, std::pair<double, double>> &m =
263 byanum[atomicNumber].d_isotopeInfoMap;
264 std::map<unsigned int, std::pair<double, double>>::const_iterator item =
265 m.find(isotope);
266 if (item == m.end()) {
267 return 0.0;
268 } else {
269 return item->second.second;
270 }
271 }
272 //! \overload
273 double getAbundanceForIsotope(const std::string &elementSymbol,
274 UINT isotope) const {
275 PRECONDITION(byname.count(elementSymbol),
276 "Element '" + elementSymbol + "' not found");
277 return getAbundanceForIsotope(byname.find(elementSymbol)->second, isotope);
278 }
279 //! \overload
280 double getAbundanceForIsotope(const char *elementSymbol, UINT isotope) const {
281 return getAbundanceForIsotope(std::string(elementSymbol), isotope);
282 }
283
284 //! convenience function to determine which atom is more electronegative
285 /*!
286
287 check if atom with atomic number \c anum1 is more
288 electronegative than the one with \c anum2
289 this is rather lame but here is how we do it
290 - the atom with the higher number of outer shell electrons
291 is considered more electronegative
292 - if the # of outer shell elecs are the same
293 the atom with the lower atomic weight is more electronegative
294
295 */
296 bool moreElectroNegative(UINT anum1, UINT anum2) const {
297 PRECONDITION(anum1 < byanum.size(), "Atomic number not found");
298 PRECONDITION(anum2 < byanum.size(), "Atomic number not found");
299 // FIX: the atomic_data needs to have real electronegativity values
300 UINT ne1 = getNouterElecs(anum1);
301 UINT ne2 = getNouterElecs(anum2);
302 if (ne1 > ne2) {
303 return true;
304 }
305 if (ne1 == ne2) {
306 if (anum1 < anum2) {
307 return true;
308 }
309 }
310 return false;
311 }
312
313 private:
315 PeriodicTable &operator=(const PeriodicTable &);
316 static void initInstance();
317
318 static class std::unique_ptr<PeriodicTable> ds_instance;
319
320 std::vector<atomicData> byanum;
321 STR_UINT_MAP byname;
322};
323}; // namespace RDKit
324
325#endif
#define POSTCONDITION(expr, mess)
Definition: Invariant.h:117
#define PRECONDITION(expr, mess)
Definition: Invariant.h:109
No user-serviceable parts inside.
singleton class for retrieving information about atoms
Definition: PeriodicTable.h:32
int getMostCommonIsotope(UINT atomicNumber) const
returns the number of the most common isotope
int getMostCommonIsotope(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getRb0(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getMostCommonIsotopeMass(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getRcovalent(UINT atomicNumber) const
returns the atom's covalent radius
double getAbundanceForIsotope(UINT atomicNumber, UINT isotope) const
const INT_VECT & getValenceList(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getRb0(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getAtomicWeight(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:66
int getNouterElecs(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getAtomicWeight(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:59
int getAtomicNumber(const std::string &elementSymbol) const
overload
Definition: PeriodicTable.h:77
double getRvdw(UINT atomicNumber) const
returns the atom's van der Waals radius
int getAtomicNumber(const char *elementSymbol) const
returns the atomic number
Definition: PeriodicTable.h:71
const INT_VECT & getValenceList(UINT atomicNumber) const
int getNouterElecs(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getRvdw(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static PeriodicTable * getTable()
returns a pointer to the singleton PeriodicTable
double getMostCommonIsotopeMass(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getRb0(UINT atomicNumber) const
returns the atom's bond radius
double getMostCommonIsotopeMass(UINT atomicNumber) const
returns the mass of the most common isotope
int getDefaultValence(UINT atomicNumber) const
returns the atom's default valence
double getMassForIsotope(UINT atomicNumber, UINT isotope) const
double getRcovalent(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int getMostCommonIsotope(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const INT_VECT & getValenceList(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::string getElementSymbol(UINT atomicNumber) const
returns the atomic symbol
Definition: PeriodicTable.h:98
int getNouterElecs(UINT atomicNumber) const
returns the number of outer shell electrons
double getRvdw(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getRcovalent(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getMassForIsotope(const char *elementSymbol, UINT isotope) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getAtomicWeight(UINT atomicNumber) const
returns the atomic weight
Definition: PeriodicTable.h:53
bool moreElectroNegative(UINT anum1, UINT anum2) const
convenience function to determine which atom is more electronegative
double getMassForIsotope(const std::string &elementSymbol, UINT isotope) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getAbundanceForIsotope(const std::string &elementSymbol, UINT isotope) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int getDefaultValence(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int getDefaultValence(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double getAbundanceForIsotope(const char *elementSymbol, UINT isotope) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:217
RDKIT_STRUCTCHECKER_EXPORT unsigned getAtomicNumber(const std::string symbol)
Std stuff.
Definition: Abbreviations.h:18
std::vector< int > INT_VECT
Definition: types.h:277
std::map< std::string, UINT > STR_UINT_MAP
Definition: types.h:309
unsigned int UINT
Definition: types.h:273