1 //
2 //  Copyright (C) 2003-2015 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_GASTEIGERPARAMS_H
12 #define _RD_GASTEIGERPARAMS_H
13 
14 #include <RDGeneral/types.h>
15 #include <RDGeneral/Exceptions.h>
16 #include <string>
17 #include <map>
18 
19 namespace RDKit {
20 extern std::string paramData;
21 extern std::string additionalParamData;
22 
23 // this is a constant used during the iteration procedure for the hydrogen atoms
24 // for the remaining atoms it is computed on the fly
25 const double IONXH = 20.02;
26 
27 const double DAMP_SCALE = 0.5;
28 const double DAMP = 0.5;
29 
30 class RDKIT_PARTIALCHARGES_EXPORT GasteigerParams {
31   /* \brief Container for all the partial charge parameters
32    *
33    * It is filled by the paramData string defined in GasteigerParams.cpp
34    * The main data member is a STL map that take a pair<std::string,
35    *std::string>
36    * of element name and mode (hybridization or bonding mode) and return a
37    *vector
38    * of three parameters, used in the iterative partial charges equalization
39    *procedure
40    */
41 
42  public:
43   static const GasteigerParams *getParams(const std::string &paramData = "");
44 
~GasteigerParams()45   ~GasteigerParams() { d_paramMap.clear(); }
46 
47   DOUBLE_VECT getParams(std::string elem, std::string mode,
48                         bool throwOnFailure = false) const {
49     std::pair<std::string, std::string> query(elem, mode);
50     std::map<std::pair<std::string, std::string>, DOUBLE_VECT>::const_iterator
51         iter;
52     iter = d_paramMap.find(query);
53     if (iter != d_paramMap.end()) {
54       return iter->second;
55     } else {
56       if (throwOnFailure) {
57         std::string message =
58             "ERROR: No Gasteiger Partial Charge parameters for Element: ";
59         message += elem;
60         message += " Mode: ";
61         message += mode;
62         throw ValueErrorException(message);
63       } else {
64         iter =
65             d_paramMap.find(std::make_pair(std::string("X"), std::string("*")));
66         if (iter != d_paramMap.end()) {
67           return iter->second;
68         } else {
69           std::string message =
70               "ERROR: Default Gasteiger Partial Charge parameters are missing";
71           throw ValueErrorException(message);
72         }
73       }
74     }
75   }
76 
77   GasteigerParams(std::string paramData = "");
78 
79  private:
80   std::map<std::pair<std::string, std::string>, DOUBLE_VECT> d_paramMap;
81 
82   static class GasteigerParams *ds_instance;
83 };
84 };  // namespace RDKit
85 
86 #endif
87