Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
/**********************************************************************
base.h - Base class for OpenBabel objects
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
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_BASE_H
#define OB_BASE_H
#include <openbabel/babelconfig.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <openbabel/tokenst.h>
#ifdef UNUSED
#elif (__GNUC__ == 4)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x) /*@unused@*/ x
#else
# define UNUSED(x) x
#endif
namespace OpenBabel
{
//Forward declaration of the base class for OBMol OBReaction, OBAtom, etc.
//Declaration later in this file.
class OBBase;
class OBConversion; //used only as pointer
OBAPI std::string OBReleaseVersion();
namespace OBGenericDataType
{
enum
{
UndefinedData = 0,
PairData = 1,
EnergyData = 2,
CommentData = 3,
ConformerData = 4,
ExternalBondData = 5,
RotamerList = 6,
VirtualBondData = 7,
RingData = 8,
TorsionData = 9,
AngleData = 10,
SerialNums = 11,
UnitCell = 12,
SpinData = 13,
ChargeData = 14,
SymmetryData = 15,
// 16 - Value unused, formerly ChiralData
OccupationData = 17,
DensityData = 18,
ElectronicData = 19,
VibrationData = 20,
RotationData = 21,
NuclearData = 22,
SetData = 23,
GridData = 24,
VectorData = 25,
MatrixData = 26,
StereoData = 27,
DOSData = 28,
ElectronicTransitionData = 29,
// space for up to 2^14 more entries...
CustomData0 = 16384,
CustomData1 = 16385,
CustomData2 = 16386,
CustomData3 = 16387,
CustomData4 = 16388,
CustomData5 = 16389,
CustomData6 = 16390,
CustomData7 = 16391,
CustomData8 = 16392,
CustomData9 = 16393,
CustomData10 = 16394,
CustomData11 = 16395,
CustomData12 = 16396,
CustomData13 = 16397,
CustomData14 = 16398,
CustomData15 = 16399
};
} // end namespace
enum DataOrigin {
any,
fileformatInput,
userInput,
perceived,
external,
local
};
// Class introduction in generic.cpp
// This base class declaration has no dependence on mol.h
class OBAPI OBGenericData
{
protected:
std::string _attr;
unsigned int _type;
DataOrigin _source;
public:
OBGenericData(const std::string attr = "undefined",
const unsigned int type = OBGenericDataType::UndefinedData,
const DataOrigin source = any);
//Use default copy constructor and assignment operators
//OBGenericData(const OBGenericData&);
/* Virtual constructors added. see
http://www.parashift.com/c++-faq-lite/abcs.html#faq-22.5
to allow copying given only a base class OBGenericData pointer.
It may be necessary to cast the return pointer to the derived class
type, since we are doing without Covariant Return Types
http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8
A derived class may return NULL if copying is inappropriate */
virtual OBGenericData* Clone(OBBase* /*parent*/) const
{ return nullptr; }
virtual ~OBGenericData() {}
//Use default copy constructor and assignment operators
//OBGenericData& operator=(const OBGenericData &src);
void SetAttribute(const std::string &v)
{ _attr = v; }
void SetOrigin(const DataOrigin s) { _source = s; }
virtual const std::string &GetAttribute() const
{ return(_attr); }
unsigned int GetDataType() const
{ return(_type); }
virtual const std::string &GetValue() const
{ return _attr; }
virtual DataOrigin GetOrigin() const
{ return _source; }
};
typedef std::vector<OBGenericData*>::iterator OBDataIterator;
// introduction in base.cpp
class OBAPI OBBase
{
public:
virtual ~OBBase()
{
if (!_vdata.empty())
{
std::vector<OBGenericData*>::iterator m;
for (m = _vdata.begin();m != _vdata.end();m++)
delete *m;
_vdata.clear();
}
}
virtual bool Clear();
virtual OBBase* DoTransformations(const std::map<std::string,std::string>* /*pOptions*/,
OBConversion* /*pConv*/)
{
return this;
}
static const char* ClassDescription()
{
return "";
}
template< class T >
T* CastAndClear(bool clear=true)
{
T* pOb = dynamic_cast<T*>(this);
if(pOb && clear)// Clear only if this is of target class
Clear();
return pOb;
}
//Currently no title data member in base class.
virtual const char *GetTitle(bool UNUSED(replaceNewlines) = true) const { return "";}
virtual void SetTitle(const char *) {}
bool HasData(const std::string &);
bool HasData(const char *);
bool HasData(const unsigned int type);
void DeleteData(unsigned int type);
void DeleteData(OBGenericData*);
void DeleteData(std::vector<OBGenericData*>&);
bool DeleteData(const std::string& s);
void SetData(OBGenericData *d)
{
if(d) _vdata.push_back(d);
}
void CloneData(OBGenericData *d);
size_t DataSize() const
{ return(_vdata.size()); }
OBGenericData *GetData(const unsigned int type);
OBGenericData *GetData(const std::string&);
OBGenericData *GetData(const char *);
std::vector<OBGenericData*> GetAllData(const unsigned int type);
std::vector<OBGenericData*> &GetData() { return(_vdata); }
std::vector<OBGenericData*> GetData(DataOrigin source);
OBDataIterator BeginData()
{ return(_vdata.begin()); }
OBDataIterator EndData()
{ return(_vdata.end()); }
protected:
std::vector<OBGenericData*> _vdata;
};
} //namespace OpenBabel
#endif // OB_BASE_H
OpenBabel::OBBase
Base Class.
Definition base.h:240
OpenBabel::OBBase::EndData
OBDataIterator EndData()
Definition base.h:335
OpenBabel::OBBase::BeginData
OBDataIterator BeginData()
Definition base.h:332
OpenBabel::OBBase::GetData
std::vector< OBGenericData * > & GetData()
Definition base.h:328
OpenBabel::OBBase::DataSize
size_t DataSize() const
Definition base.h:314
OpenBabel::OBBase::SetTitle
virtual void SetTitle(const char *)
Definition base.h:287
OpenBabel::OBBase::~OBBase
virtual ~OBBase()
Definition base.h:242
OpenBabel::OBBase::DoTransformations
virtual OBBase * DoTransformations(const std::map< std::string, std::string > *, OBConversion *)
Definition base.h:261
OpenBabel::OBBase::GetTitle
virtual const char * GetTitle(bool replaceNewlines=true) const
Base type does nothing Made virtual around r3535 to simplify code which passes around OBBase*.
Definition base.h:286
OpenBabel::OBBase::ClassDescription
static const char * ClassDescription()
Definition base.h:268
OpenBabel::OBBase::CastAndClear
T * CastAndClear(bool clear=true)
By default clears the object. Called from ReadMolecule of most format classes.
Definition base.h:275
OpenBabel::OBBase::Clear
virtual bool Clear()
Clear any and all data associated with this object.
Definition base.cpp:78
OpenBabel::OBBase::SetData
void SetData(OBGenericData *d)
Adds a data object; does nothing if d==NULL.
Definition base.h:306
OpenBabel::OBBase::_vdata
std::vector< OBGenericData * > _vdata
Custom data.
Definition base.h:339
OpenBabel::OBConversion
Class to convert from one format to another.
Definition obconversion.h:60
OpenBabel::OBGenericData
Base class for generic data.
Definition base.h:189
OpenBabel::OBGenericData::_source
DataOrigin _source
source of data for accounting
Definition base.h:193
OpenBabel::OBGenericData::_type
unsigned int _type
attribute type – declared for each subclass
Definition base.h:192
OpenBabel::OBGenericData::SetOrigin
void SetOrigin(const DataOrigin s)
Set the origin of this data, which can be used to filter the data.
Definition base.h:219
OpenBabel::OBGenericData::GetDataType
unsigned int GetDataType() const
Definition base.h:224
OpenBabel::OBGenericData::SetAttribute
void SetAttribute(const std::string &v)
Set the attribute (key), which can be used to retrieve this data.
Definition base.h:216
OpenBabel::OBGenericData::OBGenericData
OBGenericData(const std::string attr="undefined", const unsigned int type=OBGenericDataType::UndefinedData, const DataOrigin source=any)
Definition generic.cpp:166
OpenBabel::OBGenericData::GetValue
virtual const std::string & GetValue() const
Base class returns a default value (the attribute type) but should never be called.
Definition base.h:228
OpenBabel::OBGenericData::~OBGenericData
virtual ~OBGenericData()
Definition base.h:211
OpenBabel::OBGenericData::Clone
virtual OBGenericData * Clone(OBBase *) const
Definition base.h:209
OpenBabel::OBGenericData::_attr
std::string _attr
attribute tag (e.g., "UnitCell", "Comment" or "Author")
Definition base.h:191
OpenBabel::OBGenericData::GetOrigin
virtual DataOrigin GetOrigin() const
Definition base.h:230
OpenBabel::OBGenericData::GetAttribute
virtual const std::string & GetAttribute() const
Definition base.h:221
OpenBabel::OBGenericDataType
Classification of data stored via OBGenericData class and subclasses.
Definition base.h:63
OpenBabel::OBGenericDataType::CustomData3
@ CustomData3
Definition base.h:161
OpenBabel::OBGenericDataType::CustomData10
@ CustomData10
Definition base.h:168
OpenBabel::OBGenericDataType::SetData
@ SetData
Set Data (a set of OBGenericData).
Definition base.h:135
OpenBabel::OBGenericDataType::UnitCell
@ UnitCell
Crystallographic unit cell data, i.e., OBUnitCell.
Definition base.h:103
OpenBabel::OBGenericDataType::SymmetryData
@ SymmetryData
Symmetry data – point and space groups, transforms, etc. i.e., OBSymmetryData.
Definition base.h:112
OpenBabel::OBGenericDataType::CustomData4
@ CustomData4
Definition base.h:162
OpenBabel::OBGenericDataType::CustomData12
@ CustomData12
Definition base.h:170
OpenBabel::OBGenericDataType::CustomData14
@ CustomData14
Definition base.h:172
OpenBabel::OBGenericDataType::StereoData
@ StereoData
Stereochemistry data (see OBStereoBase).
Definition base.h:147
OpenBabel::OBGenericDataType::CustomData7
@ CustomData7
Definition base.h:165
OpenBabel::OBGenericDataType::VectorData
@ VectorData
Vector Data (i.e., one vector like a dipole moment).
Definition base.h:141
OpenBabel::OBGenericDataType::SerialNums
@ SerialNums
Residue serial numbers.
Definition base.h:100
OpenBabel::OBGenericDataType::CustomData9
@ CustomData9
Definition base.h:167
OpenBabel::OBGenericDataType::CustomData6
@ CustomData6
Definition base.h:164
OpenBabel::OBGenericDataType::DensityData
@ DensityData
Density (cube) data and surfaces.
Definition base.h:120
OpenBabel::OBGenericDataType::RingData
@ RingData
Information on rings in a molecule, i.e., OBRingData.
Definition base.h:91
OpenBabel::OBGenericDataType::RotamerList
@ RotamerList
Information for generating & manipulating rotamers, i.e. OBRotamerList.
Definition base.h:85
OpenBabel::OBGenericDataType::VirtualBondData
@ VirtualBondData
Info. for storing bonds to atoms yet to be added, i.e. OBVirtualBond.
Definition base.h:88
OpenBabel::OBGenericDataType::CustomData1
@ CustomData1
Definition base.h:159
OpenBabel::OBGenericDataType::CustomData2
@ CustomData2
Definition base.h:160
OpenBabel::OBGenericDataType::CustomData15
@ CustomData15
Definition base.h:173
OpenBabel::OBGenericDataType::CustomData11
@ CustomData11
Definition base.h:169
OpenBabel::OBGenericDataType::MatrixData
@ MatrixData
Matrix data (i.e., a 3x3 matrix like a rotation or quadrupole moment).
Definition base.h:144
OpenBabel::OBGenericDataType::GridData
@ GridData
Grid Data (e.g., 3D grids of data a.k.a. cubes).
Definition base.h:138
OpenBabel::OBGenericDataType::ElectronicData
@ ElectronicData
Electronic levels, redox states, orbitals, etc.
Definition base.h:123
OpenBabel::OBGenericDataType::AngleData
@ AngleData
Bond angles in a molecule, i.e., OBAngle, OBAngleData.
Definition base.h:97
OpenBabel::OBGenericDataType::TorsionData
@ TorsionData
Information about torsion/dihedral angles, i.e., OBTorsionData and OBTorsion.
Definition base.h:94
OpenBabel::OBGenericDataType::ConformerData
@ ConformerData
Arbitrary information about conformers, i.e., OBConformerData.
Definition base.h:79
OpenBabel::OBGenericDataType::OccupationData
@ OccupationData
Atomic and molecular occupation data (e.g., for crystal structures).
Definition base.h:117
OpenBabel::OBGenericDataType::DOSData
@ DOSData
Density of States data (fermi energy and energy vs. density data).
Definition base.h:150
OpenBabel::OBGenericDataType::UndefinedData
@ UndefinedData
Unknown data type (default).
Definition base.h:67
OpenBabel::OBGenericDataType::CustomData8
@ CustomData8
Definition base.h:166
OpenBabel::OBGenericDataType::SpinData
@ SpinData
Spin data, including NMR, atomic and molecular spin, etc.
Definition base.h:106
OpenBabel::OBGenericDataType::VibrationData
@ VibrationData
Vibrational modes, frequencies, etc.
Definition base.h:126
OpenBabel::OBGenericDataType::RotationData
@ RotationData
Rotational energy information.
Definition base.h:129
OpenBabel::OBGenericDataType::ExternalBondData
@ ExternalBondData
Bond data external to OpenBabel, i.e., OBExternalBond, OBExternalBondData.
Definition base.h:82
OpenBabel::OBGenericDataType::CommentData
@ CommentData
Storing text comments (one per molecule, atom, bond, etc.) (for other data, e.g., author,...
Definition base.h:76
OpenBabel::OBGenericDataType::CustomData0
@ CustomData0
Custom (user-defined data).
Definition base.h:158
OpenBabel::OBGenericDataType::NuclearData
@ NuclearData
Nuclear transitions (e.g., decay, capture, fission, fusion).
Definition base.h:132
OpenBabel::OBGenericDataType::ChargeData
@ ChargeData
Arbitrary partial and total charges, dipole moments, etc.
Definition base.h:109
OpenBabel::OBGenericDataType::ElectronicTransitionData
@ ElectronicTransitionData
Electronic transition data (e.g., UV/Vis, excitation energies, etc.).
Definition base.h:153
OpenBabel::OBGenericDataType::EnergyData
@ EnergyData
Energetics data (e.g., total energy, heat of formation, etc.).
Definition base.h:73
OpenBabel::OBGenericDataType::CustomData5
@ CustomData5
Definition base.h:163
OpenBabel::OBGenericDataType::PairData
@ PairData
Arbitrary key/value data, i.e., OBPairData.
Definition base.h:70
OpenBabel::OBGenericDataType::CustomData13
@ CustomData13
Definition base.h:171
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::OBReleaseVersion
std::string OBReleaseVersion()
Definition base.cpp:31
OpenBabel::DataOrigin
DataOrigin
Definition base.h:176
OpenBabel::any
@ any
Undefined or unspecified (default).
Definition base.h:177
OpenBabel::local
@ local
Not for routine external use (e.g. in sdf or cml properties).
Definition base.h:182
OpenBabel::external
@ external
Added by an external program.
Definition base.h:181
OpenBabel::fileformatInput
@ fileformatInput
Read from an input file.
Definition base.h:178
OpenBabel::userInput
@ userInput
Added by the user.
Definition base.h:179
OpenBabel::perceived
@ perceived
Perceived by Open Babel library methods.
Definition base.h:180
OpenBabel::OBDataIterator
std::vector< OBGenericData * >::iterator OBDataIterator
A standard iterator over vectors of OBGenericData (e.g., inherited from OBBase).
Definition base.h:235
tokenst.h
Tokenize strings, open data files.