RDCode: PeriodicTable.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories

# PeriodicTable.h

Go to the documentation of this file.

    00001 //
    00002 //  Copyright (C) 2001-2006 Rational Discovery LLC
    00003 //
    00004 //   @@ All Rights Reserved  @@
    00005 //
    00006 #ifndef _RD_PERIODIC_TABLE_H
    00007 #define _RD_PERIODIC_TABLE_H
    00008
    00009 #include <map>
    00010 #include <vector>
    00011 #include <RDGeneral/types.h>
    00012 #include "atomic_data.h"
    00013
    00014 namespace RDKit {
    00015
    00016   //! singleton class for retrieving information about atoms
    00017   /*!
    00018     Use the singleton like this:
    00019
    00020     \verbatim
    00021     const PeriodicTable *tbl = PeriodicTable::getTable();
    00022     tbl->getAtomicWeight(6); // get atomic weight for Carbon
    00023     tbl->getAtomicWeight("C"); // get atomic weight for Carbon
    00024     \endverbatim
    00025
    00026   */
    00027   class PeriodicTable {
    00028
    00029   public:
    00030
    00031     //! returns a pointer to the singleton PeriodicTable
    00032     /*
    00033         \return a pointer to the singleton ParamCollection
    00034
    00035         <b>Notes:</b>
    00036           - do <b>not</b> delete the pointer returned here
    00037           - if the singleton PeriodicTable has already been instantiated and
    00038             the singleton will be returned, otherwise the singleton will
    00039             be constructed.
    00040
    00041      */
    00042     static PeriodicTable *getTable();
    00043
    00044     ~PeriodicTable() {
    00045       byanum.clear();
    00046       byname.clear();
    00047     };
    00048
    00049
    00050     //! returns the atomic weight
    00051     double getAtomicWeight( UINT atomicNumber ) const {
    00052       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00053       double mass = byanum[atomicNumber].Mass();
    00054       return mass;
    00055     }
    00056     //! \overload
    00057     double getAtomicWeight( const std::string &elementSymbol) const {
    00058       PRECONDITION(byname.count(elementSymbol),"Element not found");
    00059       int anum = byname.find(elementSymbol)->second;
    00060       double mass = byanum[anum].Mass();
    00061       return mass;
    00062     }
    00063     //! \overload
    00064     double getAtomicWeight( char * elementSymbol ) const {
    00065       return getAtomicWeight(std::string(elementSymbol));
    00066     }
    00067
    00068     //! returns the atomic number
    00069     int getAtomicNumber( char *elementSymbol ) const {
    00070       std::string symb(elementSymbol);
    00071
    00072       return getAtomicNumber(symb);
    00073     }
    00074     //! overload
    00075     int getAtomicNumber( const std::string &elementSymbol ) const {
    00076       PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
    00077       int anum = byname.find(elementSymbol)->second;
    00078       return anum;
    00079     }
    00080
    00081     //! returns the atomic symbol
    00082     std::string getElementSymbol(UINT atomicNumber) const {
    00083       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00084       return byanum[atomicNumber].Symbol();
    00085     }
    00086
    00087     //! returns the atom's van der Waals radius
    00088     double getRvdw(UINT atomicNumber) const {
    00089       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00090       return byanum[atomicNumber].Rvdw();
    00091     }
    00092     //! \overload
    00093     double getRvdw(const std::string &elementSymbol ) const {
    00094       PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
    00095       return getRvdw(byname.find(elementSymbol)->second);
    00096     }
    00097     //! \overload
    00098     double getRvdw(char *elementSymbol ) const {
    00099       return getRvdw(std::string(elementSymbol));
    00100     }
    00101
    00102     //! returns the atom's covalent radius
    00103     double getRcovalent(UINT atomicNumber) const {
    00104       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00105       return byanum[atomicNumber].Rcov();
    00106     }
    00107     //! \overload
    00108     double getRcovalent(const std::string &elementSymbol) const {
    00109       PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
    00110       return getRcovalent(byname.find(elementSymbol)->second);
    00111     }
    00112     //! \overload
    00113     double getRcovalent(char *elementSymbol ) const {
    00114       return getRcovalent(std::string(elementSymbol));
    00115     }
    00116
    00117     //! returns the atom's bond radius
    00118     double getRb0(UINT atomicNumber) const {
    00119       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00120       return byanum[atomicNumber].Rb0();
    00121     }
    00122     //! \overload
    00123     double getRb0(const std::string &elementSymbol) const {
    00124       PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
    00125       return getRb0(byname.find(elementSymbol)->second);
    00126     }
    00127     //! \overload
    00128     double getRb0(char *elementSymbol ) const {
    00129       return getRb0(std::string(elementSymbol));
    00130     }
    00131
    00132     //! returns the atom's default valence
    00133     int getDefaultValence(UINT atomicNumber) const {
    00134       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00135       return byanum[atomicNumber].DefaultValence();
    00136     }
    00137     //! \overload
    00138     int getDefaultValence(const std::string &elementSymbol) const {
    00139       PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
    00140       return getDefaultValence(byname.find(elementSymbol)->second);
    00141     }
    00142     //! \overload
    00143     int getDefaultValence(char *elementSymbol ) const {
    00144       return getDefaultValence(std::string(elementSymbol));
    00145     }
    00146
    00147     //! returns a vector of all stable valences. For atoms where
    00148     //! we really don't have any idea what a reasonable maximum
    00149     //! valence is (like transition metals), the vector ends with -1
    00150     const INT_VECT &getValenceList( UINT atomicNumber ) const {
    00151       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00152       return byanum[atomicNumber].ValenceList();
    00153     }
    00154     //! \overload
    00155     const INT_VECT &getValenceList( const std::string &elementSymbol) const {
    00156       PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
    00157       return getValenceList(byname.find(elementSymbol)->second);
    00158     }
    00159     //! \overload
    00160     const INT_VECT &getValenceList(char *elementSymbol ) const {
    00161       return getValenceList(std::string(elementSymbol));
    00162     }
    00163
    00164     //! returns the number of outer shell electrons
    00165     int getNouterElecs( UINT atomicNumber ) const {
    00166       PRECONDITION(atomicNumber<byanum.size(),"Atomic number not found");
    00167       return byanum[atomicNumber].NumOuterShellElec();
    00168     }
    00169     //! \overload
    00170     int getNouterElecs( const std::string &elementSymbol) const {
    00171       PRECONDITION(byname.count(elementSymbol),"Element '" + elementSymbol +"' not found");
    00172       return getNouterElecs(byname.find(elementSymbol)->second);
    00173     }
    00174     //! \overload
    00175     int getNouterElecs(char *elementSymbol ) const {
    00176       return getNouterElecs(std::string(elementSymbol));
    00177     }
    00178
    00179     //! convenience function to determine which atom is more electronegative
    00180     /*!
    00181
    00182        check if atom with atomic number \c anum1 is more
    00183        electronegative than the one with \c anum2
    00184        this is rather lame but here is how we do it
    00185          - the atom with the higher number of outer shell electrons
    00186            is considered more electronegative
    00187          - if the # of outer shell elecs are the same
    00188            the atom with the lower atomic weight is more electronegative
    00189
    00190     */
    00191     bool moreElectroNegative(UINT anum1, UINT anum2) const {
    00192       PRECONDITION(anum1<byanum.size(),"Atomic number not found");
    00193       PRECONDITION(anum2<byanum.size(),"Atomic number not found");
    00194       // FIX: the atomic_data needs to have real electronegativity values
    00195       UINT ne1 = getNouterElecs(anum1);
    00196       UINT ne2 = getNouterElecs(anum2);
    00197       if (ne1 > ne2) {
    00198         return true;
    00199       }
    00200       if (ne1 == ne2) {
    00201         if (anum1 < anum2) {
    00202           return true;
    00203         }
    00204       }
    00205       return false;
    00206     }
    00207
    00208
    00209   private:
    00210
    00211     PeriodicTable();
    00212     PeriodicTable &operator =( const PeriodicTable & );
    00213
    00214     static class PeriodicTable *ds_instance;
    00215
    00216     std::vector<atomicData> byanum;
    00217     STR_UINT_MAP byname;
    00218   };
    00219
    00220 };
    00221
    00222 #endif