4.3.4 SD Data Example

The next example will show how to use the tagged data methods.

#include "oechem.h"
#include <iostream>

using namespace OEChem;
using namespace OESystem;
using namespace std;

int main()
{
  OEMol mol;
  OEParseSmiles(mol, "c1ccccc1");
  mol.SetTitle("benzene");

  // set some sd data
  OESetSDData(mol, "color", "brown");
  OESetSDData(mol, OESDDataPair("size", "small"));

  // loop over data
  OEIter<OESDDataPair> dp;
  for (dp=OEGetSDDataPairs(mol);dp;++dp)
  {
    cout << dp->GetTag() << " : " << dp->GetValue() << endl;
  }

  if (OEHasSDData(mol, "color"))
    OEDeleteSDData(mol, "color");

  for (dp=OEGetSDDataPairs(mol);dp;++dp)
  {
    cout << dp->GetTag() << " : " << dp->GetValue() << endl;
  }

  return 0;
}

Note that SD tagged data is specific to MDL's SD file format. Any data added to a molecule will only be written out to SD files or OEBinary files. The SD data fields will only be filled when reading from SD files that contain SD tagged data or from OEBinary files previously created to contain this data.