00001 /********************************************************************** 00002 descriptor.h - Base class for molecular descriptors 00003 00004 Copyright (C) 2007 by Chris Morley 00005 00006 This file is part of the Open Babel project. 00007 For more information, see <http://openbabel.sourceforge.net/> 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 ***********************************************************************/ 00018 00019 #ifndef OB_DESCRIPTOR_H 00020 #define OB_DESCRIPTOR_H 00021 00022 #include <string> 00023 #include <sstream> 00024 #include <limits> 00025 00026 #include <openbabel/plugin.h> 00027 00028 namespace OpenBabel 00029 { 00030 class OBBase; //Forward declaration; used only as pointer. 00031 00032 // Class introduction in descriptor.cpp 00033 class OBAPI OBDescriptor : public OBPlugin 00034 { 00035 MAKE_PLUGIN(OBDescriptor) 00036 00037 public: 00038 const char* TypeID(){return "descriptors";}; 00039 00041 virtual double Predict(OBBase* pOb){return std::numeric_limits<double>::quiet_NaN();} 00042 00044 double PredictAndSave(OBBase* pOb); 00045 00047 virtual double GetStringValue(OBBase* pOb, std::string& svalue); 00048 00050 virtual bool Compare(OBBase* pOb, std::istream& ss, bool noEval); 00051 00055 virtual bool Display(std::string&txt, const char* param, const char* ID=NULL); 00056 00058 static bool FilterCompare(OBBase* pOb, std::istream& ss, bool noEval); 00059 00061 static void AddProperties(OBBase* pOb, const std::string& DescrList); 00062 00064 static void DeleteProperties(OBBase* pOb, const std::string& DescrList); 00065 00068 static std::string GetValues(OBBase* pOb, const std::string& DescrList); 00069 00070 protected: 00072 static std::string GetIdentifier(std::istream& optionText); 00073 00074 static double ParsePredicate(std::istream& optionText, char& ch1, char& ch2, std::string& svalue); 00075 00078 static bool ReadStringFromFilter(std::istream& ss, std::string& result); 00079 00082 static bool CompareStringWithFilter(std::istream& optionText, std::string& s, bool noEval, bool NoCompOK=false); 00083 00084 // Treats _ as not a punctuation character 00085 static bool ispunctU(char ch) 00086 { 00087 return ispunct(ch) && ch!='_'; 00088 } 00089 00091 static bool MatchPairData(OBBase* pOb, std::string& s); 00092 00093 }; 00094 00095 template <class T> 00096 static bool DoComparison(char ch1, char ch2, T& val, T& filterval) 00097 { 00098 switch(ch1) 00099 { 00100 case (0): //no comparison operator is same as = 00101 case('='): 00102 return val==filterval; //**needs a better floating point comparison** 00103 case('!'): 00104 return val!=filterval; //**needs a better floating point comparison** 00105 case('>'): 00106 if(ch2=='=') 00107 return val>=filterval; 00108 else 00109 return val>filterval; 00110 case('<'): 00111 if(ch2=='=') 00112 return val<=filterval; 00113 else 00114 return val<filterval; 00115 } 00116 return false; 00117 } 00118 00119 }//namespace 00120 #endif 00121
This file is part of the documentation for Open Babel, version 2.2.0.