compress
#
- biotite.structure.io.pdbx.compress(data, float_tolerance=None, rtol=1e-06, atol=0.0001)[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.
- float_tolerancefloat, optional
The relative error that is accepted when compressing floating point numbers. DEPRECATED: Use rtol instead.
- rtol, atolfloat, optional
The compression factor of floating point numbers is chosen such that either the relative (rtol) or absolute (atol) tolerance is fulfilled for each value, i.e. the difference between the compressed and uncompressed value is smaller than the tolerance.
- 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.
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") 937 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") 114 KB