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