Open Babel  3.0
obmolecformat.h
Go to the documentation of this file.
1 /**********************************************************************
2 obmolecformat.h - Subclass of OBFormat for conversion of OBMol.
3 
4 Copyright (C) 2005 Chris Morley
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 ***********************************************************************/
18 
19 #ifndef OB_MOLECULEFORMAT_H
20 #define OB_MOLECULEFORMAT_H
21 
22 #ifdef _MSC_VER
23  #include <unordered_map>
24 #endif
25 
26 #include <ciso646> // detect std::lib
27 #ifdef _LIBCPP_VERSION
28  #include <unordered_map>
29 #elif __GNUC__ == 4 && __GNUC_MINOR__ >= 1
30  #include <tr1/unordered_map>
31 #elif defined(USE_BOOST)
32  #include <boost/tr1/unordered_map.hpp>
33 #endif
34 
35 #include <openbabel/babelconfig.h>
36 #include <openbabel/obconversion.h>
37 #include <typeinfo>
38 #include <cstdlib>
39 
40 namespace OpenBabel {
41 
42  class OBMol;
43  class OBDescriptor;
44 #ifdef HAVE_SHARED_POINTER
45  class OBReaction;
46 #endif
47 
48 // This macro is used in DLL builds. If it has not
49 // been set in babelconfig.h, define it as nothing.
50 #ifndef OBCOMMON
51  #define OBCOMMON
52 #endif
53 
68 
70 class OBCOMMON OBMoleculeFormat : public OBFormat
71 {
72 public:
73 
75  {
76  if(!OptionsRegistered)
77  {
78  OptionsRegistered=true;
88 
89  //The follow are OBMol options, which should not be in OBConversion.
90  //But here isn't entirely appropriate either, since one could have
91  //OBMol formats loaded but which don't derived from this class.
92  //However, this possibility is remote.
106  }
107  }
108 
110  static bool ReadChemObjectImpl(OBConversion* pConv, OBFormat*);
112  static bool WriteChemObjectImpl(OBConversion* pConv, OBFormat*);
113 
115  virtual bool ReadChemObject(OBConversion* pConv)
116  { return ReadChemObjectImpl(pConv, this);}
117 
119  virtual bool WriteChemObject(OBConversion* pConv)
120  { return WriteChemObjectImpl(pConv, this);}
121 
123  static bool DoOutputOptions(OBBase* pOb, OBConversion* pConv);
124 
126 
127  static bool DeferMolOutput(OBMol* pmol, OBConversion* pConv, OBFormat* pF);
131  static bool OutputDeferredMols(OBConversion* pConv);
133  static bool DeleteDeferredMols();
135  static OBMol* MakeCombinedMolecule(OBMol* pFirst, OBMol* pSecond);
137 
138 #ifdef HAVE_SHARED_POINTER
139  static bool OutputMolsFromReaction
141  (OBReaction* pReact, OBConversion* pConv, OBFormat* pFormat);
142 #endif
143 
144 #ifdef _MSC_VER
145  typedef std::tr1::unordered_map<std::string, unsigned> NameIndexType;
146 #elif defined(_LIBCPP_VERSION)
147  typedef std::unordered_map<std::string, unsigned> NameIndexType;
148 #elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && !defined(__APPLE_CC__)) || defined (USE_BOOST)
149  typedef std::tr1::unordered_map<std::string, unsigned> NameIndexType;
150 #else
151  typedef std::map<std::string, unsigned> NameIndexType;
152 #endif
153 
154  // documentation in obmolecformat.cpp
155  static bool ReadNameIndex(NameIndexType& index, const std::string& datafilename,
156  OBFormat* pInFormat);
157 
159  const std::type_info& GetType()
160  {
161  return typeid(OBMol*);
162  }
163 
164 private:
165 
166  static bool OptionsRegistered;
167  static std::map<std::string, OBMol*> IMols;
168  static OBMol* _jmol;
169  static std::vector<OBMol> MolArray;
170  static bool StoredMolsReady;
171  static OBDescriptor* _pDesc;
172 
173 };
174 
175 }
176 #endif //OB_MOLECULEFORMAT_H
177 
std::map< std::string, unsigned > NameIndexType
Definition: obmolecformat.h:151
Definition: obconversion.h:184
virtual bool ReadChemObject(OBConversion *pConv)
The "Convert" interface for reading a new molecule.
Definition: obmolecformat.h:115
virtual bool WriteChemObject(OBConversion *pConv)
The "Convert" interface for writing a new molecule.
Definition: obmolecformat.h:119
Class to convert from one format to another.
Definition: obconversion.h:59
OBMoleculeFormat()
Definition: obmolecformat.h:74
Molecule Class.
Definition: mol.h:118
Used to store chemical reactions (i.e., reactants -> products)
Definition: reaction.h:37
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:1637
An OBFormat convenience subclass for conversion to/from OBMol data.
Definition: obmolecformat.h:70
Handle file conversions. Declaration of OBFormat, OBConversion.
Base class for molecular properties, descriptors or features.
Definition: descriptor.h:34
Base class for file formats.
Definition: format.h:44
Base Class.
Definition: base.h:239
const std::type_info & GetType()
Definition: obmolecformat.h:159
Definition: obconversion.h:184
Global namespace for all Open Babel code.
Definition: alias.h:22