Loading...
Searching...
No Matches
obmolecformat.h
Go to the documentation of this file.
/**********************************************************************
obmolecformat.h - Subclass of OBFormat for conversion of OBMol.
Copyright (C) 2005 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_MOLECULEFORMAT_H
#define OB_MOLECULEFORMAT_H
#ifdef _MSC_VER
#include <unordered_map>
#endif
#include <ciso646> // detect std::lib
#ifdef _LIBCPP_VERSION
#include <unordered_map>
#elif __GNUC__ == 4 && __GNUC_MINOR__ >= 1
#include <tr1/unordered_map>
#elif defined(USE_BOOST)
#include <boost/tr1/unordered_map.hpp>
#endif
#include <openbabel/babelconfig.h>
#include <openbabel/obconversion.h>
#include <typeinfo>
#include <cstdlib>
namespace OpenBabel {
class OBMol;
class OBDescriptor;
#ifdef HAVE_SHARED_POINTER
class OBReaction;
#endif
// This macro is used in DLL builds. If it has not
// been set in babelconfig.h, define it as nothing.
#ifndef OBCOMMON
#define OBCOMMON
#endif
class OBCOMMON OBMoleculeFormat : public OBFormat
{
public:
OBMoleculeFormat()
{
if(!OptionsRegistered)
{
OptionsRegistered=true;
OBConversion::RegisterOptionParam("b", this, 0, OBConversion::INOPTIONS);
OBConversion::RegisterOptionParam("s", this, 0, OBConversion::INOPTIONS);
OBConversion::RegisterOptionParam("title", this, 1, OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("addtotitle",this, 1, OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("property", this, 2, OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("C", this, 0, OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("j", this, 0, OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("join", this, 0, OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("separate", this, 0, OBConversion::GENOPTIONS);
//The follow are OBMol options, which should not be in OBConversion.
//But here isn't entirely appropriate either, since one could have
//OBMol formats loaded but which don't derived from this class.
//However, this possibility is remote.
OBConversion::RegisterOptionParam("s", nullptr, 1,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("v", nullptr, 1,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("h", nullptr, 0,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("d", nullptr, 0,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("b", nullptr, 0,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("c", nullptr, 0,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("p", nullptr, 1,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("t", nullptr, 0,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("k", nullptr, 0,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("filter", nullptr, 1,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("add", nullptr, 1,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("delete", nullptr, 1,OBConversion::GENOPTIONS);
OBConversion::RegisterOptionParam("append", nullptr, 1,OBConversion::GENOPTIONS);
}
}
static bool ReadChemObjectImpl(OBConversion* pConv, OBFormat*);
static bool WriteChemObjectImpl(OBConversion* pConv, OBFormat*);
virtual bool ReadChemObject(OBConversion* pConv)
{ return ReadChemObjectImpl(pConv, this);}
virtual bool WriteChemObject(OBConversion* pConv)
{ return WriteChemObjectImpl(pConv, this);}
static bool DoOutputOptions(OBBase* pOb, OBConversion* pConv);
static bool DeferMolOutput(OBMol* pmol, OBConversion* pConv, OBFormat* pF);
static bool OutputDeferredMols(OBConversion* pConv);
static bool DeleteDeferredMols();
static OBMol* MakeCombinedMolecule(OBMol* pFirst, OBMol* pSecond);
#ifdef HAVE_SHARED_POINTER
static bool OutputMolsFromReaction
(OBReaction* pReact, OBConversion* pConv, OBFormat* pFormat);
#endif
#ifdef _MSC_VER
typedef std::tr1::unordered_map<std::string, unsigned> NameIndexType;
#elif defined(_LIBCPP_VERSION)
typedef std::unordered_map<std::string, unsigned> NameIndexType;
#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && !defined(__APPLE_CC__)) || defined (USE_BOOST)
typedef std::tr1::unordered_map<std::string, unsigned> NameIndexType;
#else
typedef std::map<std::string, unsigned> NameIndexType;
#endif
// documentation in obmolecformat.cpp
static bool ReadNameIndex(NameIndexType& index, const std::string& datafilename,
OBFormat* pInFormat);
const std::type_info& GetType()
{
return typeid(OBMol*);
}
private:
static bool OptionsRegistered;
static std::map<std::string, OBMol*> IMols;
static OBMol* _jmol;
static std::vector<OBMol> MolArray;
static bool StoredMolsReady;
static OBDescriptor* _pDesc;
};
}
#endif //OB_MOLECULEFORMAT_H
OpenBabel::OBBase
Base Class.
Definition base.h:240
OpenBabel::OBConversion
Class to convert from one format to another.
Definition obconversion.h:60
OpenBabel::OBConversion::RegisterOptionParam
static void RegisterOptionParam(std::string name, OBFormat *pFormat, int numberParams=0, Option_type typ=OUTOPTIONS)
For example -h takes 0 parameters; -f takes 1. Call in a format constructor.
Definition obconversion.cpp:1665
OpenBabel::OBConversion::INOPTIONS
@ INOPTIONS
Definition obconversion.h:184
OpenBabel::OBConversion::GENOPTIONS
@ GENOPTIONS
Definition obconversion.h:184
OpenBabel::OBDescriptor
Base class for molecular properties, descriptors or features.
Definition descriptor.h:35
OpenBabel::OBFormat
Base class for file formats.
Definition format.h:45
OpenBabel::OBFormat::OBFormat
OBFormat()
Default constructor. Registration via RegisterFormat(), not via constructor as in other plugins.
Definition format.h:52
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
OpenBabel::OBMoleculeFormat::ReadNameIndex
static bool ReadNameIndex(NameIndexType &index, const std::string &datafilename, OBFormat *pInFormat)
Definition obmolecformat.cpp:492
OpenBabel::OBMoleculeFormat::ReadChemObjectImpl
static bool ReadChemObjectImpl(OBConversion *pConv, OBFormat *)
Static routine, which can be called from elsewhere.
Definition obmolecformat.cpp:36
OpenBabel::OBMoleculeFormat::WriteChemObject
virtual bool WriteChemObject(OBConversion *pConv)
The "Convert" interface for writing a new molecule.
Definition obmolecformat.h:119
OpenBabel::OBMoleculeFormat::OBMoleculeFormat
OBMoleculeFormat()
Definition obmolecformat.h:74
OpenBabel::OBMoleculeFormat::ReadChemObject
virtual bool ReadChemObject(OBConversion *pConv)
The "Convert" interface for reading a new molecule.
Definition obmolecformat.h:115
OpenBabel::OBMoleculeFormat::WriteChemObjectImpl
static bool WriteChemObjectImpl(OBConversion *pConv, OBFormat *)
Static routine, which can be called from elsewhere.
Definition obmolecformat.cpp:136
OpenBabel::OBMoleculeFormat::GetType
const std::type_info & GetType()
Definition obmolecformat.h:159
OpenBabel::OBMoleculeFormat::NameIndexType
std::map< std::string, unsigned > NameIndexType
Definition obmolecformat.h:151
OpenBabel::OBReaction
Used to store chemical reactions (i.e., reactants -> products).
Definition reaction.h:38
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
obconversion.h
Handle file conversions. Declaration of OBFormat, OBConversion.