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 > 
OpMap
typedef std::map< const char
*, OBPlugin *, CharPtrLess
PluginMapType
typedef
PluginMapType::const_iterator 
PluginIterator

Public Member Functions

virtual const char * TypeID ()
virtual bool Do (OBBase *pOb, OpMap *pOptions=NULL, const char *OptionText=NULL)=0
virtual bool WorksWith (OBBase *pOb) const =0
virtual const char * Description ()
virtual bool Display (std::string &txt, const char *param, const char *ID=NULL)
virtual OBPluginMakeInstance (const std::vector< std::string > &)
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)
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 PluginMapTypeGetTypeMap (const char *PluginID)
static OBPluginBaseFindType (PluginMapType &Map, const char *ID)

Protected Attributes

const char * _id


Detailed Description

Operations to modify molecules before output.

Since:
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]

typedef PluginMapType::const_iterator PluginIterator [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.

virtual bool Do ( OBBase pOb,
OpMap pOptions = NULL,
const char *  OptionText = 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]

Returns:
true if this op is designed to work with the class of pOb, e.g. OBMol

Implemented in OpTransform.

Referenced by OBOp::OpOptions().

static std::string OpOptions ( OBBase pOb  )  [inline, static]

Returns:
string describing options, for display with -H and to make checkboxes in GUI

Referenced by OBMol::ClassDescription().

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

Call Do() of all the OBOps whose ID is a key in the map. Called from Transform(). 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

Referenced by OBMol::DoTransformations().

virtual const char* Description (  )  [inline, virtual, inherited]

Required description of a sub-type.

Reimplemented in OBFormat, OBGroupContrib, and OpTransform.

Referenced by OBPlugin::Display(), and OBOp::OpOptions().

bool Display ( std::string &  txt,
const char *  param,
const char *  ID = NULL 
) [virtual, inherited]

Write information on a plugin class to the string txt. Return false if not written. The default implementation outputs: the ID, a tab character, and the first line of the Description. The param string can be used in derived types to provide different outputs.

Reimplemented in OBDescriptor, and OBFormat.

Referenced by OBDescriptor::Display().

virtual OBPlugin* MakeInstance ( const std::vector< std::string > &   )  [inline, virtual, inherited]

Make a new instance of the class. See OpTransform, OBGroupContrib, SmartsDescriptor classes for derived versions. Usually, the first parameter is the classname, the next three are parameters(ID, filename, description) for a constructor, and the rest data.

Reimplemented in OBGroupContrib, and OpTransform.

Referenced by OBConversion::LoadFormatFiles().

static OBPlugin* GetPlugin ( const char *  Type,
const char *  ID 
) [inline, static, inherited]

Get a pointer to a plugin from its type and ID. Return NULL if not found. Not cast to Type*.

Referenced by OBConversion::LoadFormatFiles().

const char* GetID (  )  const [inline, inherited]

Return the ID of the sub-type instance.

Referenced by OBPlugin::Display(), OBFormat::Display(), and OBDescriptor::PredictAndSave().

bool ListAsVector ( const char *  PluginID,
const char *  param,
std::vector< std::string > &  vlist 
) [static, inherited]

Output a list of sub-type classes of the the type PluginID, or, if PluginID is "plugins" or empty, a list of the base types. If PluginID is not recognized or is NULL, the base types are output and the return is false.

Referenced by OBConversion::GetSupportedInputFormat(), OBConversion::GetSupportedOutputFormat(), and OBPlugin::List().

void List ( const char *  PluginID,
const char *  param = NULL,
std::ostream *  os = &std::cout 
) [static, inherited]

As ListAsVector but sent to an ostream with a default of cout if not specified.

Referenced by OBPlugin::ListAsString().

string ListAsString ( const char *  PluginID,
const char *  param = NULL 
) [static, inherited]

As ListAsVector but returns a string containing the list.

string FirstLine ( const char *  txt  )  [static, inherited]

Utility function to return only the first line of a string.

Referenced by OBPlugin::Display(), OBFormat::Display(), and OBOp::OpOptions().

static PluginIterator Begin ( const char *  PluginID  )  [inline, static, inherited]

Return an iterator at the start of the map of the plugin types PluginID or, if there is no such map, the end of the top level plugin map.

Referenced by OBConversion::GetNextFormat(), and OBOp::OpOptions().

static PluginIterator End ( const char *  PluginID  )  [inline, static, inherited]

virtual PluginMapType& GetMap (  )  const [pure virtual, inherited]

Returns the map of the subtypes.

Referenced by OBFormat::RegisterFormat().

static PluginMapType& PluginMap (  )  [inline, static, protected, inherited]

Returns a reference to the map of the plugin types. Is a function rather than a static member variable to avoid initialization problems.

Referenced by OBPlugin::GetTypeMap(), OBPlugin::ListAsVector(), and OBFormat::RegisterFormat().

OBPlugin::PluginMapType & GetTypeMap ( const char *  PluginID  )  [static, protected, inherited]

Returns the map of a particular plugin type, e.g. GetMapType("fingerprints").

static OBPlugin* BaseFindType ( PluginMapType Map,
const char *  ID 
) [inline, static, protected, inherited]

Returns the type with the specified ID, or NULL if not found. Will be cast to the appropriate class in the calling routine.


Member Data Documentation

const char* _id [protected, inherited]


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