CIFCategory
#
- class biotite.structure.io.pdbx.CIFCategory(columns=None, name=None)[source]#
Bases:
_Component
,MutableMapping
This class represents a category in a
CIFBlock
.Columns can be accessed and modified like a dictionary. The values are
CIFColumn
objects.- Parameters:
- columnsdict, optional
The columns of the category. The keys are the column names and the values are the
CIFColumn
objects (or objects that can be coerced into aCIFColumn
). By default, an empty category is created. Each column must have the same length.- namestr, optional
The name of the category. This is only used for serialization and is automatically set, when the
CIFCategory
is added to aCIFBlock
. It only needs to be set manually, when the category is directly serialized.
- Attributes:
- namestr
The name of the category.
- row_countint
The number of rows in the category, i.e. the length of each column.
Notes
When a column containing strings with line breaks are added, these strings are written as multiline strings to the CIF file.
Examples
>>> # Add column on creation >>> category = CIFCategory({"fruit": ["apple", "banana"]}, name="fruits") >>> # Add column later on >>> category["taste"] = ["delicious", "tasty"] >>> # Add column the formal way >>> category["color"] = CIFColumn(CIFData(["red", "yellow"])) >>> # Access a column >>> print(category["fruit"].as_array()) ['apple' 'banana'] >>> print(category.serialize()) loop_ _fruits.fruit _fruits.taste _fruits.color apple delicious red banana tasty yellow
- static deserialize(text)#
Create this component by deserializing the given content.
- Parameters:
- contentstr or dict
The content to be deserialized. The type of this parameter depends on the file format. In case of CIF files, this is the text of the lines that represent this component. In case of BinaryCIF files, this is a dictionary parsed from the MessagePack data.
- serialize()#
Convert this component into a Python object that can be written to a file.
- Returns:
- contentstr or dict
The content to be serialized. The type of this return value depends on the file format. In case of CIF files, this is the text of the lines that represent this component. In case of BinaryCIF files, this is a dictionary that can be encoded into MessagePack.
- static subcomponent_class()#
Get the class of the components that are stored in this component.
- Returns:
- subcomponent_classtype
The class of the subcomponent. If this component already represents the lowest level, i.e. it does not contain subcomponents,
None
is returned.
- static supercomponent_class()#
Get the class of the component that contains this component.
- Returns:
- supercomponent_classtype
The class of the supercomponent. If this component present already the highest level, i.e. it is not contained in another component,
None
is returned.