#include <generic.h>
Inheritance diagram for OBGenericData:
Public Member Functions | |
OBGenericData () | |
OBGenericData (const OBGenericData &) | |
virtual | ~OBGenericData () |
OBGenericData & | operator= (const OBGenericData &src) |
void | SetAttribute (const std::string &v) |
virtual const std::string & | GetAttribute () const |
unsigned int | GetDataType () const |
Protected Attributes | |
std::string | _attr |
attribute tag (e.g., "UnitCell", "Comment" or "Author") | |
unsigned int | _type |
attribute type -- declared for each subclass |
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 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.
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; }
Similar code also works for OBGenericData stored in an OBAtom or OBBond (or OBResidue).
if (!atom.HasData("UserLabel")) // stored textual data as an OBPairData { OBPairData *label = new OBPairData; label->SetAttribute("UserLabel"); label->SetValue(userInput); 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 } }
OBGenericData | ( | ) |
OBGenericData | ( | const OBGenericData & | ) |
virtual ~OBGenericData | ( | ) | [inline, virtual] |
OBGenericData & operator= | ( | const OBGenericData & | src | ) |
void SetAttribute | ( | const std::string & | v | ) | [inline] |
virtual const std::string& GetAttribute | ( | ) | const [inline, virtual] |
unsigned int GetDataType | ( | ) | const [inline] |
std::string _attr [protected] |
attribute tag (e.g., "UnitCell", "Comment" or "Author")
unsigned int _type [protected] |
attribute type -- declared for each subclass