descriptor.h
Go to the documentation of this file.
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.org/>
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/babelconfig.h>
00027 #include <openbabel/plugin.h>
00028 
00029 namespace OpenBabel
00030 {
00031 class OBBase; //Forward declaration; used only as pointer.
00032 
00033 // Class introduction in descriptor.cpp
00034 class OBAPI OBDescriptor : public OBPlugin
00035 {
00036   MAKE_PLUGIN(OBDescriptor)
00037 
00038 public:
00039   const char* TypeID(){return "descriptors";};
00040 
00042   virtual double Predict(OBBase* /* pOb */, std::string* /* param */ =NULL)
00043   {return std::numeric_limits<double>::quiet_NaN();}
00044 
00046   double PredictAndSave(OBBase* pOb, std::string* param=NULL);
00047 
00049   virtual double GetStringValue(OBBase* pOb, std::string& svalue, std::string* param=NULL);
00050 
00052   virtual bool Compare(OBBase* pOb, std::istream& ss, bool noEval, std::string* param=NULL);
00053 
00057   virtual bool Display(std::string& txt, const char* param, const char* ID=NULL);
00058 
00061   virtual bool Order(double p1, double p2){ return p1<p2; }
00062   virtual bool Order(std::string s1, std::string s2){ return s1<s2; }
00063 
00065   static bool FilterCompare(OBBase* pOb, std::istream& ss, bool noEval);
00066 
00068   static void AddProperties(OBBase* pOb, const std::string& DescrList);
00069 
00071   static void DeleteProperties(OBBase* pOb, const std::string& DescrList);
00072 
00075   static std::string GetValues(OBBase* pOb, const std::string& DescrList);
00076 
00078   static std::pair<std::string, std::string> GetIdentifier(std::istream& optionText);
00079 
00080 protected:
00081 
00082   static double ParsePredicate(std::istream& optionText, char& ch1, char& ch2, std::string& svalue);
00083 
00086   static bool ReadStringFromFilter(std::istream& ss, std::string& result);
00087 
00090   static bool CompareStringWithFilter(std::istream& optionText, std::string& s, bool noEval, bool NoCompOK=false);
00091 
00092   // Treats _ as not a punctuation character
00093   static bool ispunctU(char ch)
00094   {
00095     return ispunct(ch) && ch!='_';
00096   }
00097 
00099   static bool MatchPairData(OBBase* pOb, std::string& s);
00100 };
00101 
00102 template <class T>
00103 static bool DoComparison(char ch1, char ch2, T& val, T& filterval)
00104 {
00105   switch(ch1)
00106   {
00107   case (0):  //no comparison operator is same as =
00108   case('='):
00109   return val==filterval; //**needs a better floating point comparison**
00110   case('!'):
00111   return val!=filterval; //**needs a better floating point comparison**
00112   case('>'):
00113   if(ch2=='=')
00114     return val>=filterval;
00115   else
00116     return val>filterval;
00117   case('<'):
00118   if(ch2=='=')
00119     return val<=filterval;
00120   else
00121     return val<filterval;
00122   }
00123   return false;
00124 }
00125 
00126 }//namespace
00127 #endif
00128 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines