Loading...
Searching...
No Matches
OBMoleculeFormat Class Referenceabstract

`#include <openbabel/obmolecformat.h>`

Inheritance diagram for OBMoleculeFormat:
[legend]

## Public Types

typedef std::map< const char *, OBPlugin *, CharPtrLess > | PluginMapType
typedef PluginMapType::const_iterator | PluginIterator

## Public Member Functions

| OBMoleculeFormat ()
virtual bool | ReadChemObject (OBConversion *pConv)
virtual bool | WriteChemObject (OBConversion *pConv)
const char * | TypeID ()
virtual bool | ReadMolecule (OBBase *, OBConversion *)
virtual bool | WriteMolecule (OBBase *, OBConversion *)
virtual const char * | Description ()=0
virtual const char * | TargetClassDescription ()
virtual const char * | SpecificationURL ()
virtual const char * | GetMIMEType ()
virtual unsigned int | Flags ()
virtual int | SkipObjects (int, OBConversion *)
virtual OBFormat * | MakeNewInstance ()
int | RegisterFormat (const char *ID, const char *MIME=nullptr)
virtual bool | Display (std::string &txt, const char *param, const char *ID=nullptr)
virtual OBPlugin * | MakeInstance (const std::vector< std::string > &)
virtual void | Init ()
const char * | GetID () const
virtual PluginMapType & | GetMap () const =0

## Static Public Member Functions

static bool | ReadChemObjectImpl (OBConversion *pConv, OBFormat *)
static bool | WriteChemObjectImpl (OBConversion *pConv, OBFormat *)
static bool | DoOutputOptions (OBBase *pOb, OBConversion *pConv)
static OBFormat * | FormatFromMIME (const char *MIME)
static OBPlugin * | GetPlugin (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=nullptr, std::ostream *os=&std::cout)
static std::string | ListAsString (const char *PluginID, const char *param=nullptr)
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 PluginMapType & | PluginMap ()
static PluginMapType & | GetTypeMap (const char *PluginID)
static OBPlugin * | BaseFindType (PluginMapType &Map, const char *ID)

## Protected Attributes

const char * | _id

## Static Protected Attributes

static int | AllPluginsLoaded = 0

## Routines to handle the -C option for combining data from several OBMols

typedef std::map< std::string, unsigned > | NameIndexType
const std::type_info & | GetType ()
static bool | DeferMolOutput (OBMol *pmol, OBConversion *pConv, OBFormat *pF)
static bool | OutputDeferredMols (OBConversion *pConv)
static bool | DeleteDeferredMols ()
static OBMol * | MakeCombinedMolecule (OBMol *pFirst, OBMol *pSecond)
static bool | ReadNameIndex (NameIndexType &index, const std::string &datafilename, OBFormat *pInFormat)

## Detailed Description

An OBFormat convenience subclass for conversion to/from OBMol data.

This class is not intended for direct use outside of Open Babel, unless you're writing a new format converting to or from an OBMol molecule. (e.g., see http://openbabel.org/wiki/HowTo:Add_A_New_File_Format).

An OBFormat which converts to and/or from OBMol can derive from this class to save duplicating the ReadChemObject() and/or WriteChemObject() methods. Derive directly from OBFormat if the object converted is not OBMol or if interaction with the framework is required during the execution of ReadMolecule() or WriteMolecule(), as for example in CMLFormat

## Member Typedef Documentation

## NameIndexType

typedef std::map<std::string, unsigned> NameIndexType

## Constructor & Destructor Documentation

## OBMoleculeFormat()

OBMoleculeFormat | ( |  | ) |

inline

## Member Function Documentation

## ReadChemObjectImpl()

bool ReadChemObjectImpl | ( | OBConversion * | pConv,
|  | OBFormat * | pFormat )

static

Static routine, which can be called from elsewhere.

Referenced by ReadChemObject(), and XMLMoleculeFormat::ReadChemObject().

## WriteChemObjectImpl()

bool WriteChemObjectImpl | ( | OBConversion * | pConv,
|  | OBFormat * | pFormat )

static

Static routine, which can be called from elsewhere.

Referenced by WriteChemObject(), and XMLMoleculeFormat::WriteChemObject().

## ReadChemObject()

virtual bool ReadChemObject | ( | OBConversion * | pConv | ) |

inline virtual

The "Convert" interface for reading a new molecule.

Reimplemented from OBFormat.

## WriteChemObject()

virtual bool WriteChemObject | ( | OBConversion * | pConv | ) |

inline virtual

The "Convert" interface for writing a new molecule.

Reimplemented from OBFormat.

## DoOutputOptions()

bool DoOutputOptions | ( | OBBase * | pOb,
|  | OBConversion * | pConv )

static

Applies output options to molecule. Returns false to terminate output.

Referenced by WriteChemObjectImpl().

## DeferMolOutput()

bool DeferMolOutput | ( | OBMol * | pmol,
|  | OBConversion * | pConv,
|  | OBFormat * | pF )

static

Defer output of a molecule until later, so it can be combined with others

Returns
  Success, or false if no molecule was read.

Instead of sending molecules for output via AddChemObject(), they are saved in here in OBMoleculeFormat or discarded. By default they are saved only if they are in the first input file. Parts of subsequent molecules, such as chemical structure, coordinates and OBGenericData can replace the parts in molecules with the same title that have already been stored, subject to a set of rules. After all input files have been read, the stored molecules (possibly now having augmented properties) are sent to the output format.

Is a static function with *this as parameter so that it can be called from other format classes like XMLMoleculeFormat which are not derived from OBMoleculeFormat.

Referenced by ReadChemObjectImpl().

## OutputDeferredMols()

bool OutputDeferredMols | ( | OBConversion * | pConv | ) |

static

Write out all molecules queued with DeferMolOutput.

Referenced by WriteChemObjectImpl().

## DeleteDeferredMols()

bool DeleteDeferredMols | ( |  | ) |

static

Delete the list of queued molecules from DeferMolOutput.

Referenced by DeferMolOutput(), and OutputDeferredMols().

## MakeCombinedMolecule()

OBMol * MakeCombinedMolecule | ( | OBMol * | pFirst,
|  | OBMol * | pSecond )

static

Returns
  the OBMol which combines `pFirst` and `pSecond` (i.e.)

Makes a new OBMol on the heap by combining two molecules according to the rule below. If both have OBGenericData of the same type, or OBPairData with the same attribute, the version from pFirst is used. Returns a pointer to a new OBMol which will need deleting by the calling program (probably by being sent to an output format). If the molecules cannot be regarded as being the same structure a NULL pointer is returned and an error message logged.

pFirst and pSecond and the objects they point to are not changed. (const modifiers difficult because class OBMol not designed appropriately)

Combining molecules: rules for each of the three parts Title: Use the title of pFirst unless it has none, when use that of pSecond. Warning if neither molecule has a title.

Structure

- a structure with atoms replaces one with no atoms
- a structure with bonds replaces one with no bonds, provided the formula is the same, else an error.
- structures with atoms and bonds are compared by InChI; error if not the same.
- a structure with 3D coordinates replaces one with 2D coordinates
- a structure with 2D coordinates replace one with 0D coordinates

OBGenericData OBPairData

Referenced by DeferMolOutput().

## ReadNameIndex()

bool ReadNameIndex | ( | NameIndexType & | index,
|  | const std::string & | datafilename,
|  | OBFormat * | pInFormat )

static

Attempts to read the index file datafilename.obindx successively from the following directories:

- the current directory
- that in the environment variable BABEL_DATADIR or in the macro BABEL_DATADIR if the environment variable is not set
- in a subdirectory of the BABEL_DATADIR directory with the version of OpenBabel as its name An index of type NameIndexType is then constructed. NameIndexType is defined in obmolecformat.h and may be a std::tr1::unordered_map (a hash_map) or std::map. In any case it is searched by
  NameIndexType::iterator itr = index.find(molecule_name);
  if(itr!=index.end())
  unsigned pos_in_datafile = itr->second;
  pos_in_datafile is used as a parameter in seekg() to read from the datafile

If no index is found, it is constructed from the datafile by reading all of it using the format pInFormat, and written to the directory containing the datafile. This means that this function can be used without worrying whether there is an index. It will be slow to execute the first time, but subsequent uses get the speed benefit of indexed access to the datafile.

The serialization and de-serialization of the NameIndexType is entirely in this routine and could possibly be improved. Currently re-hashing is done every time the index is read.

## GetType()

const std::type_info & GetType | ( |  | ) |

inline virtual

Returns
  the type of data converted by this format (here, OBMol)

Reimplemented from OBFormat.

## TypeID()

const char * TypeID | ( |  | ) |

inline virtual inherited

Redefined by each plugin type: "formats", "fingerprints", etc.

Reimplemented from OBPlugin.

Referenced by RegisterFormat().

## ReadMolecule()

virtual bool ReadMolecule | ( | OBBase * | ,
|  | OBConversion * | )

inline virtual inherited

The "API" interface Read function.

Reads a single object. Does not make a new object on the heap; can be used with a pointer to an chem object on the heap or the stack.

Reimplemented in XMLMoleculeFormat.

Referenced by OBMoleculeFormat::DeferMolOutput(), and OBMoleculeFormat::ReadChemObjectImpl().

## WriteMolecule()

virtual bool WriteMolecule | ( | OBBase * | ,
|  | OBConversion * | )

inline virtual inherited

The "API" interface Write function.

Writes a single object Does not delete the object; can be used with a pointer to an chem object on the heap or the stack.

Returns
  false on error.

Referenced by OBMoleculeFormat::DoOutputOptions(), OBMoleculeFormat::OutputDeferredMols(), and OBMoleculeFormat::WriteChemObjectImpl().

## Description()

virtual const char * Description | ( |  | ) |

pure virtual inherited

Information on this format. Printed out in response to -Hxxx option where xxx id the id of the format.

Must be provided by each format class. Can include a list of command line Options. These may be used to construction check boxes, radio buttons etc for GUI interface.

Reimplemented from OBPlugin.

Referenced by Display(), OBConversion::GetNextFormat(), and OBConversion::RegisterOptionParam().

## TargetClassDescription()

const char * TargetClassDescription | ( |  | ) |

virtual inherited

A decription of the chemical object converted by this format.

If not provided, the object type used by the default format is used (usually OBMol).

Referenced by Description(), and OBConversion::ReportNumberConverted().

## SpecificationURL()

virtual const char * SpecificationURL | ( |  | ) |

inline virtual inherited

Web address where the format is defined.

Referenced by Display().

## GetMIMEType()

virtual const char * GetMIMEType | ( |  | ) |

inline virtual inherited

Chemical MIME type associated with this file type (if any).

## Flags()

virtual unsigned int Flags | ( |  | ) |

inline virtual inherited

Decribes the capabilities of the format (Read only etc.).

Currently, can be a bitwise OR of any of the following NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY DEFAULTFORMAT READBINARY WRITEBINARY READXML

Referenced by Display(), OBConversion::GetNextFormat(), OBMoleculeFormat::ReadChemObjectImpl(), and RegisterFormat().

## SkipObjects()

virtual int SkipObjects | ( | int | ,
|  | OBConversion * | )

inline virtual inherited

Skip past first n objects in input stream (or current one with n=0).

Returns
  1 on success, -1 on error and 0 if not implemented

Reimplemented in XMLBaseFormat.

Referenced by OBConversion::NumInputObjects().

## MakeNewInstance()

virtual OBFormat * MakeNewInstance | ( |  | ) |

inline virtual inherited

Returns
  a pointer to a new instance of the format, or NULL if fails. Normally a single global instance is used but this may cause problems if there are member variables and the format is used in more than one place in the program.

## RegisterFormat()

int RegisterFormat | ( | const char * | ID,
|  | const char * | MIME = nullptr )

inherited

Referenced by OBConversion::RegisterFormat().

## Display()

bool Display | ( | std::string & | txt,
|  | const char * | param,
|  | const char * | ID = nullptr )

virtual inherited

Provides a description in txt of the format specified by itr. If param starts with "in", "read", "out" or "write" only the appropriate formats are output. The others return false. If param contains "verbose", the whole description is output.

Reimplemented from OBPlugin.

## FormatFromMIME()

OBFormat * FormatFromMIME | ( | const char * | MIME | ) |

static inherited

Referenced by OBConversion::FormatFromMIME().

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

- obmolecformat.h
- obmolecformat.cpp