Meta information about a molecule is stored in what is known as
``tagged data.'' The most common example of this is the data fields
found in SD files. Since SD files are a common form of data
storage and transfer from one system to another, OEChem provides
several methods to manipulate this data. A simple class,
OESDDataPair is used to set or retrieve
these pairs. OESDDataPair objects provide
SetTag /GetTag and
SetValue /GetValue methods for access to each half of the pair.
The following functions provide access to the SD data.
Use the OESetSDData method to set a tag and
value data pair. Both the tag and the value must be strings. If an
item with the same tag already exists, it is replaced. The second form
is the same as the first but uses an
OESDDataPair instance.
bool OESetSDData(OEMolBase &mol, const std::string tag, const std::string value) bool OESetSDData(OEMolBase &mol, const OESDDataPair &dp)
Use the OEAddSDData method to add a tag and
value data pair. Both the tag and the value must be strings. If an
item with the same tag already exists, another one is added. The
second form is the same as the first but uses an
OESDDataPair instance.
bool OEAddSDData(OEMolBase &mol, const std::string tag, const std::string value) bool OEAddSDData(OEMolBase &mol, const OESDDataPair &dp)
Use the OEHasSDData method to determine if a
molecule has an item with a given tag:
bool OEHasSDData(const OEMolBase &mol, const std::string tag)
Use the OEGetSDData method to get the value
for the given tag. If the molecule does not have that tag, an empty
string is returned.
std::string OEGetSDData(const OEMolBase &mol, const std::string tag)
An OESDDataIter (iterator of
SDDataPairs ) can be used in a loop as shown
in the following example.
OESystem::OEIterBase<OESDDataPair> *OEGetSDDataPairs(OEMolBase &mol)
Use OECopySDData to copy the entire set of
SD data from a source(src) molecule to a destination(dst) molecule.
boolean OECopySDData(OEMolBase &dst, OEMolBase &src)
Use OEDeleteSDData to delete a tagged
data item. All data items with the specified tag will be deleted.
bool OEDeleteSDData(OEMolBase &mol, const std::string tag)
Use OEClearSDData to clear all SD data
from a molecule.
bool OEClearSDData(OEMolBase &mol)
The following example shows how to use the tagged data methods.
1 #include "openeye.h"
2 #include "oechem.h"
3 #include <iostream>
4
5 using namespace OEChem;
6 using namespace OESystem;
7 using namespace std;
8
9 int main()
10 {
11 OEGraphMol mol;
12 OEParseSmiles(mol, "c1ccccc1");
13 mol.SetTitle("benzene");
14
15 // set some sd data
16 OESetSDData(mol, "color", "brown");
17 OESetSDData(mol, OESDDataPair("size", "small"));
18
19 // loop over data
20 OEIter<OESDDataPair> dp;
21 for (dp=OEGetSDDataPairs(mol);dp;++dp)
22 {
23 cout << dp->GetTag() << " : " << dp->GetValue() << endl;
24 }
25
26 if (OEHasSDData(mol, "color"))
27 OEDeleteSDData(mol, "color");
28
29 for (dp=OEGetSDDataPairs(mol);dp;++dp)
30 {
31 cout << dp->GetTag() << " : " << dp->GetValue() << endl;
32 }
33
34 return 0;
35 }
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.
The OESDDataPair class is also used to set
or retrieve PDB data pairs. In PDB files, this data is
stored in header lines where the first field is the tag and the
remainder of the line is the data. OESDDataPair objects
provide SetTag /GetTag and
SetValue /GetValue methods for access to each half of PDB pairs.
The following functions provide access to the PDB data.
Use OESetPDBData to set a tag and value
data pair. Both tag and value must be strings. If an item with the
same tag already exists, it is replaced. The second form is the same
as the first but uses an OESDDataPair instance.
bool OESetPDBData(OEMolBase &mol, const std::string tag, const std::string value) bool OESetPDBData(OEMolBase &mol, const OESDDataPair &dp)
Use OEAddPDBData to add a tag and value
data pair. Both tag and value must be strings. If an item with the
same tag already exists, another one is added. The second form is the
same as the first but uses an OESDDataPair instance.
Note that for PDB header items like REMARK, each line is treated as a
separate instance, so to add multiple REMARK lines be sure to use this
form instead of OESetPDBData.
bool OEAddPDBData(OEMolBase &mol, const std::string tag, const std::string value) bool OEAddPDBData(OEMolBase &mol, const OESDDataPair &dp)
To determine if a molecule has an item with tag:
bool OEHasPDBData(const OEMolBase &mol, const std::string tag)
Use OEGetPDBData to get the value for the
given tag. If the molecule does not have that tag, an empty string is
returned. Note that if there are multiple parts with the same tag,
this will only return the first instance. Using the iterator access
show below will allow retrieving multiple tags.
std::string OEGetPDBData(const OEMolBase &mol, const std::string tag)
To get access to all PDB data, an iterator of OEBPDBDataPair
can be used.
OESystem::OEIterBase<OEPDBDataPair> *OEGetPDBDataPairs(OEMolBase &mol)
To copy the entire set of PDB data from a source (src)
molecule to a destination (dst) molecule, use
OECopyPDBData .
boolean OECopyPDBData(OEMolBase &dst, OEMolBase &src)
Use OEDeletePDBData to delete a tagged
data item. All data items with the specified tag will be deleted.
bool OEDeletePDBData(OEMolBase &mol, const std::string tag)
To clear all PDB data from a molecule, use
OEClearPDBData .
bool OEClearPDBData(OEMolBase &mol)
The following example shows how to use the PDB tagged data methods.
1 #include "openeye.h"
2
3 #include <stdlib.h>
4 #include <iostream>
5
6 #include "oesystem.h"
7 #include "oechem.h"
8
9 using namespace OESystem;
10 using namespace OEChem;
11 using namespace std;
12
13 int main(int argc, char *argv[])
14 {
15 if (argc < 2)
16 {
17 printf("Usage: %s <pdbfile>\n",argv[0]);
18 return 1;
19 }
20
21 oemolistream ifs;
22 if (!ifs.open(argv[1]))
23 return 0;
24
25 // need to set input flavor to ensure PDB data is stored on molecule
26 ifs.SetFlavor(OEFormat::PDB,
27 OEIFlavor::Generic::Default |
28 OEIFlavor::PDB::Default |
29 OEIFlavor::PDB::DATA);
30
31 OEGraphMol mol;
32 while (OEReadMolecule(ifs, mol))
33 {
34 if (OEHasPDBData(mol, "COMPND"))
35 {
36 cout << "COMPND:" << endl;
37 cout << OEGetPDBData(mol, "COMPND") << endl;
38 }
39
40 if (OEHasPDBData(mol, "CRYST1"))
41 {
42 cout << "CRYST1:" << endl;
43 cout << OEGetPDBData(mol, "CRYST1") << endl;
44 }
45
46 if (OEHasPDBData(mol, "REMARK"))
47 {
48 cout << "REMARK:" << endl;
49 for (OEIter<OEPDBDataPair> iter=OEGetPDBDataPairs(mol);iter;++iter)
50 if (!strcmp(iter->GetTag(),"REMARK"))
51 cout << iter->GetValue() << endl;
52 }
53 }
54 return 0;
55 }
56
For using tag data with multi-conformer molecules, see Section 5.6.