Open Babel  3.0
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
OBOp Class Referenceabstract

#include <openbabel/op.h>

Inheritance diagram for OBOp:
OBPlugin OpTransform

Public Types

typedef const std::map< std::string, std::string > OpMap
 
typedef std::map< const char *, OBPlugin *, CharPtrLessPluginMapType
 
typedef PluginMapType::const_iterator PluginIterator
 

Public Member Functions

virtual const char * TypeID ()
 
virtual bool Do (OBBase *pOb, const char *OptionText=NULL, OpMap *pOptions=NULL, OBConversion *pConv=NULL)=0
 
virtual bool WorksWith (OBBase *pOb) const =0
 
virtual bool ProcessVec (std::vector< OBBase *> &)
 
virtual const char * Description ()
 
virtual bool Display (std::string &txt, const char *param, const char *ID=NULL)
 
virtual OBPluginMakeInstance (const std::vector< std::string > &)
 
virtual void Init ()
 
const char * GetID () const
 
virtual PluginMapTypeGetMap () const =0
 

Static Public Member Functions

static std::string OpOptions (OBBase *pOb)
 
static bool DoOps (OBBase *pOb, OpMap *pOptions, OBConversion *pConv)
 
static OBPluginGetPlugin (const char *Type, const char *ID)
 
static bool ListAsVector (const char *PluginID, const char *param, std::vector< std::string > &vlist)
 
static void List (const char *PluginID, const char *param=NULL, std::ostream *os=&std::cout)
 
static std::string ListAsString (const char *PluginID, const char *param=NULL)
 
static std::string FirstLine (const char *txt)
 
static PluginIterator Begin (const char *PluginID)
 
static PluginIterator End (const char *PluginID)
 
static void LoadAllPlugins ()
 

Static Protected Member Functions

static PluginMapTypePluginMap ()
 
static PluginMapTypeGetTypeMap (const char *PluginID)
 
static OBPluginBaseFindType (PluginMapType &Map, const char *ID)
 

Protected Attributes

const char * _id
 

Static Protected Attributes

static int AllPluginsLoaded = 0
 

Detailed Description

Operations to modify molecules before output.

Since
version 2.2

Classes derived from OBOp implement options for the obabel program (for both its commandline and GUI interfaces). It is intended for options that carry out some modification on the molecule(or reaction) after it has been input, but before it is output. An example is the –center option implemented in the OpCenter class in ops.cpp, which is a duplicate of the built in -c option for centering coordinates.

The advantage of plugin classes is that no existing code has to be modified when a new class is added. You can list those that are present by obabel -L ops or from a menu item in the GUI.

Any OBOp derived class has to have a constructor, a function returning a short description, and a Do() function which does the work. It also needs a WorksWith() function which is always the same when operating on OBMol objects. (It is not made a default to reducecode dependencies.) A single global instance of the class needs to be instantiated to define the ID, by which the class is subsequently accessed.

OBOp works by two of its static functions being called from code in transform.cpp:

Options which need parameters are passed these (space delimited) in the text parameter of the Do() function. They can also access other general options specified on the command line by examining the the OpMap parameter.

To use an OBOp class from the API it is necessary to use an extra step in case it isn't present. So to apply the OBOp class with ID gen3D to your mol

OBOp* pOp = OBOp::FindType("gen3D");
if(!pOp)
...report error
pOp->Do(mol);

Member Typedef Documentation

◆ OpMap

typedef const std::map<std::string, std::string> OpMap

Member Function Documentation

◆ TypeID()

virtual const char* TypeID ( )
inlinevirtual

Provides the name of this kind of plugin. Use -L "ops" to list from commandline.

Reimplemented from OBPlugin.

◆ Do()

virtual bool Do ( OBBase pOb,
const char *  OptionText = NULL,
OpMap pOptions = NULL,
OBConversion pConv = NULL 
)
pure virtual

Required function that does the work. Normally return true, unless object is not to be output.

Implemented in OpTransform.

Referenced by OBOp::DoOps().

◆ WorksWith()

virtual bool WorksWith ( OBBase pOb) const
pure virtual
Returns
true if this op is designed to work with the class of pOb, e.g. OBMol

Implemented in OpTransform.

Referenced by OBOp::OpOptions().

◆ ProcessVec()

virtual bool ProcessVec ( std::vector< OBBase *> &  )
inlinevirtual

Do something with an array of objects. Used a a callback routine in OpSort, etc.

◆ OpOptions()

static std::string OpOptions ( OBBase pOb)
inlinestatic
Returns
string describing options, for display with -H and to make checkboxes in GUI

◆ DoOps()

static bool DoOps ( OBBase pOb,
OpMap pOptions,
OBConversion pConv 
)
inlinestatic

Call Do() of all the OBOps whose ID is a key in the map. Called from DoTransformations(). The map has general options like -x or –multicharoption The key is the option name and the value, if any, is text which follows the option name. In some cases, there may be several parameters, space separated)

Returns
false indicating object should not be output, if any Do() returns false

The documentation for this class was generated from the following file: