You are reading the documentation for version 2.3 of OpenStructure. You may also want to read the documentation for:
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.7.1
1.8
1.9
1.10
1.11
2.0
2.1
2.2
2.3.1
2.4
devel
Storing Custom Data¶Introduction¶It is often very convenient to store any arbitrary data inside an Entity. A few examples are:
In OpenStructure this is supported by the use of generic properties. Most
building blocks are derived from
The view variants will reflect the generic properties of the handle variants. A generic property key is always a string, and a value can be one of string, float, int or bool. For each of these data types, methods to retrieve and store values are available both in Python and C++. Storing and Accessing Data¶All OpenStructure building blocks that are To store a float value with the key ‘myfloatprop’ in all atoms of an entity: import math
for atom in entity.GetAtomList():
val=5*math.sin(0.4*atom.GetPos().x)
atom.SetFloatProp("myfloatprop", val)
If a GenericProp at a given level (i.e. atom, bond, residue, chain or entity) already exists, it will be overwritten. To check if it exists, use: exists=atom.HasProp("myfloatprop")
print(exists)
To access the value of a generic property, we first check if the property exists and then access it, using the method suitable for the data type of the property. For the previously set property myfloatprop of the data type real, at the atom level: for atom in entity.GetAtomList():
if atom.HasProp("myfloatprop"):
print(atom.GetFloatProp("myfloatprop"))
When trying to access a property that has not been set, or one that has been set, but at a different level, an error is thrown. The same is true when trying to access a property of a different data type, e.g.: # all of the following lines will throw errors
# error because the property does not exist
print(atom.GetFloatProp("unknownprop"))
# error because the property was set at another level
print(entity.GetFloatProp("myfloatprop"))
# error because the data type of the property is different
print(atom.GetStringProp("myfloatprop"))
Use of Generic Properties in Queries¶The Queries can also be used for numeric generic properties (i.e. bool, int, float), but the syntax is slightly different. To access any generic properties, it needs to be specified that they are generic and at which level (chain, residue, atom) they are defined. Therefore, all generic properties start with a ‘g’, followed by an ‘a’, ‘r’ or ‘c’ for atom, residue or chain level respectively. For more details see Queries. API documentation¶
|
ContentsSearchEnter search terms or a module, class or function name. Previous topicNext topic
You are here
|