Open Babel  3.0
descriptor.h
Go to the documentation of this file.
1 /**********************************************************************
2 descriptor.h - Base class for molecular descriptors
3 
4 Copyright (C) 2007 by Chris Morley
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 ***********************************************************************/
18 
19 #ifndef OB_DESCRIPTOR_H
20 #define OB_DESCRIPTOR_H
21 
22 #include <string>
23 #include <sstream>
24 #include <limits>
25 
26 #include <openbabel/babelconfig.h>
27 #include <openbabel/plugin.h>
28 
29 namespace OpenBabel
30 {
31 class OBBase; //Forward declaration; used only as pointer.
32 
33 // Class introduction in descriptor.cpp
34 class OBAPI OBDescriptor : public OBPlugin
35 {
37 
38 public:
39  const char* TypeID(){return "descriptors";};
40 
42  virtual double Predict(OBBase* /* pOb */, std::string* /* param */ =NULL)
43  {return std::numeric_limits<double>::quiet_NaN();}
44 
46  double PredictAndSave(OBBase* pOb, std::string* param=NULL);
47 
49  virtual double GetStringValue(OBBase* pOb, std::string& svalue, std::string* param=NULL);
50 
52  virtual bool Compare(OBBase* pOb, std::istream& ss, bool noEval, std::string* param=NULL);
53 
57  virtual bool Display(std::string& txt, const char* param, const char* ID=NULL);
58 
61  virtual bool Order(double p1, double p2){ return p1<p2; }
62  virtual bool Order(std::string s1, std::string s2){ return s1<s2; }
63 
65  static bool FilterCompare(OBBase* pOb, std::istream& ss, bool noEval);
66 
68  static void AddProperties(OBBase* pOb, const std::string& DescrList);
69 
71  static void DeleteProperties(OBBase* pOb, const std::string& DescrList);
72 
75  static std::string GetValues(OBBase* pOb, const std::string& DescrList);
76 
78  static std::pair<std::string, std::string> GetIdentifier(std::istream& optionText);
79 
80 protected:
81 
82  static double ParsePredicate(std::istream& optionText, char& ch1, char& ch2, std::string& svalue);
83 
86  static bool ReadStringFromFilter(std::istream& ss, std::string& result);
87 
90  static bool CompareStringWithFilter(std::istream& optionText, std::string& s, bool noEval, bool NoCompOK=false);
91 
92  // Treats _ as not a punctuation character and since 2.3.2 also $ # and %
93  static bool ispunctU(char ch)
94  {
95  return ispunct(ch) && ch!='_' && ch!='$' && ch!='#' && ch!='%';
96  }
97 
99  static bool MatchPairData(OBBase* pOb, std::string& s);
100 };
101 
102 template <class T>
103 static bool DoComparison(char ch1, char ch2, T& val, T& filterval)
104 {
105  switch(ch1)
106  {
107  case (0): //no comparison operator is same as =
108  case('='):
109  return val==filterval; //**needs a better floating point comparison**
110  case('!'):
111  return val!=filterval; //**needs a better floating point comparison**
112  case('>'):
113  if(ch2=='=')
114  return val>=filterval;
115  else
116  return val>filterval;
117  case('<'):
118  if(ch2=='=')
119  return val<=filterval;
120  else
121  return val<filterval;
122  }
123  return false;
124 }
125 
126 }//namespace
127 #endif
128 
Definition: residue.h:336
static bool ispunctU(char ch)
Definition: descriptor.h:93
Base class for all types of dynamic classes discovered at runtime.
Definition: plugin.h:52
static bool DoComparison(char ch1, char ch2, T &val, T &filterval)
Definition: descriptor.h:103
virtual bool Order(std::string s1, std::string s2)
Definition: descriptor.h:62
#define MAKE_PLUGIN(BaseClass)
Definition: plugin.h:195
Simplify &#39;plugin&#39; classes to be discovered and/or loaded at runtime.
virtual bool Order(double p1, double p2)
Definition: descriptor.h:61
const char * TypeID()
Redefined by each plugin type: "formats", "fingerprints", etc.
Definition: descriptor.h:39
virtual double Predict(OBBase *, std::string *=NULL)
Definition: descriptor.h:42
Base class for molecular properties, descriptors or features.
Definition: descriptor.h:34
Base Class.
Definition: base.h:239
Global namespace for all Open Babel code.
Definition: alias.h:22