OBOp Class Reference

Operations to modify molecules before output. More...

#include <openbabel/op.h>

Inheritance diagram for OBOp:

List of all members.

Public Types

typedef const std::map
< std::string, std::string > 
typedef std::map< const char
*, OBPlugin *, CharPtrLess

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 Protected Member Functions

static PluginMapTypePluginMap ()
static void LoadAllPlugins ()
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.

version 2.2

Classes derived from OBOp implement options for the babel 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 babel -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 clas with ID gen3D to your mol

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

Member Typedef Documentation

typedef const std::map<std::string, std::string> OpMap
typedef std::map<const char*, OBPlugin*, CharPtrLess> PluginMapType [inherited]

Member Function Documentation

virtual const char* TypeID (  )  [inline, virtual]

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

Reimplemented from OBPlugin.

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().

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

Implemented in OpTransform.

Referenced by OBOp::OpOptions().

virtual bool ProcessVec ( std::vector< OBBase * > &   )  [inline, virtual]

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

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

Referenced by OBMol::ClassDescription().

static bool DoOps ( OBBase pOb,
OpMap pOptions,
OBConversion pConv 
) [inline, static]

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)

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

Referenced by OBMol::DoTransformations().

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines