1 // $Id$ 2 // 3 // Copyright (C) 2003-2006 Rational Discovery LLC 4 // 5 // @@ All Rights Reserved @@ 6 // This file is part of the RDKit. 7 // The contents are covered by the terms of the BSD license 8 // which is included in the file license.txt, found at the root 9 // of the RDKit source tree. 10 // 11 #include <boost/tokenizer.hpp> 12 typedef boost::tokenizer<boost::char_separator<char> > tokenizer; 13 #include "GasteigerParams.h" 14 15 #include <RDGeneral/BoostStartInclude.h> 16 #include <boost/flyweight.hpp> 17 #include <boost/flyweight/key_value.hpp> 18 #include <boost/flyweight/no_tracking.hpp> 19 #include <RDGeneral/BoostEndInclude.h> 20 21 #include <sstream> 22 #include <locale> 23 24 namespace RDKit { 25 26 /*! \brief Gasteiger partial charge parameters 27 */ 28 std::string defaultParamData = 29 "H * 7.17 6.24 -0.56 \n \ 30 C sp3 7.98 9.18 1.88 \n \ 31 C sp2 8.79 9.32 1.51 \n \ 32 C sp 10.39 9.45 0.73 \n \ 33 N sp3 11.54 10.82 1.36 \n \ 34 N sp2 12.87 11.15 0.85 \n \ 35 N sp 15.68 11.7 -0.27 \n \ 36 O sp3 14.18 12.92 1.39 \n \ 37 O sp2 17.07 13.79 0.47 \n \ 38 F sp3 14.66 13.85 2.31 \n \ 39 Cl sp3 11.00 9.69 1.35 \n \ 40 Br sp3 10.08 8.47 1.16 \n \ 41 I sp3 9.9 7.96 0.96 \n \ 42 S sp3 10.14 9.13 1.38 \n \ 43 S so 10.14 9.13 1.38 \n \ 44 S so2 12.00 10.81 1.20 \n \ 45 S sp2 10.88 9.49 1.33 \n \ 46 P sp3 8.90 8.24 0.96 \n \ 47 X * 0.00 0.00 0.00 \n \ 48 "; 49 50 /*! \brief additional Gasteiger partial charge parameters 51 generated using the calculation in PyBabel: 52 http://mgltools.scripps.edu/api/PyBabel/PyBabel.gasteiger-pysrc.html 53 54 */ 55 std::string additionalParamData = 56 "P sp2 9.665 8.530 0.735 \n \ 57 Si sp3 7.300 6.567 0.657 \n \ 58 Si sp2 7.905 6.748 0.443 \n \ 59 Si sp 9.065 7.027 -0.002 \n \ 60 B sp3 5.980 6.820 1.605 \n \ 61 B sp2 6.420 6.807 1.322 \n \ 62 Be sp3 3.845 6.755 3.165 \n \ 63 Be sp2 4.005 6.725 3.035 \n \ 64 Mg sp2 3.565 5.572 2.197 \n \ 65 Mg sp3 3.300 5.587 2.447 \n \ 66 Mg sp 4.040 5.472 1.823 \n \ 67 Al sp3 5.375 4.953 0.867 \n \ 68 Al sp2 5.795 5.020 0.695 \n \ 69 "; 70 71 typedef boost::flyweight< 72 boost::flyweights::key_value<std::string, GasteigerParams>, 73 boost::flyweights::no_tracking> gparam_flyweight; 74 GasteigerParams(std::string paramData)75GasteigerParams::GasteigerParams(std::string paramData) { 76 boost::char_separator<char> eolSep("\n"); 77 boost::char_separator<char> spaceSep(" \t"); 78 if (paramData == "") { 79 paramData = defaultParamData + additionalParamData; 80 } 81 tokenizer lines(paramData, eolSep); 82 d_paramMap.clear(); 83 std::istringstream istr; 84 istr.imbue(std::locale("C")); 85 for (tokenizer::iterator lineIter = lines.begin(); lineIter != lines.end(); 86 ++lineIter) { 87 std::string dataLine = *lineIter; 88 tokenizer tokens(dataLine, spaceSep); 89 if (tokens.begin() != tokens.end()) { 90 tokenizer::iterator tokIter = tokens.begin(); 91 92 // read the element and the mode 93 std::string elem = *tokIter; 94 ++tokIter; 95 std::string mode = *tokIter; 96 ++tokIter; 97 98 // read in the parameters 99 DOUBLE_VECT params(3); 100 101 istr.clear(); 102 istr.str(*tokIter); 103 istr >> params[0]; 104 ++tokIter; 105 istr.clear(); 106 istr.str(*tokIter); 107 istr >> params[1]; 108 ++tokIter; 109 istr.clear(); 110 istr.str(*tokIter); 111 istr >> params[2]; 112 ++tokIter; 113 114 std::pair<std::string, std::string> key(elem, mode); 115 d_paramMap[key] = params; 116 } 117 } 118 } 119 getParams(const std::string & paramData)120const GasteigerParams *GasteigerParams::getParams( 121 const std::string ¶mData) { 122 const GasteigerParams *res = &(gparam_flyweight(paramData).get()); 123 return res; 124 } 125 } 126