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 #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 */
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 
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  static void initInstance();
314 
315  static class PeriodicTable *ds_instance;
316 
317  std::vector<atomicData> byanum;
318  STR_UINT_MAP byname;
319 };
320 };
321 
322 #endif
#define POSTCONDITION(expr, mess)
Definition: Invariant.h:115
double getRvdw(const char *elementSymbol) const
double getRb0(const char *elementSymbol) const
bool moreElectroNegative(UINT anum1, UINT anum2) const
convenience function to determine which atom is more electronegative
int getDefaultValence(UINT atomicNumber) const
returns the atom&#39;s default valence
double getAbundanceForIsotope(const char *elementSymbol, UINT isotope) const
int getNouterElecs(UINT atomicNumber) const
returns the number of outer shell electrons
double getAbundanceForIsotope(UINT atomicNumber, UINT isotope) const
int getNouterElecs(const std::string &elementSymbol) const
double getAtomicWeight(const std::string &elementSymbol) const
Definition: PeriodicTable.h:58
double getRcovalent(const std::string &elementSymbol) const
int getDefaultValence(const std::string &elementSymbol) const
double getMassForIsotope(const std::string &elementSymbol, UINT isotope) const
int getAtomicNumber(const char *elementSymbol) const
returns the atomic number
Definition: PeriodicTable.h:70
double getAtomicWeight(const char *elementSymbol) const
Definition: PeriodicTable.h:65
double getRvdw(const std::string &elementSymbol) const
No user-serviceable parts inside.
double getMostCommonIsotopeMass(UINT atomicNumber) const
returns the mass of the most common isotope
double getMostCommonIsotopeMass(const char *elementSymbol) const
int getMostCommonIsotope(const char *elementSymbol) const
int getMostCommonIsotope(UINT atomicNumber) const
returns the number of the most common isotope
int getNouterElecs(const char *elementSymbol) const
std::map< std::string, UINT > STR_UINT_MAP
Definition: types.h:220
std::string getElementSymbol(UINT atomicNumber) const
returns the atomic symbol
Definition: PeriodicTable.h:95
std::vector< int > INT_VECT
Definition: types.h:188
int getAtomicNumber(const std::string &elementSymbol) const
overload
Definition: PeriodicTable.h:76
double getMostCommonIsotopeMass(const std::string &elementSymbol) const
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
unsigned int UINT
Definition: types.h:184
double getMassForIsotope(UINT atomicNumber, UINT isotope) const
double getAtomicWeight(UINT atomicNumber) const
returns the atomic weight
Definition: PeriodicTable.h:52
singleton class for retrieving information about atoms
Definition: PeriodicTable.h:31
double getRcovalent(const char *elementSymbol) const
double getRvdw(UINT atomicNumber) const
returns the atom&#39;s van der Waals radius
static PeriodicTable * getTable()
returns a pointer to the singleton PeriodicTable
int getDefaultValence(const char *elementSymbol) const
double getAbundanceForIsotope(const std::string &elementSymbol, UINT isotope) const
const INT_VECT & getValenceList(const std::string &elementSymbol) const
double getRb0(const std::string &elementSymbol) const
#define PRECONDITION(expr, mess)
Definition: Invariant.h:107
int getMostCommonIsotope(const std::string &elementSymbol) const
const INT_VECT & getValenceList(const char *elementSymbol) const
double getRcovalent(UINT atomicNumber) const
returns the atom&#39;s covalent radius
const INT_VECT & getValenceList(UINT atomicNumber) const
double getRb0(UINT atomicNumber) const
returns the atom&#39;s bond radius
double getMassForIsotope(const char *elementSymbol, UINT isotope) const