RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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 PeriodicTable(const PeriodicTable &) = delete;
48
50 byanum.clear();
51 byname.clear();
52 }
53
54 //! returns the atomic weight
55 double getAtomicWeight(UINT atomicNumber) const {
56 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
57 double mass = byanum[atomicNumber].Mass();
58 return mass;
59 }
60 //! \overload
61 double getAtomicWeight(const std::string &elementSymbol) const {
62 PRECONDITION(byname.count(elementSymbol), "Element not found");
63 int anum = byname.find(elementSymbol)->second;
64 double mass = byanum[anum].Mass();
65 return mass;
66 }
67 //! \overload
68 double getAtomicWeight(const char *elementSymbol) const {
69 return getAtomicWeight(std::string(elementSymbol));
70 }
71
72 //! returns the atomic number
73 int getAtomicNumber(const char *elementSymbol) const {
74 std::string symb(elementSymbol);
75
76 return getAtomicNumber(symb);
77 }
78 //! overload
79 int getAtomicNumber(const std::string &elementSymbol) const {
80 // this little optimization actually makes a measurable difference
81 // in molecule-construction time
82 int anum = -1;
83 if (elementSymbol == "C") {
84 anum = 6;
85 } else if (elementSymbol == "N") {
86 anum = 7;
87 } else if (elementSymbol == "O") {
88 anum = 8;
89 } else {
90 auto iter = byname.find(elementSymbol);
91 if (iter != byname.end()) {
92 anum = iter->second;
93 }
94 }
95 POSTCONDITION(anum > -1, "Element '" + elementSymbol + "' not found");
96 return anum;
97 }
98
99 //! returns the atomic symbol
100 std::string getElementSymbol(UINT atomicNumber) const {
101 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
102 return byanum[atomicNumber].Symbol();
103 }
104
105 //! returns the full element name
106 std::string getElementName(UINT atomicNumber) const {
107 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
108 return byanum[atomicNumber].Name();
109 }
110
111 //! returns the atom's van der Waals radius
112 double getRvdw(UINT atomicNumber) const {
113 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
114 return byanum[atomicNumber].Rvdw();
115 }
116 //! \overload
117 double getRvdw(const std::string &elementSymbol) const {
118 PRECONDITION(byname.count(elementSymbol),
119 "Element '" + elementSymbol + "' not found");
120 return getRvdw(byname.find(elementSymbol)->second);
121 }
122 //! \overload
123 double getRvdw(const char *elementSymbol) const {
124 return getRvdw(std::string(elementSymbol));
125 }
126
127 //! returns the atom's covalent radius
128 double getRcovalent(UINT atomicNumber) const {
129 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
130 return byanum[atomicNumber].Rcov();
131 }
132 //! \overload
133 double getRcovalent(const std::string &elementSymbol) const {
134 PRECONDITION(byname.count(elementSymbol),
135 "Element '" + elementSymbol + "' not found");
136 return getRcovalent(byname.find(elementSymbol)->second);
137 }
138 //! \overload
139 double getRcovalent(const char *elementSymbol) const {
140 return getRcovalent(std::string(elementSymbol));
141 }
142
143 //! returns the atom's bond radius
144 double getRb0(UINT atomicNumber) const {
145 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
146 return byanum[atomicNumber].Rb0();
147 }
148 //! \overload
149 double getRb0(const std::string &elementSymbol) const {
150 PRECONDITION(byname.count(elementSymbol),
151 "Element '" + elementSymbol + "' not found");
152 return getRb0(byname.find(elementSymbol)->second);
153 }
154 //! \overload
155 double getRb0(const char *elementSymbol) const {
156 return getRb0(std::string(elementSymbol));
157 }
158
159 //! returns the atom's default valence
160 int getDefaultValence(UINT atomicNumber) const {
161 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
162 return byanum[atomicNumber].DefaultValence();
163 }
164 //! \overload
165 int getDefaultValence(const std::string &elementSymbol) const {
166 PRECONDITION(byname.count(elementSymbol),
167 "Element '" + elementSymbol + "' not found");
168 return getDefaultValence(byname.find(elementSymbol)->second);
169 }
170 //! \overload
171 int getDefaultValence(const char *elementSymbol) const {
172 return getDefaultValence(std::string(elementSymbol));
173 }
174
175 //! returns a vector of all stable valences. For atoms where
176 //! we really don't have any idea what a reasonable maximum
177 //! valence is (like transition metals), the vector ends with -1
178 const INT_VECT &getValenceList(UINT atomicNumber) const {
179 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
180 return byanum[atomicNumber].ValenceList();
181 }
182 //! \overload
183 const INT_VECT &getValenceList(const std::string &elementSymbol) const {
184 PRECONDITION(byname.count(elementSymbol),
185 "Element '" + elementSymbol + "' not found");
186 return getValenceList(byname.find(elementSymbol)->second);
187 }
188 //! \overload
189 const INT_VECT &getValenceList(const char *elementSymbol) const {
190 return getValenceList(std::string(elementSymbol));
191 }
192
193 //! returns the number of outer shell electrons
194 int getNouterElecs(UINT atomicNumber) const {
195 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
196 return byanum[atomicNumber].NumOuterShellElec();
197 }
198 //! \overload
199 int getNouterElecs(const std::string &elementSymbol) const {
200 PRECONDITION(byname.count(elementSymbol),
201 "Element '" + elementSymbol + "' not found");
202 return getNouterElecs(byname.find(elementSymbol)->second);
203 }
204 //! \overload
205 int getNouterElecs(const char *elementSymbol) const {
206 return getNouterElecs(std::string(elementSymbol));
207 }
208
209 //! returns the number of the most common isotope
210 int getMostCommonIsotope(UINT atomicNumber) const {
211 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
212 return byanum[atomicNumber].MostCommonIsotope();
213 }
214 //! \overload
215 int getMostCommonIsotope(const std::string &elementSymbol) const {
216 PRECONDITION(byname.count(elementSymbol),
217 "Element '" + elementSymbol + "' not found");
218 return getMostCommonIsotope(byname.find(elementSymbol)->second);
219 }
220 //! \overload
221 int getMostCommonIsotope(const char *elementSymbol) const {
222 return getMostCommonIsotope(std::string(elementSymbol));
223 }
224
225 //! returns the mass of the most common isotope
226 double getMostCommonIsotopeMass(UINT atomicNumber) const {
227 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
228 return byanum[atomicNumber].MostCommonIsotopeMass();
229 }
230 //! \overload
231 double getMostCommonIsotopeMass(const std::string &elementSymbol) const {
232 PRECONDITION(byname.count(elementSymbol),
233 "Element '" + elementSymbol + "' not found");
234 return getMostCommonIsotopeMass(byname.find(elementSymbol)->second);
235 }
236 //! \overload
237 double getMostCommonIsotopeMass(const char *elementSymbol) const {
238 return getMostCommonIsotopeMass(std::string(elementSymbol));
239 }
240
241 //! returns the mass of a particular isotope; zero if that
242 //! isotope is unknown.
243 double getMassForIsotope(UINT atomicNumber, UINT isotope) const {
244 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
245 const std::map<unsigned int, std::pair<double, double>> &m =
246 byanum[atomicNumber].d_isotopeInfoMap;
247 std::map<unsigned int, std::pair<double, double>>::const_iterator item =
248 m.find(isotope);
249 if (item == m.end()) {
250 return 0.0;
251 } else {
252 return item->second.first;
253 }
254 }
255 //! \overload
256 double getMassForIsotope(const std::string &elementSymbol,
257 UINT isotope) const {
258 PRECONDITION(byname.count(elementSymbol),
259 "Element '" + elementSymbol + "' not found");
260 return getMassForIsotope(byname.find(elementSymbol)->second, isotope);
261 }
262 //! \overload
263 double getMassForIsotope(const char *elementSymbol, UINT isotope) const {
264 return getMassForIsotope(std::string(elementSymbol), isotope);
265 }
266 //! returns the abundance of a particular isotope; zero if that
267 //! isotope is unknown.
268 double getAbundanceForIsotope(UINT atomicNumber, UINT isotope) const {
269 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
270 const std::map<unsigned int, std::pair<double, double>> &m =
271 byanum[atomicNumber].d_isotopeInfoMap;
272 std::map<unsigned int, std::pair<double, double>>::const_iterator item =
273 m.find(isotope);
274 if (item == m.end()) {
275 return 0.0;
276 } else {
277 return item->second.second;
278 }
279 }
280 //! \overload
281 double getAbundanceForIsotope(const std::string &elementSymbol,
282 UINT isotope) const {
283 PRECONDITION(byname.count(elementSymbol),
284 "Element '" + elementSymbol + "' not found");
285 return getAbundanceForIsotope(byname.find(elementSymbol)->second, isotope);
286 }
287 //! \overload
288 double getAbundanceForIsotope(const char *elementSymbol, UINT isotope) const {
289 return getAbundanceForIsotope(std::string(elementSymbol), isotope);
290 }
291
292 //! convenience function to determine which atom is more electronegative
293 /*!
294
295 check if atom with atomic number \c anum1 is more
296 electronegative than the one with \c anum2
297 this is rather lame but here is how we do it
298 - the atom with the higher number of outer shell electrons
299 is considered more electronegative
300 - if the # of outer shell elecs are the same
301 the atom with the lower atomic weight is more electronegative
302
303 */
304 bool moreElectroNegative(UINT anum1, UINT anum2) const {
305 PRECONDITION(anum1 < byanum.size(), "Atomic number not found");
306 PRECONDITION(anum2 < byanum.size(), "Atomic number not found");
307 // FIX: the atomic_data needs to have real electronegativity values
308 UINT ne1 = getNouterElecs(anum1);
309 UINT ne2 = getNouterElecs(anum2);
310 if (ne1 > ne2) {
311 return true;
312 }
313 if (ne1 == ne2) {
314 if (anum1 < anum2) {
315 return true;
316 }
317 }
318 return false;
319 }
320
321 //! returns the maximum recognized atomic number
322 UINT getMaxAtomicNumber() const { return byanum.size() - 1; }
323 //! returns the row of the periodic table
324 UINT getRow(UINT atomicNumber) const {
325 PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
326 return byanum[atomicNumber].Row();
327 }
328 //! \overload
329 UINT getRow(const std::string &elementSymbol) const {
330 PRECONDITION(byname.count(elementSymbol),
331 "Element '" + elementSymbol + "' not found");
332 return getRow(byname.find(elementSymbol)->second);
333 }
334 //! \overload
335 UINT getRow(const char *elementSymbol) const {
336 return getRow(std::string(elementSymbol));
337 }
338
339 private:
341 static void initInstance();
342
343 static class std::unique_ptr<PeriodicTable> ds_instance;
344
345 std::vector<atomicData> byanum;
346 STR_UINT_MAP byname;
347};
348}; // namespace RDKit
349
350#endif
#define POSTCONDITION(expr, mess)
Definition Invariant.h:116
#define PRECONDITION(expr, mess)
Definition Invariant.h:108
No user-serviceable parts inside.
singleton class for retrieving information about atoms
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...
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...
int getAtomicNumber(const std::string &elementSymbol) const
overload
double getRvdw(UINT atomicNumber) const
returns the atom's van der Waals radius
int getAtomicNumber(const char *elementSymbol) const
returns the atomic number
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...
UINT getRow(UINT atomicNumber) const
returns the row of the periodic table
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
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...
UINT getRow(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
PeriodicTable(const PeriodicTable &)=delete
double getMassForIsotope(const char *elementSymbol, UINT isotope) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
UINT getRow(const char *elementSymbol) 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
PeriodicTable & operator=(const PeriodicTable &)=delete
bool moreElectroNegative(UINT anum1, UINT anum2) const
convenience function to determine which atom is more electronegative
UINT getMaxAtomicNumber() const
returns the maximum recognized atomic number
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...
std::string getElementName(UINT atomicNumber) const
returns the full element name
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:321
Std stuff.
std::vector< int > INT_VECT
Definition types.h:223
std::map< std::string, UINT > STR_UINT_MAP
Definition types.h:255
unsigned int UINT
Definition types.h:219