RDKit: PeriodicTable.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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