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  */
31  class PeriodicTable {
32 
33  public:
34 
35  //! returns a pointer to the singleton PeriodicTable
36  /*
37  \return a pointer to the singleton ParamCollection
38 
39  <b>Notes:</b>
40  - do <b>not</b> delete the pointer returned here
41  - if the singleton PeriodicTable has already been instantiated and
42  the singleton will be returned, otherwise the singleton will
43  be constructed.
44 
45  */
46  static PeriodicTable *getTable();
47 
49  byanum.clear();
50  byname.clear();
51  };
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") anum=6;
84  else if(elementSymbol=="N") anum=7;
85  else if(elementSymbol=="O") anum=8;
86  else{
87  STR_UINT_MAP::const_iterator iter=byname.find(elementSymbol);
88  if(iter!=byname.end())
89  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),"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),"Element '" + elementSymbol +"' not found");
124  return getRcovalent(byname.find(elementSymbol)->second);
125  }
126  //! \overload
127  double getRcovalent(const char *elementSymbol ) const {
128  return getRcovalent(std::string(elementSymbol));
129  }
130 
131  //! returns the atom's bond radius
132  double getRb0(UINT atomicNumber) const {
133  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
134  return byanum[atomicNumber].Rb0();
135  }
136  //! \overload
137  double getRb0(const std::string &elementSymbol) const {
138  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
139  return getRb0(byname.find(elementSymbol)->second);
140  }
141  //! \overload
142  double getRb0(const char *elementSymbol ) const {
143  return getRb0(std::string(elementSymbol));
144  }
145 
146  //! returns the atom's default valence
147  int getDefaultValence(UINT atomicNumber) const {
148  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
149  return byanum[atomicNumber].DefaultValence();
150  }
151  //! \overload
152  int getDefaultValence(const std::string &elementSymbol) const {
153  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
154  return getDefaultValence(byname.find(elementSymbol)->second);
155  }
156  //! \overload
157  int getDefaultValence(const char *elementSymbol ) const {
158  return getDefaultValence(std::string(elementSymbol));
159  }
160 
161  //! returns a vector of all stable valences. For atoms where
162  //! we really don't have any idea what a reasonable maximum
163  //! valence is (like transition metals), the vector ends with -1
164  const INT_VECT &getValenceList( UINT atomicNumber ) const {
165  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
166  return byanum[atomicNumber].ValenceList();
167  }
168  //! \overload
169  const INT_VECT &getValenceList( const std::string &elementSymbol) const {
170  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
171  return getValenceList(byname.find(elementSymbol)->second);
172  }
173  //! \overload
174  const INT_VECT &getValenceList(const char *elementSymbol ) const {
175  return getValenceList(std::string(elementSymbol));
176  }
177 
178  //! returns the number of outer shell electrons
179  int getNouterElecs( UINT atomicNumber ) const {
180  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
181  return byanum[atomicNumber].NumOuterShellElec();
182  }
183  //! \overload
184  int getNouterElecs( const std::string &elementSymbol) const {
185  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
186  return getNouterElecs(byname.find(elementSymbol)->second);
187  }
188  //! \overload
189  int getNouterElecs(const char *elementSymbol ) const {
190  return getNouterElecs(std::string(elementSymbol));
191  }
192 
193  //! returns the number of the most common isotope
194  int getMostCommonIsotope( UINT atomicNumber ) const {
195  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
196  return byanum[atomicNumber].MostCommonIsotope();
197  }
198  //! \overload
199  int getMostCommonIsotope( const std::string &elementSymbol) const {
200  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
201  return getMostCommonIsotope(byname.find(elementSymbol)->second);
202  }
203  //! \overload
204  int getMostCommonIsotope(const char *elementSymbol ) const {
205  return getMostCommonIsotope(std::string(elementSymbol));
206  }
207 
208  //! returns the mass of the most common isotope
209  double getMostCommonIsotopeMass( UINT atomicNumber ) const {
210  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
211  return byanum[atomicNumber].MostCommonIsotopeMass();
212  }
213  //! \overload
214  double getMostCommonIsotopeMass( const std::string &elementSymbol) const {
215  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
216  return getMostCommonIsotopeMass(byname.find(elementSymbol)->second);
217  }
218  //! \overload
219  double getMostCommonIsotopeMass(const char *elementSymbol ) const {
220  return getMostCommonIsotopeMass(std::string(elementSymbol));
221  }
222 
223 
224  //! returns the mass of a particular isotope; zero if that
225  //! isotope is unknown.
226  double getMassForIsotope( UINT atomicNumber, UINT isotope ) const {
227  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
228  const std::map<unsigned int,std::pair<double,double> > &m=byanum[atomicNumber].d_isotopeInfoMap;
229  std::map<unsigned int,std::pair<double,double> >::const_iterator item=m.find(isotope);
230  if(item==m.end()) {
231  return 0.0;
232  } else {
233  return item->second.first;
234  }
235  }
236  //! \overload
237  double getMassForIsotope( const std::string &elementSymbol, UINT isotope) const {
238  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
239  return getMassForIsotope(byname.find(elementSymbol)->second,isotope);
240  }
241  //! \overload
242  double getMassForIsotope(const char *elementSymbol, UINT isotope ) const {
243  return getMassForIsotope(std::string(elementSymbol),isotope);
244  }
245  //! returns the abundance of a particular isotope; zero if that
246  //! isotope is unknown.
247  double getAbundanceForIsotope( UINT atomicNumber, UINT isotope ) const {
248  PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
249  const std::map<unsigned int,std::pair<double,double> > &m=byanum[atomicNumber].d_isotopeInfoMap;
250  std::map<unsigned int,std::pair<double,double> >::const_iterator item=m.find(isotope);
251  if(item==m.end()) {
252  return 0.0;
253  } else {
254  return item->second.second;
255  }
256  }
257  //! \overload
258  double getAbundanceForIsotope( const std::string &elementSymbol, UINT isotope) const {
259  PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
260  return getAbundanceForIsotope(byname.find(elementSymbol)->second,isotope);
261  }
262  //! \overload
263  double getAbundanceForIsotope(const char *elementSymbol, UINT isotope ) const {
264  return getAbundanceForIsotope(std::string(elementSymbol),isotope);
265  }
266 
267 
268  //! convenience function to determine which atom is more electronegative
269  /*!
270 
271  check if atom with atomic number \c anum1 is more
272  electronegative than the one with \c anum2
273  this is rather lame but here is how we do it
274  - the atom with the higher number of outer shell electrons
275  is considered more electronegative
276  - if the # of outer shell elecs are the same
277  the atom with the lower atomic weight is more electronegative
278 
279  */
280  bool moreElectroNegative(UINT anum1, UINT anum2) const {
281  PRECONDITION(anum1<byanum.size(),"Atomic number not found");
282  PRECONDITION(anum2<byanum.size(),"Atomic number not found");
283  // FIX: the atomic_data needs to have real electronegativity values
284  UINT ne1 = getNouterElecs(anum1);
285  UINT ne2 = getNouterElecs(anum2);
286  if (ne1 > ne2) {
287  return true;
288  }
289  if (ne1 == ne2) {
290  if (anum1 < anum2) {
291  return true;
292  }
293  }
294  return false;
295  }
296 
297 
298  private:
299 
300  PeriodicTable();
301  PeriodicTable &operator =( const PeriodicTable & );
302 
303  static class PeriodicTable *ds_instance;
304 
305  std::vector<atomicData> byanum;
306  STR_UINT_MAP byname;
307  };
308 
309 };
310 
311 #endif
#define POSTCONDITION(expr, mess)
Definition: Invariant.h:124
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:61
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:73
double getAtomicWeight(const char *elementSymbol) const
Definition: PeriodicTable.h:68
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:179
std::string getElementSymbol(UINT atomicNumber) const
returns the atomic symbol
Definition: PeriodicTable.h:96
std::vector< int > INT_VECT
Definition: types.h:146
int getAtomicNumber(const std::string &elementSymbol) const
overload
Definition: PeriodicTable.h:79
double getMostCommonIsotopeMass(const std::string &elementSymbol) const
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
unsigned int UINT
Definition: types.h:142
double getMassForIsotope(UINT atomicNumber, UINT isotope) const
double getAtomicWeight(UINT atomicNumber) const
returns the atomic weight
Definition: PeriodicTable.h:55
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:119
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