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 
19 namespace 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  */
45  static PeriodicTable *getTable();
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()) anum = iter->second;
90  }
91  POSTCONDITION(anum > -1, "Element '" + elementSymbol + "' not found");
92  return anum;
93  }
94 
95  //! returns the atomic symbol
96  std::string getElementSymbol(UINT atomicNumber) const {
97  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
98  return byanum[atomicNumber].Symbol();
99  }
100 
101  //! returns the atom's van der Waals radius
102  double getRvdw(UINT atomicNumber) const {
103  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
104  return byanum[atomicNumber].Rvdw();
105  }
106  //! \overload
107  double getRvdw(const std::string &elementSymbol) const {
108  PRECONDITION(byname.count(elementSymbol),
109  "Element '" + elementSymbol + "' not found");
110  return getRvdw(byname.find(elementSymbol)->second);
111  }
112  //! \overload
113  double getRvdw(const char *elementSymbol) const {
114  return getRvdw(std::string(elementSymbol));
115  }
116 
117  //! returns the atom's covalent radius
118  double getRcovalent(UINT atomicNumber) const {
119  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
120  return byanum[atomicNumber].Rcov();
121  }
122  //! \overload
123  double getRcovalent(const std::string &elementSymbol) const {
124  PRECONDITION(byname.count(elementSymbol),
125  "Element '" + elementSymbol + "' not found");
126  return getRcovalent(byname.find(elementSymbol)->second);
127  }
128  //! \overload
129  double getRcovalent(const char *elementSymbol) const {
130  return getRcovalent(std::string(elementSymbol));
131  }
132 
133  //! returns the atom's bond radius
134  double getRb0(UINT atomicNumber) const {
135  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
136  return byanum[atomicNumber].Rb0();
137  }
138  //! \overload
139  double getRb0(const std::string &elementSymbol) const {
140  PRECONDITION(byname.count(elementSymbol),
141  "Element '" + elementSymbol + "' not found");
142  return getRb0(byname.find(elementSymbol)->second);
143  }
144  //! \overload
145  double getRb0(const char *elementSymbol) const {
146  return getRb0(std::string(elementSymbol));
147  }
148 
149  //! returns the atom's default valence
150  int getDefaultValence(UINT atomicNumber) const {
151  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
152  return byanum[atomicNumber].DefaultValence();
153  }
154  //! \overload
155  int getDefaultValence(const std::string &elementSymbol) const {
156  PRECONDITION(byname.count(elementSymbol),
157  "Element '" + elementSymbol + "' not found");
158  return getDefaultValence(byname.find(elementSymbol)->second);
159  }
160  //! \overload
161  int getDefaultValence(const char *elementSymbol) const {
162  return getDefaultValence(std::string(elementSymbol));
163  }
164 
165  //! returns a vector of all stable valences. For atoms where
166  //! we really don't have any idea what a reasonable maximum
167  //! valence is (like transition metals), the vector ends with -1
168  const INT_VECT &getValenceList(UINT atomicNumber) const {
169  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
170  return byanum[atomicNumber].ValenceList();
171  }
172  //! \overload
173  const INT_VECT &getValenceList(const std::string &elementSymbol) const {
174  PRECONDITION(byname.count(elementSymbol),
175  "Element '" + elementSymbol + "' not found");
176  return getValenceList(byname.find(elementSymbol)->second);
177  }
178  //! \overload
179  const INT_VECT &getValenceList(const char *elementSymbol) const {
180  return getValenceList(std::string(elementSymbol));
181  }
182 
183  //! returns the number of outer shell electrons
184  int getNouterElecs(UINT atomicNumber) const {
185  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
186  return byanum[atomicNumber].NumOuterShellElec();
187  }
188  //! \overload
189  int getNouterElecs(const std::string &elementSymbol) const {
190  PRECONDITION(byname.count(elementSymbol),
191  "Element '" + elementSymbol + "' not found");
192  return getNouterElecs(byname.find(elementSymbol)->second);
193  }
194  //! \overload
195  int getNouterElecs(const char *elementSymbol) const {
196  return getNouterElecs(std::string(elementSymbol));
197  }
198 
199  //! returns the number of the most common isotope
200  int getMostCommonIsotope(UINT atomicNumber) const {
201  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
202  return byanum[atomicNumber].MostCommonIsotope();
203  }
204  //! \overload
205  int getMostCommonIsotope(const std::string &elementSymbol) const {
206  PRECONDITION(byname.count(elementSymbol),
207  "Element '" + elementSymbol + "' not found");
208  return getMostCommonIsotope(byname.find(elementSymbol)->second);
209  }
210  //! \overload
211  int getMostCommonIsotope(const char *elementSymbol) const {
212  return getMostCommonIsotope(std::string(elementSymbol));
213  }
214 
215  //! returns the mass of the most common isotope
216  double getMostCommonIsotopeMass(UINT atomicNumber) const {
217  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
218  return byanum[atomicNumber].MostCommonIsotopeMass();
219  }
220  //! \overload
221  double getMostCommonIsotopeMass(const std::string &elementSymbol) const {
222  PRECONDITION(byname.count(elementSymbol),
223  "Element '" + elementSymbol + "' not found");
224  return getMostCommonIsotopeMass(byname.find(elementSymbol)->second);
225  }
226  //! \overload
227  double getMostCommonIsotopeMass(const char *elementSymbol) const {
228  return getMostCommonIsotopeMass(std::string(elementSymbol));
229  }
230 
231  //! returns the mass of a particular isotope; zero if that
232  //! isotope is unknown.
233  double getMassForIsotope(UINT atomicNumber, UINT isotope) const {
234  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
235  const std::map<unsigned int, std::pair<double, double>> &m =
236  byanum[atomicNumber].d_isotopeInfoMap;
237  std::map<unsigned int, std::pair<double, double>>::const_iterator item =
238  m.find(isotope);
239  if (item == m.end()) {
240  return 0.0;
241  } else {
242  return item->second.first;
243  }
244  }
245  //! \overload
246  double getMassForIsotope(const std::string &elementSymbol,
247  UINT isotope) const {
248  PRECONDITION(byname.count(elementSymbol),
249  "Element '" + elementSymbol + "' not found");
250  return getMassForIsotope(byname.find(elementSymbol)->second, isotope);
251  }
252  //! \overload
253  double getMassForIsotope(const char *elementSymbol, UINT isotope) const {
254  return getMassForIsotope(std::string(elementSymbol), isotope);
255  }
256  //! returns the abundance of a particular isotope; zero if that
257  //! isotope is unknown.
258  double getAbundanceForIsotope(UINT atomicNumber, UINT isotope) const {
259  PRECONDITION(atomicNumber < byanum.size(), "Atomic number not found");
260  const std::map<unsigned int, std::pair<double, double>> &m =
261  byanum[atomicNumber].d_isotopeInfoMap;
262  std::map<unsigned int, std::pair<double, double>>::const_iterator item =
263  m.find(isotope);
264  if (item == m.end()) {
265  return 0.0;
266  } else {
267  return item->second.second;
268  }
269  }
270  //! \overload
271  double getAbundanceForIsotope(const std::string &elementSymbol,
272  UINT isotope) const {
273  PRECONDITION(byname.count(elementSymbol),
274  "Element '" + elementSymbol + "' not found");
275  return getAbundanceForIsotope(byname.find(elementSymbol)->second, isotope);
276  }
277  //! \overload
278  double getAbundanceForIsotope(const char *elementSymbol, UINT isotope) const {
279  return getAbundanceForIsotope(std::string(elementSymbol), isotope);
280  }
281 
282  //! convenience function to determine which atom is more electronegative
283  /*!
284 
285  check if atom with atomic number \c anum1 is more
286  electronegative than the one with \c anum2
287  this is rather lame but here is how we do it
288  - the atom with the higher number of outer shell electrons
289  is considered more electronegative
290  - if the # of outer shell elecs are the same
291  the atom with the lower atomic weight is more electronegative
292 
293  */
294  bool moreElectroNegative(UINT anum1, UINT anum2) const {
295  PRECONDITION(anum1 < byanum.size(), "Atomic number not found");
296  PRECONDITION(anum2 < byanum.size(), "Atomic number not found");
297  // FIX: the atomic_data needs to have real electronegativity values
298  UINT ne1 = getNouterElecs(anum1);
299  UINT ne2 = getNouterElecs(anum2);
300  if (ne1 > ne2) {
301  return true;
302  }
303  if (ne1 == ne2) {
304  if (anum1 < anum2) {
305  return true;
306  }
307  }
308  return false;
309  }
310 
311  private:
312  PeriodicTable();
313  PeriodicTable &operator=(const PeriodicTable &);
314  static void initInstance();
315 
316  static class std::unique_ptr<PeriodicTable> ds_instance;
317 
318  std::vector<atomicData> byanum;
319  STR_UINT_MAP byname;
320 };
321 }; // namespace RDKit
322 
323 #endif
POSTCONDITION
#define POSTCONDITION(expr, mess)
Definition: Invariant.h:117
RDKit::PeriodicTable::getRcovalent
double getRcovalent(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:129
RDKit::INT_VECT
std::vector< int > INT_VECT
Definition: types.h:254
types.h
RDKit::PeriodicTable::getAbundanceForIsotope
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...
Definition: PeriodicTable.h:271
RDKit::PeriodicTable::getRb0
double getRb0(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:145
RDKit::PeriodicTable::getAbundanceForIsotope
double getAbundanceForIsotope(const char *elementSymbol, UINT isotope) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:278
RDKit::PeriodicTable::getValenceList
const INT_VECT & getValenceList(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:179
RDKit::PeriodicTable::getNouterElecs
int getNouterElecs(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:195
RDKit::PeriodicTable
singleton class for retrieving information about atoms
Definition: PeriodicTable.h:32
RDKit::PeriodicTable::getDefaultValence
int getDefaultValence(UINT atomicNumber) const
returns the atom's default valence
Definition: PeriodicTable.h:150
RDKit::PeriodicTable::getNouterElecs
int getNouterElecs(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:189
RDKit::PeriodicTable::getNouterElecs
int getNouterElecs(UINT atomicNumber) const
returns the number of outer shell electrons
Definition: PeriodicTable.h:184
RDKit::PeriodicTable::getAtomicNumber
int getAtomicNumber(const char *elementSymbol) const
returns the atomic number
Definition: PeriodicTable.h:71
RDKit::PeriodicTable::getMostCommonIsotope
int getMostCommonIsotope(UINT atomicNumber) const
returns the number of the most common isotope
Definition: PeriodicTable.h:200
RDKit::PeriodicTable::getMostCommonIsotope
int getMostCommonIsotope(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:205
RDKit::PeriodicTable::getMassForIsotope
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...
Definition: PeriodicTable.h:246
RDKit::UINT
unsigned int UINT
Definition: types.h:250
RDKit::PeriodicTable::getAtomicNumber
int getAtomicNumber(const std::string &elementSymbol) const
overload
Definition: PeriodicTable.h:77
RDKit::STR_UINT_MAP
std::map< std::string, UINT > STR_UINT_MAP
Definition: types.h:286
RDKit::PeriodicTable::getRcovalent
double getRcovalent(UINT atomicNumber) const
returns the atom's covalent radius
Definition: PeriodicTable.h:118
RDKit::PeriodicTable::getRvdw
double getRvdw(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:107
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:307
RDKit::PeriodicTable::getMostCommonIsotopeMass
double getMostCommonIsotopeMass(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:227
RDKit::PeriodicTable::getMostCommonIsotope
int getMostCommonIsotope(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:211
RDKit::PeriodicTable::moreElectroNegative
bool moreElectroNegative(UINT anum1, UINT anum2) const
convenience function to determine which atom is more electronegative
Definition: PeriodicTable.h:294
RDKit::PeriodicTable::getValenceList
const INT_VECT & getValenceList(UINT atomicNumber) const
Definition: PeriodicTable.h:168
RDKit::PeriodicTable::getDefaultValence
int getDefaultValence(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:155
RDKit::PeriodicTable::getAbundanceForIsotope
double getAbundanceForIsotope(UINT atomicNumber, UINT isotope) const
Definition: PeriodicTable.h:258
RDKit::PeriodicTable::getRb0
double getRb0(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:139
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::PeriodicTable::getRb0
double getRb0(UINT atomicNumber) const
returns the atom's bond radius
Definition: PeriodicTable.h:134
RDKit::PeriodicTable::~PeriodicTable
~PeriodicTable()
Definition: PeriodicTable.h:47
RDKit::PeriodicTable::getMassForIsotope
double getMassForIsotope(const char *elementSymbol, UINT isotope) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:253
RDKit::PeriodicTable::getMostCommonIsotopeMass
double getMostCommonIsotopeMass(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:221
atomic_data.h
No user-serviceable parts inside.
RDKit::PeriodicTable::getElementSymbol
std::string getElementSymbol(UINT atomicNumber) const
returns the atomic symbol
Definition: PeriodicTable.h:96
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:109
RDKit::PeriodicTable::getRcovalent
double getRcovalent(const std::string &elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:123
RDKit::StructureCheck::getAtomicNumber
RDKIT_STRUCTCHECKER_EXPORT unsigned getAtomicNumber(const std::string symbol)
RDKit::PeriodicTable::getAtomicWeight
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
RDKit::PeriodicTable::getMostCommonIsotopeMass
double getMostCommonIsotopeMass(UINT atomicNumber) const
returns the mass of the most common isotope
Definition: PeriodicTable.h:216
RDKit::PeriodicTable::getAtomicWeight
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
RDKit::PeriodicTable::getRvdw
double getRvdw(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:113
RDKit::PeriodicTable::getAtomicWeight
double getAtomicWeight(UINT atomicNumber) const
returns the atomic weight
Definition: PeriodicTable.h:53
RDKit::PeriodicTable::getMassForIsotope
double getMassForIsotope(UINT atomicNumber, UINT isotope) const
Definition: PeriodicTable.h:233
RDKit::PeriodicTable::getDefaultValence
int getDefaultValence(const char *elementSymbol) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PeriodicTable.h:161
RDKit::PeriodicTable::getRvdw
double getRvdw(UINT atomicNumber) const
returns the atom's van der Waals radius
Definition: PeriodicTable.h:102
RDKit::PeriodicTable::getValenceList
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...
Definition: PeriodicTable.h:173
export.h