Loading...
Searching...
No Matches
OBGenericData Class Reference

`#include <openbabel/generic.h>`

Inheritance diagram for OBGenericData:
[legend]

## Public Member Functions

| OBGenericData (const std::string attr="undefined", const unsigned int type=OBGenericDataType::UndefinedData, const DataOrigin source=any)
virtual OBGenericData * | Clone (OBBase *) const
virtual | ~OBGenericData ()
void | SetAttribute (const std::string &v)
void | SetOrigin (const DataOrigin s)
virtual const std::string & | GetAttribute () const
unsigned int | GetDataType () const
virtual const std::string & | GetValue () const
virtual DataOrigin | GetOrigin () const

## Protected Attributes

std::string | _attr
unsigned int | _type
DataOrigin | _source

## Detailed Description

Base class for generic data.

OBGenericData is an abstract base class which defines an interface for storage, retrieval, and indexing of arbitrary generic data. Subclasses of OBGenericData can be used to store custom data on a per-atom, per-bond, per-molecule, or per-residue basis. Open Babel currently supports a small subset of chemical functionality as OBGenericData types, which will expand over time to support additional interconversion (e.g., spectroscopy, dynamics, surfaces...)

For more information on currently supported types, please see the developer wiki: http://openbabel.org/wiki/Generic_Data

For your own custom data, either define a custom subclass using an id from the OBGenericDataType::CustomData0 to OBGenericDataType::CustomData15 slots, or store your data as a string and use OBPairData for key/value access. The latter is highly recommended for various text descriptors e.g., in QSAR, atom or bond labels, or other textual data.

New in Open Babel, version 2.1 is the template-based OBPairTemplate, which can be used to store arbitrary data types. There are predefined types OBPairInteger and OBPairFloatingPoint for storing integers and floating-point values without converting to a string representation.

Also new is the "source" or "origin" of a data entry, enumerated by DataOrigin. This can be accessed by SetOrigin() and GetOrigin(), as well as via "filtering" methods in OBBase, allowing you to separate data read in from a file, added by a user, or assigned by Open Babel internally.

While the library and import routines will set DataOrigin correctly, you should try to annotate data added by your code. Typically this would either be userAdded or external. The former refers to something the user requested as an annotation, while the latter refers to annotations your code adds automatically.

Example code using OBGenericData:

if (mol.HasData(OBGenericDataType::UnitCell))
{
uc = (OBUnitCell*)mol.GetData(OBGenericDataType::UnitCell);
sprintf(buffer,
"%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f",
uc->GetA(), uc->GetB(), uc->GetC(),
uc->GetAlpha() , uc->GetBeta(), uc->GetGamma());
ofs << buffer << endl;
}
...
vector<OBGenericData*>::iterator k;
vector<OBGenericData*> vdata = mol.GetData();
for (k = vdata.begin();k != vdata.end();++k)
if ((*k)->GetDataType() == OBGenericDataType::PairData)
{
ofs << "> <" << (*k)->GetAttribute() << ">" << endl;
ofs << ((OBPairData*)(*k))->GetValue() << endl << endl;
}
OpenBabel::OBGenericData
Base class for generic data.
Definition base.h:189
OpenBabel::OBPairData
Used to store arbitrary text attribute/value relationships.
Definition generic.h:113
OpenBabel::OBUnitCell
Used for storing information about periodic boundary conditions with conversion to/from translation v...
Definition generic.h:298
OpenBabel::OBGenericDataType::UnitCell
@ UnitCell
Crystallographic unit cell data, i.e., OBUnitCell.
Definition base.h:103
OpenBabel::OBGenericDataType::PairData
@ PairData
Arbitrary key/value data, i.e., OBPairData.
Definition base.h:70

Similar code also works for OBGenericData stored in an OBAtom or OBBond or OBResidue. These examples show use of DataOrigin outside of the Open Babel library.

string atomLabel; // e.g., from the user adding annotation to an atom
if (!atom.HasData("UserLabel")) // stored textual data as an OBPairData
{
OBPairData *label = new OBPairData;
label->SetAttribute("UserLabel");
label->SetValue(atomLabel);
label->SetOrigin(userInput); // set by user, not by Open Babel
atom.SetData(label);
}
...
if (bond.HasData("DisplayType")) // e.g. in a visualization tool
{
OBPairData *display = dynamic_cast<OBPairData *> bond.GetData("DisplayType");
if (display->GetValue() == "wireframe")
{
... // display a wireframe view
}
}
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::SetAttribute
void SetAttribute(const std::string &v)
Set the attribute (key), which can be used to retrieve this data.
Definition base.h:216
OpenBabel::OBPairData::GetValue
virtual const std::string & GetValue() const
Base class returns a default value (the attribute type) but should never be called.
Definition generic.h:122
OpenBabel::OBPairData::SetValue
void SetValue(const char *v)
Definition generic.h:120
OpenBabel::userInput
@ userInput
Added by the user.
Definition base.h:179

When designing a class derived from OBGenericData you must add a Clone() function. For classes used with OBMol this is used when an OBMol object is copied. If your class member variables contain pointers to atoms or bonds then it will be necessary to ensure that these are updated in Clone() to refer to the new molecule. Without these and similar pointers it is more likely that the very simple clone function

virtual OBGenericData* Clone(OBBase* parent) const
{return new MyNewClass(*this);}
OpenBabel::OBBase
Base Class.
Definition base.h:240
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::Clone
virtual OBGenericData * Clone(OBBase *) const
Definition base.h:209

and the compiler generated copy constructor would be sufficient.

It is recommended that, if possible, OBGenericData classes do not store atom and bond pointers. Using atom and bond indices instead would allow the simple version of Clone() above. See OBRotameterData::Clone for an example of a more complicated version. For classes which are not intended to support copying, Clone() can return nullptr

virtual OBGenericData* Clone(OBBase* parent) const
{return nullptr;}

Clone() is a pure virtual function so that you need to decide what kind of function you need and include it explicitly.

## Constructor & Destructor Documentation

## OBGenericData()

OBGenericData | ( | const std::string | attr = "undefined",
|  | const unsigned int | type = OBGenericDataType::UndefinedData,
|  | const DataOrigin | source = any )

Referenced by OBSetData::AddData(), AliasData::AliasData(), AliasData::Clone(), OBAngleData::Clone(), OBCommentData::Clone(), OBConformerData::Clone(), OBDOSData::Clone(), OBElectronicTransitionData::Clone(), OBExternalBondData::Clone(), Clone(), OBMatrixData::Clone(), OBNasaThermoData::Clone(), OBOrbitalData::Clone(), OBPairData::Clone(), OBPairTemplate< int >::Clone(), OBRateData::Clone(), OBRingData::Clone(), OBRotamerList::Clone(), OBRotationData::Clone(), OBSerialNums::Clone(), OBSetData::Clone(), OBSymmetryData::Clone(), OBTorsionData::Clone(), OBUnitCell::Clone(), OBVectorData::Clone(), OBVibrationData::Clone(), OBVirtualBond::Clone(), OBSetData::DeleteData(), OBSetData::GetData(), OBSetData::GetData(), OBAngleData::OBAngleData(), OBAngleData::OBAngleData(), OBCommentData::OBCommentData(), OBCommentData::OBCommentData(), OBConformerData::OBConformerData(), OBConformerData::OBConformerData(), OBDOSData::OBDOSData(), OBElectronicTransitionData::OBElectronicTransitionData(), OBExternalBondData::OBExternalBondData(), OBGridData::OBGridData(), OBMatrixData::OBMatrixData(), OBOrbitalData::OBOrbitalData(), OBPairData::OBPairData(), OBPairTemplate< int >::OBPairTemplate(), OBRateData::OBRateData(), OBRingData::OBRingData(), OBRingData::OBRingData(), OBRotationData::OBRotationData(), OBSerialNums::OBSerialNums(), OBSerialNums::OBSerialNums(), OBSetData::OBSetData(), OBStereoBase::OBStereoBase(), OBSymmetryData::OBSymmetryData(), OBSymmetryData::OBSymmetryData(), OBTorsionData::OBTorsionData(), OBTorsionData::OBTorsionData(), OBUnitCell::OBUnitCell(), OBUnitCell::OBUnitCell(), OBVectorData::OBVectorData(), OBVibrationData::OBVibrationData(), OBVirtualBond::OBVirtualBond(), and OBVirtualBond::OBVirtualBond().

## ~OBGenericData()

virtual ~OBGenericData | ( |  | ) |

inline virtual

## Member Function Documentation

## Clone()

virtual OBGenericData * Clone | ( | OBBase * |  | ) | const

inline virtual

Reimplemented in AliasData, OBAngleData, OBCisTransStereo, OBCommentData, OBConformerData, OBDOSData, OBElectronicTransitionData, OBExternalBondData, OBMatrixData, OBNasaThermoData, OBOrbitalData, OBPairData, OBPairTemplate< ValueT >, OBPairTemplate< bool >, OBPairTemplate< double >, OBPairTemplate< int >, OBRateData, OBRingData, OBRotamerList, OBRotationData, OBSerialNums, OBSetData, OBSquarePlanarStereo, OBSymmetryData, OBTetrahedralStereo, OBTorsionData, OBUnitCell, OBVectorData, OBVibrationData, and OBVirtualBond.

Referenced by OBBase::CloneData(), OBAtom::Duplicate(), OBMoleculeFormat::MakeCombinedMolecule(), and OBMol::operator=().

## SetAttribute()

void SetAttribute | ( | const std::string & | v | ) |

inline

Set the attribute (key), which can be used to retrieve this data.

Referenced by OBGastChrg::AssignPartialCharges(), OBMol::DoTransformations(), AliasData::Expand(), OBMol::FindLSSR(), OBMol::FindSSSR(), OBForceField::GetAtomTypes(), OBMol::GetFormula(), OBMol::GetLSSR(), OBForceField::GetPartialCharges(), OBMol::GetSSSR(), OBDescriptor::PredictAndSave(), and OBMol::SetFormula().

## SetOrigin()

void SetOrigin | ( | const DataOrigin | s | ) |

inline

Set the origin of this data, which can be used to filter the data.

Referenced by OBGastChrg::AssignPartialCharges(), OBMol::DoTransformations(), OBMol::FindAngles(), OBMol::FindLSSR(), OBMol::FindSSSR(), OBMol::FindTorsions(), OBMol::GetFormula(), OBMol::GetLSSR(), OBMol::GetSSSR(), OBDescriptor::PredictAndSave(), and OBMol::SetFormula().

## GetAttribute()

virtual const std::string & GetAttribute | ( |  | ) | const

inline virtual

Returns
  The attribute (key), which can be used to retrieve this data

Referenced by OBMoleculeFormat::MakeCombinedMolecule().

## GetDataType()

unsigned int GetDataType | ( |  | ) | const

inline

Returns
  the data type for this object as defined in OBGenericDataType

## GetValue()

virtual const std::string & GetValue | ( |  | ) | const

inline virtual

Base class returns a default value (the attribute type) but should never be called.

Reimplemented in OBCommentData, and OBPairData.

Referenced by OBDepict::DrawMolecule(), OBDescriptor::FilterCompare(), and OBDescriptor::GetValues().

## GetOrigin()

virtual DataOrigin GetOrigin | ( |  | ) | const

inline virtual

## Member Data Documentation

## _attr

std::string _attr

protected

attribute tag (e.g., "UnitCell", "Comment" or "Author")

Referenced by OBRotamerList::Clone(), GetAttribute(), GetValue(), OBGenericData(), OBNasaThermoData::OBNasaThermoData(), OBRotamerList::OBRotamerList(), OBSymmetryData::OBSymmetryData(), and SetAttribute().

## _type

unsigned int _type

protected

attribute type – declared for each subclass

Referenced by OBRotamerList::Clone(), GetDataType(), OBGenericData(), OBNasaThermoData::OBNasaThermoData(), OBRotamerList::OBRotamerList(), and OBSymmetryData::OBSymmetryData().

## _source

DataOrigin _source

protected

source of data for accounting

Referenced by GetOrigin(), OBGenericData(), OBSymmetryData::OBSymmetryData(), OBAngleData::operator=(), OBConformerData::operator=(), OBSymmetryData::operator=(), OBTorsionData::operator=(), and SetOrigin().

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

- base.h
- generic.cpp