biotite.structure.io.pdbx.BinaryCIFData

class biotite.structure.io.pdbx.BinaryCIFData(array, encoding=None)[source]

Bases: _Component

This class represents the data in a BinaryCIFColumn.

Parameters
arrayarray_like or int or float or str

The data array to be stored. If a single item is given, it is converted into an array.

encodinglist of Encoding

The encoding steps that are successively applied to the data.

Examples

>>> data = BinaryCIFData([1, 2, 3])
>>> print(data.array)
[1 2 3]
>>> print(len(data))
3
>>> # A single item is converted into an array
>>> data = BinaryCIFData("apple")
>>> print(data.array)
['apple']

Well-chosen encoding can significantly reduce the serialized data size:

>>> # Default uncompressed encoding
>>> array = np.arange(100)
>>> uncompressed_bytes = BinaryCIFData(array).serialize()["data"]
>>> print(len(uncompressed_bytes))
400
>>> # Delta encoding followed by run-length encoding
>>> # [0, 1, 2, ...] -> [0, 1, 1, ...] -> [0, 1, 1, 99]
>>> compressed_bytes = BinaryCIFData(
...     array,
...     encoding = [
...         # [0, 1, 2, ...] -> [0, 1, 1, ...]
...         DeltaEncoding(),
...         # [0, 1, 1, ...] -> [0, 1, 1, 99]
...         RunLengthEncoding(),
...         # [0, 1, 1, 99] -> b"\x00\x00..."
...         ByteArrayEncoding()
...     ]
... ).serialize()["data"]
>>> print(len(compressed_bytes))
16
Attributes
arrayndarray

The stored data array.

encodinglist of Encoding

The encoding steps.

static deserialize(content)

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.