Most objects created in OEChem are able to store relatively arbitrary data or generic data. This allows for easy tagging of atoms, bonds and molecules for processing and annotation. In fact, molecules can also store other molecules as generic data as well as other high level OEChem objects such as OESurfaces, OEScalarGrids and OESkewGrids.
The basic interface for generic data is through the GetData and SetData methods of molecules, atoms and bonds. For example:
from openeye.oechem import *
target = OEGraphMol()
query = OEGraphMol()
# do something with target and query
target.SetData('original query', query)
# and later on...
query = target.GetData('original query')
Generic data is also saved when molecules are written out as OEB files as described in Chapter 4.3. This makes it particularly useful for purposes of annotation.
By default, SetData converts the given data into the closest
data type possible:
| Example | Python Data Type | C++ Data Type |
| 1 | Integer | int |
| 1.0 | Number | double |
| 'foo' | String | std::string |
| True | Boolean | bool |
| (1,2,3) | Tuple of Integers | int * |
| (1.0,2.0,3.0) | Tuple of Numbers | double * |
| (False, True) | Tuple of Booleans | bool * |
| [1,2,3] | List of Integers | std::vector<int> |
| [1.0,2.0,3.0] | List of Numbers | std::vector<double> |
| [False, True] | List of Booleans | std::vector<bool> |
Conversely, GetData automatically converts any C++ data type into the closest Python data type.
Sometimes more control is required when setting internal datatypes, SetData optionally takes a third argument specifying the desired stored data type. This is useful when converting C++ examples to python or making sure that the stored data is of a particular type. Similar to the automatic SetData conversion, python tuples are converted to arrays and python lists are convered to std::vectors. Note that not all types are aupported in arrays or vectors.
| type code | meaning | Note |
| 'c' | char | (vector only) |
| 'b' | signed char | (vector only) |
| 'B' | unsigned char | (vector only) |
| 'h' | signed short | (vector only) |
| 'H' | unsigned short | (vector only) |
| 'i' | signed int | |
| 'I' | unsigned int | (vector only) |
| 'f' | float | |
| 'd' | double | |
| 's' | string | (no vector or array) |
| '?' | boolean |
Example usage:
m.SetData('foo', (1,2,3,4,5), 'h') # saves an array of shorts
m.SetData('bar', [1,2,3,4,5], 'h') # saves a std::vector of shorts
Note: Setting two different data types to the same name will cause an internal warning to be sent to the current error stream and the second call will not set the internal data. Unfortunately, no exception is raised.