Loading...
Searching...
No Matches
descriptor.h
Go to the documentation of this file.
/**********************************************************************
descriptor.h - Base class for molecular descriptors
Copyright (C) 2007 by Chris Morley
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#ifndef OB_DESCRIPTOR_H
#define OB_DESCRIPTOR_H
#include <string>
#include <sstream>
#include <limits>
#include <openbabel/babelconfig.h>
#include <openbabel/plugin.h>
namespace OpenBabel
{
class OBBase; //Forward declaration; used only as pointer.
// Class introduction in descriptor.cpp
class OBAPI OBDescriptor : public OBPlugin
{
MAKE_PLUGIN(OBDescriptor)
public:
const char* TypeID(){return "descriptors";};
virtual double Predict(OBBase* /* pOb */, std::string* /* param */ =nullptr)
{return std::numeric_limits<double>::quiet_NaN();}
double PredictAndSave(OBBase* pOb, std::string* param=nullptr);
virtual double GetStringValue(OBBase* pOb, std::string& svalue, std::string* param=nullptr);
virtual bool Compare(OBBase* pOb, std::istream& ss, bool noEval, std::string* param=nullptr);
virtual bool Display(std::string& txt, const char* param, const char* ID=nullptr);
virtual bool Order(double p1, double p2){ return p1<p2; }
virtual bool Order(std::string s1, std::string s2){ return s1<s2; }
static bool FilterCompare(OBBase* pOb, std::istream& ss, bool noEval);
static void AddProperties(OBBase* pOb, const std::string& DescrList);
static void DeleteProperties(OBBase* pOb, const std::string& DescrList);
static std::string GetValues(OBBase* pOb, const std::string& DescrList);
static std::pair<std::string, std::string> GetIdentifier(std::istream& optionText);
protected:
static double ParsePredicate(std::istream& optionText, char& ch1, char& ch2, std::string& svalue);
static bool ReadStringFromFilter(std::istream& ss, std::string& result);
static bool CompareStringWithFilter(std::istream& optionText, std::string& s, bool noEval, bool NoCompOK=false);
// Treats _ as not a punctuation character and since 2.3.2 also $ # and %
static bool ispunctU(char ch)
{
return ispunct(ch) && ch!='_' && ch!='$' && ch!='#' && ch!='%';
}
static bool MatchPairData(OBBase* pOb, std::string& s);
};
template <class T>
static bool DoComparison(char ch1, char ch2, T& val, T& filterval)
{
switch(ch1)
{
case (0): //no comparison operator is same as =
case('='):
return val==filterval; //**needs a better floating point comparison**
case('!'):
return val!=filterval; //**needs a better floating point comparison**
case('>'):
if(ch2=='=')
return val>=filterval;
else
return val>filterval;
case('<'):
if(ch2=='=')
return val<=filterval;
else
return val<filterval;
}
return false;
}
}//namespace
#endif
OpenBabel::OBBase
Base Class.
Definition base.h:240
OpenBabel::OBDescriptor
Base class for molecular properties, descriptors or features.
Definition descriptor.h:35
OpenBabel::OBDescriptor::ispunctU
static bool ispunctU(char ch)
Definition descriptor.h:93
OpenBabel::OBDescriptor::Predict
virtual double Predict(OBBase *, std::string *=nullptr)
Definition descriptor.h:42
OpenBabel::OBDescriptor::Order
virtual bool Order(double p1, double p2)
Definition descriptor.h:61
OpenBabel::OBDescriptor::Order
virtual bool Order(std::string s1, std::string s2)
Definition descriptor.h:62
OpenBabel::OBDescriptor::TypeID
const char * TypeID()
Redefined by each plugin type: "formats", "fingerprints", etc.
Definition descriptor.h:39
OpenBabel::OBPlugin
Base class for all types of dynamic classes discovered at runtime.
Definition plugin.h:53
MAKE_PLUGIN
#define MAKE_PLUGIN(BaseClass)
Definition plugin.h:195
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::DoComparison
static bool DoComparison(char ch1, char ch2, T &val, T &filterval)
Definition descriptor.h:103
plugin.h
Simplify 'plugin' classes to be discovered and/or loaded at runtime.