compress
#
- biotite.structure.io.pdbx.compress(data, float_tolerance=1e-06)[source]#
Try to reduce the size of a BinaryCIF file (or block, category, etc.) by testing different data encodings for each data array and selecting the one, which results in the smallest size.
- Parameters:
- dataBinaryCIFFile or BinaryCIFBlock or BinaryCIFCategory or BinaryCIFColumn or BinaryCIFData
The data to compress.
- Returns:
- compressed_fileBinaryCIFFile or BinaryCIFBlock or BinaryCIFCategory or BinaryCIFColumn or BinaryCIFData
The compressed data with the same type as the input data. If no improved compression is found for a
BinaryCIFData
array, the input data is kept. Hence, the return value is no deep copy of the input data.- float_tolerancefloat, optional
The relative error that is accepted when compressing floating point numbers.
Examples
>>> from io import BytesIO >>> pdbx_file = BinaryCIFFile() >>> set_structure(pdbx_file, atom_array_stack) >>> # Write uncompressed file >>> uncompressed_file = BytesIO() >>> pdbx_file.write(uncompressed_file) >>> _ = uncompressed_file.seek(0) >>> print(f"{len(uncompressed_file.read()) // 1000} KB") 927 KB >>> # Write compressed file >>> pdbx_file = compress(pdbx_file) >>> compressed_file = BytesIO() >>> pdbx_file.write(compressed_file) >>> _ = compressed_file.seek(0) >>> print(f"{len(compressed_file.read()) // 1000} KB") 111 KB